Pull in RustPython parser (#6099)

This commit is contained in:
Micha Reiser 2023-07-27 11:29:11 +02:00 committed by GitHub
parent 86539c1fc5
commit 40f54375cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
779 changed files with 108400 additions and 2078 deletions

View file

@ -14,9 +14,9 @@ license = { workspace = true }
[dependencies]
ruff_python_ast = { path = "../ruff_python_ast" }
rustpython-parser = { workspace = true }
ruff_python_literal = { path = "../ruff_python_literal" }
ruff_python_parser = { path = "../ruff_python_parser" }
ruff_source_file = { path = "../ruff_source_file" }
once_cell = { workspace = true }
rustpython-literal = { workspace = true }
rustpython-ast = { workspace = true }

View file

@ -1,14 +1,14 @@
//! Generate Python source code from an abstract syntax tree (AST).
use rustpython_ast::ArgWithDefault;
use ruff_python_ast::ArgWithDefault;
use std::ops::Deref;
use rustpython_ast::{
use ruff_python_ast::{
self as ast, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, ConversionFlag,
ExceptHandler, Expr, Identifier, MatchCase, Operator, Pattern, Stmt, Suite, TypeParam,
TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, WithItem,
};
use rustpython_literal::escape::{AsciiEscape, Escape, UnicodeEscape};
use ruff_python_literal::escape::{AsciiEscape, Escape, UnicodeEscape};
use ruff_source_file::LineEnding;
@ -972,7 +972,7 @@ impl<'a> Generator<'a> {
let (op, prec) = opprec!(
un,
op,
rustpython_ast::UnaryOp,
ruff_python_ast::UnaryOp,
Invert("~", INVERT),
Not("not ", NOT),
UAdd("+", UADD),
@ -1298,7 +1298,7 @@ impl<'a> Generator<'a> {
if fp.is_infinite() {
self.p(inf_str);
} else {
self.p(&rustpython_literal::float::to_string(*fp));
self.p(&ruff_python_literal::float::to_string(*fp));
}
}
Constant::Complex { real, imag } => {
@ -1475,8 +1475,8 @@ impl<'a> Generator<'a> {
#[cfg(test)]
mod tests {
use rustpython_ast::{Mod, ModModule, Stmt};
use rustpython_parser::{self, Mode, Parse};
use ruff_python_ast::{Mod, ModModule, Stmt};
use ruff_python_parser::{self, Mode, Parse};
use ruff_source_file::LineEnding;
@ -1509,7 +1509,7 @@ mod tests {
let indentation = Indentation::default();
let quote = Quote::default();
let line_ending = LineEnding::default();
let ast = rustpython_parser::parse(contents, Mode::Jupyter, "<filename>").unwrap();
let ast = ruff_python_parser::parse(contents, Mode::Jupyter, "<filename>").unwrap();
let Mod::Module(ModModule { body, .. }) = ast else {
panic!("Source code didn't return ModModule")
};

View file

@ -2,9 +2,9 @@ mod generator;
mod stylist;
pub use generator::Generator;
use ruff_python_ast::Suite;
use ruff_python_parser::{lexer, Mode, Parse, ParseError};
use ruff_source_file::Locator;
use rustpython_ast::Suite;
use rustpython_parser::{lexer, Mode, Parse, ParseError};
pub use stylist::{Quote, Stylist};
/// Run round-trip source code generation on a given Python code.

View file

@ -4,10 +4,10 @@ use std::fmt;
use std::ops::Deref;
use once_cell::unsync::OnceCell;
use ruff_python_literal::escape::Quote as StrQuote;
use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::Tok;
use ruff_source_file::{find_newline, LineEnding};
use rustpython_literal::escape::Quote as StrQuote;
use rustpython_parser::lexer::LexResult;
use rustpython_parser::Tok;
use ruff_python_ast::str::leading_quote;
use ruff_source_file::Locator;
@ -163,8 +163,8 @@ impl Deref for Indentation {
#[cfg(test)]
mod tests {
use rustpython_parser::lexer::lex;
use rustpython_parser::Mode;
use ruff_python_parser::lexer::lex;
use ruff_python_parser::Mode;
use ruff_source_file::{find_newline, LineEnding};