Skip to content

Commit

Permalink
Update prev token end before token bump (#11473)
Browse files Browse the repository at this point in the history
## Summary

This PR fixes a bug where the parser would bump the token before
updating the `prev_token_end`. The order should be reversed.
  • Loading branch information
dhruvmanila committed May 30, 2024
1 parent 6b078a7 commit 9fbcbf9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/ruff_python_parser/src/parser/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl<'src> Parser<'src> {
// Non-soft keyword
self.add_error(
ParseErrorType::OtherError(format!(
"Expected an identifier, but found a keyword '{}' that cannot be used here",
"Expected an identifier, but found a keyword {} that cannot be used here",
self.current_token_kind()
)),
range,
Expand Down
9 changes: 4 additions & 5 deletions crates/ruff_python_parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,8 @@ impl<'src> Parser<'src> {

/// Moves the parser to the next token.
fn do_bump(&mut self, kind: TokenKind) {
self.tokens.bump(kind);

self.current_token_id.increment();

if !matches!(
self.tokens.current_kind(),
self.current_token_kind(),
// TODO explore including everything up to the dedent as part of the body.
TokenKind::Dedent
// Don't include newlines in the body
Expand All @@ -337,6 +333,9 @@ impl<'src> Parser<'src> {
) {
self.prev_token_end = self.current_token_range().end();
}

self.tokens.bump(kind);
self.current_token_id.increment();
}

/// Returns the next token kind without consuming it.
Expand Down

0 comments on commit 9fbcbf9

Please sign in to comment.