Move more things around in collect_tokens_trailing_token
.
To make things a little clearer, and to avoid some `mut` variables.
This commit is contained in:
parent
8b5a7eb7f4
commit
f5b28968db
1 changed files with 18 additions and 23 deletions
|
@ -276,37 +276,32 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
let replace_ranges_end = self.capture_state.replace_ranges.len();
|
let replace_ranges_end = self.capture_state.replace_ranges.len();
|
||||||
|
|
||||||
let mut end_pos = self.num_bump_calls;
|
|
||||||
|
|
||||||
let mut captured_trailing = false;
|
|
||||||
|
|
||||||
// Capture a trailing token if requested by the callback 'f'
|
// Capture a trailing token if requested by the callback 'f'
|
||||||
match trailing {
|
let captured_trailing = match trailing {
|
||||||
TrailingToken::None => {}
|
TrailingToken::None => false,
|
||||||
TrailingToken::Gt => {
|
TrailingToken::Gt => {
|
||||||
assert_eq!(self.token.kind, token::Gt);
|
assert_eq!(self.token.kind, token::Gt);
|
||||||
|
false
|
||||||
}
|
}
|
||||||
TrailingToken::Semi => {
|
TrailingToken::Semi => {
|
||||||
assert_eq!(self.token.kind, token::Semi);
|
assert_eq!(self.token.kind, token::Semi);
|
||||||
end_pos += 1;
|
true
|
||||||
captured_trailing = true;
|
|
||||||
}
|
|
||||||
TrailingToken::MaybeComma => {
|
|
||||||
if self.token.kind == token::Comma {
|
|
||||||
end_pos += 1;
|
|
||||||
captured_trailing = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
TrailingToken::MaybeComma => self.token.kind == token::Comma,
|
||||||
|
};
|
||||||
|
|
||||||
// If we 'broke' the last token (e.g. breaking a '>>' token to two '>' tokens),
|
assert!(
|
||||||
// then extend the range of captured tokens to include it, since the parser
|
!(self.break_last_token && captured_trailing),
|
||||||
// was not actually bumped past it. When the `LazyAttrTokenStream` gets converted
|
"Cannot set break_last_token and have trailing token"
|
||||||
// into an `AttrTokenStream`, we will create the proper token.
|
);
|
||||||
if self.break_last_token {
|
|
||||||
assert!(!captured_trailing, "Cannot set break_last_token and have trailing token");
|
let end_pos = self.num_bump_calls
|
||||||
end_pos += 1;
|
+ captured_trailing as usize
|
||||||
}
|
// If we 'broke' the last token (e.g. breaking a '>>' token to two '>' tokens), then
|
||||||
|
// extend the range of captured tokens to include it, since the parser was not actually
|
||||||
|
// bumped past it. When the `LazyAttrTokenStream` gets converted into an
|
||||||
|
// `AttrTokenStream`, we will create the proper token.
|
||||||
|
+ self.break_last_token as usize;
|
||||||
|
|
||||||
let num_calls = end_pos - start_pos;
|
let num_calls = end_pos - start_pos;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue