Skip to content

Fix range field order #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ast/asdl_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ def visitProduct(self, product, type, depth):
self.emit_attrs(depth)

self.emit(f"pub struct {product_name}<R = TextRange> {{", depth)
self.emit_range(product.attributes, depth + 1)
for f in product.fields:
self.visit(f, type_info, "pub ", depth + 1)
assert bool(product.attributes) == type_info.no_cfg(self.type_info)
self.emit_range(product.attributes, depth + 1)
self.emit("}", depth)

field_names = [f'"{f.name}"' for f in product.fields]
Expand Down Expand Up @@ -505,7 +505,7 @@ def visitModule(self, mod, depth):
self.will_map_user(user)
}
#[cfg(not(feature = "all-nodes-with-ranges"))]
fn will_map_user_cfg(&mut self, user: &crate::EmptyRange<U>) -> crate::EmptyRange<Self::TargetU> {
fn will_map_user_cfg(&mut self, _user: &crate::EmptyRange<U>) -> crate::EmptyRange<Self::TargetU> {
crate::EmptyRange::default()
}
fn map_user(&mut self, user: U, context: Self::UserContext) -> Result<Self::TargetU, Self::Error>;
Expand Down
2 changes: 1 addition & 1 deletion ast/src/gen/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait Fold<U> {
#[cfg(not(feature = "all-nodes-with-ranges"))]
fn will_map_user_cfg(
&mut self,
user: &crate::EmptyRange<U>,
_user: &crate::EmptyRange<U>,
) -> crate::EmptyRange<Self::TargetU> {
crate::EmptyRange::default()
}
Expand Down
14 changes: 7 additions & 7 deletions ast/src/gen/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2047,11 +2047,11 @@ impl Node for Cmpop {

#[derive(Clone, Debug, PartialEq)]
pub struct Comprehension<R = TextRange> {
pub range: OptionalRange<R>,
pub target: Expr<R>,
pub iter: Expr<R>,
pub ifs: Vec<Expr<R>>,
pub is_async: bool,
pub range: OptionalRange<R>,
}

impl<R> Node for Comprehension<R> {
Expand Down Expand Up @@ -2089,14 +2089,14 @@ impl<R> Node for Excepthandler<R> {

#[derive(Clone, Debug, PartialEq)]
pub struct Arguments<R = TextRange> {
pub range: OptionalRange<R>,
pub posonlyargs: Vec<Arg<R>>,
pub args: Vec<Arg<R>>,
pub vararg: Option<Box<Arg<R>>>,
pub kwonlyargs: Vec<Arg<R>>,
pub kw_defaults: Vec<Expr<R>>,
pub kwarg: Option<Box<Arg<R>>>,
pub defaults: Vec<Expr<R>>,
pub range: OptionalRange<R>,
}

impl<R> Node for Arguments<R> {
Expand All @@ -2114,10 +2114,10 @@ impl<R> Node for Arguments<R> {

#[derive(Clone, Debug, PartialEq)]
pub struct Arg<R = TextRange> {
pub range: R,
pub arg: Identifier,
pub annotation: Option<Box<Expr<R>>>,
pub type_comment: Option<String>,
pub range: R,
}

impl<R> Node for Arg<R> {
Expand All @@ -2127,9 +2127,9 @@ impl<R> Node for Arg<R> {

#[derive(Clone, Debug, PartialEq)]
pub struct Keyword<R = TextRange> {
pub range: R,
pub arg: Option<Identifier>,
pub value: Expr<R>,
pub range: R,
}

impl<R> Node for Keyword<R> {
Expand All @@ -2139,9 +2139,9 @@ impl<R> Node for Keyword<R> {

#[derive(Clone, Debug, PartialEq)]
pub struct Alias<R = TextRange> {
pub range: R,
pub name: Identifier,
pub asname: Option<Identifier>,
pub range: R,
}

impl<R> Node for Alias<R> {
Expand All @@ -2151,9 +2151,9 @@ impl<R> Node for Alias<R> {

#[derive(Clone, Debug, PartialEq)]
pub struct Withitem<R = TextRange> {
pub range: OptionalRange<R>,
pub context_expr: Expr<R>,
pub optional_vars: Option<Box<Expr<R>>>,
pub range: OptionalRange<R>,
}

impl<R> Node for Withitem<R> {
Expand All @@ -2163,10 +2163,10 @@ impl<R> Node for Withitem<R> {

#[derive(Clone, Debug, PartialEq)]
pub struct MatchCase<R = TextRange> {
pub range: OptionalRange<R>,
pub pattern: Pattern<R>,
pub guard: Option<Box<Expr<R>>>,
pub body: Vec<Stmt<R>>,
pub range: OptionalRange<R>,
}

impl<R> Node for MatchCase<R> {
Expand Down
22 changes: 10 additions & 12 deletions parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -956,18 +956,16 @@ FuncDef: ast::Stmt = {

Parameters: ast::Arguments = {
<location:@L> "(" <a: (ParameterList<TypedParameter, StarTypedParameter>)?> ")" <end_location:@R> =>? {
let args = validate_arguments(
a.unwrap_or_else(|| ast::Arguments {
posonlyargs: vec![],
args: vec![],
vararg: None,
kwonlyargs: vec![],
kw_defaults: vec![],
kwarg: None,
defaults: vec![],
range: optional_range(location, end_location)
})
)?;
let args = a.map(validate_arguments).transpose()?.unwrap_or_else(|| ast::Arguments {
posonlyargs: vec![],
args: vec![],
vararg: None,
kwonlyargs: vec![],
kw_defaults: vec![],
kwarg: None,
defaults: vec![],
range: optional_range(location, end_location)
});

Ok(args)
}
Expand Down
24 changes: 11 additions & 13 deletions parser/src/python.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading