impl From<T> for ast::Ast (#62)

This commit is contained in:
Jeong, YunWon 2023-05-21 22:44:07 +09:00 committed by GitHub
parent 33a3c407a9
commit d4084fb17a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 628 additions and 0 deletions

View file

@ -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