mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
impl From<T> for ast::Ast
This commit is contained in:
parent
33a3c407a9
commit
58db5ed2a0
2 changed files with 628 additions and 0 deletions
|
@ -322,6 +322,16 @@ class StructVisitor(EmitVisitor):
|
|||
const FIELD_NAMES: &'static [&'static str] = &[];
|
||||
}
|
||||
""", 0)
|
||||
for dfn in mod.dfns:
|
||||
rust_name = rust_type_name(dfn.name)
|
||||
generics = "" if self.type_info[dfn.name].is_simple else "<R>"
|
||||
self.emit(f"""
|
||||
impl<R> From<{rust_name}{generics}> for Ast<R> {{
|
||||
fn from(node: {rust_name}{generics}) -> Self {{
|
||||
Ast::{rust_name}(node)
|
||||
}}
|
||||
}}
|
||||
""", 0)
|
||||
|
||||
for dfn in mod.dfns:
|
||||
self.visit(dfn)
|
||||
|
@ -385,6 +395,11 @@ class StructVisitor(EmitVisitor):
|
|||
{rust_name}::{cons.name}
|
||||
}}
|
||||
}}
|
||||
impl<R> From<{rust_name}{cons.name}> for Ast<R> {{
|
||||
fn from(_: {rust_name}{cons.name}) -> Self {{
|
||||
{rust_name}::{cons.name}.into()
|
||||
}}
|
||||
}}
|
||||
impl Node for {rust_name}{cons.name} {{
|
||||
const NAME: &'static str = "{cons.name}";
|
||||
const FIELD_NAMES: &'static [&'static str] = &[];
|
||||
|
@ -447,6 +462,11 @@ class StructVisitor(EmitVisitor):
|
|||
{rust_name}::{t.name}(payload)
|
||||
}}
|
||||
}}
|
||||
impl<R> From<{payload_name}<R>> for Ast<R> {{
|
||||
fn from(payload: {payload_name}<R>) -> Self {{
|
||||
{rust_name}::from(payload).into()
|
||||
}}
|
||||
}}
|
||||
""",
|
||||
depth,
|
||||
)
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue