mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
keep original Arguments as PythonArguments
This commit is contained in:
parent
b4d0eafd3e
commit
23020027d1
39 changed files with 722 additions and 5615 deletions
|
@ -808,7 +808,7 @@ impl<R> PyNode for ast::ExcepthandlerExceptHandler<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R> PyNode for ast::Arguments<R> {
|
||||
impl<R> PyNode for ast::PythonArguments<R> {
|
||||
#[inline]
|
||||
fn py_type_cache() -> &'static OnceCell<(Py<PyAny>, Py<PyAny>)> {
|
||||
static PY_TYPE: OnceCell<(Py<PyAny>, Py<PyAny>)> = OnceCell::new();
|
||||
|
@ -2288,7 +2288,7 @@ impl ToPyAst for ast::ExcepthandlerExceptHandler<TextRange> {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToPyAst for ast::Arguments<TextRange> {
|
||||
impl ToPyAst for ast::PythonArguments<TextRange> {
|
||||
#[inline]
|
||||
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
|
||||
let cache = Self::py_type_cache().get().unwrap();
|
||||
|
@ -4312,7 +4312,7 @@ impl ToPyAst for ast::ExcepthandlerExceptHandler<SourceRange> {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToPyAst for ast::Arguments<SourceRange> {
|
||||
impl ToPyAst for ast::PythonArguments<SourceRange> {
|
||||
#[inline]
|
||||
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
|
||||
let cache = Self::py_type_cache().get().unwrap();
|
||||
|
@ -4820,7 +4820,7 @@ fn init_types(py: Python) -> PyResult<()> {
|
|||
cache_py_type::<ast::Comprehension>(ast_module)?;
|
||||
cache_py_type::<ast::Excepthandler>(ast_module)?;
|
||||
cache_py_type::<ast::ExcepthandlerExceptHandler>(ast_module)?;
|
||||
cache_py_type::<ast::Arguments>(ast_module)?;
|
||||
cache_py_type::<ast::PythonArguments>(ast_module)?;
|
||||
cache_py_type::<ast::Arg>(ast_module)?;
|
||||
cache_py_type::<ast::Keyword>(ast_module)?;
|
||||
cache_py_type::<ast::Alias>(ast_module)?;
|
||||
|
|
|
@ -3289,10 +3289,10 @@ impl ExcepthandlerExceptHandler {
|
|||
|
||||
#[pyclass(module="rustpython_ast.located", name="_arguments", extends=super::Ast, frozen)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Arguments(pub &'static ast::Arguments<SourceRange>);
|
||||
pub struct Arguments(pub &'static ast::PythonArguments<SourceRange>);
|
||||
|
||||
impl From<&'static ast::Arguments<SourceRange>> for Arguments {
|
||||
fn from(node: &'static ast::Arguments<SourceRange>) -> Self {
|
||||
impl From<&'static ast::PythonArguments<SourceRange>> for Arguments {
|
||||
fn from(node: &'static ast::PythonArguments<SourceRange>) -> Self {
|
||||
Arguments(node)
|
||||
}
|
||||
}
|
||||
|
@ -3304,7 +3304,7 @@ impl ToPyObject for Arguments {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToPyWrapper for ast::Arguments<SourceRange> {
|
||||
impl ToPyWrapper for ast::PythonArguments<SourceRange> {
|
||||
#[inline]
|
||||
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
|
||||
Ok(Arguments(self).to_object(py))
|
||||
|
@ -4392,7 +4392,7 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
|
|||
super::init_type::<Comprehension, ast::Comprehension>(py, m)?;
|
||||
super::init_type::<Excepthandler, ast::Excepthandler>(py, m)?;
|
||||
super::init_type::<ExcepthandlerExceptHandler, ast::ExcepthandlerExceptHandler>(py, m)?;
|
||||
super::init_type::<Arguments, ast::Arguments>(py, m)?;
|
||||
super::init_type::<Arguments, ast::PythonArguments>(py, m)?;
|
||||
super::init_type::<Arg, ast::Arg>(py, m)?;
|
||||
super::init_type::<Keyword, ast::Keyword>(py, m)?;
|
||||
super::init_type::<Alias, ast::Alias>(py, m)?;
|
||||
|
|
|
@ -3289,10 +3289,10 @@ impl ExcepthandlerExceptHandler {
|
|||
|
||||
#[pyclass(module="rustpython_ast.ranged", name="_arguments", extends=super::Ast, frozen)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Arguments(pub &'static ast::Arguments<TextRange>);
|
||||
pub struct Arguments(pub &'static ast::PythonArguments<TextRange>);
|
||||
|
||||
impl From<&'static ast::Arguments<TextRange>> for Arguments {
|
||||
fn from(node: &'static ast::Arguments<TextRange>) -> Self {
|
||||
impl From<&'static ast::PythonArguments<TextRange>> for Arguments {
|
||||
fn from(node: &'static ast::PythonArguments<TextRange>) -> Self {
|
||||
Arguments(node)
|
||||
}
|
||||
}
|
||||
|
@ -3304,7 +3304,7 @@ impl ToPyObject for Arguments {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToPyWrapper for ast::Arguments<TextRange> {
|
||||
impl ToPyWrapper for ast::PythonArguments<TextRange> {
|
||||
#[inline]
|
||||
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
|
||||
Ok(Arguments(self).to_object(py))
|
||||
|
@ -4096,7 +4096,7 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
|
|||
super::init_type::<Comprehension, ast::Comprehension>(py, m)?;
|
||||
super::init_type::<Excepthandler, ast::Excepthandler>(py, m)?;
|
||||
super::init_type::<ExcepthandlerExceptHandler, ast::ExcepthandlerExceptHandler>(py, m)?;
|
||||
super::init_type::<Arguments, ast::Arguments>(py, m)?;
|
||||
super::init_type::<Arguments, ast::PythonArguments>(py, m)?;
|
||||
super::init_type::<Arg, ast::Arg>(py, m)?;
|
||||
super::init_type::<Keyword, ast::Keyword>(py, m)?;
|
||||
super::init_type::<Alias, ast::Alias>(py, m)?;
|
||||
|
|
|
@ -78,14 +78,14 @@ impl ToPyAst for ConversionFlag {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R> ToPyAst for ast::FunctionArguments<R>
|
||||
impl<R> ToPyAst for ast::Arguments<R>
|
||||
where
|
||||
Self: Clone,
|
||||
ast::Arguments<R>: ToPyAst,
|
||||
R: Clone,
|
||||
ast::PythonArguments<R>: ToPyAst,
|
||||
{
|
||||
#[inline]
|
||||
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
|
||||
let arguments = ast::Arguments::from(self.clone());
|
||||
let arguments = self.to_python_arguments();
|
||||
arguments.to_py_ast(py)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,11 +93,10 @@ impl<T: ToPyWrapper> ToPyWrapper for Vec<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[pyclass(module = "rustpython_ast", name = "AST", subclass)]
|
||||
impl<R> ToPyWrapper for ast::FunctionArguments<R>
|
||||
impl<R> ToPyWrapper for ast::Arguments<R>
|
||||
where
|
||||
Self: Clone,
|
||||
ast::Arguments<R>: ToPyWrapper,
|
||||
ast::PythonArguments<R>: ToPyWrapper,
|
||||
{
|
||||
#[inline]
|
||||
fn to_py_wrapper(&'static self, _py: Python) -> PyResult<Py<PyAny>> {
|
||||
|
@ -106,7 +105,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[pyclass(module = "rustpython_ast", subclass)]
|
||||
#[pyclass(module = "rustpython_ast", name = "AST", subclass)]
|
||||
pub struct Ast;
|
||||
|
||||
#[pymethods]
|
||||
|
|
234
ast/asdl_rs.py
234
ast/asdl_rs.py
|
@ -59,19 +59,21 @@ arg_with_default = asdl.Type(
|
|||
asdl.Product(
|
||||
[
|
||||
asdl.Field("arg", "def"),
|
||||
asdl.Field("expr", "default", opt=True), # order is important for cost-free borrow!
|
||||
asdl.Field(
|
||||
"expr", "default", opt=True
|
||||
), # order is important for cost-free borrow!
|
||||
],
|
||||
),
|
||||
)
|
||||
arg_with_default.doc = f"""
|
||||
An alternative type of AST `arg`. This is used for function arguments *with* default value.
|
||||
Used by `FunctionArguments` original type.
|
||||
An alternative type of AST `arg`. This is used for each function argument that might have a default value.
|
||||
Used by `Arguments` original type.
|
||||
|
||||
{ORIGINAL_NODE_WARNING}
|
||||
""".strip()
|
||||
|
||||
function_arguments = asdl.Type(
|
||||
"function_arguments",
|
||||
alt_arguments = asdl.Type(
|
||||
"alt:arguments",
|
||||
asdl.Product(
|
||||
[
|
||||
asdl.Field("arg_with_default", "posonlyargs", seq=True),
|
||||
|
@ -82,21 +84,26 @@ function_arguments = asdl.Type(
|
|||
]
|
||||
),
|
||||
)
|
||||
function_arguments.doc = f"""
|
||||
An alternative type of AST `arguments`. This is parser-friendly definition of function arguments.
|
||||
`defaults` and `kw_defaults` are placed under each `arg_with_default` typed fields.
|
||||
alt_arguments.doc = f"""
|
||||
An alternative type of AST `arguments`. This is parser-friendly and human-friendly definition of function arguments.
|
||||
This form also has advantage to implement pre-order traverse.
|
||||
`defaults` and `kw_defaults` fields are removed and the default values are placed under each `arg_with_default` typed argument.
|
||||
`vararg` and `kwarg` are still typed as `arg` because they never can have a default value.
|
||||
|
||||
The matching Python style AST type is [PythonArguments]. While [PythonArguments] has ordered `kwonlyargs` fields by
|
||||
default existence, [Arguments] has location-ordered kwonlyargs fields.
|
||||
|
||||
{ORIGINAL_NODE_WARNING}
|
||||
""".strip()
|
||||
|
||||
# Must be used only for rust types, not python types
|
||||
CUSTOM_TYPES = [
|
||||
function_arguments,
|
||||
alt_arguments,
|
||||
arg_with_default,
|
||||
]
|
||||
|
||||
CUSTOM_REPLACEMENTS = {
|
||||
"arguments": function_arguments,
|
||||
"arguments": alt_arguments,
|
||||
}
|
||||
CUSTOM_ATTACHMENTS = [
|
||||
arg_with_default,
|
||||
|
@ -202,6 +209,16 @@ class TypeInfo:
|
|||
def is_custom(self):
|
||||
return self.type.name in [t.name for t in CUSTOM_TYPES]
|
||||
|
||||
@property
|
||||
def is_custom_replaced(self):
|
||||
return self.type.name in CUSTOM_REPLACEMENTS
|
||||
|
||||
@property
|
||||
def custom(self):
|
||||
if self.type.name in CUSTOM_REPLACEMENTS:
|
||||
return CUSTOM_REPLACEMENTS[self.type.name]
|
||||
return self.type
|
||||
|
||||
def no_cfg(self, typeinfo):
|
||||
if self.is_product:
|
||||
return self.has_attributes
|
||||
|
@ -216,19 +233,25 @@ class TypeInfo:
|
|||
|
||||
@property
|
||||
def full_field_name(self):
|
||||
name = self.name
|
||||
if name.startswith("alt:"):
|
||||
name = name[4:]
|
||||
if self.enum_name is None:
|
||||
return self.name
|
||||
return name
|
||||
else:
|
||||
return f"{self.enum_name}_{rust_field_name(self.name)}"
|
||||
return f"{self.enum_name}_{rust_field_name(name)}"
|
||||
|
||||
@property
|
||||
def full_type_name(self):
|
||||
rust_name = rust_type_name(self.name)
|
||||
if self.enum_name is None:
|
||||
return rust_name
|
||||
else:
|
||||
name = rust_type_name(self.enum_name) + rust_name
|
||||
return name
|
||||
name = self.name
|
||||
if name.startswith("alt:"):
|
||||
name = name[4:]
|
||||
rust_name = rust_type_name(name)
|
||||
if self.enum_name is not None:
|
||||
rust_name = rust_type_name(self.enum_name) + rust_name
|
||||
if self.is_custom_replaced:
|
||||
rust_name = "Python" + rust_name
|
||||
return rust_name
|
||||
|
||||
def determine_user_data(self, type_info, stack):
|
||||
if self.name in stack:
|
||||
|
@ -249,6 +272,10 @@ class TypeInfo:
|
|||
class TypeInfoMixin:
|
||||
type_info: Dict[str, TypeInfo]
|
||||
|
||||
def customized_type_info(self, type_name):
|
||||
info = self.type_info[type_name]
|
||||
return self.type_info[info.custom.name]
|
||||
|
||||
def has_user_data(self, typ):
|
||||
return self.type_info[typ].has_user_data
|
||||
|
||||
|
@ -295,11 +322,12 @@ class FindUserDataTypesVisitor(asdl.VisitorBase):
|
|||
info.determine_user_data(self.type_info, stack)
|
||||
|
||||
def visitType(self, type):
|
||||
self.type_info[type.name] = TypeInfo(type)
|
||||
self.visit(type.value, type)
|
||||
key = type.name
|
||||
info = self.type_info[key] = TypeInfo(type)
|
||||
self.visit(type.value, info)
|
||||
|
||||
def visitSum(self, sum, type):
|
||||
info = self.type_info[type.name]
|
||||
def visitSum(self, sum, info):
|
||||
type = info.type
|
||||
info.is_simple = is_simple(sum)
|
||||
for cons in sum.types:
|
||||
self.visit(cons, type, info.is_simple)
|
||||
|
@ -326,8 +354,8 @@ class FindUserDataTypesVisitor(asdl.VisitorBase):
|
|||
info.enum_name = type.name
|
||||
info.is_simple = simple
|
||||
|
||||
def visitProduct(self, product, type):
|
||||
info = self.type_info[type.name]
|
||||
def visitProduct(self, product, info):
|
||||
type = info.type
|
||||
if product.attributes:
|
||||
# attributes means located, which has the `range: R` field
|
||||
info.has_user_data = True
|
||||
|
@ -373,8 +401,9 @@ class StructVisitor(EmitVisitor):
|
|||
0,
|
||||
)
|
||||
for dfn in mod.dfns:
|
||||
dfn = maybe_custom(dfn)
|
||||
rust_name = rust_type_name(dfn.name)
|
||||
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 "<R>"
|
||||
if dfn.name == "mod":
|
||||
# This is exceptional rule to other enums.
|
||||
|
@ -395,8 +424,8 @@ class StructVisitor(EmitVisitor):
|
|||
0,
|
||||
)
|
||||
for dfn in mod.dfns:
|
||||
dfn = maybe_custom(dfn)
|
||||
rust_name = rust_type_name(dfn.name)
|
||||
info = self.customized_type_info(dfn.name)
|
||||
rust_name = info.full_type_name
|
||||
generics = "" if self.type_info[dfn.name].is_simple else "<R>"
|
||||
self.emit(
|
||||
f"""
|
||||
|
@ -562,12 +591,12 @@ class StructVisitor(EmitVisitor):
|
|||
self.emit(f"{cons.name},", depth)
|
||||
|
||||
def visitField(self, field, parent, vis, depth, constructor=None):
|
||||
if field.type in CUSTOM_REPLACEMENTS:
|
||||
type_name = CUSTOM_REPLACEMENTS[field.type].name
|
||||
else:
|
||||
type_name = field.type
|
||||
typ = rust_type_name(type_name)
|
||||
field_type = self.type_info.get(type_name)
|
||||
try:
|
||||
field_type = self.customized_type_info(field.type)
|
||||
typ = field_type.full_type_name
|
||||
except KeyError:
|
||||
field_type = None
|
||||
typ = rust_type_name(field.type)
|
||||
if field_type and not field_type.is_simple:
|
||||
typ = f"{typ}<R>"
|
||||
# don't box if we're doing Vec<T>, but do box if we're doing Vec<Option<Box<T>>>
|
||||
|
@ -594,7 +623,7 @@ class StructVisitor(EmitVisitor):
|
|||
|
||||
def visitProduct(self, product, type, depth):
|
||||
type_info = self.type_info[type.name]
|
||||
product_name = rust_type_name(type.name)
|
||||
product_name = type_info.full_type_name
|
||||
self.emit_attrs(depth)
|
||||
self.emit(f"pub struct {product_name}<R = TextRange> {{", depth)
|
||||
self.emit_range(product.attributes, depth + 1)
|
||||
|
@ -663,14 +692,14 @@ class FoldTraitDefVisitor(EmitVisitor):
|
|||
self.emit("}", depth)
|
||||
|
||||
def visitType(self, type, depth):
|
||||
name = type.name
|
||||
apply_u, apply_target_u = self.apply_generics(name, "U", "Self::TargetU")
|
||||
enum_name = rust_type_name(name)
|
||||
info = self.type_info[type.name]
|
||||
apply_u, apply_target_u = self.apply_generics(info.name, "U", "Self::TargetU")
|
||||
enum_name = info.full_type_name
|
||||
self.emit(
|
||||
f"fn fold_{name}(&mut self, node: {enum_name}{apply_u}) -> Result<{enum_name}{apply_target_u}, Self::Error> {{",
|
||||
f"fn fold_{info.full_field_name}(&mut self, node: {enum_name}{apply_u}) -> Result<{enum_name}{apply_target_u}, Self::Error> {{",
|
||||
depth,
|
||||
)
|
||||
self.emit(f"fold_{name}(self, node)", depth + 1)
|
||||
self.emit(f"fold_{info.full_field_name}(self, node)", depth + 1)
|
||||
self.emit("}", depth)
|
||||
|
||||
if isinstance(type.value, asdl.Sum) and not is_simple(type.value):
|
||||
|
@ -678,9 +707,10 @@ class FoldTraitDefVisitor(EmitVisitor):
|
|||
self.visit(cons, type, depth)
|
||||
|
||||
def visitConstructor(self, cons, type, depth):
|
||||
info = self.type_info[type.name]
|
||||
apply_u, apply_target_u = self.apply_generics(type.name, "U", "Self::TargetU")
|
||||
enum_name = rust_type_name(type.name)
|
||||
func_name = f"fold_{type.name}_{rust_field_name(cons.name)}"
|
||||
func_name = f"fold_{info.full_field_name}_{rust_field_name(cons.name)}"
|
||||
self.emit(
|
||||
f"fn {func_name}(&mut self, node: {enum_name}{cons.name}{apply_u}) -> Result<{enum_name}{cons.name}{apply_target_u}, Self::Error> {{",
|
||||
depth,
|
||||
|
@ -743,7 +773,8 @@ class FoldImplVisitor(EmitVisitor):
|
|||
apply_t, apply_u, apply_target_u = self.apply_generics(
|
||||
type.name, "T", "U", "F::TargetU"
|
||||
)
|
||||
enum_name = rust_type_name(type.name)
|
||||
info = self.type_info[type.name]
|
||||
enum_name = info.full_type_name
|
||||
|
||||
cons_type_name = f"{enum_name}{cons.name}"
|
||||
|
||||
|
@ -754,21 +785,20 @@ class FoldImplVisitor(EmitVisitor):
|
|||
depth + 1,
|
||||
)
|
||||
self.emit(
|
||||
f"folder.fold_{type.name}_{rust_field_name(cons.name)}(self)", depth + 2
|
||||
f"folder.fold_{info.full_field_name}_{rust_field_name(cons.name)}(self)",
|
||||
depth + 2,
|
||||
)
|
||||
self.emit("}", depth + 1)
|
||||
self.emit("}", depth)
|
||||
|
||||
self.emit(
|
||||
f"pub fn fold_{type.name}_{rust_field_name(cons.name)}<U, F: Fold<U> + ?Sized>(#[allow(unused)] folder: &mut F, node: {cons_type_name}{apply_u}) -> Result<{enum_name}{cons.name}{apply_target_u}, F::Error> {{",
|
||||
f"pub fn fold_{info.full_field_name}_{rust_field_name(cons.name)}<U, F: Fold<U> + ?Sized>(#[allow(unused)] folder: &mut F, node: {cons_type_name}{apply_u}) -> Result<{enum_name}{cons.name}{apply_target_u}, F::Error> {{",
|
||||
depth,
|
||||
)
|
||||
|
||||
type_info = self.type_info[type.name]
|
||||
|
||||
fields_pattern = self.make_pattern(cons.fields)
|
||||
|
||||
map_user_suffix = "" if type_info.has_attributes else "_cfg"
|
||||
map_user_suffix = "" if info.has_attributes else "_cfg"
|
||||
self.emit(
|
||||
f"""
|
||||
let {cons_type_name} {{ {fields_pattern} }} = node;
|
||||
|
@ -785,11 +815,12 @@ class FoldImplVisitor(EmitVisitor):
|
|||
self.emit("}", depth + 2)
|
||||
|
||||
def visitProduct(self, product, type, depth):
|
||||
info = self.type_info[type.name]
|
||||
name = type.name
|
||||
apply_t, apply_u, apply_target_u = self.apply_generics(
|
||||
name, "T", "U", "F::TargetU"
|
||||
)
|
||||
struct_name = rust_type_name(name)
|
||||
struct_name = info.full_type_name
|
||||
has_attributes = bool(product.attributes)
|
||||
|
||||
self.emit(f"impl<T, U> Foldable<T, U> for {struct_name}{apply_t} {{", depth)
|
||||
|
@ -798,12 +829,12 @@ class FoldImplVisitor(EmitVisitor):
|
|||
"fn fold<F: Fold<T, TargetU = U> + ?Sized>(self, folder: &mut F) -> Result<Self::Mapped, F::Error> {",
|
||||
depth + 1,
|
||||
)
|
||||
self.emit(f"folder.fold_{name}(self)", depth + 2)
|
||||
self.emit(f"folder.fold_{info.full_field_name}(self)", depth + 2)
|
||||
self.emit("}", depth + 1)
|
||||
self.emit("}", depth)
|
||||
|
||||
self.emit(
|
||||
f"pub fn fold_{name}<U, F: Fold<U> + ?Sized>(#[allow(unused)] folder: &mut F, node: {struct_name}{apply_u}) -> Result<{struct_name}{apply_target_u}, F::Error> {{",
|
||||
f"pub fn fold_{info.full_field_name}<U, F: Fold<U> + ?Sized>(#[allow(unused)] folder: &mut F, node: {struct_name}{apply_u}) -> Result<{struct_name}{apply_target_u}, F::Error> {{",
|
||||
depth,
|
||||
)
|
||||
|
||||
|
@ -871,7 +902,8 @@ class VisitorModuleVisitor(StructVisitor):
|
|||
self.emit("#[allow(unused_variables)]", depth)
|
||||
self.emit("pub trait Visitor<R=crate::text_size::TextRange> {", depth)
|
||||
|
||||
for dfn in mod.dfns + CUSTOM_TYPES:
|
||||
for dfn in mod.dfns:
|
||||
dfn = self.customized_type_info(dfn.name).type
|
||||
self.visit(dfn, depth + 1)
|
||||
self.emit("}", depth)
|
||||
|
||||
|
@ -1163,11 +1195,13 @@ class ToPyo3AstVisitor(EmitVisitor):
|
|||
self.visit(type.value, type)
|
||||
|
||||
def visitProduct(self, product, type):
|
||||
rust_name = rust_type_name(type.name)
|
||||
info = self.type_info[type.name]
|
||||
rust_name = info.full_type_name
|
||||
self.emit_to_pyo3_with_fields(product, type, rust_name)
|
||||
|
||||
def visitSum(self, sum, type):
|
||||
rust_name = rust_type_name(type.name)
|
||||
info = self.type_info[type.name]
|
||||
rust_name = info.full_type_name
|
||||
simple = is_simple(sum)
|
||||
if is_simple(sum):
|
||||
return
|
||||
|
@ -1320,8 +1354,9 @@ class Pyo3StructVisitor(EmitVisitor):
|
|||
def ref(self):
|
||||
return "&" if self.borrow else ""
|
||||
|
||||
def emit_class(self, name, rust_name, simple, base="super::Ast"):
|
||||
info = self.type_info[name]
|
||||
def emit_class(self, info, simple, base="super::Ast"):
|
||||
inner_name = info.full_type_name
|
||||
rust_name = self.type_info[info.custom.name].full_type_name
|
||||
if simple:
|
||||
generics = ""
|
||||
else:
|
||||
|
@ -1332,23 +1367,24 @@ class Pyo3StructVisitor(EmitVisitor):
|
|||
into = f"{rust_name}"
|
||||
else:
|
||||
subclass = ""
|
||||
body = f"(pub {self.ref_def} ast::{rust_name}{generics})"
|
||||
body = f"(pub {self.ref_def} ast::{inner_name}{generics})"
|
||||
into = f"{rust_name}(node)"
|
||||
|
||||
self.emit(
|
||||
f"""
|
||||
#[pyclass(module="{self.module_name}", name="_{name}", extends={base}, frozen{subclass})]
|
||||
#[pyclass(module="{self.module_name}", name="_{info.name}", extends={base}, frozen{subclass})]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct {rust_name} {body};
|
||||
|
||||
impl From<{self.ref_def} ast::{rust_name}{generics}> for {rust_name} {{
|
||||
fn from({"" if body else "_"}node: {self.ref_def} ast::{rust_name}{generics}) -> Self {{
|
||||
impl From<{self.ref_def} ast::{inner_name}{generics}> for {rust_name} {{
|
||||
fn from({"" if body else "_"}node: {self.ref_def} ast::{inner_name}{generics}) -> Self {{
|
||||
{into}
|
||||
}}
|
||||
}}
|
||||
""",
|
||||
0,
|
||||
)
|
||||
|
||||
if subclass:
|
||||
self.emit(
|
||||
f"""
|
||||
|
@ -1390,7 +1426,7 @@ class Pyo3StructVisitor(EmitVisitor):
|
|||
)
|
||||
|
||||
if not subclass:
|
||||
self.emit_wrapper(rust_name)
|
||||
self.emit_wrapper(info)
|
||||
|
||||
def emit_getter(self, owner, type_name):
|
||||
self.emit(
|
||||
|
@ -1448,10 +1484,12 @@ class Pyo3StructVisitor(EmitVisitor):
|
|||
0,
|
||||
)
|
||||
|
||||
def emit_wrapper(self, rust_name):
|
||||
def emit_wrapper(self, info):
|
||||
inner_name = info.full_type_name
|
||||
rust_name = self.type_info[info.custom.name].full_type_name
|
||||
self.emit(
|
||||
f"""
|
||||
impl ToPyWrapper for ast::{rust_name}{self.generics} {{
|
||||
impl ToPyWrapper for ast::{inner_name}{self.generics} {{
|
||||
#[inline]
|
||||
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {{
|
||||
Ok({rust_name}(self).to_object(py))
|
||||
|
@ -1469,10 +1507,11 @@ class Pyo3StructVisitor(EmitVisitor):
|
|||
self.visit(type.value, type, depth)
|
||||
|
||||
def visitSum(self, sum, type, depth=0):
|
||||
info = self.type_info[type.name]
|
||||
rust_name = rust_type_name(type.name)
|
||||
|
||||
simple = is_simple(sum)
|
||||
self.emit_class(type.name, rust_name, simple)
|
||||
self.emit_class(info, simple)
|
||||
|
||||
if not simple:
|
||||
self.emit(
|
||||
|
@ -1501,8 +1540,9 @@ class Pyo3StructVisitor(EmitVisitor):
|
|||
self.visit(cons, rust_name, simple, depth + 1)
|
||||
|
||||
def visitProduct(self, product, type, depth=0):
|
||||
info = self.type_info[type.name]
|
||||
rust_name = rust_type_name(type.name)
|
||||
self.emit_class(type.name, rust_name, False)
|
||||
self.emit_class(info, False)
|
||||
if self.borrow:
|
||||
self.emit_getter(product, rust_name)
|
||||
|
||||
|
@ -1525,9 +1565,9 @@ class Pyo3StructVisitor(EmitVisitor):
|
|||
depth,
|
||||
)
|
||||
else:
|
||||
info = self.type_info[cons.name]
|
||||
self.emit_class(
|
||||
cons.name,
|
||||
f"{parent}{cons.name}",
|
||||
info,
|
||||
simple=False,
|
||||
base=parent,
|
||||
)
|
||||
|
@ -1548,23 +1588,25 @@ class Pyo3PymoduleVisitor(EmitVisitor):
|
|||
self.visit(type.value, type.name, depth)
|
||||
|
||||
def visitProduct(self, product, name, depth=0):
|
||||
rust_name = rust_type_name(name)
|
||||
self.emit_fields(name, rust_name, False)
|
||||
info = self.type_info[name]
|
||||
self.emit_fields(info, False)
|
||||
|
||||
def visitSum(self, sum, name, depth):
|
||||
rust_name = rust_type_name(name)
|
||||
info = self.type_info[name]
|
||||
simple = is_simple(sum)
|
||||
self.emit_fields(name, rust_name, True)
|
||||
self.emit_fields(info, True)
|
||||
|
||||
for cons in sum.types:
|
||||
self.visit(cons, name, simple, depth)
|
||||
|
||||
def visitConstructor(self, cons, parent, simple, depth):
|
||||
rust_name = rust_type_name(parent) + rust_type_name(cons.name)
|
||||
self.emit_fields(cons.name, rust_name, simple)
|
||||
info = self.type_info[cons.name]
|
||||
self.emit_fields(info, simple)
|
||||
|
||||
def emit_fields(self, name, rust_name, simple):
|
||||
self.emit(f"super::init_type::<{rust_name}, ast::{rust_name}>(py, m)?;", 1)
|
||||
def emit_fields(self, info, simple):
|
||||
inner_name = info.full_type_name
|
||||
rust_name = self.type_info[info.custom.name].full_type_name
|
||||
self.emit(f"super::init_type::<{rust_name}, ast::{inner_name}>(py, m)?;", 1)
|
||||
|
||||
|
||||
class StdlibClassDefVisitor(EmitVisitor):
|
||||
|
@ -1576,7 +1618,9 @@ class StdlibClassDefVisitor(EmitVisitor):
|
|||
self.visit(type.value, type.name, depth)
|
||||
|
||||
def visitSum(self, sum, name, depth):
|
||||
struct_name = "Node" + rust_type_name(name)
|
||||
# info = self.type_info[self.type_info[name].custom.name]
|
||||
info = self.type_info[name]
|
||||
struct_name = "Node" + info.full_type_name
|
||||
self.emit(
|
||||
f'#[pyclass(module = "_ast", name = {json.dumps(name)}, base = "NodeAst")]',
|
||||
depth,
|
||||
|
@ -1594,11 +1638,13 @@ class StdlibClassDefVisitor(EmitVisitor):
|
|||
self.gen_class_def(name, product.fields, product.attributes, depth)
|
||||
|
||||
def gen_class_def(self, name, fields, attrs, depth, base=None):
|
||||
|
||||
info = self.type_info[self.type_info[name].custom.name]
|
||||
if base is None:
|
||||
base = "NodeAst"
|
||||
struct_name = "Node" + rust_type_name(name)
|
||||
struct_name = "Node" + info.full_type_name
|
||||
else:
|
||||
struct_name = base + rust_type_name(name)
|
||||
struct_name = "Node" + info.full_type_name
|
||||
self.emit(
|
||||
f'#[pyclass(module = "_ast", name = {json.dumps(name)}, base = {json.dumps(base)})]',
|
||||
depth,
|
||||
|
@ -1673,7 +1719,8 @@ class StdlibTraitImplVisitor(EmitVisitor):
|
|||
self.visit(type.value, type.name, depth)
|
||||
|
||||
def visitSum(self, sum, name, depth):
|
||||
rust_name = rust_type_name(name)
|
||||
info = self.type_info[name]
|
||||
rust_name = info.full_type_name
|
||||
|
||||
self.emit("// sum", depth)
|
||||
self.emit(f"impl Node for ast::located::{rust_name} {{", depth)
|
||||
|
@ -1746,7 +1793,8 @@ class StdlibTraitImplVisitor(EmitVisitor):
|
|||
self.emit("}", depth + 1)
|
||||
|
||||
def visitProduct(self, product, name, depth):
|
||||
struct_name = rust_type_name(name)
|
||||
info = self.type_info[name]
|
||||
struct_name = info.full_type_name
|
||||
|
||||
self.emit("// product", depth)
|
||||
self.emit(f"impl Node for ast::located::{struct_name} {{", depth)
|
||||
|
@ -1892,8 +1940,7 @@ def write_located_def(mod, type_info, f):
|
|||
|
||||
|
||||
def write_pyo3_node(type_info, f):
|
||||
def write(info: TypeInfo):
|
||||
rust_name = info.full_type_name
|
||||
def write(info: TypeInfo, rust_name: str):
|
||||
if info.is_simple:
|
||||
generics = ""
|
||||
else:
|
||||
|
@ -1911,10 +1958,14 @@ def write_pyo3_node(type_info, f):
|
|||
""",
|
||||
)
|
||||
|
||||
for info in type_info.values():
|
||||
for type_name, info in type_info.items():
|
||||
rust_name = info.full_type_name
|
||||
if info.is_custom:
|
||||
continue
|
||||
write(info)
|
||||
if type_name != info.type.name:
|
||||
rust_name = "Python" + rust_name
|
||||
else:
|
||||
continue
|
||||
write(info, rust_name)
|
||||
|
||||
|
||||
def write_to_pyo3(mod, type_info, f):
|
||||
|
@ -1973,20 +2024,21 @@ def write_pyo3_wrapper(mod, type_info, namespace, f):
|
|||
Pyo3StructVisitor(namespace, f, type_info).visit(mod)
|
||||
|
||||
if namespace == "located":
|
||||
for type_info in type_info.values():
|
||||
if not type_info.is_simple or not type_info.is_sum:
|
||||
for info in type_info.values():
|
||||
if not info.is_simple or not info.is_sum:
|
||||
continue
|
||||
|
||||
rust_name = type_info.full_type_name
|
||||
rust_name = info.full_type_name
|
||||
inner_name = type_info[info.custom.name].full_type_name
|
||||
f.write(
|
||||
f"""
|
||||
impl ToPyWrapper for ast::{rust_name} {{
|
||||
impl ToPyWrapper for ast::{inner_name} {{
|
||||
#[inline]
|
||||
fn to_py_wrapper(&self, py: Python) -> PyResult<Py<PyAny>> {{
|
||||
match &self {{
|
||||
""",
|
||||
)
|
||||
for cons in type_info.type.value.types:
|
||||
for cons in info.type.value.types:
|
||||
f.write(
|
||||
f"Self::{cons.name} => Ok({rust_name}{cons.name}.to_object(py)),",
|
||||
)
|
||||
|
@ -1998,7 +2050,7 @@ def write_pyo3_wrapper(mod, type_info, namespace, f):
|
|||
""",
|
||||
)
|
||||
|
||||
for cons in type_info.type.value.types:
|
||||
for cons in info.type.value.types:
|
||||
f.write(
|
||||
f"""
|
||||
impl ToPyWrapper for ast::{rust_name}{cons.name} {{
|
||||
|
@ -2030,7 +2082,7 @@ def write_parse_def(mod, type_info, f):
|
|||
cons_name = rust_type_name(info.name)
|
||||
|
||||
f.write(f"""
|
||||
impl Parse for ast::{info.rust_sum_name} {{
|
||||
impl Parse for ast::{info.full_type_name} {{
|
||||
fn lex_starts_at(
|
||||
source: &str,
|
||||
offset: TextSize,
|
||||
|
|
|
@ -420,11 +420,11 @@ pub trait Fold<U> {
|
|||
) -> Result<ExcepthandlerExceptHandler<Self::TargetU>, Self::Error> {
|
||||
fold_excepthandler_except_handler(self, node)
|
||||
}
|
||||
fn fold_function_arguments(
|
||||
fn fold_arguments(
|
||||
&mut self,
|
||||
node: FunctionArguments<U>,
|
||||
) -> Result<FunctionArguments<Self::TargetU>, Self::Error> {
|
||||
fold_function_arguments(self, node)
|
||||
node: Arguments<U>,
|
||||
) -> Result<Arguments<Self::TargetU>, Self::Error> {
|
||||
fold_arguments(self, node)
|
||||
}
|
||||
fn fold_arg(&mut self, node: Arg<U>) -> Result<Arg<Self::TargetU>, Self::Error> {
|
||||
fold_arg(self, node)
|
||||
|
@ -2356,20 +2356,20 @@ pub fn fold_excepthandler_except_handler<U, F: Fold<U> + ?Sized>(
|
|||
range,
|
||||
})
|
||||
}
|
||||
impl<T, U> Foldable<T, U> for FunctionArguments<T> {
|
||||
type Mapped = FunctionArguments<U>;
|
||||
impl<T, U> Foldable<T, U> for Arguments<T> {
|
||||
type Mapped = Arguments<U>;
|
||||
fn fold<F: Fold<T, TargetU = U> + ?Sized>(
|
||||
self,
|
||||
folder: &mut F,
|
||||
) -> Result<Self::Mapped, F::Error> {
|
||||
folder.fold_function_arguments(self)
|
||||
folder.fold_arguments(self)
|
||||
}
|
||||
}
|
||||
pub fn fold_function_arguments<U, F: Fold<U> + ?Sized>(
|
||||
pub fn fold_arguments<U, F: Fold<U> + ?Sized>(
|
||||
#[allow(unused)] folder: &mut F,
|
||||
node: FunctionArguments<U>,
|
||||
) -> Result<FunctionArguments<F::TargetU>, F::Error> {
|
||||
let FunctionArguments {
|
||||
node: Arguments<U>,
|
||||
) -> Result<Arguments<F::TargetU>, F::Error> {
|
||||
let Arguments {
|
||||
posonlyargs,
|
||||
args,
|
||||
vararg,
|
||||
|
@ -2384,7 +2384,7 @@ pub fn fold_function_arguments<U, F: Fold<U> + ?Sized>(
|
|||
let kwonlyargs = Foldable::fold(kwonlyargs, folder)?;
|
||||
let kwarg = Foldable::fold(kwarg, folder)?;
|
||||
let range = folder.map_user_cfg(range, context)?;
|
||||
Ok(FunctionArguments {
|
||||
Ok(Arguments {
|
||||
posonlyargs,
|
||||
args,
|
||||
vararg,
|
||||
|
|
|
@ -15,7 +15,7 @@ pub enum Ast<R = TextRange> {
|
|||
Cmpop(Cmpop),
|
||||
Comprehension(Comprehension<R>),
|
||||
Excepthandler(Excepthandler<R>),
|
||||
FunctionArguments(FunctionArguments<R>),
|
||||
Arguments(Arguments<R>),
|
||||
Arg(Arg<R>),
|
||||
Keyword(Keyword<R>),
|
||||
Alias(Alias<R>),
|
||||
|
@ -89,9 +89,9 @@ impl<R> From<Excepthandler<R>> for Ast<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R> From<FunctionArguments<R>> for Ast<R> {
|
||||
fn from(node: FunctionArguments<R>) -> Self {
|
||||
Ast::FunctionArguments(node)
|
||||
impl<R> From<Arguments<R>> for Ast<R> {
|
||||
fn from(node: Arguments<R>) -> Self {
|
||||
Ast::Arguments(node)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ impl<R> Node for Mod<R> {
|
|||
pub struct StmtFunctionDef<R = TextRange> {
|
||||
pub range: R,
|
||||
pub name: Identifier,
|
||||
pub args: Box<FunctionArguments<R>>,
|
||||
pub args: Box<Arguments<R>>,
|
||||
pub body: Vec<Stmt<R>>,
|
||||
pub decorator_list: Vec<Expr<R>>,
|
||||
pub returns: Option<Box<Expr<R>>>,
|
||||
|
@ -273,7 +273,7 @@ impl<R> From<StmtFunctionDef<R>> for Ast<R> {
|
|||
pub struct StmtAsyncFunctionDef<R = TextRange> {
|
||||
pub range: R,
|
||||
pub name: Identifier,
|
||||
pub args: Box<FunctionArguments<R>>,
|
||||
pub args: Box<Arguments<R>>,
|
||||
pub body: Vec<Stmt<R>>,
|
||||
pub decorator_list: Vec<Expr<R>>,
|
||||
pub returns: Option<Box<Expr<R>>>,
|
||||
|
@ -1020,7 +1020,7 @@ impl<R> From<ExprUnaryOp<R>> for Ast<R> {
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ExprLambda<R = TextRange> {
|
||||
pub range: R,
|
||||
pub args: Box<FunctionArguments<R>>,
|
||||
pub args: Box<Arguments<R>>,
|
||||
pub body: Box<Expr<R>>,
|
||||
}
|
||||
|
||||
|
@ -2679,7 +2679,7 @@ impl<R> Node for Excepthandler<R> {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Arguments<R = TextRange> {
|
||||
pub struct PythonArguments<R = TextRange> {
|
||||
pub range: OptionalRange<R>,
|
||||
pub posonlyargs: Vec<Arg<R>>,
|
||||
pub args: Vec<Arg<R>>,
|
||||
|
@ -2690,7 +2690,7 @@ pub struct Arguments<R = TextRange> {
|
|||
pub defaults: Vec<Expr<R>>,
|
||||
}
|
||||
|
||||
impl<R> Node for Arguments<R> {
|
||||
impl<R> Node for PythonArguments<R> {
|
||||
const NAME: &'static str = "arguments";
|
||||
const FIELD_NAMES: &'static [&'static str] = &[
|
||||
"posonlyargs",
|
||||
|
@ -2988,13 +2988,18 @@ impl<R> Node for TypeIgnore<R> {
|
|||
const FIELD_NAMES: &'static [&'static str] = &[];
|
||||
}
|
||||
|
||||
/// An alternative type of AST `arguments`. This is parser-friendly definition of function arguments.
|
||||
/// `defaults` and `kw_defaults` are placed under each `arg_with_default` typed fields.
|
||||
/// An alternative type of AST `arguments`. This is parser-friendly and human-friendly definition of function arguments.
|
||||
/// This form also has advantage to implement pre-order traverse.
|
||||
/// `defaults` and `kw_defaults` fields are removed and the default values are placed under each `arg_with_default` typed argument.
|
||||
/// `vararg` and `kwarg` are still typed as `arg` because they never can have a default value.
|
||||
///
|
||||
/// The matching Python style AST type is [PythonArguments]. While [PythonArguments] has ordered `kwonlyargs` fields by
|
||||
/// default existence, [Arguments] has location-ordered kwonlyargs fields.
|
||||
///
|
||||
/// NOTE: This type is different from original Python AST.
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct FunctionArguments<R = TextRange> {
|
||||
pub struct Arguments<R = TextRange> {
|
||||
pub range: OptionalRange<R>,
|
||||
pub posonlyargs: Vec<ArgWithDefault<R>>,
|
||||
pub args: Vec<ArgWithDefault<R>>,
|
||||
|
@ -3003,14 +3008,14 @@ pub struct FunctionArguments<R = TextRange> {
|
|||
pub kwarg: Option<Box<Arg<R>>>,
|
||||
}
|
||||
|
||||
impl<R> Node for FunctionArguments<R> {
|
||||
const NAME: &'static str = "function_arguments";
|
||||
impl<R> Node for Arguments<R> {
|
||||
const NAME: &'static str = "alt:arguments";
|
||||
const FIELD_NAMES: &'static [&'static str] =
|
||||
&["posonlyargs", "args", "vararg", "kwonlyargs", "kwarg"];
|
||||
}
|
||||
|
||||
/// An alternative type of AST `arg`. This is used for function arguments *with* default value.
|
||||
/// Used by `FunctionArguments` original type.
|
||||
/// An alternative type of AST `arg`. This is used for each function argument that might have a default value.
|
||||
/// Used by `Arguments` original type.
|
||||
///
|
||||
/// NOTE: This type is different from original Python AST.
|
||||
|
||||
|
|
|
@ -660,11 +660,11 @@ impl Located for Excepthandler {
|
|||
}
|
||||
}
|
||||
|
||||
pub type Arguments = crate::generic::Arguments<SourceRange>;
|
||||
pub type PythonArguments = crate::generic::PythonArguments<SourceRange>;
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
|
||||
impl Located for Arguments {
|
||||
impl Located for PythonArguments {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.range
|
||||
}
|
||||
|
@ -816,11 +816,11 @@ impl Located for TypeIgnore {
|
|||
}
|
||||
}
|
||||
|
||||
pub type FunctionArguments = crate::generic::FunctionArguments<SourceRange>;
|
||||
pub type Arguments = crate::generic::Arguments<SourceRange>;
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
|
||||
impl Located for FunctionArguments {
|
||||
impl Located for Arguments {
|
||||
fn range(&self) -> SourceRange {
|
||||
self.range
|
||||
}
|
||||
|
|
|
@ -394,7 +394,7 @@ impl Ranged for crate::Excepthandler {
|
|||
}
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::Arguments<TextRange> {
|
||||
impl Ranged for crate::generic::PythonArguments<TextRange> {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
|
@ -497,7 +497,7 @@ impl Ranged for crate::TypeIgnore {
|
|||
}
|
||||
|
||||
#[cfg(feature = "all-nodes-with-ranges")]
|
||||
impl Ranged for crate::generic::FunctionArguments<TextRange> {
|
||||
impl Ranged for crate::generic::Arguments<TextRange> {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -42,7 +42,7 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
|||
fn generic_visit_stmt_function_def(&mut self, node: StmtFunctionDef<R>) {
|
||||
{
|
||||
let value = node.args;
|
||||
self.visit_function_arguments(*value);
|
||||
self.visit_arguments(*value);
|
||||
}
|
||||
for value in node.body {
|
||||
self.visit_stmt(value);
|
||||
|
@ -60,7 +60,7 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
|||
fn generic_visit_stmt_async_function_def(&mut self, node: StmtAsyncFunctionDef<R>) {
|
||||
{
|
||||
let value = node.args;
|
||||
self.visit_function_arguments(*value);
|
||||
self.visit_arguments(*value);
|
||||
}
|
||||
for value in node.body {
|
||||
self.visit_stmt(value);
|
||||
|
@ -424,7 +424,7 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
|||
fn generic_visit_expr_lambda(&mut self, node: ExprLambda<R>) {
|
||||
{
|
||||
let value = node.args;
|
||||
self.visit_function_arguments(*value);
|
||||
self.visit_arguments(*value);
|
||||
}
|
||||
{
|
||||
let value = node.body;
|
||||
|
@ -810,12 +810,4 @@ pub trait Visitor<R = crate::text_size::TextRange> {
|
|||
self.visit_pattern(value);
|
||||
}
|
||||
}
|
||||
fn visit_function_arguments(&mut self, node: FunctionArguments<R>) {
|
||||
self.generic_visit_function_arguments(node)
|
||||
}
|
||||
fn generic_visit_function_arguments(&mut self, node: FunctionArguments<R>) {}
|
||||
fn visit_arg_with_default(&mut self, node: ArgWithDefault<R>) {
|
||||
self.generic_visit_arg_with_default(node)
|
||||
}
|
||||
fn generic_visit_arg_with_default(&mut self, node: ArgWithDefault<R>) {}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ impl Cmpop {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R> FunctionArguments<R> {
|
||||
impl<R> Arguments<R> {
|
||||
pub fn empty(range: OptionalRange<R>) -> Self {
|
||||
Self {
|
||||
range,
|
||||
|
@ -95,8 +95,14 @@ impl<R> ArgWithDefault<R> {
|
|||
where
|
||||
R: Clone,
|
||||
{
|
||||
#[allow(clippy::useless_conversion)] // false positive due to cfg
|
||||
let range = OptionalRange::from(def.range.clone()); // FIXME: def.range.start()..default.range.end()
|
||||
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,
|
||||
|
@ -129,7 +135,7 @@ impl<R> ArgWithDefault<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R> FunctionArguments<R> {
|
||||
impl<R> Arguments<R> {
|
||||
pub fn defaults(&self) -> impl std::iter::Iterator<Item = &Expr<R>> {
|
||||
self.posonlyargs
|
||||
.iter()
|
||||
|
@ -151,11 +157,11 @@ impl<R> FunctionArguments<R> {
|
|||
(args, with_defaults)
|
||||
}
|
||||
|
||||
pub fn to_arguments(&self) -> Arguments<R>
|
||||
pub fn to_python_arguments(&self) -> PythonArguments<R>
|
||||
where
|
||||
R: Clone,
|
||||
{
|
||||
let FunctionArguments {
|
||||
let Arguments {
|
||||
range,
|
||||
posonlyargs,
|
||||
args,
|
||||
|
@ -192,7 +198,7 @@ impl<R> FunctionArguments<R> {
|
|||
kw_only.push(arg);
|
||||
}
|
||||
|
||||
Arguments {
|
||||
PythonArguments {
|
||||
range: range.clone(),
|
||||
posonlyargs: pos_only,
|
||||
args: pos_args,
|
||||
|
@ -204,8 +210,8 @@ impl<R> FunctionArguments<R> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn into_arguments(self) -> Arguments<R> {
|
||||
let FunctionArguments {
|
||||
pub fn into_python_arguments(self) -> PythonArguments<R> {
|
||||
let Arguments {
|
||||
range,
|
||||
posonlyargs,
|
||||
args,
|
||||
|
@ -242,7 +248,7 @@ impl<R> FunctionArguments<R> {
|
|||
kw_only.push(arg);
|
||||
}
|
||||
|
||||
Arguments {
|
||||
PythonArguments {
|
||||
range,
|
||||
posonlyargs: pos_only,
|
||||
args: pos_args,
|
||||
|
@ -255,12 +261,12 @@ impl<R> FunctionArguments<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R> Arguments<R> {
|
||||
pub fn into_function_arguments(self) -> FunctionArguments<R>
|
||||
impl<R> PythonArguments<R> {
|
||||
pub fn into_arguments(self) -> Arguments<R>
|
||||
where
|
||||
R: Clone,
|
||||
{
|
||||
let Arguments {
|
||||
let PythonArguments {
|
||||
range,
|
||||
posonlyargs,
|
||||
args,
|
||||
|
@ -301,7 +307,7 @@ impl<R> Arguments<R> {
|
|||
kw_only.push(arg);
|
||||
}
|
||||
|
||||
FunctionArguments {
|
||||
Arguments {
|
||||
range,
|
||||
posonlyargs: pos_only,
|
||||
args: pos_args,
|
||||
|
@ -312,9 +318,9 @@ impl<R> Arguments<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R> From<FunctionArguments<R>> for Arguments<R> {
|
||||
fn from(arguments: FunctionArguments<R>) -> Self {
|
||||
arguments.into_arguments()
|
||||
impl<R> From<Arguments<R>> for PythonArguments<R> {
|
||||
fn from(arguments: Arguments<R>) -> Self {
|
||||
arguments.into_python_arguments()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
//! Python AST node definitions and utilities.
|
||||
//!
|
||||
//! AST nodes are very similary defined like [Python AST](https://docs.python.org/3/library/ast.html).
|
||||
//! But a few exceptions exist due to parser optimization.
|
||||
//! They can be transformed to matching Python-styled AST in reasonable cost.
|
||||
//!
|
||||
//! [PythonArguments] is replaced by [Arguments]. The new [Arguments] type representation uses a new type
|
||||
//! [ArgWithDefault] to represent arguments with default values. See each type documentation for more details.
|
||||
|
||||
mod builtin;
|
||||
mod generic;
|
||||
mod impls;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
Arg, Arguments, Boolop, Cmpop, Comprehension, Constant, ConversionFlag, Expr, ArgWithDefault,
|
||||
FunctionArguments, Identifier, Operator,
|
||||
Arg, ArgWithDefault, Arguments, Boolop, Comprehension, Constant, ConversionFlag, Expr,
|
||||
Identifier, Operator, PythonArguments,
|
||||
};
|
||||
use std::fmt;
|
||||
|
||||
|
@ -157,7 +157,7 @@ impl<'a> Unparser<'a> {
|
|||
group_if!(precedence::TEST, {
|
||||
let pos = args.args.len() + args.posonlyargs.len();
|
||||
self.p(if pos > 0 { "lambda " } else { "lambda" })?;
|
||||
self.unparse_function_arguments(args)?;
|
||||
self.unparse_arguments(args)?;
|
||||
write!(self, ": {}", **body)?;
|
||||
})
|
||||
}
|
||||
|
@ -439,7 +439,7 @@ impl<'a> Unparser<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn unparse_function_arguments<U>(&mut self, args: &FunctionArguments<U>) -> fmt::Result {
|
||||
fn unparse_arguments<U>(&mut self, args: &Arguments<U>) -> fmt::Result {
|
||||
let mut first = true;
|
||||
for (i, arg) in args.posonlyargs.iter().chain(&args.args).enumerate() {
|
||||
self.p_delim(&mut first, ", ")?;
|
||||
|
@ -476,7 +476,7 @@ impl<'a> Unparser<'a> {
|
|||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn unparse_arguments<U>(&mut self, args: &Arguments<U>) -> fmt::Result {
|
||||
fn unparse_python_arguments<U>(&mut self, args: &PythonArguments<U>) -> fmt::Result {
|
||||
let mut first = true;
|
||||
let defaults_start = args.posonlyargs.len() + args.args.len() - args.defaults.len();
|
||||
for (i, arg) in args.posonlyargs.iter().chain(&args.args).enumerate() {
|
||||
|
|
|
@ -15,28 +15,25 @@ pub(crate) struct ArgumentList {
|
|||
}
|
||||
|
||||
// Perform validation of function/lambda arguments in a function definition.
|
||||
pub(crate) fn validate_arguments(arguments: &ast::FunctionArguments) -> Result<(), LexicalError> {
|
||||
pub(crate) fn validate_arguments(arguments: &ast::Arguments) -> Result<(), LexicalError> {
|
||||
let mut all_arg_names = FxHashSet::with_hasher(Default::default());
|
||||
|
||||
for (range, arg_name) in arguments
|
||||
.posonlyargs
|
||||
.iter()
|
||||
.chain(arguments.args.iter())
|
||||
.chain(arguments.kwonlyargs.iter())
|
||||
.map(|arg| (arg.def.range, arg.def.arg.as_str()))
|
||||
.chain(
|
||||
arguments
|
||||
.vararg
|
||||
.as_ref()
|
||||
.map(|arg| (arg.range, arg.arg.as_str())),
|
||||
)
|
||||
.chain(
|
||||
arguments
|
||||
.kwarg
|
||||
.as_ref()
|
||||
.map(|arg| (arg.range, arg.arg.as_str())),
|
||||
)
|
||||
let posonlyargs = arguments.posonlyargs.iter();
|
||||
let args = arguments.args.iter();
|
||||
let kwonlyargs = arguments.kwonlyargs.iter();
|
||||
|
||||
let vararg: Option<&ast::Arg> = arguments.vararg.as_deref();
|
||||
let kwarg: Option<&ast::Arg> = arguments.kwarg.as_deref();
|
||||
|
||||
for arg in posonlyargs
|
||||
.chain(args)
|
||||
.chain(kwonlyargs)
|
||||
.map(|arg| &arg.def)
|
||||
.chain(vararg)
|
||||
.chain(kwarg)
|
||||
{
|
||||
let range = arg.range;
|
||||
let arg_name = arg.arg.as_str();
|
||||
if !all_arg_names.insert(arg_name) {
|
||||
return Err(LexicalError {
|
||||
error: LexicalErrorType::DuplicateArgumentError(arg_name.to_string()),
|
||||
|
|
|
@ -979,11 +979,11 @@ FuncDef: ast::Stmt = {
|
|||
},
|
||||
};
|
||||
|
||||
Parameters: ast::FunctionArguments = {
|
||||
Parameters: ast::Arguments = {
|
||||
<location:@L> "(" <a: (ParameterList<TypedParameter, StarTypedParameter, DoubleStarTypedParameter>)?> ")" <end_location:@R> =>? {
|
||||
a.as_ref().map(validate_arguments).transpose()?;
|
||||
let args = a
|
||||
.unwrap_or_else(|| ast::FunctionArguments::empty(optional_range(location, end_location)));
|
||||
.unwrap_or_else(|| ast::Arguments::empty(optional_range(location, end_location)));
|
||||
|
||||
Ok(args)
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ Parameters: ast::FunctionArguments = {
|
|||
|
||||
// Note that this is a macro which is used once for function defs, and
|
||||
// once for lambda defs.
|
||||
ParameterList<ArgType, StarArgType, DoubleStarArgType>: ast::FunctionArguments = {
|
||||
ParameterList<ArgType, StarArgType, DoubleStarArgType>: ast::Arguments = {
|
||||
<location:@L> <param1:ParameterDefs<ArgType>> <args2:("," <ParameterListStarArgs<ArgType, StarArgType, DoubleStarArgType>>)?> ","? <end_location:@R> =>? {
|
||||
validate_pos_params(¶m1)?;
|
||||
let (posonlyargs, args) = param1;
|
||||
|
@ -999,7 +999,7 @@ ParameterList<ArgType, StarArgType, DoubleStarArgType>: ast::FunctionArguments =
|
|||
// Now gather rest of parameters:
|
||||
let (vararg, kwonlyargs, kwarg) = args2.unwrap_or((None, vec![], None));
|
||||
|
||||
Ok(ast::FunctionArguments {
|
||||
Ok(ast::Arguments {
|
||||
posonlyargs,
|
||||
args,
|
||||
kwonlyargs,
|
||||
|
@ -1017,7 +1017,7 @@ ParameterList<ArgType, StarArgType, DoubleStarArgType>: ast::FunctionArguments =
|
|||
let kwonlyargs = vec![];
|
||||
let kwarg = kw;
|
||||
|
||||
Ok(ast::FunctionArguments {
|
||||
Ok(ast::Arguments {
|
||||
posonlyargs,
|
||||
args,
|
||||
kwonlyargs,
|
||||
|
@ -1028,7 +1028,7 @@ ParameterList<ArgType, StarArgType, DoubleStarArgType>: ast::FunctionArguments =
|
|||
},
|
||||
<location:@L> <params:ParameterListStarArgs<ArgType, StarArgType, DoubleStarArgType>> ","? <end_location:@R> => {
|
||||
let (vararg, kwonlyargs, kwarg) = params;
|
||||
ast::FunctionArguments {
|
||||
ast::Arguments {
|
||||
posonlyargs: vec![],
|
||||
args: vec![],
|
||||
kwonlyargs,
|
||||
|
@ -1038,7 +1038,7 @@ ParameterList<ArgType, StarArgType, DoubleStarArgType>: ast::FunctionArguments =
|
|||
}
|
||||
},
|
||||
<location:@L> <kwarg:KwargParameter<DoubleStarArgType>> ","? <end_location:@R> => {
|
||||
ast::FunctionArguments {
|
||||
ast::Arguments {
|
||||
posonlyargs: vec![],
|
||||
args: vec![],
|
||||
kwonlyargs: vec![],
|
||||
|
@ -1197,7 +1197,7 @@ LambdaDef: ast::Expr = {
|
|||
<location:@L> "lambda" <p:ParameterList<UntypedParameter, StarUntypedParameter, StarUntypedParameter>?> ":" <body:Test<"all">> <end_location:@R> =>? {
|
||||
p.as_ref().map(validate_arguments).transpose()?;
|
||||
let p = p
|
||||
.unwrap_or_else(|| ast::FunctionArguments::empty(optional_range(location, end_location)));
|
||||
.unwrap_or_else(|| ast::Arguments::empty(optional_range(location, end_location)));
|
||||
|
||||
Ok(ast::Expr::Lambda(
|
||||
ast::ExprLambda {
|
||||
|
|
762
parser/src/python.rs
generated
762
parser/src/python.rs
generated
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,7 @@ Ok(
|
|||
name: Identifier(
|
||||
"f",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 6..16,
|
||||
posonlyargs: [],
|
||||
args: [],
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
name: Identifier(
|
||||
"f",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 6..22,
|
||||
posonlyargs: [],
|
||||
args: [],
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
name: Identifier(
|
||||
"f",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 5..7,
|
||||
posonlyargs: [],
|
||||
args: [],
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
name: Identifier(
|
||||
"f",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 6..25,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
name: Identifier(
|
||||
"f",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 6..31,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
name: Identifier(
|
||||
"f",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 6..35,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
name: Identifier(
|
||||
"f",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 6..45,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
name: Identifier(
|
||||
"f",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 6..13,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
name: Identifier(
|
||||
"f",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 6..19,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
value: Lambda(
|
||||
ExprLambda {
|
||||
range: 0..20,
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 7..17,
|
||||
posonlyargs: [],
|
||||
args: [],
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
value: Lambda(
|
||||
ExprLambda {
|
||||
range: 0..26,
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 7..23,
|
||||
posonlyargs: [],
|
||||
args: [],
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
value: Lambda(
|
||||
ExprLambda {
|
||||
range: 0..9,
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 0..9,
|
||||
posonlyargs: [],
|
||||
args: [],
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
value: Lambda(
|
||||
ExprLambda {
|
||||
range: 0..26,
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 7..23,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
value: Lambda(
|
||||
ExprLambda {
|
||||
range: 0..17,
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 7..14,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -10,7 +10,7 @@ Ok(
|
|||
value: Lambda(
|
||||
ExprLambda {
|
||||
range: 0..23,
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 7..20,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -37,7 +37,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 24..74,
|
||||
range: 24..73,
|
||||
pattern: MatchMapping(
|
||||
PatternMatchMapping {
|
||||
range: 29..52,
|
||||
|
@ -122,7 +122,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 103..178,
|
||||
range: 103..177,
|
||||
pattern: MatchMapping(
|
||||
PatternMatchMapping {
|
||||
range: 108..155,
|
||||
|
@ -236,7 +236,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 191..219,
|
||||
range: 191..218,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 196..203,
|
||||
|
@ -319,7 +319,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 232..260,
|
||||
range: 232..259,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 237..244,
|
||||
|
@ -402,7 +402,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 273..298,
|
||||
range: 273..297,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 278..282,
|
||||
|
|
|
@ -712,7 +712,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 544..557,
|
||||
range: 544..556,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 549..550,
|
||||
|
@ -737,7 +737,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 561..582,
|
||||
range: 561..581,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 566..567,
|
||||
|
@ -781,7 +781,7 @@ expression: parse_ast
|
|||
value: Lambda(
|
||||
ExprLambda {
|
||||
range: 590..618,
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 597..602,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -37,7 +37,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
|
|||
name: Identifier(
|
||||
"__init__",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 31..35,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
@ -76,7 +76,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
|
|||
name: Identifier(
|
||||
"method_with_default",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 70..89,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -9,7 +9,7 @@ expression: parse_ast
|
|||
value: Lambda(
|
||||
ExprLambda {
|
||||
range: 0..18,
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 7..11,
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
|
|
|
@ -17,7 +17,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 80..126,
|
||||
range: 80..103,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 85..88,
|
||||
|
@ -86,7 +86,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 139..190,
|
||||
range: 139..167,
|
||||
pattern: MatchClass(
|
||||
PatternMatchClass {
|
||||
range: 144..152,
|
||||
|
@ -163,7 +163,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 203..234,
|
||||
range: 203..229,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 208..209,
|
||||
|
@ -219,7 +219,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 234..283,
|
||||
range: 234..260,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 239..240,
|
||||
|
@ -291,7 +291,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 296..355,
|
||||
range: 296..332,
|
||||
pattern: MatchOr(
|
||||
PatternMatchOr {
|
||||
range: 301..314,
|
||||
|
@ -402,7 +402,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 368..445,
|
||||
range: 368..403,
|
||||
pattern: MatchOr(
|
||||
PatternMatchOr {
|
||||
range: 373..388,
|
||||
|
@ -527,7 +527,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 458..494,
|
||||
range: 458..489,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 463..467,
|
||||
|
@ -562,7 +562,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 494..546,
|
||||
range: 494..523,
|
||||
pattern: MatchMapping(
|
||||
PatternMatchMapping {
|
||||
range: 499..501,
|
||||
|
@ -608,7 +608,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 559..599,
|
||||
range: 559..594,
|
||||
pattern: MatchMapping(
|
||||
PatternMatchMapping {
|
||||
range: 564..579,
|
||||
|
@ -702,7 +702,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 599..692,
|
||||
range: 599..687,
|
||||
pattern: MatchOr(
|
||||
PatternMatchOr {
|
||||
range: 604..672,
|
||||
|
@ -940,7 +940,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 692..737,
|
||||
range: 692..714,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 697..699,
|
||||
|
@ -994,7 +994,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 750..805,
|
||||
range: 750..782,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 755..767,
|
||||
|
@ -1072,7 +1072,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 818..864,
|
||||
range: 818..841,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 823..826,
|
||||
|
@ -1141,7 +1141,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 877..936,
|
||||
range: 877..913,
|
||||
pattern: MatchOr(
|
||||
PatternMatchOr {
|
||||
range: 882..895,
|
||||
|
@ -1252,7 +1252,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 949..998,
|
||||
range: 949..975,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 954..955,
|
||||
|
@ -1324,7 +1324,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1011..1042,
|
||||
range: 1011..1037,
|
||||
pattern: MatchMapping(
|
||||
PatternMatchMapping {
|
||||
range: 1016..1022,
|
||||
|
@ -1389,7 +1389,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 1042..1073,
|
||||
range: 1042..1068,
|
||||
pattern: MatchMapping(
|
||||
PatternMatchMapping {
|
||||
range: 1047..1053,
|
||||
|
@ -1454,7 +1454,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 1073..1121,
|
||||
range: 1073..1098,
|
||||
pattern: MatchMapping(
|
||||
PatternMatchMapping {
|
||||
range: 1078..1083,
|
||||
|
@ -1521,7 +1521,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1138..1185,
|
||||
range: 1138..1162,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 1143..1147,
|
||||
|
@ -1582,7 +1582,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1198..1224,
|
||||
range: 1198..1219,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 1203..1204,
|
||||
|
@ -1628,7 +1628,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 1224..1268,
|
||||
range: 1224..1245,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 1229..1230,
|
||||
|
@ -1690,7 +1690,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1281..1338,
|
||||
range: 1281..1315,
|
||||
pattern: MatchMapping(
|
||||
PatternMatchMapping {
|
||||
range: 1286..1298,
|
||||
|
@ -1794,7 +1794,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1359..1415,
|
||||
range: 1359..1392,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 1364..1377,
|
||||
|
@ -1901,7 +1901,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1428..1456,
|
||||
range: 1428..1451,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 1433..1436,
|
||||
|
@ -1954,7 +1954,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 1456..1503,
|
||||
range: 1456..1498,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 1461..1467,
|
||||
|
@ -2069,7 +2069,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 1503..1552,
|
||||
range: 1503..1529,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 1508..1514,
|
||||
|
@ -2152,7 +2152,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1565..1618,
|
||||
range: 1565..1595,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 1570..1580,
|
||||
|
@ -2235,7 +2235,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1631..1687,
|
||||
range: 1631..1664,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 1636..1649,
|
||||
|
@ -2327,7 +2327,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1703..1749,
|
||||
range: 1703..1726,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 1708..1711,
|
||||
|
@ -2393,7 +2393,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1762..1812,
|
||||
range: 1762..1789,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 1767..1774,
|
||||
|
@ -2482,7 +2482,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1825..1872,
|
||||
range: 1825..1849,
|
||||
pattern: MatchSingleton(
|
||||
PatternMatchSingleton {
|
||||
range: 1830..1834,
|
||||
|
@ -2536,7 +2536,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1885..1929,
|
||||
range: 1885..1906,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 1890..1891,
|
||||
|
@ -2598,7 +2598,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 1942..1990,
|
||||
range: 1942..1967,
|
||||
pattern: MatchSingleton(
|
||||
PatternMatchSingleton {
|
||||
range: 1947..1952,
|
||||
|
@ -2654,7 +2654,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 2003..2030,
|
||||
range: 2003..2025,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 2008..2010,
|
||||
|
@ -2692,7 +2692,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 2030..2059,
|
||||
range: 2030..2054,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 2035..2039,
|
||||
|
@ -2745,7 +2745,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 2059..2104,
|
||||
range: 2059..2081,
|
||||
pattern: MatchValue(
|
||||
PatternMatchValue {
|
||||
range: 2064..2066,
|
||||
|
@ -2807,7 +2807,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 2117..2161,
|
||||
range: 2117..2138,
|
||||
pattern: MatchAs(
|
||||
PatternMatchAs {
|
||||
range: 2122..2123,
|
||||
|
@ -2866,7 +2866,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 2174..2230,
|
||||
range: 2174..2207,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 2179..2192,
|
||||
|
@ -2953,7 +2953,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 2243..2330,
|
||||
range: 2243..2307,
|
||||
pattern: MatchOr(
|
||||
PatternMatchOr {
|
||||
range: 2248..2278,
|
||||
|
@ -3130,7 +3130,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 2343..2383,
|
||||
range: 2343..2378,
|
||||
pattern: MatchMapping(
|
||||
PatternMatchMapping {
|
||||
range: 2348..2363,
|
||||
|
@ -3224,7 +3224,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 2383..2477,
|
||||
range: 2383..2472,
|
||||
pattern: MatchOr(
|
||||
PatternMatchOr {
|
||||
range: 2388..2457,
|
||||
|
@ -3462,7 +3462,7 @@ expression: parse_ast
|
|||
],
|
||||
},
|
||||
MatchCase {
|
||||
range: 2477..2522,
|
||||
range: 2477..2499,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 2482..2484,
|
||||
|
@ -3542,7 +3542,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 2543..2591,
|
||||
range: 2543..2568,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 2548..2553,
|
||||
|
@ -3647,7 +3647,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 2612..2661,
|
||||
range: 2612..2638,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 2617..2623,
|
||||
|
@ -3726,7 +3726,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 2675..2720,
|
||||
range: 2675..2697,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 2680..2682,
|
||||
|
@ -3809,7 +3809,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 2736..2783,
|
||||
range: 2736..2760,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 2741..2745,
|
||||
|
@ -3900,7 +3900,7 @@ expression: parse_ast
|
|||
),
|
||||
cases: [
|
||||
MatchCase {
|
||||
range: 2802..2830,
|
||||
range: 2802..2829,
|
||||
pattern: MatchSequence(
|
||||
PatternMatchSequence {
|
||||
range: 2807..2814,
|
||||
|
|
|
@ -9,7 +9,7 @@ expression: parse_ast
|
|||
name: Identifier(
|
||||
"args_to_tuple",
|
||||
),
|
||||
args: FunctionArguments {
|
||||
args: Arguments {
|
||||
range: 19..29,
|
||||
posonlyargs: [],
|
||||
args: [],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue