mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-12 23:55:21 +00:00
impl From<T> for ast::Ast (#62)
This commit is contained in:
parent
33a3c407a9
commit
d4084fb17a
2 changed files with 628 additions and 0 deletions
|
@ -322,6 +322,16 @@ class StructVisitor(EmitVisitor):
|
||||||
const FIELD_NAMES: &'static [&'static str] = &[];
|
const FIELD_NAMES: &'static [&'static str] = &[];
|
||||||
}
|
}
|
||||||
""", 0)
|
""", 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:
|
for dfn in mod.dfns:
|
||||||
self.visit(dfn)
|
self.visit(dfn)
|
||||||
|
@ -385,6 +395,11 @@ class StructVisitor(EmitVisitor):
|
||||||
{rust_name}::{cons.name}
|
{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} {{
|
impl Node for {rust_name}{cons.name} {{
|
||||||
const NAME: &'static str = "{cons.name}";
|
const NAME: &'static str = "{cons.name}";
|
||||||
const FIELD_NAMES: &'static [&'static str] = &[];
|
const FIELD_NAMES: &'static [&'static str] = &[];
|
||||||
|
@ -447,6 +462,11 @@ class StructVisitor(EmitVisitor):
|
||||||
{rust_name}::{t.name}(payload)
|
{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,
|
depth,
|
||||||
)
|
)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue