@@ -45,9 +45,8 @@ struct TokenTreesReader<'a> {
45
45
impl < ' a > TokenTreesReader < ' a > {
46
46
// Parse a stream of tokens into a list of `TokenTree`s, up to an `Eof`.
47
47
fn parse_all_token_trees ( & mut self ) -> PResult < ' a , TokenStream > {
48
+ self . token = self . string_reader . next_token ( ) . 0 ;
48
49
let mut buf = TokenStreamBuilder :: default ( ) ;
49
-
50
- self . bump ( ) ;
51
50
loop {
52
51
match self . token . kind {
53
52
token:: OpenDelim ( delim) => buf. push ( self . parse_token_tree_open_delim ( delim) ) ,
@@ -116,7 +115,7 @@ impl<'a> TokenTreesReader<'a> {
116
115
117
116
// Parse the open delimiter.
118
117
self . open_braces . push ( ( delim, self . token . span ) ) ;
119
- self . bump ( ) ;
118
+ self . token = self . string_reader . next_token ( ) . 0 ;
120
119
121
120
// Parse the token trees within the delimiters.
122
121
// We stop at any delimiter so we can try to recover if the user
@@ -155,7 +154,7 @@ impl<'a> TokenTreesReader<'a> {
155
154
self . matching_delim_spans . push ( ( open_brace, open_brace_span, close_brace_span) ) ;
156
155
}
157
156
// Parse the closing delimiter.
158
- self . bump ( ) ;
157
+ self . token = self . string_reader . next_token ( ) . 0 ;
159
158
}
160
159
// Incorrect delimiter.
161
160
token:: CloseDelim ( other) => {
@@ -202,7 +201,7 @@ impl<'a> TokenTreesReader<'a> {
202
201
// bar(baz(
203
202
// } // Incorrect delimiter but matches the earlier `{`
204
203
if !self . open_braces . iter ( ) . any ( |& ( b, _) | b == other) {
205
- self . bump ( ) ;
204
+ self . token = self . string_reader . next_token ( ) . 0 ;
206
205
}
207
206
}
208
207
token:: Eof => {
@@ -248,22 +247,15 @@ impl<'a> TokenTreesReader<'a> {
248
247
fn parse_token_tree_other ( & mut self ) -> TokenTree {
249
248
// `spacing` for the returned token is determined by the next token:
250
249
// its kind and its `preceded_by_whitespace` status.
251
- let tok = self . token . take ( ) ;
252
- let is_next_tok_preceded_by_whitespace = self . bump ( ) ;
253
- let spacing = if is_next_tok_preceded_by_whitespace || !self . token . is_op ( ) {
250
+ let this_tok = self . token . take ( ) ;
251
+ let ( next_tok , is_next_tok_preceded_by_whitespace) = self . string_reader . next_token ( ) ;
252
+ let this_spacing = if is_next_tok_preceded_by_whitespace || !next_tok . is_op ( ) {
254
253
Spacing :: Alone
255
254
} else {
256
255
Spacing :: Joint
257
256
} ;
258
- TokenTree :: Token ( tok, spacing)
259
- }
260
-
261
- // Set `self.token` to the next token. Returns a bool indicating if that
262
- // token was preceded by whitespace.
263
- fn bump ( & mut self ) -> bool {
264
- let ( token, spacing) = self . string_reader . next_token ( ) ;
265
- self . token = token;
266
- spacing
257
+ self . token = next_tok;
258
+ TokenTree :: Token ( this_tok, this_spacing)
267
259
}
268
260
}
269
261
0 commit comments