mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:45:24 +00:00
Re-integrate RustPython parser repository (#4359)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
865205d992
commit
be6e00ef6e
270 changed files with 3061 additions and 3361 deletions
|
@ -1,5 +1,5 @@
|
|||
use ruff_text_size::TextRange;
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
use rustpython_parser::ast::{self, Expr, ExprKind, Keyword};
|
||||
|
||||
fn relocate_keyword(keyword: &mut Keyword, location: TextRange) {
|
||||
keyword.range = location;
|
||||
|
@ -11,31 +11,31 @@ fn relocate_keyword(keyword: &mut Keyword, location: TextRange) {
|
|||
pub fn relocate_expr(expr: &mut Expr, location: TextRange) {
|
||||
expr.range = location;
|
||||
match &mut expr.node {
|
||||
ExprKind::BoolOp { values, .. } => {
|
||||
ExprKind::BoolOp(ast::ExprBoolOp { values, .. }) => {
|
||||
for expr in values {
|
||||
relocate_expr(expr, location);
|
||||
}
|
||||
}
|
||||
ExprKind::NamedExpr { target, value } => {
|
||||
ExprKind::NamedExpr(ast::ExprNamedExpr { target, value }) => {
|
||||
relocate_expr(target, location);
|
||||
relocate_expr(value, location);
|
||||
}
|
||||
ExprKind::BinOp { left, right, .. } => {
|
||||
ExprKind::BinOp(ast::ExprBinOp { left, right, .. }) => {
|
||||
relocate_expr(left, location);
|
||||
relocate_expr(right, location);
|
||||
}
|
||||
ExprKind::UnaryOp { operand, .. } => {
|
||||
ExprKind::UnaryOp(ast::ExprUnaryOp { operand, .. }) => {
|
||||
relocate_expr(operand, location);
|
||||
}
|
||||
ExprKind::Lambda { body, .. } => {
|
||||
ExprKind::Lambda(ast::ExprLambda { body, .. }) => {
|
||||
relocate_expr(body, location);
|
||||
}
|
||||
ExprKind::IfExp { test, body, orelse } => {
|
||||
ExprKind::IfExp(ast::ExprIfExp { test, body, orelse }) => {
|
||||
relocate_expr(test, location);
|
||||
relocate_expr(body, location);
|
||||
relocate_expr(orelse, location);
|
||||
}
|
||||
ExprKind::Dict { keys, values } => {
|
||||
ExprKind::Dict(ast::ExprDict { keys, values }) => {
|
||||
for expr in keys.iter_mut().flatten() {
|
||||
relocate_expr(expr, location);
|
||||
}
|
||||
|
@ -43,44 +43,44 @@ pub fn relocate_expr(expr: &mut Expr, location: TextRange) {
|
|||
relocate_expr(expr, location);
|
||||
}
|
||||
}
|
||||
ExprKind::Set { elts } => {
|
||||
ExprKind::Set(ast::ExprSet { elts }) => {
|
||||
for expr in elts {
|
||||
relocate_expr(expr, location);
|
||||
}
|
||||
}
|
||||
ExprKind::ListComp { elt, .. } => {
|
||||
ExprKind::ListComp(ast::ExprListComp { elt, .. }) => {
|
||||
relocate_expr(elt, location);
|
||||
}
|
||||
ExprKind::SetComp { elt, .. } => {
|
||||
ExprKind::SetComp(ast::ExprSetComp { elt, .. }) => {
|
||||
relocate_expr(elt, location);
|
||||
}
|
||||
ExprKind::DictComp { key, value, .. } => {
|
||||
ExprKind::DictComp(ast::ExprDictComp { key, value, .. }) => {
|
||||
relocate_expr(key, location);
|
||||
relocate_expr(value, location);
|
||||
}
|
||||
ExprKind::GeneratorExp { elt, .. } => {
|
||||
ExprKind::GeneratorExp(ast::ExprGeneratorExp { elt, .. }) => {
|
||||
relocate_expr(elt, location);
|
||||
}
|
||||
ExprKind::Await { value } => relocate_expr(value, location),
|
||||
ExprKind::Yield { value } => {
|
||||
ExprKind::Await(ast::ExprAwait { value }) => relocate_expr(value, location),
|
||||
ExprKind::Yield(ast::ExprYield { value }) => {
|
||||
if let Some(expr) = value {
|
||||
relocate_expr(expr, location);
|
||||
}
|
||||
}
|
||||
ExprKind::YieldFrom { value } => relocate_expr(value, location),
|
||||
ExprKind::Compare {
|
||||
ExprKind::YieldFrom(ast::ExprYieldFrom { value }) => relocate_expr(value, location),
|
||||
ExprKind::Compare(ast::ExprCompare {
|
||||
left, comparators, ..
|
||||
} => {
|
||||
}) => {
|
||||
relocate_expr(left, location);
|
||||
for expr in comparators {
|
||||
relocate_expr(expr, location);
|
||||
}
|
||||
}
|
||||
ExprKind::Call {
|
||||
ExprKind::Call(ast::ExprCall {
|
||||
func,
|
||||
args,
|
||||
keywords,
|
||||
} => {
|
||||
}) => {
|
||||
relocate_expr(func, location);
|
||||
for expr in args {
|
||||
relocate_expr(expr, location);
|
||||
|
@ -89,42 +89,42 @@ pub fn relocate_expr(expr: &mut Expr, location: TextRange) {
|
|||
relocate_keyword(keyword, location);
|
||||
}
|
||||
}
|
||||
ExprKind::FormattedValue {
|
||||
ExprKind::FormattedValue(ast::ExprFormattedValue {
|
||||
value, format_spec, ..
|
||||
} => {
|
||||
}) => {
|
||||
relocate_expr(value, location);
|
||||
if let Some(expr) = format_spec {
|
||||
relocate_expr(expr, location);
|
||||
}
|
||||
}
|
||||
ExprKind::JoinedStr { values } => {
|
||||
ExprKind::JoinedStr(ast::ExprJoinedStr { values }) => {
|
||||
for expr in values {
|
||||
relocate_expr(expr, location);
|
||||
}
|
||||
}
|
||||
ExprKind::Constant { .. } => {}
|
||||
ExprKind::Attribute { value, .. } => {
|
||||
ExprKind::Constant(_) => {}
|
||||
ExprKind::Attribute(ast::ExprAttribute { value, .. }) => {
|
||||
relocate_expr(value, location);
|
||||
}
|
||||
ExprKind::Subscript { value, slice, .. } => {
|
||||
ExprKind::Subscript(ast::ExprSubscript { value, slice, .. }) => {
|
||||
relocate_expr(value, location);
|
||||
relocate_expr(slice, location);
|
||||
}
|
||||
ExprKind::Starred { value, .. } => {
|
||||
ExprKind::Starred(ast::ExprStarred { value, .. }) => {
|
||||
relocate_expr(value, location);
|
||||
}
|
||||
ExprKind::Name { .. } => {}
|
||||
ExprKind::List { elts, .. } => {
|
||||
ExprKind::Name(_) => {}
|
||||
ExprKind::List(ast::ExprList { elts, .. }) => {
|
||||
for expr in elts {
|
||||
relocate_expr(expr, location);
|
||||
}
|
||||
}
|
||||
ExprKind::Tuple { elts, .. } => {
|
||||
ExprKind::Tuple(ast::ExprTuple { elts, .. }) => {
|
||||
for expr in elts {
|
||||
relocate_expr(expr, location);
|
||||
}
|
||||
}
|
||||
ExprKind::Slice { lower, upper, step } => {
|
||||
ExprKind::Slice(ast::ExprSlice { lower, upper, step }) => {
|
||||
if let Some(expr) = lower {
|
||||
relocate_expr(expr, location);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue