@@ -118,29 +118,36 @@ impl<'a> StringReader<'a> {
118
118
}
119
119
}
120
120
121
- /// Returns the next token. EFFECT: advances the string_reader.
121
+ /// Returns the next token, including trivia like whitespace or comments.
122
+ ///
123
+ /// `Err(())` means that some errors were encountered, which can be
124
+ /// retrieved using `buffer_fatal_errors`.
122
125
pub fn try_next_token ( & mut self ) -> Result < Token , ( ) > {
123
126
let ( token, _raw_span) = self . try_next_token_with_raw_span ( ) ?;
124
127
Ok ( token)
125
128
}
126
129
130
+ /// Returns the next token, including trivia like whitespace or comments.
131
+ ///
132
+ /// Aborts in case of an error.
127
133
pub fn next_token ( & mut self ) -> Token {
128
134
let res = self . try_next_token ( ) ;
129
135
self . unwrap_or_abort ( res)
130
136
}
131
137
132
- fn try_real_token ( & mut self ) -> Result < ( Token , Span ) , ( ) > {
133
- loop {
134
- let t = self . try_next_token_with_raw_span ( ) ?;
135
- match t. 0 . kind {
136
- token:: Whitespace | token:: Comment | token:: Shebang ( _) => continue ,
137
- _ => return Ok ( t) ,
138
+ /// Returns the next token, skipping over trivia.
139
+ /// Also returns an unoverriden span which can be used to check tokens
140
+ fn real_token ( & mut self ) -> ( Token , Span ) {
141
+ let res = try {
142
+ loop {
143
+ let t = self . try_next_token_with_raw_span ( ) ?;
144
+ match t. 0 . kind {
145
+ token:: Whitespace | token:: Comment | token:: Shebang ( _) => continue ,
146
+ _ => break t,
147
+ }
138
148
}
139
- }
140
- }
149
+ } ;
141
150
142
- fn real_token ( & mut self ) -> ( Token , Span ) {
143
- let res = self . try_real_token ( ) ;
144
151
self . unwrap_or_abort ( res)
145
152
}
146
153
0 commit comments