@@ -320,9 +320,15 @@ impl TokenType {
320320 }
321321}
322322
323+ /// Used by [`Parser::expect_any_with_type`].
323324#[ derive( Copy , Clone , Debug ) ]
324325enum TokenExpectType {
326+ /// Unencountered tokens are inserted into [`Parser::expected_tokens`].
327+ /// See [`Parser::check`].
325328 Expect ,
329+
330+ /// Unencountered tokens are not inserted into [`Parser::expected_tokens`].
331+ /// See [`Parser::check_noexpect`].
326332 NoExpect ,
327333}
328334
@@ -766,13 +772,17 @@ impl<'a> Parser<'a> {
766772 }
767773 }
768774
775+ /// Checks if the next token is contained within `kets`, and returns `true` if so.
769776 fn expect_any_with_type ( & mut self , kets : & [ & TokenKind ] , expect : TokenExpectType ) -> bool {
770777 kets. iter ( ) . any ( |k| match expect {
771778 TokenExpectType :: Expect => self . check ( k) ,
772- TokenExpectType :: NoExpect => self . token == * * k ,
779+ TokenExpectType :: NoExpect => self . check_noexpect ( k ) ,
773780 } )
774781 }
775782
783+ /// Parses a sequence until the specified delimiters. The function
784+ /// `f` must consume tokens until reaching the next separator or
785+ /// closing bracket.
776786 fn parse_seq_to_before_tokens < T > (
777787 & mut self ,
778788 kets : & [ & TokenKind ] ,
@@ -791,13 +801,15 @@ impl<'a> Parser<'a> {
791801 }
792802 if let Some ( t) = & sep. sep {
793803 if first {
804+ // no separator for the first element
794805 first = false ;
795806 } else {
807+ // check for separator
796808 match self . expect ( t) {
797- Ok ( false ) => {
809+ Ok ( false ) /* not recovered */ => {
798810 self . current_closure . take ( ) ;
799811 }
800- Ok ( true ) => {
812+ Ok ( true ) /* recovered */ => {
801813 self . current_closure . take ( ) ;
802814 recovered = true ;
803815 break ;
@@ -965,19 +977,19 @@ impl<'a> Parser<'a> {
965977 Ok ( ( ) )
966978 }
967979
968- /// Parses a sequence, not including the closing delimiter . The function
980+ /// Parses a sequence, not including the delimiters . The function
969981 /// `f` must consume tokens until reaching the next separator or
970982 /// closing bracket.
971983 fn parse_seq_to_before_end < T > (
972984 & mut self ,
973985 ket : & TokenKind ,
974986 sep : SeqSep ,
975987 f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
976- ) -> PResult < ' a , ( ThinVec < T > , bool , bool ) > {
988+ ) -> PResult < ' a , ( ThinVec < T > , bool /* trailing */ , bool /* recovered */ ) > {
977989 self . parse_seq_to_before_tokens ( & [ ket] , sep, TokenExpectType :: Expect , f)
978990 }
979991
980- /// Parses a sequence, including the closing delimiter. The function
992+ /// Parses a sequence, including only the closing delimiter. The function
981993 /// `f` must consume tokens until reaching the next separator or
982994 /// closing bracket.
983995 fn parse_seq_to_end < T > (
@@ -993,7 +1005,7 @@ impl<'a> Parser<'a> {
9931005 Ok ( ( val, trailing) )
9941006 }
9951007
996- /// Parses a sequence, including the closing delimiter . The function
1008+ /// Parses a sequence, including both delimiters . The function
9971009 /// `f` must consume tokens until reaching the next separator or
9981010 /// closing bracket.
9991011 fn parse_unspanned_seq < T > (
@@ -1002,16 +1014,19 @@ impl<'a> Parser<'a> {
10021014 ket : & TokenKind ,
10031015 sep : SeqSep ,
10041016 f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
1005- ) -> PResult < ' a , ( ThinVec < T > , bool ) > {
1017+ ) -> PResult < ' a , ( ThinVec < T > , bool /* trailing */ ) > {
10061018 self . expect ( bra) ?;
10071019 self . parse_seq_to_end ( ket, sep, f)
10081020 }
10091021
1022+ /// Parses a comma-separated sequence, including both delimiters.
1023+ /// The function `f` must consume tokens until reaching the next separator or
1024+ /// closing bracket.
10101025 fn parse_delim_comma_seq < T > (
10111026 & mut self ,
10121027 delim : Delimiter ,
10131028 f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
1014- ) -> PResult < ' a , ( ThinVec < T > , bool ) > {
1029+ ) -> PResult < ' a , ( ThinVec < T > , bool /* trailing */ ) > {
10151030 self . parse_unspanned_seq (
10161031 & token:: OpenDelim ( delim) ,
10171032 & token:: CloseDelim ( delim) ,
@@ -1020,10 +1035,13 @@ impl<'a> Parser<'a> {
10201035 )
10211036 }
10221037
1038+ /// Parses a comma-separated sequence delimited by parentheses (e.g. `(x, y)`).
1039+ /// The function `f` must consume tokens until reaching the next separator or
1040+ /// closing bracket.
10231041 fn parse_paren_comma_seq < T > (
10241042 & mut self ,
10251043 f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
1026- ) -> PResult < ' a , ( ThinVec < T > , bool ) > {
1044+ ) -> PResult < ' a , ( ThinVec < T > , bool /* trailing */ ) > {
10271045 self . parse_delim_comma_seq ( Delimiter :: Parenthesis , f)
10281046 }
10291047
0 commit comments