mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-19 02:55:20 +00:00
Remove unused parser modes
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary This PR removes the `Interactive` and `FunctionType` parser modes that are unused by ruff <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan `cargo test` <!-- How was it tested? -->
This commit is contained in:
parent
7c7231db2e
commit
f45e8645d7
15 changed files with 15156 additions and 15587 deletions
|
@ -115,7 +115,7 @@ pub use parse::Parse;
|
|||
pub use parser::{parse, parse_starts_at, parse_tokens, ParseError, ParseErrorType};
|
||||
#[allow(deprecated)]
|
||||
pub use parser::{parse_expression, parse_expression_starts_at, parse_program};
|
||||
use ruff_python_ast::{CmpOp, Expr, Mod, ModModule, Ranged, Suite};
|
||||
use ruff_python_ast::{CmpOp, Expr, ModModule, Ranged, Suite};
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
pub use string::FStringErrorType;
|
||||
pub use token::{StringKind, Tok, TokenKind};
|
||||
|
@ -149,10 +149,7 @@ pub fn parse_program_tokens(
|
|||
lxr: Vec<LexResult>,
|
||||
source_path: &str,
|
||||
) -> anyhow::Result<Suite, ParseError> {
|
||||
parser::parse_tokens(lxr, Mode::Module, source_path).map(|top| match top {
|
||||
Mod::Module(ModModule { body, .. }) => body,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
ModModule::parse_tokens(lxr, source_path).map(|module| module.body)
|
||||
}
|
||||
|
||||
/// Return the `Range` of the first `Tok::Colon` token in a `Range`.
|
||||
|
@ -270,8 +267,6 @@ impl LocatedCmpOp {
|
|||
pub enum Mode {
|
||||
/// The code consists of a sequence of statements.
|
||||
Module,
|
||||
/// The code consists of a sequence of interactive statement.
|
||||
Interactive,
|
||||
/// The code consists of a single expression.
|
||||
Expression,
|
||||
/// The code consists of a sequence of statements which are part of a
|
||||
|
|
|
@ -74,7 +74,7 @@ impl Parse for ast::ModModule {
|
|||
) -> Result<Self, ParseError> {
|
||||
match parse_tokens(lxr, Mode::Module, source_path)? {
|
||||
ast::Mod::Module(m) => Ok(m),
|
||||
_ => unreachable!("Mode::Module doesn't return other variant"),
|
||||
ast::Mod::Expression(_) => unreachable!("Mode::Module doesn't return other variant"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,20 +88,7 @@ impl Parse for ast::ModExpression {
|
|||
) -> Result<Self, ParseError> {
|
||||
match parse_tokens(lxr, Mode::Expression, source_path)? {
|
||||
ast::Mod::Expression(m) => Ok(m),
|
||||
_ => unreachable!("Mode::Module doesn't return other variant"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for ast::ModInteractive {
|
||||
const MODE: Mode = Mode::Interactive;
|
||||
fn parse_tokens(
|
||||
lxr: impl IntoIterator<Item = LexResult>,
|
||||
source_path: &str,
|
||||
) -> Result<Self, ParseError> {
|
||||
match parse_tokens(lxr, Mode::Interactive, source_path)? {
|
||||
ast::Mod::Interactive(m) => Ok(m),
|
||||
_ => unreachable!("Mode::Module doesn't return other variant"),
|
||||
ast::Mod::Module(_) => unreachable!("Mode::Module doesn't return other variant"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ use crate::{
|
|||
Mode, Parse,
|
||||
};
|
||||
use ruff_python_ast as ast;
|
||||
use ruff_python_ast::ModModule;
|
||||
|
||||
/// Parse a full Python program usually consisting of multiple lines.
|
||||
///
|
||||
|
@ -48,10 +49,7 @@ use ruff_python_ast as ast;
|
|||
/// ```
|
||||
#[deprecated = "Use ruff_python_ast::Suite::parse from ruff_python_parser::Parse trait."]
|
||||
pub fn parse_program(source: &str, source_path: &str) -> Result<ast::Suite, ParseError> {
|
||||
parse(source, Mode::Module, source_path).map(|top| match top {
|
||||
ast::Mod::Module(ast::ModModule { body, .. }) => body,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
ModModule::parse(source, source_path).map(|module| module.body)
|
||||
}
|
||||
|
||||
/// Parses a single Python expression.
|
||||
|
@ -718,7 +716,6 @@ except* OSError as e:
|
|||
|
||||
assert!(parse(source, Mode::Expression, "<embedded>").is_ok());
|
||||
assert!(parse(source, Mode::Module, "<embedded>").is_ok());
|
||||
assert!(parse(source, Mode::Interactive, "<embedded>").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -22,7 +22,6 @@ grammar(mode: Mode);
|
|||
// By having only a single pub function, we reduce this to one.
|
||||
pub(crate) Top: ast::Mod = {
|
||||
<start:@L> StartModule <body:Program> <end:@R> => ast::ModModule { body, range: (start..end).into() }.into(),
|
||||
<start:@L> StartInteractive <body:Program> <end:@R> => ast::ModInteractive { body, range: (start..end).into() }.into(),
|
||||
<start:@L> StartExpression <body:TestList> ("\n")* <end:@R> => ast::ModExpression { body: Box::new(body), range: (start..end).into() }.into()
|
||||
};
|
||||
|
||||
|
@ -1743,7 +1742,6 @@ extern {
|
|||
Indent => token::Tok::Indent,
|
||||
Dedent => token::Tok::Dedent,
|
||||
StartModule => token::Tok::StartModule,
|
||||
StartInteractive => token::Tok::StartInteractive,
|
||||
StartExpression => token::Tok::StartExpression,
|
||||
"+" => token::Tok::Plus,
|
||||
"-" => token::Tok::Minus,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -31,7 +31,7 @@ where
|
|||
pub fn new(lexer: I, mode: Mode) -> Self {
|
||||
Self {
|
||||
underlying: lexer.multipeek(), // spell-checker:ignore multipeek
|
||||
start_of_line: matches!(mode, Mode::Interactive | Mode::Module),
|
||||
start_of_line: matches!(mode, Mode::Module),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,11 +140,7 @@ where
|
|||
|
||||
matches!(
|
||||
tok,
|
||||
Tok::StartModule
|
||||
| Tok::StartInteractive
|
||||
| Tok::Newline
|
||||
| Tok::Indent
|
||||
| Tok::Dedent
|
||||
Tok::StartModule | Tok::Newline | Tok::Indent | Tok::Dedent
|
||||
)
|
||||
})
|
||||
});
|
||||
|
|
|
@ -203,7 +203,6 @@ pub enum Tok {
|
|||
|
||||
// RustPython specific.
|
||||
StartModule,
|
||||
StartInteractive,
|
||||
StartExpression,
|
||||
}
|
||||
|
||||
|
@ -211,7 +210,6 @@ impl Tok {
|
|||
pub fn start_marker(mode: Mode) -> Self {
|
||||
match mode {
|
||||
Mode::Module | Mode::Jupyter => Tok::StartModule,
|
||||
Mode::Interactive => Tok::StartInteractive,
|
||||
Mode::Expression => Tok::StartExpression,
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +238,6 @@ impl fmt::Display for Tok {
|
|||
Indent => f.write_str("Indent"),
|
||||
Dedent => f.write_str("Dedent"),
|
||||
StartModule => f.write_str("StartProgram"),
|
||||
StartInteractive => f.write_str("StartInteractive"),
|
||||
StartExpression => f.write_str("StartExpression"),
|
||||
EndOfFile => f.write_str("EOF"),
|
||||
Lpar => f.write_str("'('"),
|
||||
|
@ -872,7 +869,6 @@ impl TokenKind {
|
|||
Tok::With => TokenKind::With,
|
||||
Tok::Yield => TokenKind::Yield,
|
||||
Tok::StartModule => TokenKind::StartModule,
|
||||
Tok::StartInteractive => TokenKind::StartInteractive,
|
||||
Tok::StartExpression => TokenKind::StartExpression,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue