52 lines
2.0 KiB
Rust
52 lines
2.0 KiB
Rust
mod enum_ast_node;
|
|
mod leaf_enum_ast_node;
|
|
mod struct_ast_node;
|
|
mod leaf_struct_ast_node;
|
|
mod polymorphic_type_ast_node;
|
|
mod polymorphic_enum_loop_ast_node;
|
|
|
|
use crate::spec::BuildSpec;
|
|
use proc_macro2::TokenStream;
|
|
use quote::{format_ident, quote};
|
|
use crate::ast_node::enum_ast_node::make_enum_ast_node_impl;
|
|
use crate::ast_node::leaf_enum_ast_node::make_leaf_enum_ast_node_impl;
|
|
use crate::ast_node::leaf_struct_ast_node::make_leaf_struct_ast_node_impl;
|
|
use crate::ast_node::polymorphic_enum_loop_ast_node::make_polymorphic_enum_loop_ast_node_impl;
|
|
use crate::ast_node::polymorphic_type_ast_node::make_polymorphic_type_ast_node_impl;
|
|
use crate::ast_node::struct_ast_node::make_struct_ast_node_impl;
|
|
|
|
pub fn make_ast_node_impl(build_spec: &BuildSpec) -> Option<TokenStream> {
|
|
match build_spec {
|
|
BuildSpec::Enum(enum_spec) => {
|
|
Some(make_enum_ast_node_impl(enum_spec))
|
|
}
|
|
BuildSpec::LeafEnum(leaf_enum) => {
|
|
Some(make_leaf_enum_ast_node_impl(leaf_enum))
|
|
}
|
|
BuildSpec::Struct(struct_spec) => {
|
|
Some(make_struct_ast_node_impl(struct_spec))
|
|
}
|
|
BuildSpec::LeafStruct(leaf_struct) => {
|
|
Some(make_leaf_struct_ast_node_impl(leaf_struct))
|
|
}
|
|
BuildSpec::Production(_) => None,
|
|
BuildSpec::NodeProduction(_) => None,
|
|
BuildSpec::PolymorphicType(polymorphic_type) => {
|
|
Some(make_polymorphic_type_ast_node_impl(polymorphic_type))
|
|
}
|
|
BuildSpec::PolymorphicEnumLoop(polymorphic_enum_loop) => {
|
|
Some(make_polymorphic_enum_loop_ast_node_impl(polymorphic_enum_loop))
|
|
}
|
|
BuildSpec::PolymorphicPassThrough(_) => None,
|
|
}
|
|
}
|
|
|
|
pub fn make_ast_enum_member(build_spec: &BuildSpec) -> Option<TokenStream> {
|
|
match build_spec {
|
|
BuildSpec::Struct(struct_spec) => {
|
|
let type_ident = format_ident!("{}", struct_spec.build());
|
|
Some(quote! { #type_ident(#type_ident) })
|
|
}
|
|
_ => None,
|
|
}
|
|
} |