Skip to content

Commit 6c5c311

Browse files
authored
Fix range field order (#56)
* Skip validate_arguments when empty * Fix `range` field order * Fix unused variable
1 parent 531e41a commit 6c5c311

File tree

38 files changed

+211
-215
lines changed

38 files changed

+211
-215
lines changed

ast/asdl_rs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ def visitProduct(self, product, type, depth):
471471
self.emit_attrs(depth)
472472

473473
self.emit(f"pub struct {product_name}<R = TextRange> {{", depth)
474+
self.emit_range(product.attributes, depth + 1)
474475
for f in product.fields:
475476
self.visit(f, type_info, "pub ", depth + 1)
476477
assert bool(product.attributes) == type_info.no_cfg(self.type_info)
477-
self.emit_range(product.attributes, depth + 1)
478478
self.emit("}", depth)
479479

480480
field_names = [f'"{f.name}"' for f in product.fields]
@@ -505,7 +505,7 @@ def visitModule(self, mod, depth):
505505
self.will_map_user(user)
506506
}
507507
#[cfg(not(feature = "all-nodes-with-ranges"))]
508-
fn will_map_user_cfg(&mut self, user: &crate::EmptyRange<U>) -> crate::EmptyRange<Self::TargetU> {
508+
fn will_map_user_cfg(&mut self, _user: &crate::EmptyRange<U>) -> crate::EmptyRange<Self::TargetU> {
509509
crate::EmptyRange::default()
510510
}
511511
fn map_user(&mut self, user: U, context: Self::UserContext) -> Result<Self::TargetU, Self::Error>;

ast/src/gen/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub trait Fold<U> {
1313
#[cfg(not(feature = "all-nodes-with-ranges"))]
1414
fn will_map_user_cfg(
1515
&mut self,
16-
user: &crate::EmptyRange<U>,
16+
_user: &crate::EmptyRange<U>,
1717
) -> crate::EmptyRange<Self::TargetU> {
1818
crate::EmptyRange::default()
1919
}

ast/src/gen/generic.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,11 +2047,11 @@ impl Node for Cmpop {
20472047

20482048
#[derive(Clone, Debug, PartialEq)]
20492049
pub struct Comprehension<R = TextRange> {
2050+
pub range: OptionalRange<R>,
20502051
pub target: Expr<R>,
20512052
pub iter: Expr<R>,
20522053
pub ifs: Vec<Expr<R>>,
20532054
pub is_async: bool,
2054-
pub range: OptionalRange<R>,
20552055
}
20562056

20572057
impl<R> Node for Comprehension<R> {
@@ -2089,14 +2089,14 @@ impl<R> Node for Excepthandler<R> {
20892089

20902090
#[derive(Clone, Debug, PartialEq)]
20912091
pub struct Arguments<R = TextRange> {
2092+
pub range: OptionalRange<R>,
20922093
pub posonlyargs: Vec<Arg<R>>,
20932094
pub args: Vec<Arg<R>>,
20942095
pub vararg: Option<Box<Arg<R>>>,
20952096
pub kwonlyargs: Vec<Arg<R>>,
20962097
pub kw_defaults: Vec<Expr<R>>,
20972098
pub kwarg: Option<Box<Arg<R>>>,
20982099
pub defaults: Vec<Expr<R>>,
2099-
pub range: OptionalRange<R>,
21002100
}
21012101

21022102
impl<R> Node for Arguments<R> {
@@ -2114,10 +2114,10 @@ impl<R> Node for Arguments<R> {
21142114

21152115
#[derive(Clone, Debug, PartialEq)]
21162116
pub struct Arg<R = TextRange> {
2117+
pub range: R,
21172118
pub arg: Identifier,
21182119
pub annotation: Option<Box<Expr<R>>>,
21192120
pub type_comment: Option<String>,
2120-
pub range: R,
21212121
}
21222122

21232123
impl<R> Node for Arg<R> {
@@ -2127,9 +2127,9 @@ impl<R> Node for Arg<R> {
21272127

21282128
#[derive(Clone, Debug, PartialEq)]
21292129
pub struct Keyword<R = TextRange> {
2130+
pub range: R,
21302131
pub arg: Option<Identifier>,
21312132
pub value: Expr<R>,
2132-
pub range: R,
21332133
}
21342134

21352135
impl<R> Node for Keyword<R> {
@@ -2139,9 +2139,9 @@ impl<R> Node for Keyword<R> {
21392139

21402140
#[derive(Clone, Debug, PartialEq)]
21412141
pub struct Alias<R = TextRange> {
2142+
pub range: R,
21422143
pub name: Identifier,
21432144
pub asname: Option<Identifier>,
2144-
pub range: R,
21452145
}
21462146

21472147
impl<R> Node for Alias<R> {
@@ -2151,9 +2151,9 @@ impl<R> Node for Alias<R> {
21512151

21522152
#[derive(Clone, Debug, PartialEq)]
21532153
pub struct Withitem<R = TextRange> {
2154+
pub range: OptionalRange<R>,
21542155
pub context_expr: Expr<R>,
21552156
pub optional_vars: Option<Box<Expr<R>>>,
2156-
pub range: OptionalRange<R>,
21572157
}
21582158

21592159
impl<R> Node for Withitem<R> {
@@ -2163,10 +2163,10 @@ impl<R> Node for Withitem<R> {
21632163

21642164
#[derive(Clone, Debug, PartialEq)]
21652165
pub struct MatchCase<R = TextRange> {
2166+
pub range: OptionalRange<R>,
21662167
pub pattern: Pattern<R>,
21672168
pub guard: Option<Box<Expr<R>>>,
21682169
pub body: Vec<Stmt<R>>,
2169-
pub range: OptionalRange<R>,
21702170
}
21712171

21722172
impl<R> Node for MatchCase<R> {

parser/src/python.lalrpop

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -956,18 +956,16 @@ FuncDef: ast::Stmt = {
956956

957957
Parameters: ast::Arguments = {
958958
<location:@L> "(" <a: (ParameterList<TypedParameter, StarTypedParameter>)?> ")" <end_location:@R> =>? {
959-
let args = validate_arguments(
960-
a.unwrap_or_else(|| ast::Arguments {
961-
posonlyargs: vec![],
962-
args: vec![],
963-
vararg: None,
964-
kwonlyargs: vec![],
965-
kw_defaults: vec![],
966-
kwarg: None,
967-
defaults: vec![],
968-
range: optional_range(location, end_location)
969-
})
970-
)?;
959+
let args = a.map(validate_arguments).transpose()?.unwrap_or_else(|| ast::Arguments {
960+
posonlyargs: vec![],
961+
args: vec![],
962+
vararg: None,
963+
kwonlyargs: vec![],
964+
kw_defaults: vec![],
965+
kwarg: None,
966+
defaults: vec![],
967+
range: optional_range(location, end_location)
968+
});
971969

972970
Ok(args)
973971
}

parser/src/python.rs

Lines changed: 11 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__context__tests__assign_list_comp.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__context__tests__assign_set_comp.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__context__tests__assign_with.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__function__tests__function_kw_only_args.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__function__tests__function_kw_only_args_with_defaults.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__function__tests__function_no_args.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)