Skip to content

Commit

Permalink
add Parser::add_unsupported_syntax_error
Browse files Browse the repository at this point in the history
  • Loading branch information
ntBre committed Feb 26, 2025
1 parent 821331a commit 7fa1359
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 11 additions & 1 deletion crates/ruff_python_parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::parser::progress::{ParserProgress, TokenId};
use crate::token::TokenValue;
use crate::token_set::TokenSet;
use crate::token_source::{TokenSource, TokenSourceCheckpoint};
use crate::{Mode, ParseError, ParseErrorType, TokenKind};
use crate::{Mode, ParseError, ParseErrorType, TokenKind, UnsupportedSyntaxErrorKind};
use crate::{Parsed, Tokens};

pub use crate::parser::options::ParseOptions;
Expand Down Expand Up @@ -438,6 +438,16 @@ impl<'src> Parser<'src> {
inner(&mut self.errors, error, ranged.range());
}

/// Add an [`UnsupportedSyntaxError`] with the given [`UnsupportedSyntaxErrorKind`] and
/// [`TextRange`].
fn add_unsupported_syntax_error(&mut self, kind: UnsupportedSyntaxErrorKind, range: TextRange) {
self.unsupported_syntax_errors.push(UnsupportedSyntaxError {
kind,
range,
target_version: self.options.target_version,
});
}

/// Returns `true` if the current token is of the given kind.
fn at(&self, kind: TokenKind) -> bool {
self.current_token_kind() == kind
Expand Down
11 changes: 5 additions & 6 deletions crates/ruff_python_parser/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::parser::{
};
use crate::token::{TokenKind, TokenValue};
use crate::token_set::TokenSet;
use crate::{Mode, ParseErrorType, UnsupportedSyntaxError, UnsupportedSyntaxErrorKind};
use crate::{Mode, ParseErrorType, UnsupportedSyntaxErrorKind};

use super::expression::ExpressionContext;
use super::Parenthesized;
Expand Down Expand Up @@ -2278,11 +2278,10 @@ impl<'src> Parser<'src> {
// pass

if self.options.target_version < PythonVersion::PY310 {
self.unsupported_syntax_errors.push(UnsupportedSyntaxError {
kind: UnsupportedSyntaxErrorKind::MatchBeforePy310,
range: match_range,
target_version: self.options.target_version,
});
self.add_unsupported_syntax_error(
UnsupportedSyntaxErrorKind::MatchBeforePy310,
match_range,
);
}

ast::StmtMatch {
Expand Down

0 comments on commit 7fa1359

Please sign in to comment.