@@ -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
@@ -758,13 +764,17 @@ impl<'a> Parser<'a> {
758764 }
759765 }
760766
767+ /// Checks if the next token is contained within `kets`, and returns `true` if so.
761768 fn expect_any_with_type ( & mut self , kets : & [ & TokenKind ] , expect : TokenExpectType ) -> bool {
762769 kets. iter ( ) . any ( |k| match expect {
763770 TokenExpectType :: Expect => self . check ( k) ,
764- TokenExpectType :: NoExpect => self . token == * * k ,
771+ TokenExpectType :: NoExpect => self . check_noexpect ( k ) ,
765772 } )
766773 }
767774
775+ /// Parses a sequence until the specified delimiters. The function
776+ /// `f` must consume tokens until reaching the next separator or
777+ /// closing bracket.
768778 fn parse_seq_to_before_tokens < T > (
769779 & mut self ,
770780 kets : & [ & TokenKind ] ,
@@ -783,13 +793,15 @@ impl<'a> Parser<'a> {
783793 }
784794 if let Some ( t) = & sep. sep {
785795 if first {
796+ // no separator for the first element
786797 first = false ;
787798 } else {
799+ // check for separator
788800 match self . expect ( t) {
789- Ok ( false ) => {
801+ Ok ( false ) /* not recovered */ => {
790802 self . current_closure . take ( ) ;
791803 }
792- Ok ( true ) => {
804+ Ok ( true ) /* recovered */ => {
793805 self . current_closure . take ( ) ;
794806 recovered = true ;
795807 break ;
@@ -957,19 +969,19 @@ impl<'a> Parser<'a> {
957969 Ok ( ( ) )
958970 }
959971
960- /// Parses a sequence, not including the closing delimiter . The function
972+ /// Parses a sequence, not including the delimiters . The function
961973 /// `f` must consume tokens until reaching the next separator or
962974 /// closing bracket.
963975 fn parse_seq_to_before_end < T > (
964976 & mut self ,
965977 ket : & TokenKind ,
966978 sep : SeqSep ,
967979 f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
968- ) -> PResult < ' a , ( ThinVec < T > , bool , bool ) > {
980+ ) -> PResult < ' a , ( ThinVec < T > , bool /* trailing */ , bool /* recovered */ ) > {
969981 self . parse_seq_to_before_tokens ( & [ ket] , sep, TokenExpectType :: Expect , f)
970982 }
971983
972- /// Parses a sequence, including the closing delimiter. The function
984+ /// Parses a sequence, including only the closing delimiter. The function
973985 /// `f` must consume tokens until reaching the next separator or
974986 /// closing bracket.
975987 fn parse_seq_to_end < T > (
@@ -985,7 +997,7 @@ impl<'a> Parser<'a> {
985997 Ok ( ( val, trailing) )
986998 }
987999
988- /// Parses a sequence, including the closing delimiter . The function
1000+ /// Parses a sequence, including both delimiters . The function
9891001 /// `f` must consume tokens until reaching the next separator or
9901002 /// closing bracket.
9911003 fn parse_unspanned_seq < T > (
@@ -994,16 +1006,19 @@ impl<'a> Parser<'a> {
9941006 ket : & TokenKind ,
9951007 sep : SeqSep ,
9961008 f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
997- ) -> PResult < ' a , ( ThinVec < T > , bool ) > {
1009+ ) -> PResult < ' a , ( ThinVec < T > , bool /* trailing */ ) > {
9981010 self . expect ( bra) ?;
9991011 self . parse_seq_to_end ( ket, sep, f)
10001012 }
10011013
1014+ /// Parses a comma-separated sequence, including both delimiters.
1015+ /// The function `f` must consume tokens until reaching the next separator or
1016+ /// closing bracket.
10021017 fn parse_delim_comma_seq < T > (
10031018 & mut self ,
10041019 delim : Delimiter ,
10051020 f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
1006- ) -> PResult < ' a , ( ThinVec < T > , bool ) > {
1021+ ) -> PResult < ' a , ( ThinVec < T > , bool /* trailing */ ) > {
10071022 self . parse_unspanned_seq (
10081023 & token:: OpenDelim ( delim) ,
10091024 & token:: CloseDelim ( delim) ,
@@ -1012,10 +1027,13 @@ impl<'a> Parser<'a> {
10121027 )
10131028 }
10141029
1030+ /// Parses a comma-separated sequence delimited by parentheses (e.g. `(x, y)`).
1031+ /// The function `f` must consume tokens until reaching the next separator or
1032+ /// closing bracket.
10151033 fn parse_paren_comma_seq < T > (
10161034 & mut self ,
10171035 f : impl FnMut ( & mut Parser < ' a > ) -> PResult < ' a , T > ,
1018- ) -> PResult < ' a , ( ThinVec < T > , bool ) > {
1036+ ) -> PResult < ' a , ( ThinVec < T > , bool /* trailing */ ) > {
10191037 self . parse_delim_comma_seq ( Delimiter :: Parenthesis , f)
10201038 }
10211039
0 commit comments