Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillig committed Mar 13, 2024
1 parent 1fff186 commit d110e74
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
19 changes: 14 additions & 5 deletions crates/parser2/src/parser/expr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::convert::Infallible;
use std::convert::{identity, Infallible};
use unwrap_infallible::UnwrapInfallible;

use super::{
Expand Down Expand Up @@ -487,13 +487,18 @@ fn is_call_expr<S: TokenStream>(parser: &mut Parser<S>) -> bool {

let mut is_call = true;
if parser.current_kind() == Some(SyntaxKind::Lt) {
is_call &= parser.parses_without_error(GenericArgListScope::default())
is_call &= parser
.parse_ok(GenericArgListScope::default())
.is_ok_and(identity)
}

if parser.current_kind() != Some(SyntaxKind::LParen) {
false
} else {
is_call && parser.parses_without_error(CallArgListScope::default())
is_call
&& parser
.parse_ok(CallArgListScope::default())
.is_ok_and(identity)
}
})
}
Expand All @@ -510,7 +515,9 @@ fn is_method_call<S: TokenStream>(parser: &mut Parser<S>) -> bool {
}

if parser.current_kind() == Some(SyntaxKind::Lt)
&& !parser.parses_without_error(GenericArgListScope::default())
&& !parser
.parse_ok(GenericArgListScope::default())
.is_ok_and(identity)
{
return false;
}
Expand All @@ -519,7 +526,9 @@ fn is_method_call<S: TokenStream>(parser: &mut Parser<S>) -> bool {
false
} else {
parser.set_newline_as_trivia(is_trivia);
parser.parses_without_error(CallArgListScope::default())
parser
.parse_ok(CallArgListScope::default())
.is_ok_and(identity)
}
});
parser.set_newline_as_trivia(is_trivia);
Expand Down
14 changes: 0 additions & 14 deletions crates/parser2/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ impl<S: TokenStream> Parser<S> {
self.parse_ok(scope).map(|_| ())
}

// xxx needed?
pub fn parse_ok<T, E>(&mut self, mut scope: T) -> Result<bool, E>
where
T: Parse<Error = E> + 'static,
Expand All @@ -234,19 +233,6 @@ impl<S: TokenStream> Parser<S> {
res.map(|_| ok)
}

// xxx do we ever want to use this?
pub fn parses_without_error<T, E>(&mut self, mut scope: T) -> bool
where
T: Parse<Error = E> + 'static,
E: Recoverable,
{
debug_assert!(self.is_dry_run());
let checkpoint = self.enter(scope.clone(), None);
let r = scope.parse(self);
let is_err = self.leave(checkpoint);
r.is_ok() && !is_err
}

// xxx remove?
pub fn parse_or_recover<T>(&mut self, mut scope: T) -> Result<(), Recovery<ErrProof>>
where
Expand Down
6 changes: 4 additions & 2 deletions crates/parser2/src/parser/use_tree.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cell::Cell, rc::Rc};
use std::{cell::Cell, convert::identity, rc::Rc};

use crate::{parser::path::is_path_segment, ParseError, SyntaxKind, TextRange};

Expand Down Expand Up @@ -79,7 +79,9 @@ impl super::Parse for UsePathScope {
loop {
let is_path_segment = parser.dry_run(|parser| {
parser.bump_if(SyntaxKind::Colon2)
&& parser.parses_without_error(UsePathSegmentScope::default())
&& parser
.parse_ok(UsePathSegmentScope::default())
.is_ok_and(identity)
});
if is_path_segment {
if self.is_glob.get() {
Expand Down

0 comments on commit d110e74

Please sign in to comment.