Skip to content

Commit 6ebf27d

Browse files
committed
add Parser::add_unsupported_syntax_error
1 parent 9387989 commit 6ebf27d

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

crates/ruff_python_parser/src/parser/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::parser::progress::{ParserProgress, TokenId};
1111
use crate::token::TokenValue;
1212
use crate::token_set::TokenSet;
1313
use crate::token_source::{TokenSource, TokenSourceCheckpoint};
14-
use crate::{Mode, ParseError, ParseErrorType, TokenKind};
14+
use crate::{Mode, ParseError, ParseErrorType, TokenKind, UnsupportedSyntaxErrorKind};
1515
use crate::{Parsed, Tokens};
1616

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

441+
/// Add an [`UnsupportedSyntaxError`] with the given [`UnsupportedSyntaxErrorKind`] and
442+
/// [`TextRange`].
443+
fn add_unsupported_syntax_error(&mut self, kind: UnsupportedSyntaxErrorKind, range: TextRange) {
444+
self.unsupported_syntax_errors.push(UnsupportedSyntaxError {
445+
kind,
446+
range,
447+
target_version: self.options.target_version,
448+
});
449+
}
450+
441451
/// Returns `true` if the current token is of the given kind.
442452
fn at(&self, kind: TokenKind) -> bool {
443453
self.current_token_kind() == kind

crates/ruff_python_parser/src/parser/statement.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::parser::{
1717
};
1818
use crate::token::{TokenKind, TokenValue};
1919
use crate::token_set::TokenSet;
20-
use crate::{Mode, ParseErrorType, UnsupportedSyntaxError, UnsupportedSyntaxErrorKind};
20+
use crate::{Mode, ParseErrorType, UnsupportedSyntaxErrorKind};
2121

2222
use super::expression::ExpressionContext;
2323
use super::Parenthesized;
@@ -2278,11 +2278,10 @@ impl<'src> Parser<'src> {
22782278
// pass
22792279

22802280
if self.options.target_version < PythonVersion::PY310 {
2281-
self.unsupported_syntax_errors.push(UnsupportedSyntaxError {
2282-
kind: UnsupportedSyntaxErrorKind::MatchBeforePy310,
2283-
range: match_range,
2284-
target_version: self.options.target_version,
2285-
});
2281+
self.add_unsupported_syntax_error(
2282+
UnsupportedSyntaxErrorKind::MatchBeforePy310,
2283+
match_range,
2284+
);
22862285
}
22872286

22882287
ast::StmtMatch {

0 commit comments

Comments
 (0)