Various refactoring.
This commit is contained in:
parent
eb83d1202a
commit
e21b428e26
@ -1,10 +1,40 @@
|
|||||||
pub mod leaf_enum_build_fn;
|
use crate::build_fn::leaf_enum_build_fn::make_leaf_enum_build_fn;
|
||||||
pub mod leaf_struct_build_fn;
|
use crate::build_fn::leaf_struct_build_fn::make_leaf_struct_build_fn;
|
||||||
pub mod node_production_build_fn;
|
use crate::build_fn::node_production_build_fn::make_node_production_build_fn;
|
||||||
pub mod polymorphic_build_build_fn;
|
use crate::build_fn::polymorphic_enum_loop_build_fn::make_polymorphic_enum_loop_build_fn;
|
||||||
pub mod polymorphic_enum_build_fn;
|
use crate::build_fn::polymorphic_type_build_fn::make_polymorphic_type_build_fn;
|
||||||
pub mod polymorphic_enum_loop_build_fn;
|
use crate::build_fn::production_build_fn::make_production_build_fn;
|
||||||
pub mod polymorphic_type_build_fn;
|
use crate::build_fn::struct_build_fn::make_struct_build_fn;
|
||||||
pub mod production_build_fn;
|
use crate::build_fn::tree_enum_build_fn::make_enum_build_fn;
|
||||||
pub mod struct_build_fn;
|
use crate::spec::BuildSpec;
|
||||||
pub mod tree_enum_build_fn;
|
use proc_macro2::TokenStream;
|
||||||
|
|
||||||
|
mod leaf_enum_build_fn;
|
||||||
|
mod leaf_struct_build_fn;
|
||||||
|
mod node_production_build_fn;
|
||||||
|
mod polymorphic_build_build_fn;
|
||||||
|
mod polymorphic_enum_build_fn;
|
||||||
|
mod polymorphic_enum_loop_build_fn;
|
||||||
|
mod polymorphic_type_build_fn;
|
||||||
|
mod production_build_fn;
|
||||||
|
mod struct_build_fn;
|
||||||
|
mod tree_enum_build_fn;
|
||||||
|
|
||||||
|
pub fn make_build_fn(build_spec: &BuildSpec) -> TokenStream {
|
||||||
|
match build_spec {
|
||||||
|
BuildSpec::Struct(struct_spec) => make_struct_build_fn(struct_spec),
|
||||||
|
BuildSpec::LeafStruct(leaf_struct_spec) => make_leaf_struct_build_fn(leaf_struct_spec),
|
||||||
|
BuildSpec::Enum(enum_spec) => make_enum_build_fn(enum_spec),
|
||||||
|
BuildSpec::LeafEnum(leaf_enum_spec) => make_leaf_enum_build_fn(leaf_enum_spec),
|
||||||
|
BuildSpec::Production(production_spec) => make_production_build_fn(production_spec),
|
||||||
|
BuildSpec::NodeProduction(node_production_spec) => {
|
||||||
|
make_node_production_build_fn(node_production_spec)
|
||||||
|
}
|
||||||
|
BuildSpec::PolymorphicType(polymorphic_type_spec) => {
|
||||||
|
make_polymorphic_type_build_fn(polymorphic_type_spec)
|
||||||
|
}
|
||||||
|
BuildSpec::PolymorphicEnumLoop(polymorphic_enum_loop_spec) => {
|
||||||
|
make_polymorphic_enum_loop_build_fn(polymorphic_enum_loop_spec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,18 +1,11 @@
|
|||||||
mod build_fn;
|
mod build_fn;
|
||||||
pub mod deserialize;
|
mod deserialize;
|
||||||
mod pretty_print;
|
mod pretty_print;
|
||||||
mod spec;
|
mod spec;
|
||||||
mod type_gen;
|
mod type_gen;
|
||||||
mod util;
|
|
||||||
|
|
||||||
use crate::build_fn::enum_build_fn::make_enum_build_fn;
|
use crate::build_fn::make_build_fn;
|
||||||
use crate::build_fn::leaf_enum_build_fn::make_leaf_enum_build_fn;
|
use crate::deserialize::deserialize_yaml_spec;
|
||||||
use crate::build_fn::leaf_struct_build_fn::make_leaf_struct_build_fn;
|
|
||||||
use crate::build_fn::polymorphic_build_build_fn::make_polymorphic_build_build_fn;
|
|
||||||
use crate::build_fn::polymorphic_build_fn::make_polymorphic_build_fn;
|
|
||||||
use crate::build_fn::polymorphic_enum_build_fn::make_polymorphic_enum_build_fn;
|
|
||||||
use crate::build_fn::production_build_fn::make_production_build_fn;
|
|
||||||
use crate::build_fn::struct_build_fn::make_struct_build_fn;
|
|
||||||
use crate::pretty_print::make_pretty_print_impl;
|
use crate::pretty_print::make_pretty_print_impl;
|
||||||
use crate::type_gen::make_type;
|
use crate::type_gen::make_type;
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
@ -39,24 +32,21 @@ fn debug_built_spec(build_spec: &BuildSpec, token_stream: &TokenStream) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
BuildSpec::Production(production_build_spec) => {
|
BuildSpec::Production(production_build_spec) => {
|
||||||
println!("Production Spec - rule: {}", production_build_spec.rule());
|
println!("Production Spec - name: {}", production_build_spec.name());
|
||||||
}
|
}
|
||||||
BuildSpec::Polymorphic(polymorphic_build_spec) => {
|
BuildSpec::NodeProduction(node_production_build_spec) => {
|
||||||
|
println!("Node Production Spec - name: {}", node_production_build_spec.name());
|
||||||
|
}
|
||||||
|
BuildSpec::PolymorphicType(polymorphic_build_spec) => {
|
||||||
println!(
|
println!(
|
||||||
"Polymorphic Type Spec - name: {}",
|
"Polymorphic Type Spec - name: {}",
|
||||||
polymorphic_build_spec.name()
|
polymorphic_build_spec.name()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
BuildSpec::PolymorphicBuild(polymorphic_build_build_spec) => {
|
BuildSpec::PolymorphicEnumLoop(polymorphic_enum_loop_build_spec) => {
|
||||||
println!(
|
println!(
|
||||||
"Polymorphic Build Spec - name: {}",
|
"Polymorphic Enum Loop Spec - name: {}",
|
||||||
polymorphic_build_build_spec.name()
|
polymorphic_enum_loop_build_spec.name()
|
||||||
);
|
|
||||||
}
|
|
||||||
BuildSpec::PolymorphicEnum(polymorphic_enum_build_spec) => {
|
|
||||||
println!(
|
|
||||||
"Polymorphic Enum Spec - name: {}",
|
|
||||||
polymorphic_enum_build_spec.name()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,49 +68,13 @@ fn token_stream_to_string(token_stream: TokenStream) -> String {
|
|||||||
fn generate_build_file(build_specs: &[BuildSpec]) -> AstGeneratedFile {
|
fn generate_build_file(build_specs: &[BuildSpec]) -> AstGeneratedFile {
|
||||||
let build_fns = build_specs
|
let build_fns = build_specs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|build_spec| match build_spec {
|
.map(|build_spec| {
|
||||||
BuildSpec::Enum(enum_build_spec) => {
|
let build_fn = make_build_fn(build_spec);
|
||||||
let stream = make_enum_build_fn(enum_build_spec);
|
debug_built_spec(build_spec, &build_fn);
|
||||||
debug_built_spec(build_spec, &stream);
|
build_fn
|
||||||
stream
|
|
||||||
}
|
|
||||||
BuildSpec::LeafEnum(leaf_enum_build_spec) => {
|
|
||||||
let stream = make_leaf_enum_build_fn(leaf_enum_build_spec);
|
|
||||||
debug_built_spec(build_spec, &stream);
|
|
||||||
stream
|
|
||||||
}
|
|
||||||
BuildSpec::Struct(struct_build_spec) => {
|
|
||||||
let stream = make_struct_build_fn(struct_build_spec);
|
|
||||||
debug_built_spec(build_spec, &stream);
|
|
||||||
stream
|
|
||||||
}
|
|
||||||
BuildSpec::LeafStruct(leaf_struct_build_spec) => {
|
|
||||||
let stream = make_leaf_struct_build_fn(leaf_struct_build_spec);
|
|
||||||
debug_built_spec(build_spec, &stream);
|
|
||||||
stream
|
|
||||||
}
|
|
||||||
BuildSpec::Production(production_build_spec) => {
|
|
||||||
let stream = make_production_build_fn(production_build_spec);
|
|
||||||
debug_built_spec(build_spec, &stream);
|
|
||||||
stream
|
|
||||||
}
|
|
||||||
BuildSpec::Polymorphic(polymorphic_build_spec) => {
|
|
||||||
let stream = make_polymorphic_build_fn(polymorphic_build_spec);
|
|
||||||
debug_built_spec(build_spec, &stream);
|
|
||||||
stream
|
|
||||||
}
|
|
||||||
BuildSpec::PolymorphicBuild(polymorphic_build_build_spec) => {
|
|
||||||
let stream = make_polymorphic_build_build_fn(polymorphic_build_build_spec);
|
|
||||||
debug_built_spec(build_spec, &stream);
|
|
||||||
stream
|
|
||||||
}
|
|
||||||
BuildSpec::PolymorphicEnum(polymorphic_enum_build_spec) => {
|
|
||||||
let stream = make_polymorphic_enum_build_fn(polymorphic_enum_build_spec);
|
|
||||||
debug_built_spec(build_spec, &stream);
|
|
||||||
stream
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let combined = quote! {
|
let combined = quote! {
|
||||||
//noinspection RsUnusedImport
|
//noinspection RsUnusedImport
|
||||||
use crate::parser::Rule;
|
use crate::parser::Rule;
|
||||||
@ -131,6 +85,7 @@ fn generate_build_file(build_specs: &[BuildSpec]) -> AstGeneratedFile {
|
|||||||
|
|
||||||
#(#build_fns)*
|
#(#build_fns)*
|
||||||
};
|
};
|
||||||
|
|
||||||
AstGeneratedFile {
|
AstGeneratedFile {
|
||||||
name: String::from("build.rs"),
|
name: String::from("build.rs"),
|
||||||
contents: token_stream_to_string(combined),
|
contents: token_stream_to_string(combined),
|
||||||
@ -172,6 +127,10 @@ fn generate_pretty_print_file(build_specs: &[BuildSpec]) -> AstGeneratedFile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_build_specs(yaml: &str) -> Vec<BuildSpec> {
|
||||||
|
deserialize_yaml_spec(yaml)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn generate_files(build_specs: &[BuildSpec]) -> Vec<AstGeneratedFile> {
|
pub fn generate_files(build_specs: &[BuildSpec]) -> Vec<AstGeneratedFile> {
|
||||||
vec![
|
vec![
|
||||||
generate_build_file(build_specs),
|
generate_build_file(build_specs),
|
||||||
|
|||||||
@ -73,6 +73,10 @@ impl PolymorphicEnumLoopRuleBuild {
|
|||||||
children,
|
children,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn name(&self) -> &str {
|
||||||
|
&self.name
|
||||||
|
}
|
||||||
|
|
||||||
pub fn variant(&self) -> &str {
|
pub fn variant(&self) -> &str {
|
||||||
&self.variant
|
&self.variant
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user