@@ -335,18 +335,6 @@ impl TokenType {
335
335
}
336
336
}
337
337
338
- /// Used by [`Parser::expect_any_with_type`].
339
- #[ derive( Copy , Clone , Debug ) ]
340
- enum TokenExpectType {
341
- /// Unencountered tokens are inserted into [`Parser::expected_tokens`].
342
- /// See [`Parser::check`].
343
- Expect ,
344
-
345
- /// Unencountered tokens are not inserted into [`Parser::expected_tokens`].
346
- /// See [`Parser::check_noexpect`].
347
- NoExpect ,
348
- }
349
-
350
338
/// A sequence separator.
351
339
#[ derive( Debug ) ]
352
340
struct SeqSep {
@@ -807,29 +795,31 @@ impl<'a> Parser<'a> {
807
795
}
808
796
809
797
/// Checks if the next token is contained within `kets`, and returns `true` if so.
810
- fn expect_any_with_type ( & mut self , kets : & [ & TokenKind ] , expect : TokenExpectType ) -> bool {
811
- kets. iter ( ) . any ( |k| match expect {
812
- TokenExpectType :: Expect => self . check ( k) ,
813
- TokenExpectType :: NoExpect => self . check_noexpect ( k) ,
814
- } )
798
+ fn expect_any_with_type (
799
+ & mut self ,
800
+ kets_expected : & [ & TokenKind ] ,
801
+ kets_not_expected : & [ & TokenKind ] ,
802
+ ) -> bool {
803
+ kets_expected. iter ( ) . any ( |k| self . check ( k) )
804
+ || kets_not_expected. iter ( ) . any ( |k| self . check_noexpect ( k) )
815
805
}
816
806
817
807
/// Parses a sequence until the specified delimiters. The function
818
808
/// `f` must consume tokens until reaching the next separator or
819
809
/// closing bracket.
820
810
fn parse_seq_to_before_tokens < T > (
821
811
& mut self ,
822
- kets : & [ & TokenKind ] ,
812
+ kets_expected : & [ & TokenKind ] ,
813
+ kets_not_expected : & [ & TokenKind ] ,
823
814
sep : SeqSep ,
824
- expect : TokenExpectType ,
825
815
mut f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
826
816
) -> PResult < ' a , ( ThinVec < T > , Trailing , Recovered ) > {
827
817
let mut first = true ;
828
818
let mut recovered = Recovered :: No ;
829
819
let mut trailing = Trailing :: No ;
830
820
let mut v = ThinVec :: new ( ) ;
831
821
832
- while !self . expect_any_with_type ( kets , expect ) {
822
+ while !self . expect_any_with_type ( kets_expected , kets_not_expected ) {
833
823
if let token:: CloseDelim ( ..) | token:: Eof = self . token . kind {
834
824
break ;
835
825
}
@@ -927,7 +917,8 @@ impl<'a> Parser<'a> {
927
917
if self . token == token:: Colon {
928
918
// we will try to recover in `maybe_recover_struct_lit_bad_delims`
929
919
return Err ( expect_err) ;
930
- } else if let [ token:: CloseDelim ( Delimiter :: Parenthesis ) ] = kets
920
+ } else if let [ token:: CloseDelim ( Delimiter :: Parenthesis ) ] =
921
+ kets_expected
931
922
{
932
923
return Err ( expect_err) ;
933
924
} else {
@@ -940,7 +931,9 @@ impl<'a> Parser<'a> {
940
931
}
941
932
}
942
933
}
943
- if sep. trailing_sep_allowed && self . expect_any_with_type ( kets, expect) {
934
+ if sep. trailing_sep_allowed
935
+ && self . expect_any_with_type ( kets_expected, kets_not_expected)
936
+ {
944
937
trailing = Trailing :: Yes ;
945
938
break ;
946
939
}
@@ -1020,7 +1013,7 @@ impl<'a> Parser<'a> {
1020
1013
sep : SeqSep ,
1021
1014
f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
1022
1015
) -> PResult < ' a , ( ThinVec < T > , Trailing , Recovered ) > {
1023
- self . parse_seq_to_before_tokens ( & [ ket] , sep , TokenExpectType :: Expect , f)
1016
+ self . parse_seq_to_before_tokens ( & [ ket] , & [ ] , sep , f)
1024
1017
}
1025
1018
1026
1019
/// Parses a sequence, including only the closing delimiter. The function
0 commit comments