diff --git a/crates/ruff_python_parser/src/parser/expression.rs b/crates/ruff_python_parser/src/parser/expression.rs index d2bb54379e6ab..dc761bd3f1684 100644 --- a/crates/ruff_python_parser/src/parser/expression.rs +++ b/crates/ruff_python_parser/src/parser/expression.rs @@ -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, diff --git a/crates/ruff_python_parser/src/parser/mod.rs b/crates/ruff_python_parser/src/parser/mod.rs index 28922254e94f3..1c6e08f572348 100644 --- a/crates/ruff_python_parser/src/parser/mod.rs +++ b/crates/ruff_python_parser/src/parser/mod.rs @@ -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 @@ -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.