mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
No Attributed + custom for Range PoC
This commit is contained in:
parent
ba0ae51e82
commit
904f5c8b37
10 changed files with 1732 additions and 1184 deletions
184
ast/asdl_rs.py
184
ast/asdl_rs.py
|
@ -84,6 +84,7 @@ class TypeInfo:
|
|||
enum_name: Optional[str]
|
||||
has_user_data: Optional[bool]
|
||||
has_attributes: bool
|
||||
is_simple: bool
|
||||
empty_field: bool
|
||||
children: set
|
||||
boxed: bool
|
||||
|
@ -95,6 +96,7 @@ class TypeInfo:
|
|||
self.enum_name = None
|
||||
self.has_user_data = None
|
||||
self.has_attributes = False
|
||||
self.is_simple = False
|
||||
self.empty_field = False
|
||||
self.children = set()
|
||||
self.boxed = False
|
||||
|
@ -104,6 +106,14 @@ class TypeInfo:
|
|||
def __repr__(self):
|
||||
return f"<TypeInfo: {self.name}>"
|
||||
|
||||
def needs_cfg(self, typeinfo):
|
||||
if self.product:
|
||||
return self.has_attributes
|
||||
elif self.enum_name:
|
||||
return typeinfo[self.enum_name].has_attributes
|
||||
else:
|
||||
return self.has_attributes
|
||||
|
||||
@property
|
||||
def rust_name(self):
|
||||
return rust_type_name(self.name)
|
||||
|
@ -124,19 +134,6 @@ class TypeInfo:
|
|||
name = rust_type_name(self.enum_name) + rust_name
|
||||
return name
|
||||
|
||||
@property
|
||||
def rust_suffix(self):
|
||||
if self.product:
|
||||
if self.has_attributes:
|
||||
return "Data"
|
||||
else:
|
||||
return ""
|
||||
else:
|
||||
if self.has_attributes:
|
||||
return "Kind"
|
||||
else:
|
||||
return ""
|
||||
|
||||
def determine_user_data(self, type_info, stack):
|
||||
if self.name in stack:
|
||||
return None
|
||||
|
@ -208,6 +205,7 @@ class FindUserDataTypesVisitor(asdl.VisitorBase):
|
|||
info = self.type_info[name]
|
||||
if is_simple(sum):
|
||||
info.has_user_data = False
|
||||
info.is_simple = True
|
||||
else:
|
||||
for t in sum.types:
|
||||
t_info = TypeInfo(t.name)
|
||||
|
@ -277,6 +275,16 @@ class StructVisitor(EmitVisitor):
|
|||
def emit_attrs(self, depth):
|
||||
self.emit("#[derive(Clone, Debug, PartialEq)]", depth)
|
||||
|
||||
def emit_custom(self, has_attributes, depth):
|
||||
if has_attributes:
|
||||
self.emit("pub custom: U,", depth + 1)
|
||||
else:
|
||||
self.emit('#[cfg(feature = "more-attributes")]', depth + 1)
|
||||
self.emit("pub custom: U,", depth + 1)
|
||||
self.emit('#[cfg(not(feature = "more-attributes"))]', depth + 1)
|
||||
self.emit("pub custom: std::marker::PhantomData<U>,", depth + 1)
|
||||
|
||||
|
||||
def simple_sum(self, sum, name, depth):
|
||||
rust_name = rust_type_name(name)
|
||||
self.emit_attrs(depth)
|
||||
|
@ -289,7 +297,6 @@ class StructVisitor(EmitVisitor):
|
|||
|
||||
def sum_with_constructors(self, sum, name, depth):
|
||||
type_info = self.type_info[name]
|
||||
suffix = type_info.rust_suffix
|
||||
rust_name = rust_type_name(name)
|
||||
# all the attributes right now are for location, so if it has attrs we
|
||||
# can just wrap it in Attributed<>
|
||||
|
@ -297,10 +304,9 @@ class StructVisitor(EmitVisitor):
|
|||
for t in sum.types:
|
||||
self.sum_subtype_struct(type_info, t, rust_name, depth)
|
||||
|
||||
generics, generics_applied = self.apply_generics(name, "U = ()", "U")
|
||||
self.emit_attrs(depth)
|
||||
self.emit("#[derive(is_macro::Is)]", depth)
|
||||
self.emit(f"pub enum {rust_name}{suffix}{generics} {{", depth)
|
||||
self.emit(f"pub enum {rust_name}<U> {{", 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:
|
||||
|
@ -308,33 +314,29 @@ class StructVisitor(EmitVisitor):
|
|||
f'#[is(name = "{rust_field_name(t.name)}_{rust_name.lower()}")]',
|
||||
depth + 1,
|
||||
)
|
||||
(t_generics_applied,) = self.apply_generics(t.name, "U")
|
||||
self.emit(
|
||||
f"{t.name}({rust_name}{t.name}{t_generics_applied}),", depth + 1
|
||||
f"{t.name}({rust_name}{t.name}<U>),", depth + 1
|
||||
)
|
||||
self.emit("}", depth)
|
||||
if type_info.has_attributes:
|
||||
self.emit(
|
||||
f"pub type {rust_name}<U = ()> = Attributed<{rust_name}{suffix}{generics_applied}, U>;",
|
||||
depth,
|
||||
)
|
||||
self.emit("", depth)
|
||||
|
||||
def sum_subtype_struct(self, sum_type_info, t, rust_name, depth):
|
||||
self.emit_attrs(depth)
|
||||
generics, generics_applied = self.apply_generics(t.name, "U = ()", "U")
|
||||
payload_name = f"{rust_name}{t.name}"
|
||||
self.emit(f"pub struct {payload_name}{generics} {{", depth)
|
||||
self.emit(f"pub struct {payload_name}<U> {{", depth)
|
||||
for f in t.fields:
|
||||
self.visit(f, sum_type_info, "pub ", depth + 1, t.name)
|
||||
self.emit("pub range: TextRange", depth + 1)
|
||||
|
||||
assert sum_type_info.has_attributes == self.type_info[t.name].needs_cfg(self.type_info)
|
||||
self.emit_custom(sum_type_info.has_attributes, depth)
|
||||
|
||||
self.emit("}", depth)
|
||||
self.emit(
|
||||
textwrap.dedent(
|
||||
f"""
|
||||
impl{generics_applied} From<{payload_name}{generics_applied}> for {rust_name}{sum_type_info.rust_suffix}{generics_applied} {{
|
||||
fn from(payload: {payload_name}{generics_applied}) -> Self {{
|
||||
{rust_name}{sum_type_info.rust_suffix}::{t.name}(payload)
|
||||
impl<U> From<{payload_name}<U>> for {rust_name}<U> {{
|
||||
fn from(payload: {payload_name}<U>) -> Self {{
|
||||
{rust_name}::{t.name}(payload)
|
||||
}}
|
||||
}}
|
||||
"""
|
||||
|
@ -342,12 +344,14 @@ class StructVisitor(EmitVisitor):
|
|||
depth,
|
||||
)
|
||||
|
||||
self.emit(f"impl{generics_applied} Ranged for {payload_name}{generics_applied} {{", depth)
|
||||
self.emit("#[inline]", depth + 1)
|
||||
self.emit("fn range(&self) -> TextRange {", depth + 1)
|
||||
self.emit("self.range", depth + 2)
|
||||
self.emit("}", depth + 1)
|
||||
self.emit("}", depth)
|
||||
# if not sum_type_info.has_attributes:
|
||||
# self.emit('#[cfg(feature = "more-attributes")]', depth)
|
||||
# self.emit(f"impl Ranged for {payload_name}<TextRange> {{", depth)
|
||||
# self.emit("#[inline]", depth + 1)
|
||||
# self.emit("fn range(&self) -> TextRange {", depth + 1)
|
||||
# self.emit("self.custom", depth + 2)
|
||||
# self.emit("}", depth + 1)
|
||||
# self.emit("}", depth)
|
||||
self.emit("", depth)
|
||||
|
||||
def visitConstructor(self, cons, parent, depth):
|
||||
|
@ -362,7 +366,7 @@ class StructVisitor(EmitVisitor):
|
|||
def visitField(self, field, parent, vis, depth, constructor=None):
|
||||
typ = rust_type_name(field.type)
|
||||
field_type = self.type_info.get(field.type)
|
||||
if field_type and field_type.has_user_data:
|
||||
if field_type and not field_type.is_simple:
|
||||
typ = f"{typ}<U>"
|
||||
# don't box if we're doing Vec<T>, but do box if we're doing Vec<Option<Box<T>>>
|
||||
if (
|
||||
|
@ -388,41 +392,23 @@ class StructVisitor(EmitVisitor):
|
|||
|
||||
def visitProduct(self, product, name, depth):
|
||||
type_info = self.type_info[name]
|
||||
generics, generics_applied = self.apply_generics(name, "U = ()", "U")
|
||||
data_name = rust_name = rust_type_name(name)
|
||||
if product.attributes:
|
||||
data_name = rust_name + "Data"
|
||||
product_name = rust_type_name(name)
|
||||
self.emit_attrs(depth)
|
||||
has_expr = product_has_expr(product)
|
||||
if has_expr:
|
||||
data_def = f"{data_name}{generics}"
|
||||
else:
|
||||
data_def = data_name
|
||||
generics_applied = ""
|
||||
|
||||
self.emit(f"pub struct {data_def} {{", depth)
|
||||
self.emit(f"pub struct {product_name}<U> {{", depth)
|
||||
for f in product.fields:
|
||||
self.visit(f, type_info, "pub ", depth + 1)
|
||||
self.emit("pub range: TextRange", depth + 1)
|
||||
assert bool(product.attributes) == type_info.needs_cfg(self.type_info)
|
||||
self.emit_custom(product.attributes, depth + 1)
|
||||
self.emit("}", depth)
|
||||
|
||||
self.emit(f"impl{generics_applied} Ranged for {data_name}{generics_applied} {{", depth)
|
||||
self.emit("#[inline]", depth + 1)
|
||||
self.emit("fn range(&self) -> TextRange {", depth + 1)
|
||||
self.emit("self.range", depth + 2)
|
||||
self.emit("}", depth + 1)
|
||||
self.emit("}", depth)
|
||||
self.emit("", depth)
|
||||
|
||||
if product.attributes:
|
||||
# attributes should just be location info
|
||||
if not has_expr:
|
||||
generics_applied = ""
|
||||
self.emit(
|
||||
f"pub type {rust_name}<U = ()> = Attributed<{data_name}{generics_applied}, U>;",
|
||||
depth,
|
||||
)
|
||||
|
||||
# self.emit('#[cfg(feature = "more-attributes")]', depth)
|
||||
# self.emit(f"impl Ranged for {product_name}<TextRange> {{", depth)
|
||||
# self.emit("#[inline]", depth + 1)
|
||||
# self.emit("fn range(&self) -> TextRange {", depth + 1)
|
||||
# self.emit("self.custom", depth + 2)
|
||||
# self.emit("}", depth + 1)
|
||||
# self.emit("}", depth)
|
||||
self.emit("", depth)
|
||||
|
||||
|
||||
|
@ -511,7 +497,7 @@ class FoldImplVisitor(EmitVisitor):
|
|||
self.emit("match node {", depth + 1)
|
||||
for cons in sum.types:
|
||||
fields_pattern = self.make_pattern(
|
||||
enum_name, type_info.rust_suffix, cons.name, cons.fields, simple
|
||||
enum_name, cons.name, cons.fields, simple
|
||||
)
|
||||
self.emit(
|
||||
f"{fields_pattern[0]} {{ {fields_pattern[1]}}} {fields_pattern[2]} => {{",
|
||||
|
@ -552,19 +538,19 @@ class FoldImplVisitor(EmitVisitor):
|
|||
rust_name = struct_name + "Data"
|
||||
else:
|
||||
rust_name = struct_name
|
||||
fields_pattern = self.make_pattern(rust_name, struct_name, None, product.fields, False)
|
||||
fields_pattern = self.make_pattern(rust_name, struct_name, product.fields, False)
|
||||
self.emit(f"let {rust_name} {{ {fields_pattern[1]} }} = node;", depth + 1)
|
||||
self.gen_construction(rust_name, product.fields, "", depth + 1, False)
|
||||
if has_attributes:
|
||||
self.emit("})", depth)
|
||||
self.emit("}", depth)
|
||||
|
||||
def make_pattern(self, rust_name, suffix, fieldname: str, fields, simple_sum: bool):
|
||||
def make_pattern(self, rust_name, fieldname: str, fields, simple_sum: bool):
|
||||
if fields or not simple_sum:
|
||||
header = f"{rust_name}{suffix}::{fieldname}({rust_name}{fieldname}"
|
||||
header = f"{rust_name}::{fieldname}({rust_name}{fieldname}"
|
||||
footer = ")"
|
||||
else:
|
||||
header = f"{rust_name}{suffix}::{fieldname}"
|
||||
header = f"{rust_name}::{fieldname}"
|
||||
footer = ""
|
||||
|
||||
body = ",".join(rust_field(f.name) for f in fields)
|
||||
|
@ -977,11 +963,6 @@ class ChainOfVisitors:
|
|||
|
||||
|
||||
def write_ast_def(mod, type_info, f):
|
||||
f.write("""
|
||||
use crate::text_size::{TextRange};
|
||||
use crate::Ranged;
|
||||
""")
|
||||
|
||||
StructVisitor(f, type_info).visit(mod)
|
||||
|
||||
|
||||
|
@ -996,33 +977,43 @@ def write_visitor_def(mod, type_info, f):
|
|||
VisitorModuleVisitor(f, type_info).visit(mod)
|
||||
|
||||
|
||||
def write_located_def(mod, type_info, f):
|
||||
f.write(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
use rustpython_parser_core::source_code::SourceRange;
|
||||
|
||||
pub type Located<T> = super::generic::Attributed<T, SourceRange>;
|
||||
"""
|
||||
)
|
||||
)
|
||||
def write_ranged_def(mod, type_info, f):
|
||||
for info in type_info.values():
|
||||
if info.empty_field:
|
||||
continue
|
||||
if info.has_user_data:
|
||||
if not info.is_simple:
|
||||
if info.needs_cfg:
|
||||
f.write('#[cfg(feature = "more-attributes")]')
|
||||
f.write(f"""
|
||||
impl Ranged for {info.rust_sum_name} {{
|
||||
fn range(&self) -> TextRange {{
|
||||
self.custom
|
||||
}}
|
||||
}}
|
||||
""")
|
||||
generics = "::<TextRange>"
|
||||
else:
|
||||
generics = ""
|
||||
f.write(
|
||||
f"pub type {info.rust_sum_name} = crate::generic::{info.rust_sum_name}{generics};\n"
|
||||
)
|
||||
|
||||
def write_located_def(mod, type_info, f):
|
||||
for info in type_info.values():
|
||||
if not info.is_simple:
|
||||
if info.needs_cfg:
|
||||
f.write('#[cfg(feature = "more-attributes")]')
|
||||
f.write(f"""
|
||||
impl Located for {info.rust_sum_name} {{
|
||||
fn range(&self) -> SourceRange {{
|
||||
self.custom
|
||||
}}
|
||||
}}
|
||||
""")
|
||||
generics = "::<SourceRange>"
|
||||
else:
|
||||
generics = ""
|
||||
f.write(
|
||||
f"pub type {info.rust_sum_name} = super::generic::{info.rust_sum_name}{generics};\n"
|
||||
f"pub type {info.rust_sum_name} = crate::generic::{info.rust_sum_name}{generics};\n"
|
||||
)
|
||||
if info.rust_suffix:
|
||||
if info.rust_suffix == "Data" and not info.has_expr:
|
||||
generics = ""
|
||||
f.write(
|
||||
f"pub type {info.rust_sum_name}{info.rust_suffix} = super::generic::{info.rust_sum_name}{info.rust_suffix}{generics};\n"
|
||||
)
|
||||
|
||||
|
||||
def write_ast_mod(mod, type_info, f):
|
||||
f.write(
|
||||
|
@ -1064,6 +1055,7 @@ def main(
|
|||
for filename, write in [
|
||||
("generic", write_ast_def),
|
||||
("fold", write_fold_def),
|
||||
("ranged", write_ranged_def),
|
||||
("located", write_located_def),
|
||||
("visitor", write_visitor_def),
|
||||
]:
|
||||
|
|
|
@ -161,7 +161,7 @@ pub fn fold_stmt<U, F: Fold<U> + ?Sized>(
|
|||
node: Stmt<U>,
|
||||
) -> Result<Stmt<F::TargetU>, F::Error> {
|
||||
fold_attributed(folder, node, |folder, node| match node {
|
||||
StmtKind::FunctionDef(StmtFunctionDef {
|
||||
Stmt::FunctionDef(StmtFunctionDef {
|
||||
range,
|
||||
name,
|
||||
args,
|
||||
|
@ -169,7 +169,7 @@ pub fn fold_stmt<U, F: Fold<U> + ?Sized>(
|
|||
decorator_list,
|
||||
returns,
|
||||
type_comment,
|
||||
}) => Ok(StmtKind::FunctionDef(StmtFunctionDef {
|
||||
}) => Ok(Stmt::FunctionDef(StmtFunctionDef {
|
||||
name: Foldable::fold(name, folder)?,
|
||||
args: Foldable::fold(args, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
|
@ -178,7 +178,7 @@ pub fn fold_stmt<U, F: Fold<U> + ?Sized>(
|
|||
type_comment: Foldable::fold(type_comment, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::AsyncFunctionDef(StmtAsyncFunctionDef {
|
||||
Stmt::AsyncFunctionDef(StmtAsyncFunctionDef {
|
||||
range,
|
||||
name,
|
||||
args,
|
||||
|
@ -186,7 +186,7 @@ pub fn fold_stmt<U, F: Fold<U> + ?Sized>(
|
|||
decorator_list,
|
||||
returns,
|
||||
type_comment,
|
||||
}) => Ok(StmtKind::AsyncFunctionDef(StmtAsyncFunctionDef {
|
||||
}) => Ok(Stmt::AsyncFunctionDef(StmtAsyncFunctionDef {
|
||||
name: Foldable::fold(name, folder)?,
|
||||
args: Foldable::fold(args, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
|
@ -195,14 +195,14 @@ pub fn fold_stmt<U, F: Fold<U> + ?Sized>(
|
|||
type_comment: Foldable::fold(type_comment, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::ClassDef(StmtClassDef {
|
||||
Stmt::ClassDef(StmtClassDef {
|
||||
range,
|
||||
name,
|
||||
bases,
|
||||
keywords,
|
||||
body,
|
||||
decorator_list,
|
||||
}) => Ok(StmtKind::ClassDef(StmtClassDef {
|
||||
}) => Ok(Stmt::ClassDef(StmtClassDef {
|
||||
name: Foldable::fold(name, folder)?,
|
||||
bases: Foldable::fold(bases, folder)?,
|
||||
keywords: Foldable::fold(keywords, folder)?,
|
||||
|
@ -210,57 +210,57 @@ pub fn fold_stmt<U, F: Fold<U> + ?Sized>(
|
|||
decorator_list: Foldable::fold(decorator_list, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Return(StmtReturn { range, value }) => Ok(StmtKind::Return(StmtReturn {
|
||||
Stmt::Return(StmtReturn { range, value }) => Ok(Stmt::Return(StmtReturn {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Delete(StmtDelete { range, targets }) => Ok(StmtKind::Delete(StmtDelete {
|
||||
Stmt::Delete(StmtDelete { range, targets }) => Ok(Stmt::Delete(StmtDelete {
|
||||
targets: Foldable::fold(targets, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Assign(StmtAssign {
|
||||
Stmt::Assign(StmtAssign {
|
||||
range,
|
||||
targets,
|
||||
value,
|
||||
type_comment,
|
||||
}) => Ok(StmtKind::Assign(StmtAssign {
|
||||
}) => Ok(Stmt::Assign(StmtAssign {
|
||||
targets: Foldable::fold(targets, folder)?,
|
||||
value: Foldable::fold(value, folder)?,
|
||||
type_comment: Foldable::fold(type_comment, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::AugAssign(StmtAugAssign {
|
||||
Stmt::AugAssign(StmtAugAssign {
|
||||
range,
|
||||
target,
|
||||
op,
|
||||
value,
|
||||
}) => Ok(StmtKind::AugAssign(StmtAugAssign {
|
||||
}) => Ok(Stmt::AugAssign(StmtAugAssign {
|
||||
target: Foldable::fold(target, folder)?,
|
||||
op: Foldable::fold(op, folder)?,
|
||||
value: Foldable::fold(value, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::AnnAssign(StmtAnnAssign {
|
||||
Stmt::AnnAssign(StmtAnnAssign {
|
||||
range,
|
||||
target,
|
||||
annotation,
|
||||
value,
|
||||
simple,
|
||||
}) => Ok(StmtKind::AnnAssign(StmtAnnAssign {
|
||||
}) => Ok(Stmt::AnnAssign(StmtAnnAssign {
|
||||
target: Foldable::fold(target, folder)?,
|
||||
annotation: Foldable::fold(annotation, folder)?,
|
||||
value: Foldable::fold(value, folder)?,
|
||||
simple: Foldable::fold(simple, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::For(StmtFor {
|
||||
Stmt::For(StmtFor {
|
||||
range,
|
||||
target,
|
||||
iter,
|
||||
body,
|
||||
orelse,
|
||||
type_comment,
|
||||
}) => Ok(StmtKind::For(StmtFor {
|
||||
}) => Ok(Stmt::For(StmtFor {
|
||||
target: Foldable::fold(target, folder)?,
|
||||
iter: Foldable::fold(iter, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
|
@ -268,14 +268,14 @@ pub fn fold_stmt<U, F: Fold<U> + ?Sized>(
|
|||
type_comment: Foldable::fold(type_comment, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::AsyncFor(StmtAsyncFor {
|
||||
Stmt::AsyncFor(StmtAsyncFor {
|
||||
range,
|
||||
target,
|
||||
iter,
|
||||
body,
|
||||
orelse,
|
||||
type_comment,
|
||||
}) => Ok(StmtKind::AsyncFor(StmtAsyncFor {
|
||||
}) => Ok(Stmt::AsyncFor(StmtAsyncFor {
|
||||
target: Foldable::fold(target, folder)?,
|
||||
iter: Foldable::fold(iter, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
|
@ -283,127 +283,125 @@ pub fn fold_stmt<U, F: Fold<U> + ?Sized>(
|
|||
type_comment: Foldable::fold(type_comment, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::While(StmtWhile {
|
||||
Stmt::While(StmtWhile {
|
||||
range,
|
||||
test,
|
||||
body,
|
||||
orelse,
|
||||
}) => Ok(StmtKind::While(StmtWhile {
|
||||
}) => Ok(Stmt::While(StmtWhile {
|
||||
test: Foldable::fold(test, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
orelse: Foldable::fold(orelse, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::If(StmtIf {
|
||||
Stmt::If(StmtIf {
|
||||
range,
|
||||
test,
|
||||
body,
|
||||
orelse,
|
||||
}) => Ok(StmtKind::If(StmtIf {
|
||||
}) => Ok(Stmt::If(StmtIf {
|
||||
test: Foldable::fold(test, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
orelse: Foldable::fold(orelse, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::With(StmtWith {
|
||||
Stmt::With(StmtWith {
|
||||
range,
|
||||
items,
|
||||
body,
|
||||
type_comment,
|
||||
}) => Ok(StmtKind::With(StmtWith {
|
||||
}) => Ok(Stmt::With(StmtWith {
|
||||
items: Foldable::fold(items, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
type_comment: Foldable::fold(type_comment, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::AsyncWith(StmtAsyncWith {
|
||||
Stmt::AsyncWith(StmtAsyncWith {
|
||||
range,
|
||||
items,
|
||||
body,
|
||||
type_comment,
|
||||
}) => Ok(StmtKind::AsyncWith(StmtAsyncWith {
|
||||
}) => Ok(Stmt::AsyncWith(StmtAsyncWith {
|
||||
items: Foldable::fold(items, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
type_comment: Foldable::fold(type_comment, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Match(StmtMatch {
|
||||
Stmt::Match(StmtMatch {
|
||||
range,
|
||||
subject,
|
||||
cases,
|
||||
}) => Ok(StmtKind::Match(StmtMatch {
|
||||
}) => Ok(Stmt::Match(StmtMatch {
|
||||
subject: Foldable::fold(subject, folder)?,
|
||||
cases: Foldable::fold(cases, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Raise(StmtRaise { range, exc, cause }) => Ok(StmtKind::Raise(StmtRaise {
|
||||
Stmt::Raise(StmtRaise { range, exc, cause }) => Ok(Stmt::Raise(StmtRaise {
|
||||
exc: Foldable::fold(exc, folder)?,
|
||||
cause: Foldable::fold(cause, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Try(StmtTry {
|
||||
Stmt::Try(StmtTry {
|
||||
range,
|
||||
body,
|
||||
handlers,
|
||||
orelse,
|
||||
finalbody,
|
||||
}) => Ok(StmtKind::Try(StmtTry {
|
||||
}) => Ok(Stmt::Try(StmtTry {
|
||||
body: Foldable::fold(body, folder)?,
|
||||
handlers: Foldable::fold(handlers, folder)?,
|
||||
orelse: Foldable::fold(orelse, folder)?,
|
||||
finalbody: Foldable::fold(finalbody, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::TryStar(StmtTryStar {
|
||||
Stmt::TryStar(StmtTryStar {
|
||||
range,
|
||||
body,
|
||||
handlers,
|
||||
orelse,
|
||||
finalbody,
|
||||
}) => Ok(StmtKind::TryStar(StmtTryStar {
|
||||
}) => Ok(Stmt::TryStar(StmtTryStar {
|
||||
body: Foldable::fold(body, folder)?,
|
||||
handlers: Foldable::fold(handlers, folder)?,
|
||||
orelse: Foldable::fold(orelse, folder)?,
|
||||
finalbody: Foldable::fold(finalbody, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Assert(StmtAssert { range, test, msg }) => Ok(StmtKind::Assert(StmtAssert {
|
||||
Stmt::Assert(StmtAssert { range, test, msg }) => Ok(Stmt::Assert(StmtAssert {
|
||||
test: Foldable::fold(test, folder)?,
|
||||
msg: Foldable::fold(msg, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Import(StmtImport { range, names }) => Ok(StmtKind::Import(StmtImport {
|
||||
Stmt::Import(StmtImport { range, names }) => Ok(Stmt::Import(StmtImport {
|
||||
names: Foldable::fold(names, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::ImportFrom(StmtImportFrom {
|
||||
Stmt::ImportFrom(StmtImportFrom {
|
||||
range,
|
||||
module,
|
||||
names,
|
||||
level,
|
||||
}) => Ok(StmtKind::ImportFrom(StmtImportFrom {
|
||||
}) => Ok(Stmt::ImportFrom(StmtImportFrom {
|
||||
module: Foldable::fold(module, folder)?,
|
||||
names: Foldable::fold(names, folder)?,
|
||||
level: Foldable::fold(level, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Global(StmtGlobal { range, names }) => Ok(StmtKind::Global(StmtGlobal {
|
||||
Stmt::Global(StmtGlobal { range, names }) => Ok(Stmt::Global(StmtGlobal {
|
||||
names: Foldable::fold(names, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Nonlocal(StmtNonlocal { range, names }) => Ok(StmtKind::Nonlocal(StmtNonlocal {
|
||||
Stmt::Nonlocal(StmtNonlocal { range, names }) => Ok(Stmt::Nonlocal(StmtNonlocal {
|
||||
names: Foldable::fold(names, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Expr(StmtExpr { range, value }) => Ok(StmtKind::Expr(StmtExpr {
|
||||
Stmt::Expr(StmtExpr { range, value }) => Ok(Stmt::Expr(StmtExpr {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
range,
|
||||
})),
|
||||
StmtKind::Pass(StmtPass { range }) => Ok(StmtKind::Pass(StmtPass { range })),
|
||||
StmtKind::Break(StmtBreak { range }) => Ok(StmtKind::Break(StmtBreak { range })),
|
||||
StmtKind::Continue(StmtContinue { range }) => {
|
||||
Ok(StmtKind::Continue(StmtContinue { range }))
|
||||
}
|
||||
Stmt::Pass(StmtPass { range }) => Ok(Stmt::Pass(StmtPass { range })),
|
||||
Stmt::Break(StmtBreak { range }) => Ok(Stmt::Break(StmtBreak { range })),
|
||||
Stmt::Continue(StmtContinue { range }) => Ok(Stmt::Continue(StmtContinue { range })),
|
||||
})
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for Expr<T> {
|
||||
|
@ -420,215 +418,205 @@ pub fn fold_expr<U, F: Fold<U> + ?Sized>(
|
|||
node: Expr<U>,
|
||||
) -> Result<Expr<F::TargetU>, F::Error> {
|
||||
fold_attributed(folder, node, |folder, node| match node {
|
||||
ExprKind::BoolOp(ExprBoolOp { range, op, values }) => Ok(ExprKind::BoolOp(ExprBoolOp {
|
||||
Expr::BoolOp(ExprBoolOp { range, op, values }) => Ok(Expr::BoolOp(ExprBoolOp {
|
||||
op: Foldable::fold(op, folder)?,
|
||||
values: Foldable::fold(values, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::NamedExpr(ExprNamedExpr {
|
||||
Expr::NamedExpr(ExprNamedExpr {
|
||||
range,
|
||||
target,
|
||||
value,
|
||||
}) => Ok(ExprKind::NamedExpr(ExprNamedExpr {
|
||||
}) => Ok(Expr::NamedExpr(ExprNamedExpr {
|
||||
target: Foldable::fold(target, folder)?,
|
||||
value: Foldable::fold(value, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::BinOp(ExprBinOp {
|
||||
Expr::BinOp(ExprBinOp {
|
||||
range,
|
||||
left,
|
||||
op,
|
||||
right,
|
||||
}) => Ok(ExprKind::BinOp(ExprBinOp {
|
||||
}) => Ok(Expr::BinOp(ExprBinOp {
|
||||
left: Foldable::fold(left, folder)?,
|
||||
op: Foldable::fold(op, folder)?,
|
||||
right: Foldable::fold(right, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::UnaryOp(ExprUnaryOp { range, op, operand }) => {
|
||||
Ok(ExprKind::UnaryOp(ExprUnaryOp {
|
||||
op: Foldable::fold(op, folder)?,
|
||||
operand: Foldable::fold(operand, folder)?,
|
||||
range,
|
||||
}))
|
||||
}
|
||||
ExprKind::Lambda(ExprLambda { range, args, body }) => Ok(ExprKind::Lambda(ExprLambda {
|
||||
Expr::UnaryOp(ExprUnaryOp { range, op, operand }) => Ok(Expr::UnaryOp(ExprUnaryOp {
|
||||
op: Foldable::fold(op, folder)?,
|
||||
operand: Foldable::fold(operand, folder)?,
|
||||
range,
|
||||
})),
|
||||
Expr::Lambda(ExprLambda { range, args, body }) => Ok(Expr::Lambda(ExprLambda {
|
||||
args: Foldable::fold(args, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::IfExp(ExprIfExp {
|
||||
Expr::IfExp(ExprIfExp {
|
||||
range,
|
||||
test,
|
||||
body,
|
||||
orelse,
|
||||
}) => Ok(ExprKind::IfExp(ExprIfExp {
|
||||
}) => Ok(Expr::IfExp(ExprIfExp {
|
||||
test: Foldable::fold(test, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
orelse: Foldable::fold(orelse, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::Dict(ExprDict {
|
||||
Expr::Dict(ExprDict {
|
||||
range,
|
||||
keys,
|
||||
values,
|
||||
}) => Ok(ExprKind::Dict(ExprDict {
|
||||
}) => Ok(Expr::Dict(ExprDict {
|
||||
keys: Foldable::fold(keys, folder)?,
|
||||
values: Foldable::fold(values, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::Set(ExprSet { range, elts }) => Ok(ExprKind::Set(ExprSet {
|
||||
Expr::Set(ExprSet { range, elts }) => Ok(Expr::Set(ExprSet {
|
||||
elts: Foldable::fold(elts, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::ListComp(ExprListComp {
|
||||
Expr::ListComp(ExprListComp {
|
||||
range,
|
||||
elt,
|
||||
generators,
|
||||
}) => Ok(ExprKind::ListComp(ExprListComp {
|
||||
}) => Ok(Expr::ListComp(ExprListComp {
|
||||
elt: Foldable::fold(elt, folder)?,
|
||||
generators: Foldable::fold(generators, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::SetComp(ExprSetComp {
|
||||
Expr::SetComp(ExprSetComp {
|
||||
range,
|
||||
elt,
|
||||
generators,
|
||||
}) => Ok(ExprKind::SetComp(ExprSetComp {
|
||||
}) => Ok(Expr::SetComp(ExprSetComp {
|
||||
elt: Foldable::fold(elt, folder)?,
|
||||
generators: Foldable::fold(generators, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::DictComp(ExprDictComp {
|
||||
Expr::DictComp(ExprDictComp {
|
||||
range,
|
||||
key,
|
||||
value,
|
||||
generators,
|
||||
}) => Ok(ExprKind::DictComp(ExprDictComp {
|
||||
}) => Ok(Expr::DictComp(ExprDictComp {
|
||||
key: Foldable::fold(key, folder)?,
|
||||
value: Foldable::fold(value, folder)?,
|
||||
generators: Foldable::fold(generators, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::GeneratorExp(ExprGeneratorExp {
|
||||
Expr::GeneratorExp(ExprGeneratorExp {
|
||||
range,
|
||||
elt,
|
||||
generators,
|
||||
}) => Ok(ExprKind::GeneratorExp(ExprGeneratorExp {
|
||||
}) => Ok(Expr::GeneratorExp(ExprGeneratorExp {
|
||||
elt: Foldable::fold(elt, folder)?,
|
||||
generators: Foldable::fold(generators, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::Await(ExprAwait { range, value }) => Ok(ExprKind::Await(ExprAwait {
|
||||
Expr::Await(ExprAwait { range, value }) => Ok(Expr::Await(ExprAwait {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::Yield(ExprYield { range, value }) => Ok(ExprKind::Yield(ExprYield {
|
||||
Expr::Yield(ExprYield { range, value }) => Ok(Expr::Yield(ExprYield {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::YieldFrom(ExprYieldFrom { range, value }) => {
|
||||
Ok(ExprKind::YieldFrom(ExprYieldFrom {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
range,
|
||||
}))
|
||||
}
|
||||
ExprKind::Compare(ExprCompare {
|
||||
Expr::YieldFrom(ExprYieldFrom { range, value }) => Ok(Expr::YieldFrom(ExprYieldFrom {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
range,
|
||||
})),
|
||||
Expr::Compare(ExprCompare {
|
||||
range,
|
||||
left,
|
||||
ops,
|
||||
comparators,
|
||||
}) => Ok(ExprKind::Compare(ExprCompare {
|
||||
}) => Ok(Expr::Compare(ExprCompare {
|
||||
left: Foldable::fold(left, folder)?,
|
||||
ops: Foldable::fold(ops, folder)?,
|
||||
comparators: Foldable::fold(comparators, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::Call(ExprCall {
|
||||
Expr::Call(ExprCall {
|
||||
range,
|
||||
func,
|
||||
args,
|
||||
keywords,
|
||||
}) => Ok(ExprKind::Call(ExprCall {
|
||||
}) => Ok(Expr::Call(ExprCall {
|
||||
func: Foldable::fold(func, folder)?,
|
||||
args: Foldable::fold(args, folder)?,
|
||||
keywords: Foldable::fold(keywords, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::FormattedValue(ExprFormattedValue {
|
||||
Expr::FormattedValue(ExprFormattedValue {
|
||||
range,
|
||||
value,
|
||||
conversion,
|
||||
format_spec,
|
||||
}) => Ok(ExprKind::FormattedValue(ExprFormattedValue {
|
||||
}) => Ok(Expr::FormattedValue(ExprFormattedValue {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
conversion: Foldable::fold(conversion, folder)?,
|
||||
format_spec: Foldable::fold(format_spec, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::JoinedStr(ExprJoinedStr { range, values }) => {
|
||||
Ok(ExprKind::JoinedStr(ExprJoinedStr {
|
||||
values: Foldable::fold(values, folder)?,
|
||||
range,
|
||||
}))
|
||||
}
|
||||
ExprKind::Constant(ExprConstant { range, value, kind }) => {
|
||||
Ok(ExprKind::Constant(ExprConstant {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
kind: Foldable::fold(kind, folder)?,
|
||||
range,
|
||||
}))
|
||||
}
|
||||
ExprKind::Attribute(ExprAttribute {
|
||||
Expr::JoinedStr(ExprJoinedStr { range, values }) => Ok(Expr::JoinedStr(ExprJoinedStr {
|
||||
values: Foldable::fold(values, folder)?,
|
||||
range,
|
||||
})),
|
||||
Expr::Constant(ExprConstant { range, value, kind }) => Ok(Expr::Constant(ExprConstant {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
kind: Foldable::fold(kind, folder)?,
|
||||
range,
|
||||
})),
|
||||
Expr::Attribute(ExprAttribute {
|
||||
range,
|
||||
value,
|
||||
attr,
|
||||
ctx,
|
||||
}) => Ok(ExprKind::Attribute(ExprAttribute {
|
||||
}) => Ok(Expr::Attribute(ExprAttribute {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
attr: Foldable::fold(attr, folder)?,
|
||||
ctx: Foldable::fold(ctx, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::Subscript(ExprSubscript {
|
||||
Expr::Subscript(ExprSubscript {
|
||||
range,
|
||||
value,
|
||||
slice,
|
||||
ctx,
|
||||
}) => Ok(ExprKind::Subscript(ExprSubscript {
|
||||
}) => Ok(Expr::Subscript(ExprSubscript {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
slice: Foldable::fold(slice, folder)?,
|
||||
ctx: Foldable::fold(ctx, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::Starred(ExprStarred { range, value, ctx }) => {
|
||||
Ok(ExprKind::Starred(ExprStarred {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
ctx: Foldable::fold(ctx, folder)?,
|
||||
range,
|
||||
}))
|
||||
}
|
||||
ExprKind::Name(ExprName { range, id, ctx }) => Ok(ExprKind::Name(ExprName {
|
||||
Expr::Starred(ExprStarred { range, value, ctx }) => Ok(Expr::Starred(ExprStarred {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
ctx: Foldable::fold(ctx, folder)?,
|
||||
range,
|
||||
})),
|
||||
Expr::Name(ExprName { range, id, ctx }) => Ok(Expr::Name(ExprName {
|
||||
id: Foldable::fold(id, folder)?,
|
||||
ctx: Foldable::fold(ctx, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::List(ExprList { range, elts, ctx }) => Ok(ExprKind::List(ExprList {
|
||||
Expr::List(ExprList { range, elts, ctx }) => Ok(Expr::List(ExprList {
|
||||
elts: Foldable::fold(elts, folder)?,
|
||||
ctx: Foldable::fold(ctx, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::Tuple(ExprTuple { range, elts, ctx }) => Ok(ExprKind::Tuple(ExprTuple {
|
||||
Expr::Tuple(ExprTuple { range, elts, ctx }) => Ok(Expr::Tuple(ExprTuple {
|
||||
elts: Foldable::fold(elts, folder)?,
|
||||
ctx: Foldable::fold(ctx, folder)?,
|
||||
range,
|
||||
})),
|
||||
ExprKind::Slice(ExprSlice {
|
||||
Expr::Slice(ExprSlice {
|
||||
range,
|
||||
lower,
|
||||
upper,
|
||||
step,
|
||||
}) => Ok(ExprKind::Slice(ExprSlice {
|
||||
}) => Ok(Expr::Slice(ExprSlice {
|
||||
lower: Foldable::fold(lower, folder)?,
|
||||
upper: Foldable::fold(upper, folder)?,
|
||||
step: Foldable::fold(step, folder)?,
|
||||
|
@ -790,19 +778,17 @@ pub fn fold_excepthandler<U, F: Fold<U> + ?Sized>(
|
|||
node: Excepthandler<U>,
|
||||
) -> Result<Excepthandler<F::TargetU>, F::Error> {
|
||||
fold_attributed(folder, node, |folder, node| match node {
|
||||
ExcepthandlerKind::ExceptHandler(ExcepthandlerExceptHandler {
|
||||
Excepthandler::ExceptHandler(ExcepthandlerExceptHandler {
|
||||
range,
|
||||
type_,
|
||||
name,
|
||||
body,
|
||||
}) => Ok(ExcepthandlerKind::ExceptHandler(
|
||||
ExcepthandlerExceptHandler {
|
||||
type_: Foldable::fold(type_, folder)?,
|
||||
name: Foldable::fold(name, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
range,
|
||||
},
|
||||
)),
|
||||
}) => Ok(Excepthandler::ExceptHandler(ExcepthandlerExceptHandler {
|
||||
type_: Foldable::fold(type_, folder)?,
|
||||
name: Foldable::fold(name, folder)?,
|
||||
body: Foldable::fold(body, folder)?,
|
||||
range,
|
||||
})),
|
||||
})
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for Arguments<T> {
|
||||
|
@ -979,65 +965,65 @@ pub fn fold_pattern<U, F: Fold<U> + ?Sized>(
|
|||
node: Pattern<U>,
|
||||
) -> Result<Pattern<F::TargetU>, F::Error> {
|
||||
fold_attributed(folder, node, |folder, node| match node {
|
||||
PatternKind::MatchValue(PatternMatchValue { range, value }) => {
|
||||
Ok(PatternKind::MatchValue(PatternMatchValue {
|
||||
Pattern::MatchValue(PatternMatchValue { range, value }) => {
|
||||
Ok(Pattern::MatchValue(PatternMatchValue {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
range,
|
||||
}))
|
||||
}
|
||||
PatternKind::MatchSingleton(PatternMatchSingleton { range, value }) => {
|
||||
Ok(PatternKind::MatchSingleton(PatternMatchSingleton {
|
||||
Pattern::MatchSingleton(PatternMatchSingleton { range, value }) => {
|
||||
Ok(Pattern::MatchSingleton(PatternMatchSingleton {
|
||||
value: Foldable::fold(value, folder)?,
|
||||
range,
|
||||
}))
|
||||
}
|
||||
PatternKind::MatchSequence(PatternMatchSequence { range, patterns }) => {
|
||||
Ok(PatternKind::MatchSequence(PatternMatchSequence {
|
||||
Pattern::MatchSequence(PatternMatchSequence { range, patterns }) => {
|
||||
Ok(Pattern::MatchSequence(PatternMatchSequence {
|
||||
patterns: Foldable::fold(patterns, folder)?,
|
||||
range,
|
||||
}))
|
||||
}
|
||||
PatternKind::MatchMapping(PatternMatchMapping {
|
||||
Pattern::MatchMapping(PatternMatchMapping {
|
||||
range,
|
||||
keys,
|
||||
patterns,
|
||||
rest,
|
||||
}) => Ok(PatternKind::MatchMapping(PatternMatchMapping {
|
||||
}) => Ok(Pattern::MatchMapping(PatternMatchMapping {
|
||||
keys: Foldable::fold(keys, folder)?,
|
||||
patterns: Foldable::fold(patterns, folder)?,
|
||||
rest: Foldable::fold(rest, folder)?,
|
||||
range,
|
||||
})),
|
||||
PatternKind::MatchClass(PatternMatchClass {
|
||||
Pattern::MatchClass(PatternMatchClass {
|
||||
range,
|
||||
cls,
|
||||
patterns,
|
||||
kwd_attrs,
|
||||
kwd_patterns,
|
||||
}) => Ok(PatternKind::MatchClass(PatternMatchClass {
|
||||
}) => Ok(Pattern::MatchClass(PatternMatchClass {
|
||||
cls: Foldable::fold(cls, folder)?,
|
||||
patterns: Foldable::fold(patterns, folder)?,
|
||||
kwd_attrs: Foldable::fold(kwd_attrs, folder)?,
|
||||
kwd_patterns: Foldable::fold(kwd_patterns, folder)?,
|
||||
range,
|
||||
})),
|
||||
PatternKind::MatchStar(PatternMatchStar { range, name }) => {
|
||||
Ok(PatternKind::MatchStar(PatternMatchStar {
|
||||
Pattern::MatchStar(PatternMatchStar { range, name }) => {
|
||||
Ok(Pattern::MatchStar(PatternMatchStar {
|
||||
name: Foldable::fold(name, folder)?,
|
||||
range,
|
||||
}))
|
||||
}
|
||||
PatternKind::MatchAs(PatternMatchAs {
|
||||
Pattern::MatchAs(PatternMatchAs {
|
||||
range,
|
||||
pattern,
|
||||
name,
|
||||
}) => Ok(PatternKind::MatchAs(PatternMatchAs {
|
||||
}) => Ok(Pattern::MatchAs(PatternMatchAs {
|
||||
pattern: Foldable::fold(pattern, folder)?,
|
||||
name: Foldable::fold(name, folder)?,
|
||||
range,
|
||||
})),
|
||||
PatternKind::MatchOr(PatternMatchOr { range, patterns }) => {
|
||||
Ok(PatternKind::MatchOr(PatternMatchOr {
|
||||
Pattern::MatchOr(PatternMatchOr { range, patterns }) => {
|
||||
Ok(Pattern::MatchOr(PatternMatchOr {
|
||||
patterns: Foldable::fold(patterns, folder)?,
|
||||
range,
|
||||
}))
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,95 +1,574 @@
|
|||
// File automatically generated by ast/asdl_rs.py.
|
||||
|
||||
use rustpython_parser_core::source_code::SourceRange;
|
||||
|
||||
pub type Located<T> = super::generic::Attributed<T, SourceRange>;
|
||||
pub type Mod = super::generic::Mod<SourceRange>;
|
||||
pub type ModModule = super::generic::ModModule<SourceRange>;
|
||||
pub type ModInteractive = super::generic::ModInteractive<SourceRange>;
|
||||
pub type ModExpression = super::generic::ModExpression<SourceRange>;
|
||||
pub type ModFunctionType = super::generic::ModFunctionType<SourceRange>;
|
||||
pub type Stmt = super::generic::Stmt<SourceRange>;
|
||||
pub type StmtKind = super::generic::StmtKind<SourceRange>;
|
||||
pub type StmtFunctionDef = super::generic::StmtFunctionDef<SourceRange>;
|
||||
pub type StmtAsyncFunctionDef = super::generic::StmtAsyncFunctionDef<SourceRange>;
|
||||
pub type StmtClassDef = super::generic::StmtClassDef<SourceRange>;
|
||||
pub type StmtReturn = super::generic::StmtReturn<SourceRange>;
|
||||
pub type StmtDelete = super::generic::StmtDelete<SourceRange>;
|
||||
pub type StmtAssign = super::generic::StmtAssign<SourceRange>;
|
||||
pub type StmtAugAssign = super::generic::StmtAugAssign<SourceRange>;
|
||||
pub type StmtAnnAssign = super::generic::StmtAnnAssign<SourceRange>;
|
||||
pub type StmtFor = super::generic::StmtFor<SourceRange>;
|
||||
pub type StmtAsyncFor = super::generic::StmtAsyncFor<SourceRange>;
|
||||
pub type StmtWhile = super::generic::StmtWhile<SourceRange>;
|
||||
pub type StmtIf = super::generic::StmtIf<SourceRange>;
|
||||
pub type StmtWith = super::generic::StmtWith<SourceRange>;
|
||||
pub type StmtAsyncWith = super::generic::StmtAsyncWith<SourceRange>;
|
||||
pub type StmtMatch = super::generic::StmtMatch<SourceRange>;
|
||||
pub type StmtRaise = super::generic::StmtRaise<SourceRange>;
|
||||
pub type StmtTry = super::generic::StmtTry<SourceRange>;
|
||||
pub type StmtTryStar = super::generic::StmtTryStar<SourceRange>;
|
||||
pub type StmtAssert = super::generic::StmtAssert<SourceRange>;
|
||||
pub type StmtImport = super::generic::StmtImport<SourceRange>;
|
||||
pub type StmtImportFrom = super::generic::StmtImportFrom<SourceRange>;
|
||||
pub type StmtGlobal = super::generic::StmtGlobal;
|
||||
pub type StmtNonlocal = super::generic::StmtNonlocal;
|
||||
pub type StmtExpr = super::generic::StmtExpr<SourceRange>;
|
||||
pub type Expr = super::generic::Expr<SourceRange>;
|
||||
pub type ExprKind = super::generic::ExprKind<SourceRange>;
|
||||
pub type ExprBoolOp = super::generic::ExprBoolOp<SourceRange>;
|
||||
pub type ExprNamedExpr = super::generic::ExprNamedExpr<SourceRange>;
|
||||
pub type ExprBinOp = super::generic::ExprBinOp<SourceRange>;
|
||||
pub type ExprUnaryOp = super::generic::ExprUnaryOp<SourceRange>;
|
||||
pub type ExprLambda = super::generic::ExprLambda<SourceRange>;
|
||||
pub type ExprIfExp = super::generic::ExprIfExp<SourceRange>;
|
||||
pub type ExprDict = super::generic::ExprDict<SourceRange>;
|
||||
pub type ExprSet = super::generic::ExprSet<SourceRange>;
|
||||
pub type ExprListComp = super::generic::ExprListComp<SourceRange>;
|
||||
pub type ExprSetComp = super::generic::ExprSetComp<SourceRange>;
|
||||
pub type ExprDictComp = super::generic::ExprDictComp<SourceRange>;
|
||||
pub type ExprGeneratorExp = super::generic::ExprGeneratorExp<SourceRange>;
|
||||
pub type ExprAwait = super::generic::ExprAwait<SourceRange>;
|
||||
pub type ExprYield = super::generic::ExprYield<SourceRange>;
|
||||
pub type ExprYieldFrom = super::generic::ExprYieldFrom<SourceRange>;
|
||||
pub type ExprCompare = super::generic::ExprCompare<SourceRange>;
|
||||
pub type ExprCall = super::generic::ExprCall<SourceRange>;
|
||||
pub type ExprFormattedValue = super::generic::ExprFormattedValue<SourceRange>;
|
||||
pub type ExprJoinedStr = super::generic::ExprJoinedStr<SourceRange>;
|
||||
pub type ExprConstant = super::generic::ExprConstant;
|
||||
pub type ExprAttribute = super::generic::ExprAttribute<SourceRange>;
|
||||
pub type ExprSubscript = super::generic::ExprSubscript<SourceRange>;
|
||||
pub type ExprStarred = super::generic::ExprStarred<SourceRange>;
|
||||
pub type ExprName = super::generic::ExprName;
|
||||
pub type ExprList = super::generic::ExprList<SourceRange>;
|
||||
pub type ExprTuple = super::generic::ExprTuple<SourceRange>;
|
||||
pub type ExprSlice = super::generic::ExprSlice<SourceRange>;
|
||||
pub type ExprContext = super::generic::ExprContext;
|
||||
pub type Boolop = super::generic::Boolop;
|
||||
pub type Operator = super::generic::Operator;
|
||||
pub type Unaryop = super::generic::Unaryop;
|
||||
pub type Cmpop = super::generic::Cmpop;
|
||||
pub type Comprehension = super::generic::Comprehension<SourceRange>;
|
||||
pub type Excepthandler = super::generic::Excepthandler<SourceRange>;
|
||||
pub type ExcepthandlerKind = super::generic::ExcepthandlerKind<SourceRange>;
|
||||
pub type ExcepthandlerExceptHandler = super::generic::ExcepthandlerExceptHandler<SourceRange>;
|
||||
pub type Arguments = super::generic::Arguments<SourceRange>;
|
||||
pub type Arg = super::generic::Arg<SourceRange>;
|
||||
pub type ArgData = super::generic::ArgData<SourceRange>;
|
||||
pub type Keyword = super::generic::Keyword<SourceRange>;
|
||||
pub type KeywordData = super::generic::KeywordData<SourceRange>;
|
||||
pub type Alias = super::generic::Alias<SourceRange>;
|
||||
pub type AliasData = super::generic::AliasData;
|
||||
pub type Withitem = super::generic::Withitem<SourceRange>;
|
||||
pub type MatchCase = super::generic::MatchCase<SourceRange>;
|
||||
pub type Pattern = super::generic::Pattern<SourceRange>;
|
||||
pub type PatternKind = super::generic::PatternKind<SourceRange>;
|
||||
pub type PatternMatchValue = super::generic::PatternMatchValue<SourceRange>;
|
||||
pub type PatternMatchSingleton = super::generic::PatternMatchSingleton;
|
||||
pub type PatternMatchSequence = super::generic::PatternMatchSequence<SourceRange>;
|
||||
pub type PatternMatchMapping = super::generic::PatternMatchMapping<SourceRange>;
|
||||
pub type PatternMatchClass = super::generic::PatternMatchClass<SourceRange>;
|
||||
pub type PatternMatchStar = super::generic::PatternMatchStar;
|
||||
pub type PatternMatchAs = super::generic::PatternMatchAs<SourceRange>;
|
||||
pub type PatternMatchOr = super::generic::PatternMatchOr<SourceRange>;
|
||||
pub type TypeIgnore = super::generic::TypeIgnore;
|
||||
pub type TypeIgnoreTypeIgnore = super::generic::TypeIgnoreTypeIgnore;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Mod {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Mod = crate::generic::Mod<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ModModule {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ModModule = crate::generic::ModModule<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ModInteractive {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ModInteractive = crate::generic::ModInteractive<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ModExpression {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ModExpression = crate::generic::ModExpression<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ModFunctionType {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ModFunctionType = crate::generic::ModFunctionType<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Stmt {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Stmt = crate::generic::Stmt<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtFunctionDef {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtFunctionDef = crate::generic::StmtFunctionDef<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtAsyncFunctionDef {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAsyncFunctionDef = crate::generic::StmtAsyncFunctionDef<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtClassDef {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtClassDef = crate::generic::StmtClassDef<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtReturn {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtReturn = crate::generic::StmtReturn<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtDelete {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtDelete = crate::generic::StmtDelete<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtAssign {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAssign = crate::generic::StmtAssign<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtAugAssign {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAugAssign = crate::generic::StmtAugAssign<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtAnnAssign {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAnnAssign = crate::generic::StmtAnnAssign<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtFor {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtFor = crate::generic::StmtFor<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtAsyncFor {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAsyncFor = crate::generic::StmtAsyncFor<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtWhile {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtWhile = crate::generic::StmtWhile<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtIf {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtIf = crate::generic::StmtIf<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtWith {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtWith = crate::generic::StmtWith<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtAsyncWith {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAsyncWith = crate::generic::StmtAsyncWith<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtMatch {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtMatch = crate::generic::StmtMatch<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtRaise {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtRaise = crate::generic::StmtRaise<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtTry {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtTry = crate::generic::StmtTry<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtTryStar {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtTryStar = crate::generic::StmtTryStar<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtAssert {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAssert = crate::generic::StmtAssert<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtImport {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtImport = crate::generic::StmtImport<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtImportFrom {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtImportFrom = crate::generic::StmtImportFrom<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtGlobal {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtGlobal = crate::generic::StmtGlobal<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtNonlocal {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtNonlocal = crate::generic::StmtNonlocal<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtExpr {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtExpr = crate::generic::StmtExpr<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtPass {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtPass = crate::generic::StmtPass<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtBreak {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtBreak = crate::generic::StmtBreak<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for StmtContinue {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtContinue = crate::generic::StmtContinue<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Expr {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Expr = crate::generic::Expr<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprBoolOp {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprBoolOp = crate::generic::ExprBoolOp<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprNamedExpr {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprNamedExpr = crate::generic::ExprNamedExpr<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprBinOp {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprBinOp = crate::generic::ExprBinOp<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprUnaryOp {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprUnaryOp = crate::generic::ExprUnaryOp<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprLambda {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprLambda = crate::generic::ExprLambda<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprIfExp {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprIfExp = crate::generic::ExprIfExp<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprDict {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprDict = crate::generic::ExprDict<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprSet {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprSet = crate::generic::ExprSet<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprListComp {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprListComp = crate::generic::ExprListComp<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprSetComp {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprSetComp = crate::generic::ExprSetComp<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprDictComp {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprDictComp = crate::generic::ExprDictComp<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprGeneratorExp {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprGeneratorExp = crate::generic::ExprGeneratorExp<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprAwait {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprAwait = crate::generic::ExprAwait<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprYield {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprYield = crate::generic::ExprYield<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprYieldFrom {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprYieldFrom = crate::generic::ExprYieldFrom<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprCompare {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprCompare = crate::generic::ExprCompare<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprCall {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprCall = crate::generic::ExprCall<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprFormattedValue {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprFormattedValue = crate::generic::ExprFormattedValue<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprJoinedStr {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprJoinedStr = crate::generic::ExprJoinedStr<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprConstant {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprConstant = crate::generic::ExprConstant<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprAttribute {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprAttribute = crate::generic::ExprAttribute<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprSubscript {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprSubscript = crate::generic::ExprSubscript<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprStarred {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprStarred = crate::generic::ExprStarred<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprName {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprName = crate::generic::ExprName<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprList {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprList = crate::generic::ExprList<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprTuple {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprTuple = crate::generic::ExprTuple<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExprSlice {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprSlice = crate::generic::ExprSlice<SourceRange>;
|
||||
pub type ExprContext = crate::generic::ExprContext;
|
||||
pub type Boolop = crate::generic::Boolop;
|
||||
pub type Operator = crate::generic::Operator;
|
||||
pub type Unaryop = crate::generic::Unaryop;
|
||||
pub type Cmpop = crate::generic::Cmpop;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Comprehension {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Comprehension = crate::generic::Comprehension<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Excepthandler {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Excepthandler = crate::generic::Excepthandler<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for ExcepthandlerExceptHandler {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExcepthandlerExceptHandler = crate::generic::ExcepthandlerExceptHandler<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Arguments {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Arguments = crate::generic::Arguments<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Arg {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Arg = crate::generic::Arg<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Keyword {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Keyword = crate::generic::Keyword<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Alias {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Alias = crate::generic::Alias<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Withitem {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Withitem = crate::generic::Withitem<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for MatchCase {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type MatchCase = crate::generic::MatchCase<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for Pattern {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Pattern = crate::generic::Pattern<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for PatternMatchValue {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchValue = crate::generic::PatternMatchValue<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for PatternMatchSingleton {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchSingleton = crate::generic::PatternMatchSingleton<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for PatternMatchSequence {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchSequence = crate::generic::PatternMatchSequence<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for PatternMatchMapping {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchMapping = crate::generic::PatternMatchMapping<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for PatternMatchClass {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchClass = crate::generic::PatternMatchClass<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for PatternMatchStar {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchStar = crate::generic::PatternMatchStar<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for PatternMatchAs {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchAs = crate::generic::PatternMatchAs<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for PatternMatchOr {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchOr = crate::generic::PatternMatchOr<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for TypeIgnore {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type TypeIgnore = crate::generic::TypeIgnore<SourceRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Located for TypeIgnoreTypeIgnore {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type TypeIgnoreTypeIgnore = crate::generic::TypeIgnoreTypeIgnore<SourceRange>;
|
||||
|
|
574
ast/src/gen/ranged.rs
Normal file
574
ast/src/gen/ranged.rs
Normal file
|
@ -0,0 +1,574 @@
|
|||
// File automatically generated by ast/asdl_rs.py.
|
||||
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Mod {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Mod = crate::generic::Mod<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ModModule {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ModModule = crate::generic::ModModule<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ModInteractive {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ModInteractive = crate::generic::ModInteractive<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ModExpression {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ModExpression = crate::generic::ModExpression<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ModFunctionType {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ModFunctionType = crate::generic::ModFunctionType<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Stmt {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Stmt = crate::generic::Stmt<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtFunctionDef {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtFunctionDef = crate::generic::StmtFunctionDef<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtAsyncFunctionDef {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAsyncFunctionDef = crate::generic::StmtAsyncFunctionDef<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtClassDef {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtClassDef = crate::generic::StmtClassDef<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtReturn {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtReturn = crate::generic::StmtReturn<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtDelete {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtDelete = crate::generic::StmtDelete<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtAssign {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAssign = crate::generic::StmtAssign<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtAugAssign {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAugAssign = crate::generic::StmtAugAssign<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtAnnAssign {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAnnAssign = crate::generic::StmtAnnAssign<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtFor {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtFor = crate::generic::StmtFor<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtAsyncFor {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAsyncFor = crate::generic::StmtAsyncFor<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtWhile {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtWhile = crate::generic::StmtWhile<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtIf {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtIf = crate::generic::StmtIf<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtWith {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtWith = crate::generic::StmtWith<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtAsyncWith {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAsyncWith = crate::generic::StmtAsyncWith<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtMatch {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtMatch = crate::generic::StmtMatch<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtRaise {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtRaise = crate::generic::StmtRaise<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtTry {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtTry = crate::generic::StmtTry<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtTryStar {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtTryStar = crate::generic::StmtTryStar<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtAssert {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtAssert = crate::generic::StmtAssert<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtImport {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtImport = crate::generic::StmtImport<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtImportFrom {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtImportFrom = crate::generic::StmtImportFrom<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtGlobal {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtGlobal = crate::generic::StmtGlobal<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtNonlocal {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtNonlocal = crate::generic::StmtNonlocal<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtExpr {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtExpr = crate::generic::StmtExpr<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtPass {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtPass = crate::generic::StmtPass<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtBreak {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtBreak = crate::generic::StmtBreak<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for StmtContinue {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type StmtContinue = crate::generic::StmtContinue<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Expr {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Expr = crate::generic::Expr<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprBoolOp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprBoolOp = crate::generic::ExprBoolOp<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprNamedExpr {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprNamedExpr = crate::generic::ExprNamedExpr<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprBinOp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprBinOp = crate::generic::ExprBinOp<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprUnaryOp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprUnaryOp = crate::generic::ExprUnaryOp<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprLambda {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprLambda = crate::generic::ExprLambda<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprIfExp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprIfExp = crate::generic::ExprIfExp<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprDict {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprDict = crate::generic::ExprDict<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprSet {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprSet = crate::generic::ExprSet<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprListComp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprListComp = crate::generic::ExprListComp<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprSetComp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprSetComp = crate::generic::ExprSetComp<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprDictComp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprDictComp = crate::generic::ExprDictComp<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprGeneratorExp {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprGeneratorExp = crate::generic::ExprGeneratorExp<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprAwait {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprAwait = crate::generic::ExprAwait<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprYield {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprYield = crate::generic::ExprYield<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprYieldFrom {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprYieldFrom = crate::generic::ExprYieldFrom<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprCompare {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprCompare = crate::generic::ExprCompare<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprCall {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprCall = crate::generic::ExprCall<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprFormattedValue {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprFormattedValue = crate::generic::ExprFormattedValue<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprJoinedStr {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprJoinedStr = crate::generic::ExprJoinedStr<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprConstant {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprConstant = crate::generic::ExprConstant<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprAttribute {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprAttribute = crate::generic::ExprAttribute<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprSubscript {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprSubscript = crate::generic::ExprSubscript<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprStarred {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprStarred = crate::generic::ExprStarred<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprName {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprName = crate::generic::ExprName<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprList {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprList = crate::generic::ExprList<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprTuple {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprTuple = crate::generic::ExprTuple<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExprSlice {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExprSlice = crate::generic::ExprSlice<TextRange>;
|
||||
pub type ExprContext = crate::generic::ExprContext;
|
||||
pub type Boolop = crate::generic::Boolop;
|
||||
pub type Operator = crate::generic::Operator;
|
||||
pub type Unaryop = crate::generic::Unaryop;
|
||||
pub type Cmpop = crate::generic::Cmpop;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Comprehension {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Comprehension = crate::generic::Comprehension<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Excepthandler {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Excepthandler = crate::generic::Excepthandler<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for ExcepthandlerExceptHandler {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type ExcepthandlerExceptHandler = crate::generic::ExcepthandlerExceptHandler<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Arguments {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Arguments = crate::generic::Arguments<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Arg {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Arg = crate::generic::Arg<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Keyword {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Keyword = crate::generic::Keyword<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Alias {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Alias = crate::generic::Alias<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Withitem {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Withitem = crate::generic::Withitem<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for MatchCase {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type MatchCase = crate::generic::MatchCase<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for Pattern {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type Pattern = crate::generic::Pattern<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for PatternMatchValue {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchValue = crate::generic::PatternMatchValue<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for PatternMatchSingleton {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchSingleton = crate::generic::PatternMatchSingleton<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for PatternMatchSequence {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchSequence = crate::generic::PatternMatchSequence<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for PatternMatchMapping {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchMapping = crate::generic::PatternMatchMapping<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for PatternMatchClass {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchClass = crate::generic::PatternMatchClass<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for PatternMatchStar {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchStar = crate::generic::PatternMatchStar<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for PatternMatchAs {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchAs = crate::generic::PatternMatchAs<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for PatternMatchOr {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type PatternMatchOr = crate::generic::PatternMatchOr<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for TypeIgnore {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type TypeIgnore = crate::generic::TypeIgnore<TextRange>;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
impl Ranged for TypeIgnoreTypeIgnore {
|
||||
fn range(&self) -> TextRange {
|
||||
self.custom
|
||||
}
|
||||
}
|
||||
pub type TypeIgnoreTypeIgnore = crate::generic::TypeIgnoreTypeIgnore<TextRange>;
|
|
@ -1,13 +1,14 @@
|
|||
mod builtin;
|
||||
#[cfg(feature = "fold")]
|
||||
mod fold_helpers;
|
||||
mod generic {
|
||||
pub mod generic {
|
||||
#![allow(clippy::derive_partial_eq_without_eq)]
|
||||
pub use crate::builtin::*;
|
||||
|
||||
include!("gen/generic.rs");
|
||||
}
|
||||
mod impls;
|
||||
pub mod ranged;
|
||||
// mod impls; // TODO: temp disable
|
||||
#[cfg(feature = "location")]
|
||||
mod source_locator;
|
||||
#[cfg(feature = "unparse")]
|
||||
|
@ -19,18 +20,6 @@ pub use rustpython_parser_core::{text_size, ConversionFlag};
|
|||
|
||||
pub type Suite<U = ()> = Vec<Stmt<U>>;
|
||||
|
||||
pub trait Ranged {
|
||||
fn range(&self) -> TextRange;
|
||||
|
||||
fn start(&self) -> TextSize {
|
||||
self.range().start()
|
||||
}
|
||||
|
||||
fn end(&self) -> TextSize {
|
||||
self.range().end()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "fold")]
|
||||
pub mod fold {
|
||||
use super::generic::*;
|
||||
|
@ -45,9 +34,7 @@ mod visitor {
|
|||
}
|
||||
|
||||
#[cfg(feature = "location")]
|
||||
pub mod located {
|
||||
include!("gen/located.rs");
|
||||
}
|
||||
pub mod located;
|
||||
|
||||
#[cfg(feature = "location")]
|
||||
pub use rustpython_parser_core::source_code;
|
||||
|
@ -57,6 +44,5 @@ pub use visitor::Visitor;
|
|||
#[cfg(feature = "constant-optimization")]
|
||||
mod optimizer;
|
||||
|
||||
use crate::text_size::{TextRange, TextSize};
|
||||
#[cfg(feature = "constant-optimization")]
|
||||
pub use optimizer::ConstantOptimizer;
|
||||
|
|
17
ast/src/located.rs
Normal file
17
ast/src/located.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
#![allow(clippy::derive_partial_eq_without_eq)]
|
||||
use crate::source_code::{SourceLocation, SourceRange};
|
||||
|
||||
pub trait Located {
|
||||
fn range(&self) -> SourceRange;
|
||||
|
||||
fn location(&self) -> SourceLocation {
|
||||
self.range().start()
|
||||
}
|
||||
|
||||
fn end_location(&self) -> SourceLocation {
|
||||
self.range().end()
|
||||
}
|
||||
}
|
||||
|
||||
pub use crate::builtin::*;
|
||||
include!("gen/located.rs");
|
17
ast/src/ranged.rs
Normal file
17
ast/src/ranged.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
#![allow(clippy::derive_partial_eq_without_eq)]
|
||||
use crate::text_size::{TextRange, TextSize};
|
||||
|
||||
pub trait Ranged {
|
||||
fn range(&self) -> TextRange;
|
||||
|
||||
fn start(&self) -> TextSize {
|
||||
self.range().start()
|
||||
}
|
||||
|
||||
fn end(&self) -> TextSize {
|
||||
self.range().end()
|
||||
}
|
||||
}
|
||||
|
||||
pub use crate::builtin::*;
|
||||
include!("gen/ranged.rs");
|
|
@ -4,7 +4,7 @@
|
|||
// See also: https://greentreesnakes.readthedocs.io/en/latest/nodes.html#keyword
|
||||
|
||||
use crate::{
|
||||
ast::{self, Ranged},
|
||||
ast::ranged::{self as ast, Ranged},
|
||||
lexer::{LexicalError, LexicalErrorType},
|
||||
function::{ArgumentList, parse_args, parse_params, validate_arguments},
|
||||
context::set_context,
|
||||
|
|
6
parser/src/python.rs
generated
6
parser/src/python.rs
generated
|
@ -1,7 +1,7 @@
|
|||
// auto-generated: "lalrpop 0.20.0"
|
||||
// sha3: 888004f35fc4f9b0dfa2a4425adf0308b0b1a6bb8153ba94dc5c5f28fd3e263c
|
||||
// sha3: 8a3fbd9c7ec6b7da4f0fc78dee12593317d7407da92a4ff54c0c398bf36bee6e
|
||||
use crate::{
|
||||
ast::{self, Ranged},
|
||||
ast::ranged::{self as ast, Ranged},
|
||||
lexer::{LexicalError, LexicalErrorType},
|
||||
function::{ArgumentList, parse_args, parse_params, validate_arguments},
|
||||
context::set_context,
|
||||
|
@ -22,7 +22,7 @@ extern crate alloc;
|
|||
mod __parse__Top {
|
||||
|
||||
use crate::{
|
||||
ast::{self, Ranged},
|
||||
ast::ranged::{self as ast, Ranged},
|
||||
lexer::{LexicalError, LexicalErrorType},
|
||||
function::{ArgumentList, parse_args, parse_params, validate_arguments},
|
||||
context::set_context,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue