diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3c627ddb..04a36190 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,7 +40,7 @@ jobs: - name: run tests with num-bigint run: cargo test --all --no-default-features --features num-bigint - name: run tests with malachite-bigint and all features - run: cargo test --all --features malachite-bigint,all-nodes-with-ranges,full-lexer,serde + run: cargo test --all --features malachite-bigint,full-lexer,serde lint: name: Check Rust code with rustfmt and clippy @@ -55,7 +55,7 @@ jobs: - name: run clippy run: cargo clippy --all --no-default-features --features num-bigint - name: run clippy - run: cargo clippy --all --features malachite-bigint,all-nodes-with-ranges,full-lexer,serde -- -Dwarnings + run: cargo clippy --all --features malachite-bigint,full-lexer,serde -- -Dwarnings - uses: actions/setup-python@v4 with: diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 967b0e63..fe869346 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -9,7 +9,6 @@ license = "MIT" [features] default = ["malachite-bigint"] -all-nodes-with-ranges = [] [dependencies] rustpython-parser-core = { workspace = true } diff --git a/ast/asdl_rs.py b/ast/asdl_rs.py index 7e51da78..7d5c8bbb 100755 --- a/ast/asdl_rs.py +++ b/ast/asdl_rs.py @@ -286,13 +286,6 @@ def customized_type_info(self, type_name): def has_user_data(self, typ): return self.type_info[typ].has_user_data - def apply_generics(self, typ, *generics): - needs_generics = not self.type_info[typ].is_simple - if needs_generics: - return [f"<{g}>" for g in generics] - else: - return ["" for g in generics] - class EmitVisitor(asdl.VisitorBase, TypeInfoMixin): """Visit that emits lines""" @@ -393,17 +386,14 @@ def emit_attrs(self, depth): self.emit("#[derive(Clone, Debug, PartialEq)]", depth) def emit_range(self, has_attributes, depth): - if has_attributes: - self.emit("pub range: R,", depth + 1) - else: - self.emit("pub range: OptionalRange,", depth + 1) + self.emit("pub range: TextRange,", depth + 1) def visitModule(self, mod): self.emit_attrs(0) self.emit( """ #[derive(is_macro::Is)] - pub enum Ast { + pub enum Ast { """, 0, ) @@ -411,7 +401,6 @@ def visitModule(self, mod): info = self.customized_type_info(dfn.name) dfn = info.custom rust_name = info.full_type_name - generics = "" if self.type_info[dfn.name].is_simple else "" if dfn.name == "mod": # This is exceptional rule to other enums. # Unlike other enums, this is justified because `Mod` is only used as @@ -419,11 +408,11 @@ def visitModule(self, mod): # Because it will be very rarely used in very particular applications, # "ast_" prefix to everywhere seems less useful. self.emit('#[is(name = "module")]', 1) - self.emit(f"{rust_name}({rust_name}{generics}),", 1) + self.emit(f"{rust_name}({rust_name}),", 1) self.emit( """ } - impl Node for Ast { + impl Node for Ast { const NAME: &'static str = "AST"; const FIELD_NAMES: &'static [&'static str] = &[]; } @@ -433,11 +422,10 @@ def visitModule(self, mod): for dfn in mod.dfns: info = self.customized_type_info(dfn.name) rust_name = info.full_type_name - generics = "" if self.type_info[dfn.name].is_simple else "" self.emit( f""" - impl From<{rust_name}{generics}> for Ast {{ - fn from(node: {rust_name}{generics}) -> Self {{ + impl From<{rust_name}> for Ast {{ + fn from(node: {rust_name}) -> Self {{ Ast::{rust_name}(node) }} }} @@ -462,10 +450,9 @@ def visitSum(self, sum, type, depth): else: self.sum_with_constructors(sum, type, depth) - (generics_applied,) = self.apply_generics(type.name, "R") self.emit( f""" - impl{generics_applied} Node for {rust_type_name(type.name)}{generics_applied} {{ + impl Node for {rust_type_name(type.name)} {{ const NAME: &'static str = "{type.name}"; const FIELD_NAMES: &'static [&'static str] = &[]; }} @@ -512,7 +499,7 @@ def simple_sum(self, sum, type, depth): {rust_name}::{cons.name} }} }} - impl From<{rust_name}{cons.name}> for Ast {{ + impl From<{rust_name}{cons.name}> for Ast {{ fn from(_: {rust_name}{cons.name}) -> Self {{ {rust_name}::{cons.name}.into() }} @@ -537,7 +524,7 @@ def sum_with_constructors(self, sum, type, depth): self.emit_attrs(depth) self.emit("#[derive(is_macro::Is)]", depth) - self.emit(f"pub enum {rust_name} {{", depth) + self.emit(f"pub enum {rust_name} {{", depth) needs_escape = any(rust_field_name(t.name) in RUST_KEYWORDS for t in sum.types) for t in sum.types: if needs_escape: @@ -545,7 +532,7 @@ def sum_with_constructors(self, sum, type, depth): f'#[is(name = "{rust_field_name(t.name)}_{rust_name.lower()}")]', depth + 1, ) - self.emit(f"{t.name}({rust_name}{t.name}),", depth + 1) + self.emit(f"{t.name}({rust_name}{t.name}),", depth + 1) self.emit("}", depth) self.emit("", depth) @@ -559,7 +546,7 @@ def sum_subtype_struct(self, sum_type_info, t, rust_name, depth): ) self.emit_attrs(depth) payload_name = f"{rust_name}{t.name}" - self.emit(f"pub struct {payload_name} {{", depth) + self.emit(f"pub struct {payload_name} {{", depth) self.emit_range(sum_type_info.has_attributes, depth) for f in t.fields: self.visit(f, sum_type_info, "pub ", depth + 1, t.name) @@ -572,17 +559,17 @@ def sum_subtype_struct(self, sum_type_info, t, rust_name, depth): field_names = [f'"{f.name}"' for f in t.fields] self.emit( f""" - impl Node for {payload_name} {{ + impl Node for {payload_name} {{ const NAME: &'static str = "{t.name}"; const FIELD_NAMES: &'static [&'static str] = &[{', '.join(field_names)}]; }} - impl From<{payload_name}> for {rust_name} {{ - fn from(payload: {payload_name}) -> Self {{ + impl From<{payload_name}> for {rust_name} {{ + fn from(payload: {payload_name}) -> Self {{ {rust_name}::{t.name}(payload) }} }} - impl From<{payload_name}> for Ast {{ - fn from(payload: {payload_name}) -> Self {{ + impl From<{payload_name}> for Ast {{ + fn from(payload: {payload_name}) -> Self {{ {rust_name}::from(payload).into() }} }} @@ -609,7 +596,7 @@ def visitField(self, field, parent, vis, depth, constructor=None): field_type = None typ = rust_type_name(field.type) if field_type and not field_type.is_simple: - typ = f"{typ}" + typ = f"{typ}" # don't box if we're doing Vec, but do box if we're doing Vec>> if ( field_type @@ -642,7 +629,7 @@ def visitProduct(self, product, type, depth): type_info = self.type_info[type.name] product_name = type_info.full_type_name self.emit_attrs(depth) - self.emit(f"pub struct {product_name} {{", depth) + self.emit(f"pub struct {product_name} {{", depth) self.emit_range(product.attributes, depth + 1) for f in product.fields: self.visit(f, type_info, "pub ", depth + 1) @@ -652,7 +639,7 @@ def visitProduct(self, product, type, depth): field_names = [f'"{f.name}"' for f in product.fields] self.emit( f""" - impl Node for {product_name} {{ + impl Node for {product_name} {{ const NAME: &'static str = "{type.name}"; const FIELD_NAMES: &'static [&'static str] = &[ {', '.join(field_names)} @@ -692,8 +679,6 @@ def visitSum(self, sum, name, depth): self.emit_type_alias(variant_info) self.emit_ranged_impl(variant_info) - if not info.no_cfg(self.type_info): - self.emit('#[cfg(feature = "all-nodes-with-ranges")]', 0) self.emit( f""" @@ -716,21 +701,16 @@ def visitProduct(self, product, name, depth): def emit_type_alias(self, info): return # disable - generics = "" if info.is_simple else "::" - self.emit( - f"pub type {info.full_type_name} = crate::generic::{info.full_type_name}{generics};", + f"pub type {info.full_type_name} = crate::generic::{info.full_type_name};", 0, ) self.emit("", 0) def emit_ranged_impl(self, info): - if not info.no_cfg(self.type_info): - self.emit('#[cfg(feature = "all-nodes-with-ranges")]', 0) - self.file.write( f""" - impl Ranged for crate::generic::{info.full_type_name}:: {{ + impl Ranged for crate::generic::{info.full_type_name} {{ fn range(&self) -> TextRange {{ self.range }} diff --git a/ast/src/gen/generic.rs b/ast/src/gen/generic.rs index 1f3a57df..00cb643b 100644 --- a/ast/src/gen/generic.rs +++ b/ast/src/gen/generic.rs @@ -1,335 +1,335 @@ // File automatically generated by ast/asdl_rs.py. use crate::text_size::TextRange; -#[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum Ast { +#[derive(Clone, Debug, PartialEq)] +#[derive(is_macro::Is)] +pub enum Ast { #[is(name = "module")] - Mod(Mod), - Stmt(Stmt), - Expr(Expr), + Mod(Mod), + Stmt(Stmt), + Expr(Expr), ExprContext(ExprContext), BoolOp(BoolOp), Operator(Operator), UnaryOp(UnaryOp), CmpOp(CmpOp), - Comprehension(Comprehension), - ExceptHandler(ExceptHandler), - Arguments(Arguments), - Arg(Arg), - Keyword(Keyword), - Alias(Alias), - WithItem(WithItem), - MatchCase(MatchCase), - Pattern(Pattern), - TypeIgnore(TypeIgnore), - TypeParam(TypeParam), - Decorator(Decorator), -} - -impl Node for Ast { + Comprehension(Comprehension), + ExceptHandler(ExceptHandler), + Arguments(Arguments), + Arg(Arg), + Keyword(Keyword), + Alias(Alias), + WithItem(WithItem), + MatchCase(MatchCase), + Pattern(Pattern), + TypeIgnore(TypeIgnore), + TypeParam(TypeParam), + Decorator(Decorator), +} +impl Node for Ast { const NAME: &'static str = "AST"; const FIELD_NAMES: &'static [&'static str] = &[]; } -impl From> for Ast { - fn from(node: Mod) -> Self { +impl From for Ast { + fn from(node: Mod) -> Self { Ast::Mod(node) } } -impl From> for Ast { - fn from(node: Stmt) -> Self { +impl From for Ast { + fn from(node: Stmt) -> Self { Ast::Stmt(node) } } -impl From> for Ast { - fn from(node: Expr) -> Self { +impl From for Ast { + fn from(node: Expr) -> Self { Ast::Expr(node) } } -impl From for Ast { +impl From for Ast { fn from(node: ExprContext) -> Self { Ast::ExprContext(node) } } -impl From for Ast { +impl From for Ast { fn from(node: BoolOp) -> Self { Ast::BoolOp(node) } } -impl From for Ast { +impl From for Ast { fn from(node: Operator) -> Self { Ast::Operator(node) } } -impl From for Ast { +impl From for Ast { fn from(node: UnaryOp) -> Self { Ast::UnaryOp(node) } } -impl From for Ast { +impl From for Ast { fn from(node: CmpOp) -> Self { Ast::CmpOp(node) } } -impl From> for Ast { - fn from(node: Comprehension) -> Self { +impl From for Ast { + fn from(node: Comprehension) -> Self { Ast::Comprehension(node) } } -impl From> for Ast { - fn from(node: ExceptHandler) -> Self { +impl From for Ast { + fn from(node: ExceptHandler) -> Self { Ast::ExceptHandler(node) } } -impl From> for Ast { - fn from(node: Arguments) -> Self { +impl From for Ast { + fn from(node: Arguments) -> Self { Ast::Arguments(node) } } -impl From> for Ast { - fn from(node: Arg) -> Self { +impl From for Ast { + fn from(node: Arg) -> Self { Ast::Arg(node) } } -impl From> for Ast { - fn from(node: Keyword) -> Self { +impl From for Ast { + fn from(node: Keyword) -> Self { Ast::Keyword(node) } } -impl From> for Ast { - fn from(node: Alias) -> Self { +impl From for Ast { + fn from(node: Alias) -> Self { Ast::Alias(node) } } -impl From> for Ast { - fn from(node: WithItem) -> Self { +impl From for Ast { + fn from(node: WithItem) -> Self { Ast::WithItem(node) } } -impl From> for Ast { - fn from(node: MatchCase) -> Self { +impl From for Ast { + fn from(node: MatchCase) -> Self { Ast::MatchCase(node) } } -impl From> for Ast { - fn from(node: Pattern) -> Self { +impl From for Ast { + fn from(node: Pattern) -> Self { Ast::Pattern(node) } } -impl From> for Ast { - fn from(node: TypeIgnore) -> Self { +impl From for Ast { + fn from(node: TypeIgnore) -> Self { Ast::TypeIgnore(node) } } -impl From> for Ast { - fn from(node: TypeParam) -> Self { +impl From for Ast { + fn from(node: TypeParam) -> Self { Ast::TypeParam(node) } } -impl From> for Ast { - fn from(node: Decorator) -> Self { +impl From for Ast { + fn from(node: Decorator) -> Self { Ast::Decorator(node) } } /// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod) #[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum Mod { - Module(ModModule), - Interactive(ModInteractive), - Expression(ModExpression), - FunctionType(ModFunctionType), +pub enum Mod { + Module(ModModule), + Interactive(ModInteractive), + Expression(ModExpression), + FunctionType(ModFunctionType), } /// See also [Module](https://docs.python.org/3/library/ast.html#ast.Module) #[derive(Clone, Debug, PartialEq)] -pub struct ModModule { - pub range: OptionalRange, - pub body: Vec>, - pub type_ignores: Vec>, +pub struct ModModule { + pub range: TextRange, + pub body: Vec, + pub type_ignores: Vec, } -impl Node for ModModule { +impl Node for ModModule { const NAME: &'static str = "Module"; const FIELD_NAMES: &'static [&'static str] = &["body", "type_ignores"]; } -impl From> for Mod { - fn from(payload: ModModule) -> Self { +impl From for Mod { + fn from(payload: ModModule) -> Self { Mod::Module(payload) } } -impl From> for Ast { - fn from(payload: ModModule) -> Self { +impl From for Ast { + fn from(payload: ModModule) -> Self { Mod::from(payload).into() } } /// See also [Interactive](https://docs.python.org/3/library/ast.html#ast.Interactive) #[derive(Clone, Debug, PartialEq)] -pub struct ModInteractive { - pub range: OptionalRange, - pub body: Vec>, +pub struct ModInteractive { + pub range: TextRange, + pub body: Vec, } -impl Node for ModInteractive { +impl Node for ModInteractive { const NAME: &'static str = "Interactive"; const FIELD_NAMES: &'static [&'static str] = &["body"]; } -impl From> for Mod { - fn from(payload: ModInteractive) -> Self { +impl From for Mod { + fn from(payload: ModInteractive) -> Self { Mod::Interactive(payload) } } -impl From> for Ast { - fn from(payload: ModInteractive) -> Self { +impl From for Ast { + fn from(payload: ModInteractive) -> Self { Mod::from(payload).into() } } /// See also [Expression](https://docs.python.org/3/library/ast.html#ast.Expression) #[derive(Clone, Debug, PartialEq)] -pub struct ModExpression { - pub range: OptionalRange, - pub body: Box>, +pub struct ModExpression { + pub range: TextRange, + pub body: Box, } -impl Node for ModExpression { +impl Node for ModExpression { const NAME: &'static str = "Expression"; const FIELD_NAMES: &'static [&'static str] = &["body"]; } -impl From> for Mod { - fn from(payload: ModExpression) -> Self { +impl From for Mod { + fn from(payload: ModExpression) -> Self { Mod::Expression(payload) } } -impl From> for Ast { - fn from(payload: ModExpression) -> Self { +impl From for Ast { + fn from(payload: ModExpression) -> Self { Mod::from(payload).into() } } /// See also [FunctionType](https://docs.python.org/3/library/ast.html#ast.FunctionType) #[derive(Clone, Debug, PartialEq)] -pub struct ModFunctionType { - pub range: OptionalRange, - pub argtypes: Vec>, - pub returns: Box>, +pub struct ModFunctionType { + pub range: TextRange, + pub argtypes: Vec, + pub returns: Box, } -impl Node for ModFunctionType { +impl Node for ModFunctionType { const NAME: &'static str = "FunctionType"; const FIELD_NAMES: &'static [&'static str] = &["argtypes", "returns"]; } -impl From> for Mod { - fn from(payload: ModFunctionType) -> Self { +impl From for Mod { + fn from(payload: ModFunctionType) -> Self { Mod::FunctionType(payload) } } -impl From> for Ast { - fn from(payload: ModFunctionType) -> Self { +impl From for Ast { + fn from(payload: ModFunctionType) -> Self { Mod::from(payload).into() } } -impl Node for Mod { +impl Node for Mod { const NAME: &'static str = "mod"; const FIELD_NAMES: &'static [&'static str] = &[]; } /// See also [stmt](https://docs.python.org/3/library/ast.html#ast.stmt) #[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum Stmt { +pub enum Stmt { #[is(name = "function_def_stmt")] - FunctionDef(StmtFunctionDef), + FunctionDef(StmtFunctionDef), #[is(name = "async_function_def_stmt")] - AsyncFunctionDef(StmtAsyncFunctionDef), + AsyncFunctionDef(StmtAsyncFunctionDef), #[is(name = "class_def_stmt")] - ClassDef(StmtClassDef), + ClassDef(StmtClassDef), #[is(name = "return_stmt")] - Return(StmtReturn), + Return(StmtReturn), #[is(name = "delete_stmt")] - Delete(StmtDelete), + Delete(StmtDelete), #[is(name = "assign_stmt")] - Assign(StmtAssign), + Assign(StmtAssign), #[is(name = "type_alias_stmt")] - TypeAlias(StmtTypeAlias), + TypeAlias(StmtTypeAlias), #[is(name = "aug_assign_stmt")] - AugAssign(StmtAugAssign), + AugAssign(StmtAugAssign), #[is(name = "ann_assign_stmt")] - AnnAssign(StmtAnnAssign), + AnnAssign(StmtAnnAssign), #[is(name = "for_stmt")] - For(StmtFor), + For(StmtFor), #[is(name = "async_for_stmt")] - AsyncFor(StmtAsyncFor), + AsyncFor(StmtAsyncFor), #[is(name = "while_stmt")] - While(StmtWhile), + While(StmtWhile), #[is(name = "if_stmt")] - If(StmtIf), + If(StmtIf), #[is(name = "with_stmt")] - With(StmtWith), + With(StmtWith), #[is(name = "async_with_stmt")] - AsyncWith(StmtAsyncWith), + AsyncWith(StmtAsyncWith), #[is(name = "match_stmt")] - Match(StmtMatch), + Match(StmtMatch), #[is(name = "raise_stmt")] - Raise(StmtRaise), + Raise(StmtRaise), #[is(name = "try_stmt")] - Try(StmtTry), + Try(StmtTry), #[is(name = "try_star_stmt")] - TryStar(StmtTryStar), + TryStar(StmtTryStar), #[is(name = "assert_stmt")] - Assert(StmtAssert), + Assert(StmtAssert), #[is(name = "import_stmt")] - Import(StmtImport), + Import(StmtImport), #[is(name = "import_from_stmt")] - ImportFrom(StmtImportFrom), + ImportFrom(StmtImportFrom), #[is(name = "global_stmt")] - Global(StmtGlobal), + Global(StmtGlobal), #[is(name = "nonlocal_stmt")] - Nonlocal(StmtNonlocal), + Nonlocal(StmtNonlocal), #[is(name = "expr_stmt")] - Expr(StmtExpr), + Expr(StmtExpr), #[is(name = "pass_stmt")] - Pass(StmtPass), + Pass(StmtPass), #[is(name = "break_stmt")] - Break(StmtBreak), + Break(StmtBreak), #[is(name = "continue_stmt")] - Continue(StmtContinue), + Continue(StmtContinue), } /// See also [FunctionDef](https://docs.python.org/3/library/ast.html#ast.FunctionDef) #[derive(Clone, Debug, PartialEq)] -pub struct StmtFunctionDef { - pub range: R, +pub struct StmtFunctionDef { + pub range: TextRange, pub name: Identifier, - pub args: Box>, - pub body: Vec>, - pub decorator_list: Vec>, - pub returns: Option>>, + pub args: Box, + pub body: Vec, + pub decorator_list: Vec, + pub returns: Option>, pub type_comment: Option, - pub type_params: Vec>, + pub type_params: Vec, } -impl Node for StmtFunctionDef { +impl Node for StmtFunctionDef { const NAME: &'static str = "FunctionDef"; const FIELD_NAMES: &'static [&'static str] = &[ "name", @@ -341,31 +341,31 @@ impl Node for StmtFunctionDef { "type_params", ]; } -impl From> for Stmt { - fn from(payload: StmtFunctionDef) -> Self { +impl From for Stmt { + fn from(payload: StmtFunctionDef) -> Self { Stmt::FunctionDef(payload) } } -impl From> for Ast { - fn from(payload: StmtFunctionDef) -> Self { +impl From for Ast { + fn from(payload: StmtFunctionDef) -> Self { Stmt::from(payload).into() } } /// See also [AsyncFunctionDef](https://docs.python.org/3/library/ast.html#ast.AsyncFunctionDef) #[derive(Clone, Debug, PartialEq)] -pub struct StmtAsyncFunctionDef { - pub range: R, +pub struct StmtAsyncFunctionDef { + pub range: TextRange, pub name: Identifier, - pub args: Box>, - pub body: Vec>, - pub decorator_list: Vec>, - pub returns: Option>>, + pub args: Box, + pub body: Vec, + pub decorator_list: Vec, + pub returns: Option>, pub type_comment: Option, - pub type_params: Vec>, + pub type_params: Vec, } -impl Node for StmtAsyncFunctionDef { +impl Node for StmtAsyncFunctionDef { const NAME: &'static str = "AsyncFunctionDef"; const FIELD_NAMES: &'static [&'static str] = &[ "name", @@ -377,30 +377,30 @@ impl Node for StmtAsyncFunctionDef { "type_params", ]; } -impl From> for Stmt { - fn from(payload: StmtAsyncFunctionDef) -> Self { +impl From for Stmt { + fn from(payload: StmtAsyncFunctionDef) -> Self { Stmt::AsyncFunctionDef(payload) } } -impl From> for Ast { - fn from(payload: StmtAsyncFunctionDef) -> Self { +impl From for Ast { + fn from(payload: StmtAsyncFunctionDef) -> Self { Stmt::from(payload).into() } } /// See also [ClassDef](https://docs.python.org/3/library/ast.html#ast.ClassDef) #[derive(Clone, Debug, PartialEq)] -pub struct StmtClassDef { - pub range: R, +pub struct StmtClassDef { + pub range: TextRange, pub name: Identifier, - pub bases: Vec>, - pub keywords: Vec>, - pub body: Vec>, - pub decorator_list: Vec>, - pub type_params: Vec>, + pub bases: Vec, + pub keywords: Vec, + pub body: Vec, + pub decorator_list: Vec, + pub type_params: Vec, } -impl Node for StmtClassDef { +impl Node for StmtClassDef { const NAME: &'static str = "ClassDef"; const FIELD_NAMES: &'static [&'static str] = &[ "name", @@ -411,1292 +411,1292 @@ impl Node for StmtClassDef { "type_params", ]; } -impl From> for Stmt { - fn from(payload: StmtClassDef) -> Self { +impl From for Stmt { + fn from(payload: StmtClassDef) -> Self { Stmt::ClassDef(payload) } } -impl From> for Ast { - fn from(payload: StmtClassDef) -> Self { +impl From for Ast { + fn from(payload: StmtClassDef) -> Self { Stmt::from(payload).into() } } /// See also [Return](https://docs.python.org/3/library/ast.html#ast.Return) #[derive(Clone, Debug, PartialEq)] -pub struct StmtReturn { - pub range: R, - pub value: Option>>, +pub struct StmtReturn { + pub range: TextRange, + pub value: Option>, } -impl Node for StmtReturn { +impl Node for StmtReturn { const NAME: &'static str = "Return"; const FIELD_NAMES: &'static [&'static str] = &["value"]; } -impl From> for Stmt { - fn from(payload: StmtReturn) -> Self { +impl From for Stmt { + fn from(payload: StmtReturn) -> Self { Stmt::Return(payload) } } -impl From> for Ast { - fn from(payload: StmtReturn) -> Self { +impl From for Ast { + fn from(payload: StmtReturn) -> Self { Stmt::from(payload).into() } } /// See also [Delete](https://docs.python.org/3/library/ast.html#ast.Delete) #[derive(Clone, Debug, PartialEq)] -pub struct StmtDelete { - pub range: R, - pub targets: Vec>, +pub struct StmtDelete { + pub range: TextRange, + pub targets: Vec, } -impl Node for StmtDelete { +impl Node for StmtDelete { const NAME: &'static str = "Delete"; const FIELD_NAMES: &'static [&'static str] = &["targets"]; } -impl From> for Stmt { - fn from(payload: StmtDelete) -> Self { +impl From for Stmt { + fn from(payload: StmtDelete) -> Self { Stmt::Delete(payload) } } -impl From> for Ast { - fn from(payload: StmtDelete) -> Self { +impl From for Ast { + fn from(payload: StmtDelete) -> Self { Stmt::from(payload).into() } } /// See also [Assign](https://docs.python.org/3/library/ast.html#ast.Assign) #[derive(Clone, Debug, PartialEq)] -pub struct StmtAssign { - pub range: R, - pub targets: Vec>, - pub value: Box>, +pub struct StmtAssign { + pub range: TextRange, + pub targets: Vec, + pub value: Box, pub type_comment: Option, } -impl Node for StmtAssign { +impl Node for StmtAssign { const NAME: &'static str = "Assign"; const FIELD_NAMES: &'static [&'static str] = &["targets", "value", "type_comment"]; } -impl From> for Stmt { - fn from(payload: StmtAssign) -> Self { +impl From for Stmt { + fn from(payload: StmtAssign) -> Self { Stmt::Assign(payload) } } -impl From> for Ast { - fn from(payload: StmtAssign) -> Self { +impl From for Ast { + fn from(payload: StmtAssign) -> Self { Stmt::from(payload).into() } } /// See also [TypeAlias](https://docs.python.org/3/library/ast.html#ast.TypeAlias) #[derive(Clone, Debug, PartialEq)] -pub struct StmtTypeAlias { - pub range: R, - pub name: Box>, - pub type_params: Vec>, - pub value: Box>, +pub struct StmtTypeAlias { + pub range: TextRange, + pub name: Box, + pub type_params: Vec, + pub value: Box, } -impl Node for StmtTypeAlias { +impl Node for StmtTypeAlias { const NAME: &'static str = "TypeAlias"; const FIELD_NAMES: &'static [&'static str] = &["name", "type_params", "value"]; } -impl From> for Stmt { - fn from(payload: StmtTypeAlias) -> Self { +impl From for Stmt { + fn from(payload: StmtTypeAlias) -> Self { Stmt::TypeAlias(payload) } } -impl From> for Ast { - fn from(payload: StmtTypeAlias) -> Self { +impl From for Ast { + fn from(payload: StmtTypeAlias) -> Self { Stmt::from(payload).into() } } /// See also [AugAssign](https://docs.python.org/3/library/ast.html#ast.AugAssign) #[derive(Clone, Debug, PartialEq)] -pub struct StmtAugAssign { - pub range: R, - pub target: Box>, +pub struct StmtAugAssign { + pub range: TextRange, + pub target: Box, pub op: Operator, - pub value: Box>, + pub value: Box, } -impl Node for StmtAugAssign { +impl Node for StmtAugAssign { const NAME: &'static str = "AugAssign"; const FIELD_NAMES: &'static [&'static str] = &["target", "op", "value"]; } -impl From> for Stmt { - fn from(payload: StmtAugAssign) -> Self { +impl From for Stmt { + fn from(payload: StmtAugAssign) -> Self { Stmt::AugAssign(payload) } } -impl From> for Ast { - fn from(payload: StmtAugAssign) -> Self { +impl From for Ast { + fn from(payload: StmtAugAssign) -> Self { Stmt::from(payload).into() } } /// See also [AnnAssign](https://docs.python.org/3/library/ast.html#ast.AnnAssign) #[derive(Clone, Debug, PartialEq)] -pub struct StmtAnnAssign { - pub range: R, - pub target: Box>, - pub annotation: Box>, - pub value: Option>>, +pub struct StmtAnnAssign { + pub range: TextRange, + pub target: Box, + pub annotation: Box, + pub value: Option>, pub simple: bool, } -impl Node for StmtAnnAssign { +impl Node for StmtAnnAssign { const NAME: &'static str = "AnnAssign"; const FIELD_NAMES: &'static [&'static str] = &["target", "annotation", "value", "simple"]; } -impl From> for Stmt { - fn from(payload: StmtAnnAssign) -> Self { +impl From for Stmt { + fn from(payload: StmtAnnAssign) -> Self { Stmt::AnnAssign(payload) } } -impl From> for Ast { - fn from(payload: StmtAnnAssign) -> Self { +impl From for Ast { + fn from(payload: StmtAnnAssign) -> Self { Stmt::from(payload).into() } } /// See also [For](https://docs.python.org/3/library/ast.html#ast.For) #[derive(Clone, Debug, PartialEq)] -pub struct StmtFor { - pub range: R, - pub target: Box>, - pub iter: Box>, - pub body: Vec>, - pub orelse: Vec>, +pub struct StmtFor { + pub range: TextRange, + pub target: Box, + pub iter: Box, + pub body: Vec, + pub orelse: Vec, pub type_comment: Option, } -impl Node for StmtFor { +impl Node for StmtFor { const NAME: &'static str = "For"; const FIELD_NAMES: &'static [&'static str] = &["target", "iter", "body", "orelse", "type_comment"]; } -impl From> for Stmt { - fn from(payload: StmtFor) -> Self { +impl From for Stmt { + fn from(payload: StmtFor) -> Self { Stmt::For(payload) } } -impl From> for Ast { - fn from(payload: StmtFor) -> Self { +impl From for Ast { + fn from(payload: StmtFor) -> Self { Stmt::from(payload).into() } } /// See also [AsyncFor](https://docs.python.org/3/library/ast.html#ast.AsyncFor) #[derive(Clone, Debug, PartialEq)] -pub struct StmtAsyncFor { - pub range: R, - pub target: Box>, - pub iter: Box>, - pub body: Vec>, - pub orelse: Vec>, +pub struct StmtAsyncFor { + pub range: TextRange, + pub target: Box, + pub iter: Box, + pub body: Vec, + pub orelse: Vec, pub type_comment: Option, } -impl Node for StmtAsyncFor { +impl Node for StmtAsyncFor { const NAME: &'static str = "AsyncFor"; const FIELD_NAMES: &'static [&'static str] = &["target", "iter", "body", "orelse", "type_comment"]; } -impl From> for Stmt { - fn from(payload: StmtAsyncFor) -> Self { +impl From for Stmt { + fn from(payload: StmtAsyncFor) -> Self { Stmt::AsyncFor(payload) } } -impl From> for Ast { - fn from(payload: StmtAsyncFor) -> Self { +impl From for Ast { + fn from(payload: StmtAsyncFor) -> Self { Stmt::from(payload).into() } } /// See also [While](https://docs.python.org/3/library/ast.html#ast.While) #[derive(Clone, Debug, PartialEq)] -pub struct StmtWhile { - pub range: R, - pub test: Box>, - pub body: Vec>, - pub orelse: Vec>, +pub struct StmtWhile { + pub range: TextRange, + pub test: Box, + pub body: Vec, + pub orelse: Vec, } -impl Node for StmtWhile { +impl Node for StmtWhile { const NAME: &'static str = "While"; const FIELD_NAMES: &'static [&'static str] = &["test", "body", "orelse"]; } -impl From> for Stmt { - fn from(payload: StmtWhile) -> Self { +impl From for Stmt { + fn from(payload: StmtWhile) -> Self { Stmt::While(payload) } } -impl From> for Ast { - fn from(payload: StmtWhile) -> Self { +impl From for Ast { + fn from(payload: StmtWhile) -> Self { Stmt::from(payload).into() } } /// See also [If](https://docs.python.org/3/library/ast.html#ast.If) #[derive(Clone, Debug, PartialEq)] -pub struct StmtIf { - pub range: R, - pub test: Box>, - pub body: Vec>, - pub orelse: Vec>, +pub struct StmtIf { + pub range: TextRange, + pub test: Box, + pub body: Vec, + pub orelse: Vec, } -impl Node for StmtIf { +impl Node for StmtIf { const NAME: &'static str = "If"; const FIELD_NAMES: &'static [&'static str] = &["test", "body", "orelse"]; } -impl From> for Stmt { - fn from(payload: StmtIf) -> Self { +impl From for Stmt { + fn from(payload: StmtIf) -> Self { Stmt::If(payload) } } -impl From> for Ast { - fn from(payload: StmtIf) -> Self { +impl From for Ast { + fn from(payload: StmtIf) -> Self { Stmt::from(payload).into() } } /// See also [With](https://docs.python.org/3/library/ast.html#ast.With) #[derive(Clone, Debug, PartialEq)] -pub struct StmtWith { - pub range: R, - pub items: Vec>, - pub body: Vec>, +pub struct StmtWith { + pub range: TextRange, + pub items: Vec, + pub body: Vec, pub type_comment: Option, } -impl Node for StmtWith { +impl Node for StmtWith { const NAME: &'static str = "With"; const FIELD_NAMES: &'static [&'static str] = &["items", "body", "type_comment"]; } -impl From> for Stmt { - fn from(payload: StmtWith) -> Self { +impl From for Stmt { + fn from(payload: StmtWith) -> Self { Stmt::With(payload) } } -impl From> for Ast { - fn from(payload: StmtWith) -> Self { +impl From for Ast { + fn from(payload: StmtWith) -> Self { Stmt::from(payload).into() } } /// See also [AsyncWith](https://docs.python.org/3/library/ast.html#ast.AsyncWith) #[derive(Clone, Debug, PartialEq)] -pub struct StmtAsyncWith { - pub range: R, - pub items: Vec>, - pub body: Vec>, +pub struct StmtAsyncWith { + pub range: TextRange, + pub items: Vec, + pub body: Vec, pub type_comment: Option, } -impl Node for StmtAsyncWith { +impl Node for StmtAsyncWith { const NAME: &'static str = "AsyncWith"; const FIELD_NAMES: &'static [&'static str] = &["items", "body", "type_comment"]; } -impl From> for Stmt { - fn from(payload: StmtAsyncWith) -> Self { +impl From for Stmt { + fn from(payload: StmtAsyncWith) -> Self { Stmt::AsyncWith(payload) } } -impl From> for Ast { - fn from(payload: StmtAsyncWith) -> Self { +impl From for Ast { + fn from(payload: StmtAsyncWith) -> Self { Stmt::from(payload).into() } } /// See also [Match](https://docs.python.org/3/library/ast.html#ast.Match) #[derive(Clone, Debug, PartialEq)] -pub struct StmtMatch { - pub range: R, - pub subject: Box>, - pub cases: Vec>, +pub struct StmtMatch { + pub range: TextRange, + pub subject: Box, + pub cases: Vec, } -impl Node for StmtMatch { +impl Node for StmtMatch { const NAME: &'static str = "Match"; const FIELD_NAMES: &'static [&'static str] = &["subject", "cases"]; } -impl From> for Stmt { - fn from(payload: StmtMatch) -> Self { +impl From for Stmt { + fn from(payload: StmtMatch) -> Self { Stmt::Match(payload) } } -impl From> for Ast { - fn from(payload: StmtMatch) -> Self { +impl From for Ast { + fn from(payload: StmtMatch) -> Self { Stmt::from(payload).into() } } /// See also [Raise](https://docs.python.org/3/library/ast.html#ast.Raise) #[derive(Clone, Debug, PartialEq)] -pub struct StmtRaise { - pub range: R, - pub exc: Option>>, - pub cause: Option>>, +pub struct StmtRaise { + pub range: TextRange, + pub exc: Option>, + pub cause: Option>, } -impl Node for StmtRaise { +impl Node for StmtRaise { const NAME: &'static str = "Raise"; const FIELD_NAMES: &'static [&'static str] = &["exc", "cause"]; } -impl From> for Stmt { - fn from(payload: StmtRaise) -> Self { +impl From for Stmt { + fn from(payload: StmtRaise) -> Self { Stmt::Raise(payload) } } -impl From> for Ast { - fn from(payload: StmtRaise) -> Self { +impl From for Ast { + fn from(payload: StmtRaise) -> Self { Stmt::from(payload).into() } } /// See also [Try](https://docs.python.org/3/library/ast.html#ast.Try) #[derive(Clone, Debug, PartialEq)] -pub struct StmtTry { - pub range: R, - pub body: Vec>, - pub handlers: Vec>, - pub orelse: Vec>, - pub finalbody: Vec>, +pub struct StmtTry { + pub range: TextRange, + pub body: Vec, + pub handlers: Vec, + pub orelse: Vec, + pub finalbody: Vec, } -impl Node for StmtTry { +impl Node for StmtTry { const NAME: &'static str = "Try"; const FIELD_NAMES: &'static [&'static str] = &["body", "handlers", "orelse", "finalbody"]; } -impl From> for Stmt { - fn from(payload: StmtTry) -> Self { +impl From for Stmt { + fn from(payload: StmtTry) -> Self { Stmt::Try(payload) } } -impl From> for Ast { - fn from(payload: StmtTry) -> Self { +impl From for Ast { + fn from(payload: StmtTry) -> Self { Stmt::from(payload).into() } } /// See also [TryStar](https://docs.python.org/3/library/ast.html#ast.TryStar) #[derive(Clone, Debug, PartialEq)] -pub struct StmtTryStar { - pub range: R, - pub body: Vec>, - pub handlers: Vec>, - pub orelse: Vec>, - pub finalbody: Vec>, +pub struct StmtTryStar { + pub range: TextRange, + pub body: Vec, + pub handlers: Vec, + pub orelse: Vec, + pub finalbody: Vec, } -impl Node for StmtTryStar { +impl Node for StmtTryStar { const NAME: &'static str = "TryStar"; const FIELD_NAMES: &'static [&'static str] = &["body", "handlers", "orelse", "finalbody"]; } -impl From> for Stmt { - fn from(payload: StmtTryStar) -> Self { +impl From for Stmt { + fn from(payload: StmtTryStar) -> Self { Stmt::TryStar(payload) } } -impl From> for Ast { - fn from(payload: StmtTryStar) -> Self { +impl From for Ast { + fn from(payload: StmtTryStar) -> Self { Stmt::from(payload).into() } } /// See also [Assert](https://docs.python.org/3/library/ast.html#ast.Assert) #[derive(Clone, Debug, PartialEq)] -pub struct StmtAssert { - pub range: R, - pub test: Box>, - pub msg: Option>>, +pub struct StmtAssert { + pub range: TextRange, + pub test: Box, + pub msg: Option>, } -impl Node for StmtAssert { +impl Node for StmtAssert { const NAME: &'static str = "Assert"; const FIELD_NAMES: &'static [&'static str] = &["test", "msg"]; } -impl From> for Stmt { - fn from(payload: StmtAssert) -> Self { +impl From for Stmt { + fn from(payload: StmtAssert) -> Self { Stmt::Assert(payload) } } -impl From> for Ast { - fn from(payload: StmtAssert) -> Self { +impl From for Ast { + fn from(payload: StmtAssert) -> Self { Stmt::from(payload).into() } } /// See also [Import](https://docs.python.org/3/library/ast.html#ast.Import) #[derive(Clone, Debug, PartialEq)] -pub struct StmtImport { - pub range: R, - pub names: Vec>, +pub struct StmtImport { + pub range: TextRange, + pub names: Vec, } -impl Node for StmtImport { +impl Node for StmtImport { const NAME: &'static str = "Import"; const FIELD_NAMES: &'static [&'static str] = &["names"]; } -impl From> for Stmt { - fn from(payload: StmtImport) -> Self { +impl From for Stmt { + fn from(payload: StmtImport) -> Self { Stmt::Import(payload) } } -impl From> for Ast { - fn from(payload: StmtImport) -> Self { +impl From for Ast { + fn from(payload: StmtImport) -> Self { Stmt::from(payload).into() } } /// See also [ImportFrom](https://docs.python.org/3/library/ast.html#ast.ImportFrom) #[derive(Clone, Debug, PartialEq)] -pub struct StmtImportFrom { - pub range: R, +pub struct StmtImportFrom { + pub range: TextRange, pub module: Option, - pub names: Vec>, + pub names: Vec, pub level: Option, } -impl Node for StmtImportFrom { +impl Node for StmtImportFrom { const NAME: &'static str = "ImportFrom"; const FIELD_NAMES: &'static [&'static str] = &["module", "names", "level"]; } -impl From> for Stmt { - fn from(payload: StmtImportFrom) -> Self { +impl From for Stmt { + fn from(payload: StmtImportFrom) -> Self { Stmt::ImportFrom(payload) } } -impl From> for Ast { - fn from(payload: StmtImportFrom) -> Self { +impl From for Ast { + fn from(payload: StmtImportFrom) -> Self { Stmt::from(payload).into() } } /// See also [Global](https://docs.python.org/3/library/ast.html#ast.Global) #[derive(Clone, Debug, PartialEq)] -pub struct StmtGlobal { - pub range: R, +pub struct StmtGlobal { + pub range: TextRange, pub names: Vec, } -impl Node for StmtGlobal { +impl Node for StmtGlobal { const NAME: &'static str = "Global"; const FIELD_NAMES: &'static [&'static str] = &["names"]; } -impl From> for Stmt { - fn from(payload: StmtGlobal) -> Self { +impl From for Stmt { + fn from(payload: StmtGlobal) -> Self { Stmt::Global(payload) } } -impl From> for Ast { - fn from(payload: StmtGlobal) -> Self { +impl From for Ast { + fn from(payload: StmtGlobal) -> Self { Stmt::from(payload).into() } } /// See also [Nonlocal](https://docs.python.org/3/library/ast.html#ast.Nonlocal) #[derive(Clone, Debug, PartialEq)] -pub struct StmtNonlocal { - pub range: R, +pub struct StmtNonlocal { + pub range: TextRange, pub names: Vec, } -impl Node for StmtNonlocal { +impl Node for StmtNonlocal { const NAME: &'static str = "Nonlocal"; const FIELD_NAMES: &'static [&'static str] = &["names"]; } -impl From> for Stmt { - fn from(payload: StmtNonlocal) -> Self { +impl From for Stmt { + fn from(payload: StmtNonlocal) -> Self { Stmt::Nonlocal(payload) } } -impl From> for Ast { - fn from(payload: StmtNonlocal) -> Self { +impl From for Ast { + fn from(payload: StmtNonlocal) -> Self { Stmt::from(payload).into() } } /// See also [Expr](https://docs.python.org/3/library/ast.html#ast.Expr) #[derive(Clone, Debug, PartialEq)] -pub struct StmtExpr { - pub range: R, - pub value: Box>, +pub struct StmtExpr { + pub range: TextRange, + pub value: Box, } -impl Node for StmtExpr { +impl Node for StmtExpr { const NAME: &'static str = "Expr"; const FIELD_NAMES: &'static [&'static str] = &["value"]; } -impl From> for Stmt { - fn from(payload: StmtExpr) -> Self { +impl From for Stmt { + fn from(payload: StmtExpr) -> Self { Stmt::Expr(payload) } } -impl From> for Ast { - fn from(payload: StmtExpr) -> Self { +impl From for Ast { + fn from(payload: StmtExpr) -> Self { Stmt::from(payload).into() } } /// See also [Pass](https://docs.python.org/3/library/ast.html#ast.Pass) #[derive(Clone, Debug, PartialEq)] -pub struct StmtPass { - pub range: R, +pub struct StmtPass { + pub range: TextRange, } -impl Node for StmtPass { +impl Node for StmtPass { const NAME: &'static str = "Pass"; const FIELD_NAMES: &'static [&'static str] = &[]; } -impl From> for Stmt { - fn from(payload: StmtPass) -> Self { +impl From for Stmt { + fn from(payload: StmtPass) -> Self { Stmt::Pass(payload) } } -impl From> for Ast { - fn from(payload: StmtPass) -> Self { +impl From for Ast { + fn from(payload: StmtPass) -> Self { Stmt::from(payload).into() } } /// See also [Break](https://docs.python.org/3/library/ast.html#ast.Break) #[derive(Clone, Debug, PartialEq)] -pub struct StmtBreak { - pub range: R, +pub struct StmtBreak { + pub range: TextRange, } -impl Node for StmtBreak { +impl Node for StmtBreak { const NAME: &'static str = "Break"; const FIELD_NAMES: &'static [&'static str] = &[]; } -impl From> for Stmt { - fn from(payload: StmtBreak) -> Self { +impl From for Stmt { + fn from(payload: StmtBreak) -> Self { Stmt::Break(payload) } } -impl From> for Ast { - fn from(payload: StmtBreak) -> Self { +impl From for Ast { + fn from(payload: StmtBreak) -> Self { Stmt::from(payload).into() } } /// See also [Continue](https://docs.python.org/3/library/ast.html#ast.Continue) #[derive(Clone, Debug, PartialEq)] -pub struct StmtContinue { - pub range: R, +pub struct StmtContinue { + pub range: TextRange, } -impl Node for StmtContinue { +impl Node for StmtContinue { const NAME: &'static str = "Continue"; const FIELD_NAMES: &'static [&'static str] = &[]; } -impl From> for Stmt { - fn from(payload: StmtContinue) -> Self { +impl From for Stmt { + fn from(payload: StmtContinue) -> Self { Stmt::Continue(payload) } } -impl From> for Ast { - fn from(payload: StmtContinue) -> Self { +impl From for Ast { + fn from(payload: StmtContinue) -> Self { Stmt::from(payload).into() } } -impl Node for Stmt { +impl Node for Stmt { const NAME: &'static str = "stmt"; const FIELD_NAMES: &'static [&'static str] = &[]; } /// See also [expr](https://docs.python.org/3/library/ast.html#ast.expr) #[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum Expr { +pub enum Expr { #[is(name = "bool_op_expr")] - BoolOp(ExprBoolOp), + BoolOp(ExprBoolOp), #[is(name = "named_expr_expr")] - NamedExpr(ExprNamedExpr), + NamedExpr(ExprNamedExpr), #[is(name = "bin_op_expr")] - BinOp(ExprBinOp), + BinOp(ExprBinOp), #[is(name = "unary_op_expr")] - UnaryOp(ExprUnaryOp), + UnaryOp(ExprUnaryOp), #[is(name = "lambda_expr")] - Lambda(ExprLambda), + Lambda(ExprLambda), #[is(name = "if_exp_expr")] - IfExp(ExprIfExp), + IfExp(ExprIfExp), #[is(name = "dict_expr")] - Dict(ExprDict), + Dict(ExprDict), #[is(name = "set_expr")] - Set(ExprSet), + Set(ExprSet), #[is(name = "list_comp_expr")] - ListComp(ExprListComp), + ListComp(ExprListComp), #[is(name = "set_comp_expr")] - SetComp(ExprSetComp), + SetComp(ExprSetComp), #[is(name = "dict_comp_expr")] - DictComp(ExprDictComp), + DictComp(ExprDictComp), #[is(name = "generator_exp_expr")] - GeneratorExp(ExprGeneratorExp), + GeneratorExp(ExprGeneratorExp), #[is(name = "await_expr")] - Await(ExprAwait), + Await(ExprAwait), #[is(name = "yield_expr")] - Yield(ExprYield), + Yield(ExprYield), #[is(name = "yield_from_expr")] - YieldFrom(ExprYieldFrom), + YieldFrom(ExprYieldFrom), #[is(name = "compare_expr")] - Compare(ExprCompare), + Compare(ExprCompare), #[is(name = "call_expr")] - Call(ExprCall), + Call(ExprCall), #[is(name = "formatted_value_expr")] - FormattedValue(ExprFormattedValue), + FormattedValue(ExprFormattedValue), #[is(name = "joined_str_expr")] - JoinedStr(ExprJoinedStr), + JoinedStr(ExprJoinedStr), #[is(name = "constant_expr")] - Constant(ExprConstant), + Constant(ExprConstant), #[is(name = "attribute_expr")] - Attribute(ExprAttribute), + Attribute(ExprAttribute), #[is(name = "subscript_expr")] - Subscript(ExprSubscript), + Subscript(ExprSubscript), #[is(name = "starred_expr")] - Starred(ExprStarred), + Starred(ExprStarred), #[is(name = "name_expr")] - Name(ExprName), + Name(ExprName), #[is(name = "list_expr")] - List(ExprList), + List(ExprList), #[is(name = "tuple_expr")] - Tuple(ExprTuple), + Tuple(ExprTuple), #[is(name = "slice_expr")] - Slice(ExprSlice), + Slice(ExprSlice), } /// See also [BoolOp](https://docs.python.org/3/library/ast.html#ast.BoolOp) #[derive(Clone, Debug, PartialEq)] -pub struct ExprBoolOp { - pub range: R, +pub struct ExprBoolOp { + pub range: TextRange, pub op: BoolOp, - pub values: Vec>, + pub values: Vec, } -impl Node for ExprBoolOp { +impl Node for ExprBoolOp { const NAME: &'static str = "BoolOp"; const FIELD_NAMES: &'static [&'static str] = &["op", "values"]; } -impl From> for Expr { - fn from(payload: ExprBoolOp) -> Self { +impl From for Expr { + fn from(payload: ExprBoolOp) -> Self { Expr::BoolOp(payload) } } -impl From> for Ast { - fn from(payload: ExprBoolOp) -> Self { +impl From for Ast { + fn from(payload: ExprBoolOp) -> Self { Expr::from(payload).into() } } /// See also [NamedExpr](https://docs.python.org/3/library/ast.html#ast.NamedExpr) #[derive(Clone, Debug, PartialEq)] -pub struct ExprNamedExpr { - pub range: R, - pub target: Box>, - pub value: Box>, +pub struct ExprNamedExpr { + pub range: TextRange, + pub target: Box, + pub value: Box, } -impl Node for ExprNamedExpr { +impl Node for ExprNamedExpr { const NAME: &'static str = "NamedExpr"; const FIELD_NAMES: &'static [&'static str] = &["target", "value"]; } -impl From> for Expr { - fn from(payload: ExprNamedExpr) -> Self { +impl From for Expr { + fn from(payload: ExprNamedExpr) -> Self { Expr::NamedExpr(payload) } } -impl From> for Ast { - fn from(payload: ExprNamedExpr) -> Self { +impl From for Ast { + fn from(payload: ExprNamedExpr) -> Self { Expr::from(payload).into() } } /// See also [BinOp](https://docs.python.org/3/library/ast.html#ast.BinOp) #[derive(Clone, Debug, PartialEq)] -pub struct ExprBinOp { - pub range: R, - pub left: Box>, +pub struct ExprBinOp { + pub range: TextRange, + pub left: Box, pub op: Operator, - pub right: Box>, + pub right: Box, } -impl Node for ExprBinOp { +impl Node for ExprBinOp { const NAME: &'static str = "BinOp"; const FIELD_NAMES: &'static [&'static str] = &["left", "op", "right"]; } -impl From> for Expr { - fn from(payload: ExprBinOp) -> Self { +impl From for Expr { + fn from(payload: ExprBinOp) -> Self { Expr::BinOp(payload) } } -impl From> for Ast { - fn from(payload: ExprBinOp) -> Self { +impl From for Ast { + fn from(payload: ExprBinOp) -> Self { Expr::from(payload).into() } } /// See also [UnaryOp](https://docs.python.org/3/library/ast.html#ast.UnaryOp) #[derive(Clone, Debug, PartialEq)] -pub struct ExprUnaryOp { - pub range: R, +pub struct ExprUnaryOp { + pub range: TextRange, pub op: UnaryOp, - pub operand: Box>, + pub operand: Box, } -impl Node for ExprUnaryOp { +impl Node for ExprUnaryOp { const NAME: &'static str = "UnaryOp"; const FIELD_NAMES: &'static [&'static str] = &["op", "operand"]; } -impl From> for Expr { - fn from(payload: ExprUnaryOp) -> Self { +impl From for Expr { + fn from(payload: ExprUnaryOp) -> Self { Expr::UnaryOp(payload) } } -impl From> for Ast { - fn from(payload: ExprUnaryOp) -> Self { +impl From for Ast { + fn from(payload: ExprUnaryOp) -> Self { Expr::from(payload).into() } } /// See also [Lambda](https://docs.python.org/3/library/ast.html#ast.Lambda) #[derive(Clone, Debug, PartialEq)] -pub struct ExprLambda { - pub range: R, - pub args: Box>, - pub body: Box>, +pub struct ExprLambda { + pub range: TextRange, + pub args: Box, + pub body: Box, } -impl Node for ExprLambda { +impl Node for ExprLambda { const NAME: &'static str = "Lambda"; const FIELD_NAMES: &'static [&'static str] = &["args", "body"]; } -impl From> for Expr { - fn from(payload: ExprLambda) -> Self { +impl From for Expr { + fn from(payload: ExprLambda) -> Self { Expr::Lambda(payload) } } -impl From> for Ast { - fn from(payload: ExprLambda) -> Self { +impl From for Ast { + fn from(payload: ExprLambda) -> Self { Expr::from(payload).into() } } /// See also [IfExp](https://docs.python.org/3/library/ast.html#ast.IfExp) #[derive(Clone, Debug, PartialEq)] -pub struct ExprIfExp { - pub range: R, - pub test: Box>, - pub body: Box>, - pub orelse: Box>, +pub struct ExprIfExp { + pub range: TextRange, + pub test: Box, + pub body: Box, + pub orelse: Box, } -impl Node for ExprIfExp { +impl Node for ExprIfExp { const NAME: &'static str = "IfExp"; const FIELD_NAMES: &'static [&'static str] = &["test", "body", "orelse"]; } -impl From> for Expr { - fn from(payload: ExprIfExp) -> Self { +impl From for Expr { + fn from(payload: ExprIfExp) -> Self { Expr::IfExp(payload) } } -impl From> for Ast { - fn from(payload: ExprIfExp) -> Self { +impl From for Ast { + fn from(payload: ExprIfExp) -> Self { Expr::from(payload).into() } } /// See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict) #[derive(Clone, Debug, PartialEq)] -pub struct ExprDict { - pub range: R, - pub keys: Vec>>, - pub values: Vec>, +pub struct ExprDict { + pub range: TextRange, + pub keys: Vec>, + pub values: Vec, } -impl Node for ExprDict { +impl Node for ExprDict { const NAME: &'static str = "Dict"; const FIELD_NAMES: &'static [&'static str] = &["keys", "values"]; } -impl From> for Expr { - fn from(payload: ExprDict) -> Self { +impl From for Expr { + fn from(payload: ExprDict) -> Self { Expr::Dict(payload) } } -impl From> for Ast { - fn from(payload: ExprDict) -> Self { +impl From for Ast { + fn from(payload: ExprDict) -> Self { Expr::from(payload).into() } } /// See also [Set](https://docs.python.org/3/library/ast.html#ast.Set) #[derive(Clone, Debug, PartialEq)] -pub struct ExprSet { - pub range: R, - pub elts: Vec>, +pub struct ExprSet { + pub range: TextRange, + pub elts: Vec, } -impl Node for ExprSet { +impl Node for ExprSet { const NAME: &'static str = "Set"; const FIELD_NAMES: &'static [&'static str] = &["elts"]; } -impl From> for Expr { - fn from(payload: ExprSet) -> Self { +impl From for Expr { + fn from(payload: ExprSet) -> Self { Expr::Set(payload) } } -impl From> for Ast { - fn from(payload: ExprSet) -> Self { +impl From for Ast { + fn from(payload: ExprSet) -> Self { Expr::from(payload).into() } } /// See also [ListComp](https://docs.python.org/3/library/ast.html#ast.ListComp) #[derive(Clone, Debug, PartialEq)] -pub struct ExprListComp { - pub range: R, - pub elt: Box>, - pub generators: Vec>, +pub struct ExprListComp { + pub range: TextRange, + pub elt: Box, + pub generators: Vec, } -impl Node for ExprListComp { +impl Node for ExprListComp { const NAME: &'static str = "ListComp"; const FIELD_NAMES: &'static [&'static str] = &["elt", "generators"]; } -impl From> for Expr { - fn from(payload: ExprListComp) -> Self { +impl From for Expr { + fn from(payload: ExprListComp) -> Self { Expr::ListComp(payload) } } -impl From> for Ast { - fn from(payload: ExprListComp) -> Self { +impl From for Ast { + fn from(payload: ExprListComp) -> Self { Expr::from(payload).into() } } /// See also [SetComp](https://docs.python.org/3/library/ast.html#ast.SetComp) #[derive(Clone, Debug, PartialEq)] -pub struct ExprSetComp { - pub range: R, - pub elt: Box>, - pub generators: Vec>, +pub struct ExprSetComp { + pub range: TextRange, + pub elt: Box, + pub generators: Vec, } -impl Node for ExprSetComp { +impl Node for ExprSetComp { const NAME: &'static str = "SetComp"; const FIELD_NAMES: &'static [&'static str] = &["elt", "generators"]; } -impl From> for Expr { - fn from(payload: ExprSetComp) -> Self { +impl From for Expr { + fn from(payload: ExprSetComp) -> Self { Expr::SetComp(payload) } } -impl From> for Ast { - fn from(payload: ExprSetComp) -> Self { +impl From for Ast { + fn from(payload: ExprSetComp) -> Self { Expr::from(payload).into() } } /// See also [DictComp](https://docs.python.org/3/library/ast.html#ast.DictComp) #[derive(Clone, Debug, PartialEq)] -pub struct ExprDictComp { - pub range: R, - pub key: Box>, - pub value: Box>, - pub generators: Vec>, +pub struct ExprDictComp { + pub range: TextRange, + pub key: Box, + pub value: Box, + pub generators: Vec, } -impl Node for ExprDictComp { +impl Node for ExprDictComp { const NAME: &'static str = "DictComp"; const FIELD_NAMES: &'static [&'static str] = &["key", "value", "generators"]; } -impl From> for Expr { - fn from(payload: ExprDictComp) -> Self { +impl From for Expr { + fn from(payload: ExprDictComp) -> Self { Expr::DictComp(payload) } } -impl From> for Ast { - fn from(payload: ExprDictComp) -> Self { +impl From for Ast { + fn from(payload: ExprDictComp) -> Self { Expr::from(payload).into() } } /// See also [GeneratorExp](https://docs.python.org/3/library/ast.html#ast.GeneratorExp) #[derive(Clone, Debug, PartialEq)] -pub struct ExprGeneratorExp { - pub range: R, - pub elt: Box>, - pub generators: Vec>, +pub struct ExprGeneratorExp { + pub range: TextRange, + pub elt: Box, + pub generators: Vec, } -impl Node for ExprGeneratorExp { +impl Node for ExprGeneratorExp { const NAME: &'static str = "GeneratorExp"; const FIELD_NAMES: &'static [&'static str] = &["elt", "generators"]; } -impl From> for Expr { - fn from(payload: ExprGeneratorExp) -> Self { +impl From for Expr { + fn from(payload: ExprGeneratorExp) -> Self { Expr::GeneratorExp(payload) } } -impl From> for Ast { - fn from(payload: ExprGeneratorExp) -> Self { +impl From for Ast { + fn from(payload: ExprGeneratorExp) -> Self { Expr::from(payload).into() } } /// See also [Await](https://docs.python.org/3/library/ast.html#ast.Await) #[derive(Clone, Debug, PartialEq)] -pub struct ExprAwait { - pub range: R, - pub value: Box>, +pub struct ExprAwait { + pub range: TextRange, + pub value: Box, } -impl Node for ExprAwait { +impl Node for ExprAwait { const NAME: &'static str = "Await"; const FIELD_NAMES: &'static [&'static str] = &["value"]; } -impl From> for Expr { - fn from(payload: ExprAwait) -> Self { +impl From for Expr { + fn from(payload: ExprAwait) -> Self { Expr::Await(payload) } } -impl From> for Ast { - fn from(payload: ExprAwait) -> Self { +impl From for Ast { + fn from(payload: ExprAwait) -> Self { Expr::from(payload).into() } } /// See also [Yield](https://docs.python.org/3/library/ast.html#ast.Yield) #[derive(Clone, Debug, PartialEq)] -pub struct ExprYield { - pub range: R, - pub value: Option>>, +pub struct ExprYield { + pub range: TextRange, + pub value: Option>, } -impl Node for ExprYield { +impl Node for ExprYield { const NAME: &'static str = "Yield"; const FIELD_NAMES: &'static [&'static str] = &["value"]; } -impl From> for Expr { - fn from(payload: ExprYield) -> Self { +impl From for Expr { + fn from(payload: ExprYield) -> Self { Expr::Yield(payload) } } -impl From> for Ast { - fn from(payload: ExprYield) -> Self { +impl From for Ast { + fn from(payload: ExprYield) -> Self { Expr::from(payload).into() } } /// See also [YieldFrom](https://docs.python.org/3/library/ast.html#ast.YieldFrom) #[derive(Clone, Debug, PartialEq)] -pub struct ExprYieldFrom { - pub range: R, - pub value: Box>, +pub struct ExprYieldFrom { + pub range: TextRange, + pub value: Box, } -impl Node for ExprYieldFrom { +impl Node for ExprYieldFrom { const NAME: &'static str = "YieldFrom"; const FIELD_NAMES: &'static [&'static str] = &["value"]; } -impl From> for Expr { - fn from(payload: ExprYieldFrom) -> Self { +impl From for Expr { + fn from(payload: ExprYieldFrom) -> Self { Expr::YieldFrom(payload) } } -impl From> for Ast { - fn from(payload: ExprYieldFrom) -> Self { +impl From for Ast { + fn from(payload: ExprYieldFrom) -> Self { Expr::from(payload).into() } } /// See also [Compare](https://docs.python.org/3/library/ast.html#ast.Compare) #[derive(Clone, Debug, PartialEq)] -pub struct ExprCompare { - pub range: R, - pub left: Box>, +pub struct ExprCompare { + pub range: TextRange, + pub left: Box, pub ops: Vec, - pub comparators: Vec>, + pub comparators: Vec, } -impl Node for ExprCompare { +impl Node for ExprCompare { const NAME: &'static str = "Compare"; const FIELD_NAMES: &'static [&'static str] = &["left", "ops", "comparators"]; } -impl From> for Expr { - fn from(payload: ExprCompare) -> Self { +impl From for Expr { + fn from(payload: ExprCompare) -> Self { Expr::Compare(payload) } } -impl From> for Ast { - fn from(payload: ExprCompare) -> Self { +impl From for Ast { + fn from(payload: ExprCompare) -> Self { Expr::from(payload).into() } } /// See also [Call](https://docs.python.org/3/library/ast.html#ast.Call) #[derive(Clone, Debug, PartialEq)] -pub struct ExprCall { - pub range: R, - pub func: Box>, - pub args: Vec>, - pub keywords: Vec>, +pub struct ExprCall { + pub range: TextRange, + pub func: Box, + pub args: Vec, + pub keywords: Vec, } -impl Node for ExprCall { +impl Node for ExprCall { const NAME: &'static str = "Call"; const FIELD_NAMES: &'static [&'static str] = &["func", "args", "keywords"]; } -impl From> for Expr { - fn from(payload: ExprCall) -> Self { +impl From for Expr { + fn from(payload: ExprCall) -> Self { Expr::Call(payload) } } -impl From> for Ast { - fn from(payload: ExprCall) -> Self { +impl From for Ast { + fn from(payload: ExprCall) -> Self { Expr::from(payload).into() } } /// See also [FormattedValue](https://docs.python.org/3/library/ast.html#ast.FormattedValue) #[derive(Clone, Debug, PartialEq)] -pub struct ExprFormattedValue { - pub range: R, - pub value: Box>, +pub struct ExprFormattedValue { + pub range: TextRange, + pub value: Box, pub conversion: ConversionFlag, - pub format_spec: Option>>, + pub format_spec: Option>, } -impl Node for ExprFormattedValue { +impl Node for ExprFormattedValue { const NAME: &'static str = "FormattedValue"; const FIELD_NAMES: &'static [&'static str] = &["value", "conversion", "format_spec"]; } -impl From> for Expr { - fn from(payload: ExprFormattedValue) -> Self { +impl From for Expr { + fn from(payload: ExprFormattedValue) -> Self { Expr::FormattedValue(payload) } } -impl From> for Ast { - fn from(payload: ExprFormattedValue) -> Self { +impl From for Ast { + fn from(payload: ExprFormattedValue) -> Self { Expr::from(payload).into() } } /// See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr) #[derive(Clone, Debug, PartialEq)] -pub struct ExprJoinedStr { - pub range: R, - pub values: Vec>, +pub struct ExprJoinedStr { + pub range: TextRange, + pub values: Vec, } -impl Node for ExprJoinedStr { +impl Node for ExprJoinedStr { const NAME: &'static str = "JoinedStr"; const FIELD_NAMES: &'static [&'static str] = &["values"]; } -impl From> for Expr { - fn from(payload: ExprJoinedStr) -> Self { +impl From for Expr { + fn from(payload: ExprJoinedStr) -> Self { Expr::JoinedStr(payload) } } -impl From> for Ast { - fn from(payload: ExprJoinedStr) -> Self { +impl From for Ast { + fn from(payload: ExprJoinedStr) -> Self { Expr::from(payload).into() } } /// See also [Constant](https://docs.python.org/3/library/ast.html#ast.Constant) #[derive(Clone, Debug, PartialEq)] -pub struct ExprConstant { - pub range: R, +pub struct ExprConstant { + pub range: TextRange, pub value: Constant, pub kind: Option, } -impl Node for ExprConstant { +impl Node for ExprConstant { const NAME: &'static str = "Constant"; const FIELD_NAMES: &'static [&'static str] = &["value", "kind"]; } -impl From> for Expr { - fn from(payload: ExprConstant) -> Self { +impl From for Expr { + fn from(payload: ExprConstant) -> Self { Expr::Constant(payload) } } -impl From> for Ast { - fn from(payload: ExprConstant) -> Self { +impl From for Ast { + fn from(payload: ExprConstant) -> Self { Expr::from(payload).into() } } /// See also [Attribute](https://docs.python.org/3/library/ast.html#ast.Attribute) #[derive(Clone, Debug, PartialEq)] -pub struct ExprAttribute { - pub range: R, - pub value: Box>, +pub struct ExprAttribute { + pub range: TextRange, + pub value: Box, pub attr: Identifier, pub ctx: ExprContext, } -impl Node for ExprAttribute { +impl Node for ExprAttribute { const NAME: &'static str = "Attribute"; const FIELD_NAMES: &'static [&'static str] = &["value", "attr", "ctx"]; } -impl From> for Expr { - fn from(payload: ExprAttribute) -> Self { +impl From for Expr { + fn from(payload: ExprAttribute) -> Self { Expr::Attribute(payload) } } -impl From> for Ast { - fn from(payload: ExprAttribute) -> Self { +impl From for Ast { + fn from(payload: ExprAttribute) -> Self { Expr::from(payload).into() } } /// See also [Subscript](https://docs.python.org/3/library/ast.html#ast.Subscript) #[derive(Clone, Debug, PartialEq)] -pub struct ExprSubscript { - pub range: R, - pub value: Box>, - pub slice: Box>, +pub struct ExprSubscript { + pub range: TextRange, + pub value: Box, + pub slice: Box, pub ctx: ExprContext, } -impl Node for ExprSubscript { +impl Node for ExprSubscript { const NAME: &'static str = "Subscript"; const FIELD_NAMES: &'static [&'static str] = &["value", "slice", "ctx"]; } -impl From> for Expr { - fn from(payload: ExprSubscript) -> Self { +impl From for Expr { + fn from(payload: ExprSubscript) -> Self { Expr::Subscript(payload) } } -impl From> for Ast { - fn from(payload: ExprSubscript) -> Self { +impl From for Ast { + fn from(payload: ExprSubscript) -> Self { Expr::from(payload).into() } } /// See also [Starred](https://docs.python.org/3/library/ast.html#ast.Starred) #[derive(Clone, Debug, PartialEq)] -pub struct ExprStarred { - pub range: R, - pub value: Box>, +pub struct ExprStarred { + pub range: TextRange, + pub value: Box, pub ctx: ExprContext, } -impl Node for ExprStarred { +impl Node for ExprStarred { const NAME: &'static str = "Starred"; const FIELD_NAMES: &'static [&'static str] = &["value", "ctx"]; } -impl From> for Expr { - fn from(payload: ExprStarred) -> Self { +impl From for Expr { + fn from(payload: ExprStarred) -> Self { Expr::Starred(payload) } } -impl From> for Ast { - fn from(payload: ExprStarred) -> Self { +impl From for Ast { + fn from(payload: ExprStarred) -> Self { Expr::from(payload).into() } } /// See also [Name](https://docs.python.org/3/library/ast.html#ast.Name) #[derive(Clone, Debug, PartialEq)] -pub struct ExprName { - pub range: R, +pub struct ExprName { + pub range: TextRange, pub id: String, pub ctx: ExprContext, } -impl Node for ExprName { +impl Node for ExprName { const NAME: &'static str = "Name"; const FIELD_NAMES: &'static [&'static str] = &["id", "ctx"]; } -impl From> for Expr { - fn from(payload: ExprName) -> Self { +impl From for Expr { + fn from(payload: ExprName) -> Self { Expr::Name(payload) } } -impl From> for Ast { - fn from(payload: ExprName) -> Self { +impl From for Ast { + fn from(payload: ExprName) -> Self { Expr::from(payload).into() } } /// See also [List](https://docs.python.org/3/library/ast.html#ast.List) #[derive(Clone, Debug, PartialEq)] -pub struct ExprList { - pub range: R, - pub elts: Vec>, +pub struct ExprList { + pub range: TextRange, + pub elts: Vec, pub ctx: ExprContext, } -impl Node for ExprList { +impl Node for ExprList { const NAME: &'static str = "List"; const FIELD_NAMES: &'static [&'static str] = &["elts", "ctx"]; } -impl From> for Expr { - fn from(payload: ExprList) -> Self { +impl From for Expr { + fn from(payload: ExprList) -> Self { Expr::List(payload) } } -impl From> for Ast { - fn from(payload: ExprList) -> Self { +impl From for Ast { + fn from(payload: ExprList) -> Self { Expr::from(payload).into() } } /// See also [Tuple](https://docs.python.org/3/library/ast.html#ast.Tuple) #[derive(Clone, Debug, PartialEq)] -pub struct ExprTuple { - pub range: R, - pub elts: Vec>, +pub struct ExprTuple { + pub range: TextRange, + pub elts: Vec, pub ctx: ExprContext, } -impl Node for ExprTuple { +impl Node for ExprTuple { const NAME: &'static str = "Tuple"; const FIELD_NAMES: &'static [&'static str] = &["elts", "ctx"]; } -impl From> for Expr { - fn from(payload: ExprTuple) -> Self { +impl From for Expr { + fn from(payload: ExprTuple) -> Self { Expr::Tuple(payload) } } -impl From> for Ast { - fn from(payload: ExprTuple) -> Self { +impl From for Ast { + fn from(payload: ExprTuple) -> Self { Expr::from(payload).into() } } /// See also [Slice](https://docs.python.org/3/library/ast.html#ast.Slice) #[derive(Clone, Debug, PartialEq)] -pub struct ExprSlice { - pub range: R, - pub lower: Option>>, - pub upper: Option>>, - pub step: Option>>, +pub struct ExprSlice { + pub range: TextRange, + pub lower: Option>, + pub upper: Option>, + pub step: Option>, } -impl Node for ExprSlice { +impl Node for ExprSlice { const NAME: &'static str = "Slice"; const FIELD_NAMES: &'static [&'static str] = &["lower", "upper", "step"]; } -impl From> for Expr { - fn from(payload: ExprSlice) -> Self { +impl From for Expr { + fn from(payload: ExprSlice) -> Self { Expr::Slice(payload) } } -impl From> for Ast { - fn from(payload: ExprSlice) -> Self { +impl From for Ast { + fn from(payload: ExprSlice) -> Self { Expr::from(payload).into() } } -impl Node for Expr { +impl Node for Expr { const NAME: &'static str = "expr"; const FIELD_NAMES: &'static [&'static str] = &[]; } @@ -1740,7 +1740,7 @@ impl From for ExprContext { ExprContext::Load } } -impl From for Ast { +impl From for Ast { fn from(_: ExprContextLoad) -> Self { ExprContext::Load.into() } @@ -1762,7 +1762,7 @@ impl From for ExprContext { ExprContext::Store } } -impl From for Ast { +impl From for Ast { fn from(_: ExprContextStore) -> Self { ExprContext::Store.into() } @@ -1784,7 +1784,7 @@ impl From for ExprContext { ExprContext::Del } } -impl From for Ast { +impl From for Ast { fn from(_: ExprContextDel) -> Self { ExprContext::Del.into() } @@ -1835,7 +1835,7 @@ impl From for BoolOp { BoolOp::And } } -impl From for Ast { +impl From for Ast { fn from(_: BoolOpAnd) -> Self { BoolOp::And.into() } @@ -1857,7 +1857,7 @@ impl From for BoolOp { BoolOp::Or } } -impl From for Ast { +impl From for Ast { fn from(_: BoolOpOr) -> Self { BoolOp::Or.into() } @@ -2007,7 +2007,7 @@ impl From for Operator { Operator::Add } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorAdd) -> Self { Operator::Add.into() } @@ -2029,7 +2029,7 @@ impl From for Operator { Operator::Sub } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorSub) -> Self { Operator::Sub.into() } @@ -2051,7 +2051,7 @@ impl From for Operator { Operator::Mult } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorMult) -> Self { Operator::Mult.into() } @@ -2073,7 +2073,7 @@ impl From for Operator { Operator::MatMult } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorMatMult) -> Self { Operator::MatMult.into() } @@ -2095,7 +2095,7 @@ impl From for Operator { Operator::Div } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorDiv) -> Self { Operator::Div.into() } @@ -2117,7 +2117,7 @@ impl From for Operator { Operator::Mod } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorMod) -> Self { Operator::Mod.into() } @@ -2139,7 +2139,7 @@ impl From for Operator { Operator::Pow } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorPow) -> Self { Operator::Pow.into() } @@ -2161,7 +2161,7 @@ impl From for Operator { Operator::LShift } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorLShift) -> Self { Operator::LShift.into() } @@ -2183,7 +2183,7 @@ impl From for Operator { Operator::RShift } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorRShift) -> Self { Operator::RShift.into() } @@ -2205,7 +2205,7 @@ impl From for Operator { Operator::BitOr } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorBitOr) -> Self { Operator::BitOr.into() } @@ -2227,7 +2227,7 @@ impl From for Operator { Operator::BitXor } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorBitXor) -> Self { Operator::BitXor.into() } @@ -2249,7 +2249,7 @@ impl From for Operator { Operator::BitAnd } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorBitAnd) -> Self { Operator::BitAnd.into() } @@ -2271,7 +2271,7 @@ impl From for Operator { Operator::FloorDiv } } -impl From for Ast { +impl From for Ast { fn from(_: OperatorFloorDiv) -> Self { Operator::FloorDiv.into() } @@ -2340,7 +2340,7 @@ impl From for UnaryOp { UnaryOp::Invert } } -impl From for Ast { +impl From for Ast { fn from(_: UnaryOpInvert) -> Self { UnaryOp::Invert.into() } @@ -2362,7 +2362,7 @@ impl From for UnaryOp { UnaryOp::Not } } -impl From for Ast { +impl From for Ast { fn from(_: UnaryOpNot) -> Self { UnaryOp::Not.into() } @@ -2384,7 +2384,7 @@ impl From for UnaryOp { UnaryOp::UAdd } } -impl From for Ast { +impl From for Ast { fn from(_: UnaryOpUAdd) -> Self { UnaryOp::UAdd.into() } @@ -2406,7 +2406,7 @@ impl From for UnaryOp { UnaryOp::USub } } -impl From for Ast { +impl From for Ast { fn from(_: UnaryOpUSub) -> Self { UnaryOp::USub.into() } @@ -2529,7 +2529,7 @@ impl From for CmpOp { CmpOp::Eq } } -impl From for Ast { +impl From for Ast { fn from(_: CmpOpEq) -> Self { CmpOp::Eq.into() } @@ -2551,7 +2551,7 @@ impl From for CmpOp { CmpOp::NotEq } } -impl From for Ast { +impl From for Ast { fn from(_: CmpOpNotEq) -> Self { CmpOp::NotEq.into() } @@ -2573,7 +2573,7 @@ impl From for CmpOp { CmpOp::Lt } } -impl From for Ast { +impl From for Ast { fn from(_: CmpOpLt) -> Self { CmpOp::Lt.into() } @@ -2595,7 +2595,7 @@ impl From for CmpOp { CmpOp::LtE } } -impl From for Ast { +impl From for Ast { fn from(_: CmpOpLtE) -> Self { CmpOp::LtE.into() } @@ -2617,7 +2617,7 @@ impl From for CmpOp { CmpOp::Gt } } -impl From for Ast { +impl From for Ast { fn from(_: CmpOpGt) -> Self { CmpOp::Gt.into() } @@ -2639,7 +2639,7 @@ impl From for CmpOp { CmpOp::GtE } } -impl From for Ast { +impl From for Ast { fn from(_: CmpOpGtE) -> Self { CmpOp::GtE.into() } @@ -2661,7 +2661,7 @@ impl From for CmpOp { CmpOp::Is } } -impl From for Ast { +impl From for Ast { fn from(_: CmpOpIs) -> Self { CmpOp::Is.into() } @@ -2683,7 +2683,7 @@ impl From for CmpOp { CmpOp::IsNot } } -impl From for Ast { +impl From for Ast { fn from(_: CmpOpIsNot) -> Self { CmpOp::IsNot.into() } @@ -2705,7 +2705,7 @@ impl From for CmpOp { CmpOp::In } } -impl From for Ast { +impl From for Ast { fn from(_: CmpOpIn) -> Self { CmpOp::In.into() } @@ -2727,7 +2727,7 @@ impl From for CmpOp { CmpOp::NotIn } } -impl From for Ast { +impl From for Ast { fn from(_: CmpOpNotIn) -> Self { CmpOp::NotIn.into() } @@ -2750,68 +2750,68 @@ impl Node for CmpOp { /// See also [comprehension](https://docs.python.org/3/library/ast.html#ast.comprehension) #[derive(Clone, Debug, PartialEq)] -pub struct Comprehension { - pub range: OptionalRange, - pub target: Expr, - pub iter: Expr, - pub ifs: Vec>, +pub struct Comprehension { + pub range: TextRange, + pub target: Expr, + pub iter: Expr, + pub ifs: Vec, pub is_async: bool, } -impl Node for Comprehension { +impl Node for Comprehension { const NAME: &'static str = "comprehension"; const FIELD_NAMES: &'static [&'static str] = &["target", "iter", "ifs", "is_async"]; } /// See also [excepthandler](https://docs.python.org/3/library/ast.html#ast.excepthandler) #[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum ExceptHandler { - ExceptHandler(ExceptHandlerExceptHandler), +pub enum ExceptHandler { + ExceptHandler(ExceptHandlerExceptHandler), } /// See also [ExceptHandler](https://docs.python.org/3/library/ast.html#ast.ExceptHandler) #[derive(Clone, Debug, PartialEq)] -pub struct ExceptHandlerExceptHandler { - pub range: R, - pub type_: Option>>, +pub struct ExceptHandlerExceptHandler { + pub range: TextRange, + pub type_: Option>, pub name: Option, - pub body: Vec>, + pub body: Vec, } -impl Node for ExceptHandlerExceptHandler { +impl Node for ExceptHandlerExceptHandler { const NAME: &'static str = "ExceptHandler"; const FIELD_NAMES: &'static [&'static str] = &["type", "name", "body"]; } -impl From> for ExceptHandler { - fn from(payload: ExceptHandlerExceptHandler) -> Self { +impl From for ExceptHandler { + fn from(payload: ExceptHandlerExceptHandler) -> Self { ExceptHandler::ExceptHandler(payload) } } -impl From> for Ast { - fn from(payload: ExceptHandlerExceptHandler) -> Self { +impl From for Ast { + fn from(payload: ExceptHandlerExceptHandler) -> Self { ExceptHandler::from(payload).into() } } -impl Node for ExceptHandler { +impl Node for ExceptHandler { const NAME: &'static str = "excepthandler"; const FIELD_NAMES: &'static [&'static str] = &[]; } /// See also [arguments](https://docs.python.org/3/library/ast.html#ast.arguments) #[derive(Clone, Debug, PartialEq)] -pub struct PythonArguments { - pub range: OptionalRange, - pub posonlyargs: Vec>, - pub args: Vec>, - pub vararg: Option>>, - pub kwonlyargs: Vec>, - pub kw_defaults: Vec>, - pub kwarg: Option>>, - pub defaults: Vec>, +pub struct PythonArguments { + pub range: TextRange, + pub posonlyargs: Vec, + pub args: Vec, + pub vararg: Option>, + pub kwonlyargs: Vec, + pub kw_defaults: Vec, + pub kwarg: Option>, + pub defaults: Vec, } -impl Node for PythonArguments { +impl Node for PythonArguments { const NAME: &'static str = "arguments"; const FIELD_NAMES: &'static [&'static str] = &[ "posonlyargs", @@ -2826,393 +2826,393 @@ impl Node for PythonArguments { /// See also [arg](https://docs.python.org/3/library/ast.html#ast.arg) #[derive(Clone, Debug, PartialEq)] -pub struct Arg { - pub range: R, +pub struct Arg { + pub range: TextRange, pub arg: Identifier, - pub annotation: Option>>, + pub annotation: Option>, pub type_comment: Option, } -impl Node for Arg { +impl Node for Arg { const NAME: &'static str = "arg"; const FIELD_NAMES: &'static [&'static str] = &["arg", "annotation", "type_comment"]; } /// See also [keyword](https://docs.python.org/3/library/ast.html#ast.keyword) #[derive(Clone, Debug, PartialEq)] -pub struct Keyword { - pub range: R, +pub struct Keyword { + pub range: TextRange, pub arg: Option, - pub value: Expr, + pub value: Expr, } -impl Node for Keyword { +impl Node for Keyword { const NAME: &'static str = "keyword"; const FIELD_NAMES: &'static [&'static str] = &["arg", "value"]; } /// See also [alias](https://docs.python.org/3/library/ast.html#ast.alias) #[derive(Clone, Debug, PartialEq)] -pub struct Alias { - pub range: R, +pub struct Alias { + pub range: TextRange, pub name: Identifier, pub asname: Option, } -impl Node for Alias { +impl Node for Alias { const NAME: &'static str = "alias"; const FIELD_NAMES: &'static [&'static str] = &["name", "asname"]; } /// See also [withitem](https://docs.python.org/3/library/ast.html#ast.withitem) #[derive(Clone, Debug, PartialEq)] -pub struct WithItem { - pub range: OptionalRange, - pub context_expr: Expr, - pub optional_vars: Option>>, +pub struct WithItem { + pub range: TextRange, + pub context_expr: Expr, + pub optional_vars: Option>, } -impl Node for WithItem { +impl Node for WithItem { const NAME: &'static str = "withitem"; const FIELD_NAMES: &'static [&'static str] = &["context_expr", "optional_vars"]; } /// See also [match_case](https://docs.python.org/3/library/ast.html#ast.match_case) #[derive(Clone, Debug, PartialEq)] -pub struct MatchCase { - pub range: OptionalRange, - pub pattern: Pattern, - pub guard: Option>>, - pub body: Vec>, +pub struct MatchCase { + pub range: TextRange, + pub pattern: Pattern, + pub guard: Option>, + pub body: Vec, } -impl Node for MatchCase { +impl Node for MatchCase { const NAME: &'static str = "match_case"; const FIELD_NAMES: &'static [&'static str] = &["pattern", "guard", "body"]; } /// See also [pattern](https://docs.python.org/3/library/ast.html#ast.pattern) #[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum Pattern { - MatchValue(PatternMatchValue), - MatchSingleton(PatternMatchSingleton), - MatchSequence(PatternMatchSequence), - MatchMapping(PatternMatchMapping), - MatchClass(PatternMatchClass), - MatchStar(PatternMatchStar), - MatchAs(PatternMatchAs), - MatchOr(PatternMatchOr), +pub enum Pattern { + MatchValue(PatternMatchValue), + MatchSingleton(PatternMatchSingleton), + MatchSequence(PatternMatchSequence), + MatchMapping(PatternMatchMapping), + MatchClass(PatternMatchClass), + MatchStar(PatternMatchStar), + MatchAs(PatternMatchAs), + MatchOr(PatternMatchOr), } /// See also [MatchValue](https://docs.python.org/3/library/ast.html#ast.MatchValue) #[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchValue { - pub range: R, - pub value: Box>, +pub struct PatternMatchValue { + pub range: TextRange, + pub value: Box, } -impl Node for PatternMatchValue { +impl Node for PatternMatchValue { const NAME: &'static str = "MatchValue"; const FIELD_NAMES: &'static [&'static str] = &["value"]; } -impl From> for Pattern { - fn from(payload: PatternMatchValue) -> Self { +impl From for Pattern { + fn from(payload: PatternMatchValue) -> Self { Pattern::MatchValue(payload) } } -impl From> for Ast { - fn from(payload: PatternMatchValue) -> Self { +impl From for Ast { + fn from(payload: PatternMatchValue) -> Self { Pattern::from(payload).into() } } /// See also [MatchSingleton](https://docs.python.org/3/library/ast.html#ast.MatchSingleton) #[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchSingleton { - pub range: R, +pub struct PatternMatchSingleton { + pub range: TextRange, pub value: Constant, } -impl Node for PatternMatchSingleton { +impl Node for PatternMatchSingleton { const NAME: &'static str = "MatchSingleton"; const FIELD_NAMES: &'static [&'static str] = &["value"]; } -impl From> for Pattern { - fn from(payload: PatternMatchSingleton) -> Self { +impl From for Pattern { + fn from(payload: PatternMatchSingleton) -> Self { Pattern::MatchSingleton(payload) } } -impl From> for Ast { - fn from(payload: PatternMatchSingleton) -> Self { +impl From for Ast { + fn from(payload: PatternMatchSingleton) -> Self { Pattern::from(payload).into() } } /// See also [MatchSequence](https://docs.python.org/3/library/ast.html#ast.MatchSequence) #[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchSequence { - pub range: R, - pub patterns: Vec>, +pub struct PatternMatchSequence { + pub range: TextRange, + pub patterns: Vec, } -impl Node for PatternMatchSequence { +impl Node for PatternMatchSequence { const NAME: &'static str = "MatchSequence"; const FIELD_NAMES: &'static [&'static str] = &["patterns"]; } -impl From> for Pattern { - fn from(payload: PatternMatchSequence) -> Self { +impl From for Pattern { + fn from(payload: PatternMatchSequence) -> Self { Pattern::MatchSequence(payload) } } -impl From> for Ast { - fn from(payload: PatternMatchSequence) -> Self { +impl From for Ast { + fn from(payload: PatternMatchSequence) -> Self { Pattern::from(payload).into() } } /// See also [MatchMapping](https://docs.python.org/3/library/ast.html#ast.MatchMapping) #[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchMapping { - pub range: R, - pub keys: Vec>, - pub patterns: Vec>, +pub struct PatternMatchMapping { + pub range: TextRange, + pub keys: Vec, + pub patterns: Vec, pub rest: Option, } -impl Node for PatternMatchMapping { +impl Node for PatternMatchMapping { const NAME: &'static str = "MatchMapping"; const FIELD_NAMES: &'static [&'static str] = &["keys", "patterns", "rest"]; } -impl From> for Pattern { - fn from(payload: PatternMatchMapping) -> Self { +impl From for Pattern { + fn from(payload: PatternMatchMapping) -> Self { Pattern::MatchMapping(payload) } } -impl From> for Ast { - fn from(payload: PatternMatchMapping) -> Self { +impl From for Ast { + fn from(payload: PatternMatchMapping) -> Self { Pattern::from(payload).into() } } /// See also [MatchClass](https://docs.python.org/3/library/ast.html#ast.MatchClass) #[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchClass { - pub range: R, - pub cls: Box>, - pub patterns: Vec>, +pub struct PatternMatchClass { + pub range: TextRange, + pub cls: Box, + pub patterns: Vec, pub kwd_attrs: Vec, - pub kwd_patterns: Vec>, + pub kwd_patterns: Vec, } -impl Node for PatternMatchClass { +impl Node for PatternMatchClass { const NAME: &'static str = "MatchClass"; const FIELD_NAMES: &'static [&'static str] = &["cls", "patterns", "kwd_attrs", "kwd_patterns"]; } -impl From> for Pattern { - fn from(payload: PatternMatchClass) -> Self { +impl From for Pattern { + fn from(payload: PatternMatchClass) -> Self { Pattern::MatchClass(payload) } } -impl From> for Ast { - fn from(payload: PatternMatchClass) -> Self { +impl From for Ast { + fn from(payload: PatternMatchClass) -> Self { Pattern::from(payload).into() } } /// See also [MatchStar](https://docs.python.org/3/library/ast.html#ast.MatchStar) #[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchStar { - pub range: R, +pub struct PatternMatchStar { + pub range: TextRange, pub name: Option, } -impl Node for PatternMatchStar { +impl Node for PatternMatchStar { const NAME: &'static str = "MatchStar"; const FIELD_NAMES: &'static [&'static str] = &["name"]; } -impl From> for Pattern { - fn from(payload: PatternMatchStar) -> Self { +impl From for Pattern { + fn from(payload: PatternMatchStar) -> Self { Pattern::MatchStar(payload) } } -impl From> for Ast { - fn from(payload: PatternMatchStar) -> Self { +impl From for Ast { + fn from(payload: PatternMatchStar) -> Self { Pattern::from(payload).into() } } /// See also [MatchAs](https://docs.python.org/3/library/ast.html#ast.MatchAs) #[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchAs { - pub range: R, - pub pattern: Option>>, +pub struct PatternMatchAs { + pub range: TextRange, + pub pattern: Option>, pub name: Option, } -impl Node for PatternMatchAs { +impl Node for PatternMatchAs { const NAME: &'static str = "MatchAs"; const FIELD_NAMES: &'static [&'static str] = &["pattern", "name"]; } -impl From> for Pattern { - fn from(payload: PatternMatchAs) -> Self { +impl From for Pattern { + fn from(payload: PatternMatchAs) -> Self { Pattern::MatchAs(payload) } } -impl From> for Ast { - fn from(payload: PatternMatchAs) -> Self { +impl From for Ast { + fn from(payload: PatternMatchAs) -> Self { Pattern::from(payload).into() } } /// See also [MatchOr](https://docs.python.org/3/library/ast.html#ast.MatchOr) #[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchOr { - pub range: R, - pub patterns: Vec>, +pub struct PatternMatchOr { + pub range: TextRange, + pub patterns: Vec, } -impl Node for PatternMatchOr { +impl Node for PatternMatchOr { const NAME: &'static str = "MatchOr"; const FIELD_NAMES: &'static [&'static str] = &["patterns"]; } -impl From> for Pattern { - fn from(payload: PatternMatchOr) -> Self { +impl From for Pattern { + fn from(payload: PatternMatchOr) -> Self { Pattern::MatchOr(payload) } } -impl From> for Ast { - fn from(payload: PatternMatchOr) -> Self { +impl From for Ast { + fn from(payload: PatternMatchOr) -> Self { Pattern::from(payload).into() } } -impl Node for Pattern { +impl Node for Pattern { const NAME: &'static str = "pattern"; const FIELD_NAMES: &'static [&'static str] = &[]; } /// See also [type_ignore](https://docs.python.org/3/library/ast.html#ast.type_ignore) #[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum TypeIgnore { - TypeIgnore(TypeIgnoreTypeIgnore), +pub enum TypeIgnore { + TypeIgnore(TypeIgnoreTypeIgnore), } /// See also [TypeIgnore](https://docs.python.org/3/library/ast.html#ast.TypeIgnore) #[derive(Clone, Debug, PartialEq)] -pub struct TypeIgnoreTypeIgnore { - pub range: OptionalRange, +pub struct TypeIgnoreTypeIgnore { + pub range: TextRange, pub lineno: Int, pub tag: String, } -impl Node for TypeIgnoreTypeIgnore { +impl Node for TypeIgnoreTypeIgnore { const NAME: &'static str = "TypeIgnore"; const FIELD_NAMES: &'static [&'static str] = &["lineno", "tag"]; } -impl From> for TypeIgnore { - fn from(payload: TypeIgnoreTypeIgnore) -> Self { +impl From for TypeIgnore { + fn from(payload: TypeIgnoreTypeIgnore) -> Self { TypeIgnore::TypeIgnore(payload) } } -impl From> for Ast { - fn from(payload: TypeIgnoreTypeIgnore) -> Self { +impl From for Ast { + fn from(payload: TypeIgnoreTypeIgnore) -> Self { TypeIgnore::from(payload).into() } } -impl Node for TypeIgnore { +impl Node for TypeIgnore { const NAME: &'static str = "type_ignore"; const FIELD_NAMES: &'static [&'static str] = &[]; } /// See also [type_param](https://docs.python.org/3/library/ast.html#ast.type_param) #[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum TypeParam { - TypeVar(TypeParamTypeVar), - ParamSpec(TypeParamParamSpec), - TypeVarTuple(TypeParamTypeVarTuple), +pub enum TypeParam { + TypeVar(TypeParamTypeVar), + ParamSpec(TypeParamParamSpec), + TypeVarTuple(TypeParamTypeVarTuple), } /// See also [TypeVar](https://docs.python.org/3/library/ast.html#ast.TypeVar) #[derive(Clone, Debug, PartialEq)] -pub struct TypeParamTypeVar { - pub range: R, +pub struct TypeParamTypeVar { + pub range: TextRange, pub name: Identifier, - pub bound: Option>>, + pub bound: Option>, } -impl Node for TypeParamTypeVar { +impl Node for TypeParamTypeVar { const NAME: &'static str = "TypeVar"; const FIELD_NAMES: &'static [&'static str] = &["name", "bound"]; } -impl From> for TypeParam { - fn from(payload: TypeParamTypeVar) -> Self { +impl From for TypeParam { + fn from(payload: TypeParamTypeVar) -> Self { TypeParam::TypeVar(payload) } } -impl From> for Ast { - fn from(payload: TypeParamTypeVar) -> Self { +impl From for Ast { + fn from(payload: TypeParamTypeVar) -> Self { TypeParam::from(payload).into() } } /// See also [ParamSpec](https://docs.python.org/3/library/ast.html#ast.ParamSpec) #[derive(Clone, Debug, PartialEq)] -pub struct TypeParamParamSpec { - pub range: R, +pub struct TypeParamParamSpec { + pub range: TextRange, pub name: Identifier, } -impl Node for TypeParamParamSpec { +impl Node for TypeParamParamSpec { const NAME: &'static str = "ParamSpec"; const FIELD_NAMES: &'static [&'static str] = &["name"]; } -impl From> for TypeParam { - fn from(payload: TypeParamParamSpec) -> Self { +impl From for TypeParam { + fn from(payload: TypeParamParamSpec) -> Self { TypeParam::ParamSpec(payload) } } -impl From> for Ast { - fn from(payload: TypeParamParamSpec) -> Self { +impl From for Ast { + fn from(payload: TypeParamParamSpec) -> Self { TypeParam::from(payload).into() } } /// See also [TypeVarTuple](https://docs.python.org/3/library/ast.html#ast.TypeVarTuple) #[derive(Clone, Debug, PartialEq)] -pub struct TypeParamTypeVarTuple { - pub range: R, +pub struct TypeParamTypeVarTuple { + pub range: TextRange, pub name: Identifier, } -impl Node for TypeParamTypeVarTuple { +impl Node for TypeParamTypeVarTuple { const NAME: &'static str = "TypeVarTuple"; const FIELD_NAMES: &'static [&'static str] = &["name"]; } -impl From> for TypeParam { - fn from(payload: TypeParamTypeVarTuple) -> Self { +impl From for TypeParam { + fn from(payload: TypeParamTypeVarTuple) -> Self { TypeParam::TypeVarTuple(payload) } } -impl From> for Ast { - fn from(payload: TypeParamTypeVarTuple) -> Self { +impl From for Ast { + fn from(payload: TypeParamTypeVarTuple) -> Self { TypeParam::from(payload).into() } } -impl Node for TypeParam { +impl Node for TypeParam { const NAME: &'static str = "type_param"; const FIELD_NAMES: &'static [&'static str] = &[]; } /// See also [decorator](https://docs.python.org/3/library/ast.html#ast.decorator) #[derive(Clone, Debug, PartialEq)] -pub struct Decorator { - pub range: OptionalRange, - pub expression: Expr, +pub struct Decorator { + pub range: TextRange, + pub expression: Expr, } -impl Node for Decorator { +impl Node for Decorator { const NAME: &'static str = "decorator"; const FIELD_NAMES: &'static [&'static str] = &["expression"]; } @@ -3228,16 +3228,16 @@ impl Node for Decorator { /// NOTE: This type is different from original Python AST. #[derive(Clone, Debug, PartialEq)] -pub struct Arguments { - pub range: OptionalRange, - pub posonlyargs: Vec>, - pub args: Vec>, - pub vararg: Option>>, - pub kwonlyargs: Vec>, - pub kwarg: Option>>, +pub struct Arguments { + pub range: TextRange, + pub posonlyargs: Vec, + pub args: Vec, + pub vararg: Option>, + pub kwonlyargs: Vec, + pub kwarg: Option>, } -impl Node for Arguments { +impl Node for Arguments { const NAME: &'static str = "alt:arguments"; const FIELD_NAMES: &'static [&'static str] = &["posonlyargs", "args", "vararg", "kwonlyargs", "kwarg"]; @@ -3249,13 +3249,13 @@ impl Node for Arguments { /// NOTE: This type is different from original Python AST. #[derive(Clone, Debug, PartialEq)] -pub struct ArgWithDefault { - pub range: OptionalRange, - pub def: Arg, - pub default: Option>>, +pub struct ArgWithDefault { + pub range: TextRange, + pub def: Arg, + pub default: Option>, } -impl Node for ArgWithDefault { +impl Node for ArgWithDefault { const NAME: &'static str = "arg_with_default"; const FIELD_NAMES: &'static [&'static str] = &["def", "default"]; } diff --git a/ast/src/gen/ranged.rs b/ast/src/gen/ranged.rs index 5416bacd..6ea4d7de 100644 --- a/ast/src/gen/ranged.rs +++ b/ast/src/gen/ranged.rs @@ -1,30 +1,25 @@ // File automatically generated by ast/asdl_rs.py. -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::ModModule { +impl Ranged for crate::generic::ModModule { fn range(&self) -> TextRange { self.range } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::ModInteractive { +impl Ranged for crate::generic::ModInteractive { fn range(&self) -> TextRange { self.range } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::ModExpression { +impl Ranged for crate::generic::ModExpression { fn range(&self) -> TextRange { self.range } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::ModFunctionType { +impl Ranged for crate::generic::ModFunctionType { fn range(&self) -> TextRange { self.range } } -#[cfg(feature = "all-nodes-with-ranges")] impl Ranged for crate::Mod { fn range(&self) -> TextRange { match self { @@ -36,142 +31,143 @@ impl Ranged for crate::Mod { } } -impl Ranged for crate::generic::StmtFunctionDef { +impl Ranged for crate::generic::StmtFunctionDef { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtAsyncFunctionDef { +impl Ranged for crate::generic::StmtAsyncFunctionDef { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtClassDef { +impl Ranged for crate::generic::StmtClassDef { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtReturn { +impl Ranged for crate::generic::StmtReturn { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtDelete { +impl Ranged for crate::generic::StmtDelete { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtAssign { +impl Ranged for crate::generic::StmtAssign { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtTypeAlias { +impl Ranged for crate::generic::StmtTypeAlias{ fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtAugAssign { + +impl Ranged for crate::generic::StmtAugAssign { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtAnnAssign { +impl Ranged for crate::generic::StmtAnnAssign { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtFor { +impl Ranged for crate::generic::StmtFor { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtAsyncFor { +impl Ranged for crate::generic::StmtAsyncFor { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtWhile { +impl Ranged for crate::generic::StmtWhile { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtIf { +impl Ranged for crate::generic::StmtIf { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtWith { +impl Ranged for crate::generic::StmtWith { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtAsyncWith { +impl Ranged for crate::generic::StmtAsyncWith { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtMatch { +impl Ranged for crate::generic::StmtMatch { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtRaise { +impl Ranged for crate::generic::StmtRaise { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtTry { +impl Ranged for crate::generic::StmtTry { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtTryStar { +impl Ranged for crate::generic::StmtTryStar { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtAssert { +impl Ranged for crate::generic::StmtAssert { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtImport { +impl Ranged for crate::generic::StmtImport { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtImportFrom { +impl Ranged for crate::generic::StmtImportFrom { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtGlobal { +impl Ranged for crate::generic::StmtGlobal { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtNonlocal { +impl Ranged for crate::generic::StmtNonlocal { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtExpr { +impl Ranged for crate::generic::StmtExpr { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtPass { +impl Ranged for crate::generic::StmtPass { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtBreak { +impl Ranged for crate::generic::StmtBreak { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::StmtContinue { +impl Ranged for crate::generic::StmtContinue { fn range(&self) -> TextRange { self.range } @@ -211,137 +207,137 @@ impl Ranged for crate::Stmt { } } -impl Ranged for crate::generic::ExprBoolOp { +impl Ranged for crate::generic::ExprBoolOp { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprNamedExpr { +impl Ranged for crate::generic::ExprNamedExpr { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprBinOp { +impl Ranged for crate::generic::ExprBinOp { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprUnaryOp { +impl Ranged for crate::generic::ExprUnaryOp { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprLambda { +impl Ranged for crate::generic::ExprLambda { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprIfExp { +impl Ranged for crate::generic::ExprIfExp { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprDict { +impl Ranged for crate::generic::ExprDict { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprSet { +impl Ranged for crate::generic::ExprSet { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprListComp { +impl Ranged for crate::generic::ExprListComp { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprSetComp { +impl Ranged for crate::generic::ExprSetComp { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprDictComp { +impl Ranged for crate::generic::ExprDictComp { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprGeneratorExp { +impl Ranged for crate::generic::ExprGeneratorExp { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprAwait { +impl Ranged for crate::generic::ExprAwait { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprYield { +impl Ranged for crate::generic::ExprYield { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprYieldFrom { +impl Ranged for crate::generic::ExprYieldFrom { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprCompare { +impl Ranged for crate::generic::ExprCompare { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprCall { +impl Ranged for crate::generic::ExprCall { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprFormattedValue { +impl Ranged for crate::generic::ExprFormattedValue { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprJoinedStr { +impl Ranged for crate::generic::ExprJoinedStr { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprConstant { +impl Ranged for crate::generic::ExprConstant { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprAttribute { +impl Ranged for crate::generic::ExprAttribute { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprSubscript { +impl Ranged for crate::generic::ExprSubscript { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprStarred { +impl Ranged for crate::generic::ExprStarred { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprName { +impl Ranged for crate::generic::ExprName { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprList { +impl Ranged for crate::generic::ExprList { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprTuple { +impl Ranged for crate::generic::ExprTuple { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExprSlice { +impl Ranged for crate::generic::ExprSlice { fn range(&self) -> TextRange { self.range } @@ -380,13 +376,12 @@ impl Ranged for crate::Expr { } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::Comprehension { +impl Ranged for crate::generic::Comprehension { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::ExceptHandlerExceptHandler { +impl Ranged for crate::generic::ExceptHandlerExceptHandler { fn range(&self) -> TextRange { self.range } @@ -399,75 +394,72 @@ impl Ranged for crate::ExceptHandler { } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::PythonArguments { +impl Ranged for crate::generic::PythonArguments { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::Arg { +impl Ranged for crate::generic::Arg { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::Keyword { +impl Ranged for crate::generic::Keyword { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::Alias { +impl Ranged for crate::generic::Alias { fn range(&self) -> TextRange { self.range } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::WithItem { +impl Ranged for crate::generic::WithItem { fn range(&self) -> TextRange { self.range } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::MatchCase { +impl Ranged for crate::generic::MatchCase { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::PatternMatchValue { +impl Ranged for crate::generic::PatternMatchValue { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::PatternMatchSingleton { +impl Ranged for crate::generic::PatternMatchSingleton { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::PatternMatchSequence { +impl Ranged for crate::generic::PatternMatchSequence { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::PatternMatchMapping { +impl Ranged for crate::generic::PatternMatchMapping { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::PatternMatchClass { +impl Ranged for crate::generic::PatternMatchClass { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::PatternMatchStar { +impl Ranged for crate::generic::PatternMatchStar { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::PatternMatchAs { +impl Ranged for crate::generic::PatternMatchAs { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::PatternMatchOr { +impl Ranged for crate::generic::PatternMatchOr { fn range(&self) -> TextRange { self.range } @@ -487,13 +479,11 @@ impl Ranged for crate::Pattern { } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::TypeIgnoreTypeIgnore { +impl Ranged for crate::generic::TypeIgnoreTypeIgnore { fn range(&self) -> TextRange { self.range } } -#[cfg(feature = "all-nodes-with-ranges")] impl Ranged for crate::TypeIgnore { fn range(&self) -> TextRange { match self { @@ -502,17 +492,17 @@ impl Ranged for crate::TypeIgnore { } } -impl Ranged for crate::generic::TypeParamTypeVar { +impl Ranged for crate::generic::TypeParamTypeVar { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::TypeParamParamSpec { +impl Ranged for crate::generic::TypeParamParamSpec { fn range(&self) -> TextRange { self.range } } -impl Ranged for crate::generic::TypeParamTypeVarTuple { +impl Ranged for crate::generic::TypeParamTypeVarTuple { fn range(&self) -> TextRange { self.range } @@ -527,20 +517,17 @@ impl Ranged for crate::TypeParam { } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::Decorator { +impl Ranged for crate::generic::Decorator { fn range(&self) -> TextRange { self.range } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::Arguments { +impl Ranged for crate::generic::Arguments { fn range(&self) -> TextRange { self.range } } -#[cfg(feature = "all-nodes-with-ranges")] -impl Ranged for crate::generic::ArgWithDefault { +impl Ranged for crate::generic::ArgWithDefault { fn range(&self) -> TextRange { self.range } diff --git a/ast/src/generic.rs b/ast/src/generic.rs index fe0875b9..9c038915 100644 --- a/ast/src/generic.rs +++ b/ast/src/generic.rs @@ -1,58 +1,8 @@ #![allow(clippy::derive_partial_eq_without_eq)] pub use crate::{builtin::*, text_size::TextSize, ConversionFlag, Node}; -use std::fmt::{Debug, Display, Formatter}; -use std::marker::PhantomData; +use std::fmt::Debug; -pub type Suite = Vec>; - -#[cfg(feature = "all-nodes-with-ranges")] -pub type OptionalRange = R; - -#[cfg(not(feature = "all-nodes-with-ranges"))] -pub type OptionalRange = EmptyRange; - -#[cfg(not(feature = "all-nodes-with-ranges"))] -impl From for OptionalRange { - fn from(_: R) -> Self { - Self { - phantom: PhantomData, - } - } -} - -#[derive(Eq, PartialEq, Hash, Copy, Clone)] -pub struct EmptyRange { - phantom: PhantomData, -} - -impl EmptyRange { - #[inline(always)] - pub fn new(_start: TextSize, _end: TextSize) -> Self { - Self { - phantom: PhantomData, - } - } -} - -impl Display for EmptyRange { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.write_str("()") - } -} - -impl Debug for EmptyRange { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - Display::fmt(self, f) - } -} - -impl Default for EmptyRange { - fn default() -> Self { - EmptyRange { - phantom: PhantomData, - } - } -} +pub type Suite = Vec; impl CmpOp { pub fn as_str(&self) -> &'static str { @@ -71,8 +21,8 @@ impl CmpOp { } } -impl Arguments { - pub fn empty(range: OptionalRange) -> Self { +impl Arguments { + pub fn empty(range: TextRange) -> Self { Self { range, posonlyargs: Vec::new(), @@ -85,39 +35,17 @@ impl Arguments { } #[allow(clippy::borrowed_box)] // local utility -fn clone_boxed_expr(expr: &Box>) -> Box> { - let expr: &Expr<_> = expr.as_ref(); +fn clone_boxed_expr(expr: &Box) -> Box { + let expr: &Expr = expr.as_ref(); Box::new(expr.clone()) } -impl ArgWithDefault { - pub fn from_arg(def: Arg, default: Option>) -> Self - where - R: Clone, - { - let range = { - if cfg!(feature = "all-nodes-with-ranges") { - todo!("range recovery is not implemented yet") // def.range.start()..default.range.end() - } else { - #[allow(clippy::useless_conversion)] // false positive by cfg - OptionalRange::from(def.range.clone()) - } - }; - Self { - range, - def, - default: default.map(Box::new), - } - } - - pub fn as_arg(&self) -> &Arg { +impl ArgWithDefault { + pub fn as_arg(&self) -> &Arg { &self.def } - pub fn to_arg(&self) -> (Arg, Option>>) - where - R: Clone, - { + pub fn to_arg(&self) -> (Arg, Option>) { let ArgWithDefault { range: _, def, @@ -125,7 +53,7 @@ impl ArgWithDefault { } = self; (def.clone(), default.as_ref().map(clone_boxed_expr)) } - pub fn into_arg(self) -> (Arg, Option>>) { + pub fn into_arg(self) -> (Arg, Option>) { let ArgWithDefault { range: _, def, @@ -135,8 +63,8 @@ impl ArgWithDefault { } } -impl Arguments { - pub fn defaults(&self) -> impl std::iter::Iterator> { +impl Arguments { + pub fn defaults(&self) -> impl std::iter::Iterator { self.posonlyargs .iter() .chain(self.args.iter()) @@ -144,7 +72,7 @@ impl Arguments { } #[allow(clippy::type_complexity)] - pub fn split_kwonlyargs(&self) -> (Vec<&Arg>, Vec<(&Arg, &Expr)>) { + pub fn split_kwonlyargs(&self) -> (Vec<&Arg>, Vec<(&Arg, &Expr)>) { let mut args = Vec::new(); let mut with_defaults = Vec::new(); for arg in self.kwonlyargs.iter() { @@ -156,172 +84,6 @@ impl Arguments { } (args, with_defaults) } - - pub fn to_python_arguments(&self) -> PythonArguments - where - R: Clone, - { - let Arguments { - range, - posonlyargs, - args, - vararg, - kwonlyargs, - kwarg, - } = self; - - let mut pos_only = Vec::with_capacity(posonlyargs.len()); - let mut pos_args = Vec::with_capacity(args.len()); - let mut defaults = Vec::new(); - for arg in posonlyargs { - let (arg, default) = arg.to_arg(); - if let Some(default) = default { - defaults.push(*default); - } - pos_only.push(arg); - } - for arg in args { - let (arg, default) = arg.to_arg(); - if let Some(default) = default { - defaults.push(*default); - } - pos_args.push(arg); - } - - let mut kw_only = Vec::with_capacity(kwonlyargs.len()); - let mut kw_defaults = Vec::new(); - for arg in kwonlyargs { - let (arg, default) = arg.to_arg(); - if let Some(default) = default { - kw_defaults.push(*default); - } - kw_only.push(arg); - } - - PythonArguments { - range: range.clone(), - posonlyargs: pos_only, - args: pos_args, - defaults, - vararg: vararg.clone(), - kwonlyargs: kw_only, - kw_defaults, - kwarg: kwarg.clone(), - } - } - - pub fn into_python_arguments(self) -> PythonArguments { - let Arguments { - range, - posonlyargs, - args, - vararg, - kwonlyargs, - kwarg, - } = self; - - let mut pos_only = Vec::with_capacity(posonlyargs.len()); - let mut pos_args = Vec::with_capacity(args.len()); - let mut defaults = Vec::new(); - for arg in posonlyargs { - let (arg, default) = arg.into_arg(); - if let Some(default) = default { - defaults.push(*default); - } - pos_only.push(arg); - } - for arg in args { - let (arg, default) = arg.into_arg(); - if let Some(default) = default { - defaults.push(*default); - } - pos_args.push(arg); - } - - let mut kw_only = Vec::with_capacity(kwonlyargs.len()); - let mut kw_defaults = Vec::new(); - for arg in kwonlyargs { - let (arg, default) = arg.into_arg(); - if let Some(default) = default { - kw_defaults.push(*default); - } - kw_only.push(arg); - } - - PythonArguments { - range, - posonlyargs: pos_only, - args: pos_args, - defaults, - vararg, - kwonlyargs: kw_only, - kw_defaults, - kwarg, - } - } -} - -impl PythonArguments { - pub fn into_arguments(self) -> Arguments - where - R: Clone, - { - let PythonArguments { - range, - posonlyargs, - args, - defaults, - vararg, - kwonlyargs, - kw_defaults, - kwarg, - } = self; - - let mut pos_only = Vec::with_capacity(posonlyargs.len()); - let mut pos_args = Vec::with_capacity(args.len()); - let args_len = posonlyargs.len() + args.len(); - // not optimal - let mut defaults: Vec<_> = std::iter::repeat_with(|| None) - .take(args_len - defaults.len()) - .chain(defaults.into_iter().map(Some)) - .collect(); - debug_assert_eq!(args_len, defaults.len()); - - for (arg, default) in std::iter::zip(args, defaults.drain(posonlyargs.len()..)) { - let arg = ArgWithDefault::from_arg(arg, default); - pos_args.push(arg); - } - - for (arg, default) in std::iter::zip(posonlyargs, defaults.drain(..)) { - let arg = ArgWithDefault::from_arg(arg, default); - pos_only.push(arg); - } - - let mut kw_only = Vec::with_capacity(kwonlyargs.len()); - let kw_defaults: Vec<_> = std::iter::repeat_with(|| None) - .take(kw_only.len().saturating_sub(kw_defaults.len())) - .chain(kw_defaults.into_iter().map(Some)) - .collect(); - for (arg, default) in std::iter::zip(kwonlyargs, kw_defaults) { - let arg = ArgWithDefault::from_arg(arg, default); - kw_only.push(arg); - } - - Arguments { - range, - posonlyargs: pos_only, - args: pos_args, - vararg, - kwonlyargs: kw_only, - kwarg, - } - } -} - -impl From> for PythonArguments { - fn from(arguments: Arguments) -> Self { - arguments.into_python_arguments() - } } include!("gen/generic.rs"); diff --git a/ast/src/impls.rs b/ast/src/impls.rs index d62a3c80..c4df7540 100644 --- a/ast/src/impls.rs +++ b/ast/src/impls.rs @@ -1,6 +1,6 @@ use crate::{Constant, Expr}; -impl Expr { +impl Expr { /// Returns a short name for the node suitable for use in error messages. pub fn python_name(&self) -> &'static str { match self { diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 0ce4b3cc..b6c20ff8 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -11,7 +11,6 @@ edition = "2021" [features] default = ["malachite-bigint"] serde = ["dep:serde", "rustpython-parser-core/serde"] -all-nodes-with-ranges = ["rustpython-ast/all-nodes-with-ranges"] full-lexer = [] malachite-bigint = ["dep:malachite-bigint", "rustpython-ast/malachite-bigint"] num-bigint = ["dep:num-bigint", "rustpython-ast/num-bigint"] diff --git a/parser/src/context.rs b/parser/src/context.rs index 3ba5fca3..66fea936 100644 --- a/parser/src/context.rs +++ b/parser/src/context.rs @@ -66,7 +66,6 @@ mod tests { } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_assign_list() { let source = "[x, y] = (1, 2, 3)"; let parse_ast = ast::Suite::parse(source, "").unwrap(); @@ -102,7 +101,6 @@ mod tests { } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_assign_list_comp() { let source = "x = [y for y in (1, 2, 3)]"; let parse_ast = ast::Suite::parse(source, "").unwrap(); @@ -110,7 +108,6 @@ mod tests { } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_assign_set_comp() { let source = "x = {y for y in (1, 2, 3)}"; let parse_ast = ast::Suite::parse(source, "").unwrap(); @@ -118,7 +115,6 @@ mod tests { } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_assign_with() { let source = "with 1 as x: pass"; let parse_ast = ast::Suite::parse(source, "").unwrap(); diff --git a/parser/src/function.rs b/parser/src/function.rs index 3574f78e..67749ea3 100644 --- a/parser/src/function.rs +++ b/parser/src/function.rs @@ -141,7 +141,6 @@ mod tests { use super::*; use crate::{ast, parser::ParseErrorType, Parse}; - #[cfg(feature = "all-nodes-with-ranges")] macro_rules! function_and_lambda { ($($name:ident: $code:expr,)*) => { $( @@ -154,13 +153,11 @@ mod tests { } } - #[cfg(feature = "all-nodes-with-ranges")] function_and_lambda! { test_function_no_args_with_ranges: "def f(): pass", test_function_pos_args_with_ranges: "def f(a, b, c): pass", } - #[cfg(feature = "all-nodes-with-ranges")] function_and_lambda! { test_function_no_args: "def f(): pass", test_function_pos_args: "def f(a, b, c): pass", diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 88f3acbb..afabffac 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -13,7 +13,7 @@ //! [`Mode`]: crate::mode use crate::{ - ast::{self, OptionalRange, Ranged}, + ast::{self, Ranged}, lexer::{self, LexResult, LexicalError, LexicalErrorType}, python, text_size::TextSize, @@ -23,7 +23,7 @@ use crate::{ use itertools::Itertools; use std::iter; -use crate::{lexer::Lexer, soft_keywords::SoftKeywordTransformer, text_size::TextRange}; +use crate::{lexer::Lexer, soft_keywords::SoftKeywordTransformer}; pub(super) use lalrpop_util::ParseError as LalrpopError; /// Parse Python code string to implementor's type. @@ -551,11 +551,6 @@ impl ParseErrorType { } } -#[inline(always)] -pub(super) fn optional_range(start: TextSize, end: TextSize) -> OptionalRange { - OptionalRange::::new(start, end) -} - include!("gen/parse.rs"); #[cfg(test)] @@ -612,7 +607,6 @@ mod tests { } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_lambda() { let source = "lambda x, y: x * y"; // lambda(x, y): x * y"; let parse_ast = ast::Suite::parse(source, "").unwrap(); @@ -627,7 +621,6 @@ mod tests { } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_class() { let source = "\ class Foo(A, B): @@ -640,7 +633,6 @@ class Foo(A, B): } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_class_generic_types() { let source = "\ # TypeVar @@ -671,7 +663,6 @@ class Foo[X, Y: str, *U, **P](): insta::assert_debug_snapshot!(ast::Suite::parse(source, "").unwrap()); } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_function_definition() { let source = "\ def func(a): @@ -699,7 +690,6 @@ def func[T, U: str, *Ts, **P](): } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_dict_comprehension() { let source = "{x1: x2 for y in z}"; let parse_ast = ast::Expr::parse(source, "").unwrap(); @@ -707,7 +697,6 @@ def func[T, U: str, *Ts, **P](): } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_list_comprehension() { let source = "[x for y in z]"; let parse_ast = ast::Expr::parse(source, "").unwrap(); @@ -715,7 +704,6 @@ def func[T, U: str, *Ts, **P](): } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_double_list_comprehension() { let source = "[x for y, y2 in z for a in b if a < 5 if a > 10]"; let parse_ast = ast::Expr::parse(source, "").unwrap(); @@ -723,7 +711,6 @@ def func[T, U: str, *Ts, **P](): } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_generator_comprehension() { let source = "(x for y in z)"; let parse_ast = ast::Expr::parse(source, "").unwrap(); @@ -731,7 +718,6 @@ def func[T, U: str, *Ts, **P](): } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_named_expression_generator_comprehension() { let source = "(x := y + 1 for y in z)"; let parse_ast = ast::Expr::parse(source, "").unwrap(); @@ -739,7 +725,6 @@ def func[T, U: str, *Ts, **P](): } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_if_else_generator_comprehension() { let source = "(x if y else y for y in z)"; let parse_ast = ast::Expr::parse(source, "").unwrap(); @@ -768,7 +753,6 @@ def func[T, U: str, *Ts, **P](): } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_with_statement() { let source = "\ with 0: pass @@ -838,7 +822,6 @@ array[3:5, *indexes_to_select] } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_generator_expression_argument() { let source = r#"' '.join( sql @@ -898,7 +881,6 @@ except* OSError as e: } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_parse_type_declaration() { let source = r#" type X = int @@ -942,7 +924,6 @@ type X[T] \ } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_type_as_identifier() { let source = r#"\ type *a + b, c # ((type * a) + b), c @@ -980,7 +961,6 @@ x = type = 1 } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_match_as_identifier() { let source = r#"\ match *a + b, c # ((match * a) + b), c @@ -1009,7 +989,6 @@ print(match(12)) } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_patma() { let source = r#"# Cases sampled from Lib/test/test_patma.py @@ -1181,7 +1160,6 @@ match w := x,: } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_match() { let parse_ast = ast::Suite::parse( r#" @@ -1212,7 +1190,6 @@ match x: } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn test_variadic_generics() { let parse_ast = ast::Suite::parse( r#" @@ -1242,7 +1219,6 @@ def args_to_tuple(*args: *Ts) -> Tuple[*Ts]: ... } #[test] - #[cfg(feature = "all-nodes-with-ranges")] fn decorator_ranges() { let parse_ast = ast::Suite::parse( r#" diff --git a/parser/src/python.lalrpop b/parser/src/python.lalrpop index 69172071..f1f5e523 100644 --- a/parser/src/python.lalrpop +++ b/parser/src/python.lalrpop @@ -10,7 +10,7 @@ use crate::{ context::set_context, string::parse_strings, token::{self, StringKind}, - text_size::TextSize, parser::optional_range + text_size::TextSize }; grammar; @@ -19,9 +19,9 @@ grammar; // For each public entry point, a full parse table is generated. // By having only a single pub function, we reduce this to one. pub Top: ast::Mod = { - StartModule => ast::ModModule { body, type_ignores: vec![], range: optional_range(start, end) }.into(), - StartInteractive => ast::ModInteractive { body, range: optional_range(start, end) }.into(), - StartExpression ("\n")* => ast::ModExpression { body: Box::new(body), range: optional_range(start, end) }.into() + StartModule => ast::ModModule { body, type_ignores: vec![], range: (start..end).into() }.into(), + StartInteractive => ast::ModInteractive { body, range: (start..end).into() }.into(), + StartExpression ("\n")* => ast::ModExpression { body: Box::new(body), range: (start..end).into() }.into() }; Program: ast::Suite = { @@ -394,7 +394,7 @@ MatchCase: ast::MatchCase = { pattern, guard: guard.map(Box::new), body, - range: optional_range(start, end) + range: (start..end).into() } }, } @@ -953,15 +953,15 @@ WithItems: Vec = { #[inline] WithItemsNoAs: Vec = { >> => { - all.into_iter().map(|context_expr| ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) }).collect() + all.into_iter().map(|context_expr| ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() }).collect() }, } WithItem: ast::WithItem = { - > if Goal != "as" => ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) }, + > if Goal != "as" => ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() }, > "as" > => { let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store))); - ast::WithItem { context_expr, optional_vars, range: optional_range(location, end_location) } + ast::WithItem { context_expr, optional_vars, range: (location..end_location).into() } }, }; @@ -1002,7 +1002,7 @@ Parameters: ast::Arguments = { "(" )?> ")" =>? { a.as_ref().map(validate_arguments).transpose()?; - let range = optional_range(location, end_location); + let range = (location..end_location).into(); let args = a .map(|mut arguments| { arguments.range = range; @@ -1030,7 +1030,7 @@ ParameterList: ast::Arguments = { kwonlyargs, vararg, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() }) }, > >)> ","? =>? { @@ -1048,7 +1048,7 @@ ParameterList: ast::Arguments = { kwonlyargs, vararg, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() }) }, > ","? => { @@ -1059,7 +1059,7 @@ ParameterList: ast::Arguments = { kwonlyargs, vararg, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() } }, > ","? => { @@ -1069,7 +1069,7 @@ ParameterList: ast::Arguments = { kwonlyargs: vec![], vararg: None, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() } }, }; @@ -1089,10 +1089,7 @@ ParameterDef: ast::ArgWithDefault = { => i, "=" > => { i.default = Some(Box::new(e)); - #[cfg(feature = "all-nodes-with-ranges")] - { - i.range = optional_range(i.range.start(), end_location); - } + i.range = (i.range.start()..end_location).into(); i }, }; @@ -1100,7 +1097,7 @@ ParameterDef: ast::ArgWithDefault = { UntypedParameter: ast::ArgWithDefault = { => { let def = ast::Arg { arg, annotation: None, type_comment: None, range: (location..end_location).into() }; - ast::ArgWithDefault { def, default: None, range: optional_range(location, end_location) } + ast::ArgWithDefault { def, default: None, range: (location..end_location).into() } }, }; StarUntypedParameter: ast::Arg = { @@ -1111,7 +1108,7 @@ TypedParameter: ast::ArgWithDefault = { >)?> => { let annotation = a.map(Box::new); let def = ast::Arg { arg, annotation, type_comment: None, range: (location..end_location).into() }; - ast::ArgWithDefault { def, default: None, range: optional_range(location, end_location) } + ast::ArgWithDefault { def, default: None, range: (location..end_location).into() } }, }; @@ -1203,7 +1200,7 @@ TypeParam: ast::TypeParam = { // Decorators: Decorator: ast::Decorator = { "@" "\n" => { - ast::Decorator { range: optional_range(location, end_location), expression: p } + ast::Decorator { range: (location..end_location).into(), expression: p } }, }; @@ -1252,7 +1249,7 @@ LambdaDef: ast::Expr = { "lambda" ?> ":" > =>? { p.as_ref().map(validate_arguments).transpose()?; let p = p - .unwrap_or_else(|| ast::Arguments::empty(optional_range(location, end_location))); + .unwrap_or_else(|| ast::Arguments::empty((location..end_location).into())); Ok(ast::Expr::Lambda( ast::ExprLambda { @@ -1616,7 +1613,7 @@ SingleForComprehension: ast::Comprehension = { iter, ifs, is_async, - range: optional_range(location, end_location) + range: (location..end_location).into() } } }; diff --git a/parser/src/python.rs b/parser/src/python.rs index f2a3dad2..9272c023 100644 --- a/parser/src/python.rs +++ b/parser/src/python.rs @@ -1,5 +1,5 @@ // auto-generated: "lalrpop 0.20.0" -// sha3: f0c48231ecb45a59c479cf92fe35eb8f2f2f7e09ddaa12890f247bbb8d8386ca +// sha3: 3ee291ec28e61ba013e5d3601a0837b51288e6f70f05e23af3ce17c9020e0b74 use crate::{ ast::{self as ast, Ranged, bigint::BigInt}, lexer::{LexicalError, LexicalErrorType}, @@ -7,7 +7,7 @@ use crate::{ context::set_context, string::parse_strings, token::{self, StringKind}, - text_size::TextSize, parser::optional_range + text_size::TextSize }; #[allow(unused_extern_crates)] extern crate lalrpop_util as __lalrpop_util; @@ -27,7 +27,7 @@ mod __parse__Top { context::set_context, string::parse_strings, token::{self, StringKind}, - text_size::TextSize, parser::optional_range + text_size::TextSize }; #[allow(unused_extern_crates)] extern crate lalrpop_util as __lalrpop_util; @@ -29853,7 +29853,7 @@ fn __action1< (_, end, _): (TextSize, TextSize, TextSize), ) -> ast::Mod { - ast::ModModule { body, type_ignores: vec![], range: optional_range(start, end) }.into() + ast::ModModule { body, type_ignores: vec![], range: (start..end).into() }.into() } #[allow(clippy::too_many_arguments)] @@ -29865,7 +29865,7 @@ fn __action2< (_, end, _): (TextSize, TextSize, TextSize), ) -> ast::Mod { - ast::ModInteractive { body, range: optional_range(start, end) }.into() + ast::ModInteractive { body, range: (start..end).into() }.into() } #[allow(clippy::too_many_arguments)] @@ -29878,7 +29878,7 @@ fn __action3< (_, end, _): (TextSize, TextSize, TextSize), ) -> ast::Mod { - ast::ModExpression { body: Box::new(body), range: optional_range(start, end) }.into() + ast::ModExpression { body: Box::new(body), range: (start..end).into() }.into() } #[allow(clippy::too_many_arguments)] @@ -30902,7 +30902,7 @@ fn __action83< pattern, guard: guard.map(Box::new), body, - range: optional_range(start, end) + range: (start..end).into() } } } @@ -32185,7 +32185,7 @@ fn __action157< ) -> Vec { { - all.into_iter().map(|context_expr| ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) }).collect() + all.into_iter().map(|context_expr| ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() }).collect() } } @@ -32267,7 +32267,7 @@ fn __action161< { a.as_ref().map(validate_arguments).transpose()?; - let range = optional_range(location, end_location); + let range = (location..end_location).into(); let args = a .map(|mut arguments| { arguments.range = range; @@ -32289,7 +32289,7 @@ fn __action162< { { let def = ast::Arg { arg, annotation: None, type_comment: None, range: (location..end_location).into() }; - ast::ArgWithDefault { def, default: None, range: optional_range(location, end_location) } + ast::ArgWithDefault { def, default: None, range: (location..end_location).into() } } } @@ -32316,7 +32316,7 @@ fn __action164< { let annotation = a.map(Box::new); let def = ast::Arg { arg, annotation, type_comment: None, range: (location..end_location).into() }; - ast::ArgWithDefault { def, default: None, range: optional_range(location, end_location) } + ast::ArgWithDefault { def, default: None, range: (location..end_location).into() } } } @@ -32458,7 +32458,7 @@ fn __action172< ) -> ast::Decorator { { - ast::Decorator { range: optional_range(location, end_location), expression: p } + ast::Decorator { range: (location..end_location).into(), expression: p } } } @@ -32546,7 +32546,7 @@ fn __action178< { p.as_ref().map(validate_arguments).transpose()?; let p = p - .unwrap_or_else(|| ast::Arguments::empty(optional_range(location, end_location))); + .unwrap_or_else(|| ast::Arguments::empty((location..end_location).into())); Ok(ast::Expr::Lambda( ast::ExprLambda { @@ -32993,7 +32993,7 @@ fn __action220< iter, ifs, is_async, - range: optional_range(location, end_location) + range: (location..end_location).into() } } } @@ -33450,7 +33450,7 @@ fn __action257< kwonlyargs, vararg, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() }) } } @@ -33480,7 +33480,7 @@ fn __action258< kwonlyargs, vararg, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() }) } } @@ -33502,7 +33502,7 @@ fn __action259< kwonlyargs, vararg, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() } } } @@ -33523,7 +33523,7 @@ fn __action260< kwonlyargs: vec![], vararg: None, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() } } } @@ -33690,7 +33690,7 @@ fn __action275< kwonlyargs, vararg, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() }) } } @@ -33720,7 +33720,7 @@ fn __action276< kwonlyargs, vararg, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() }) } } @@ -33742,7 +33742,7 @@ fn __action277< kwonlyargs, vararg, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() } } } @@ -33763,7 +33763,7 @@ fn __action278< kwonlyargs: vec![], vararg: None, kwarg, - range: optional_range(location, end_location) + range: (location..end_location).into() } } } @@ -33885,7 +33885,7 @@ fn __action290< (_, end_location, _): (TextSize, TextSize, TextSize), ) -> ast::WithItem { - ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) } + ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() } } #[allow(clippy::too_many_arguments)] @@ -33900,7 +33900,7 @@ fn __action291< { { let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store))); - ast::WithItem { context_expr, optional_vars, range: optional_range(location, end_location) } + ast::WithItem { context_expr, optional_vars, range: (location..end_location).into() } } } @@ -33941,7 +33941,7 @@ fn __action295< (_, end_location, _): (TextSize, TextSize, TextSize), ) -> ast::WithItem { - ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) } + ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() } } #[allow(clippy::too_many_arguments)] @@ -33956,7 +33956,7 @@ fn __action296< { { let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store))); - ast::WithItem { context_expr, optional_vars, range: optional_range(location, end_location) } + ast::WithItem { context_expr, optional_vars, range: (location..end_location).into() } } } @@ -33972,7 +33972,7 @@ fn __action297< { { let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store))); - ast::WithItem { context_expr, optional_vars, range: optional_range(location, end_location) } + ast::WithItem { context_expr, optional_vars, range: (location..end_location).into() } } } @@ -35636,10 +35636,7 @@ fn __action454< { { i.default = Some(Box::new(e)); - #[cfg(feature = "all-nodes-with-ranges")] - { - i.range = optional_range(i.range.start(), end_location); - } + i.range = (i.range.start()..end_location).into(); i } } @@ -35754,10 +35751,7 @@ fn __action465< { { i.default = Some(Box::new(e)); - #[cfg(feature = "all-nodes-with-ranges")] - { - i.range = optional_range(i.range.start(), end_location); - } + i.range = (i.range.start()..end_location).into(); i } } diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__type_as_identifier.snap b/parser/src/snapshots/rustpython_parser__parser__tests__type_as_identifier.snap index 15443421..33e89aa2 100644 --- a/parser/src/snapshots/rustpython_parser__parser__tests__type_as_identifier.snap +++ b/parser/src/snapshots/rustpython_parser__parser__tests__type_as_identifier.snap @@ -863,7 +863,7 @@ expression: "ast::Suite::parse(source, \"\").unwrap()" arg: Some( Identifier { id: "X", - range: 607..614, + range: 607..608, }, ), value: Name(