109 lines
4.3 KiB
Rust
109 lines
4.3 KiB
Rust
mod leaf_enum_spec;
|
|
mod leaf_struct_spec;
|
|
mod node_production_spec;
|
|
mod polymorphic_enum_build_inner;
|
|
mod polymorphic_enum_loop_spec;
|
|
mod polymorphic_leaf_enum;
|
|
mod polymorphic_pass_through_spec;
|
|
mod polymorphic_tree_enum;
|
|
mod polymorphic_type_spec;
|
|
mod production_spec;
|
|
mod struct_spec;
|
|
mod tree_enum_spec;
|
|
pub(crate) mod util;
|
|
|
|
use crate::deserialize::leaf_enum_spec::deserialize_leaf_enum;
|
|
use crate::deserialize::leaf_struct_spec::deserialize_leaf_struct;
|
|
use crate::deserialize::node_production_spec::deserialize_node_production;
|
|
use crate::deserialize::polymorphic_enum_build_inner::deserialize_polymorphic_enum_inner_build;
|
|
use crate::deserialize::polymorphic_enum_loop_spec::deserialize_polymorphic_enum_loop;
|
|
use crate::deserialize::polymorphic_leaf_enum::deserialize_polymorphic_leaf_enum;
|
|
use crate::deserialize::polymorphic_pass_through_spec::deserialize_polymorphic_pass_through;
|
|
use crate::deserialize::polymorphic_tree_enum::deserialize_polymorphic_tree_enum;
|
|
use crate::deserialize::polymorphic_type_spec::deserialize_polymorphic_type;
|
|
use crate::deserialize::production_spec::deserialize_production;
|
|
use crate::deserialize::struct_spec::deserialize_struct_spec;
|
|
use crate::deserialize::tree_enum_spec::deserialize_tree_enum;
|
|
use crate::spec::BuildSpec;
|
|
use yaml_rust2::{Yaml, YamlLoader};
|
|
|
|
fn deserialize_build_spec(build_spec_name: &str, build_spec: &Yaml) -> BuildSpec {
|
|
if build_spec["struct"].is_hash() {
|
|
BuildSpec::Struct(deserialize_struct_spec(
|
|
build_spec_name,
|
|
&build_spec["struct"],
|
|
))
|
|
} else if build_spec["leaf_struct"].is_hash() {
|
|
BuildSpec::LeafStruct(deserialize_leaf_struct(
|
|
build_spec_name,
|
|
&build_spec["leaf_struct"],
|
|
))
|
|
} else if build_spec["tree_enum"].is_hash() {
|
|
BuildSpec::Enum(deserialize_tree_enum(
|
|
build_spec_name,
|
|
&build_spec["tree_enum"],
|
|
))
|
|
} else if build_spec["leaf_enum"].is_hash() {
|
|
BuildSpec::LeafEnum(deserialize_leaf_enum(
|
|
build_spec_name,
|
|
&build_spec["leaf_enum"],
|
|
))
|
|
} else if build_spec["production"].is_hash() {
|
|
BuildSpec::Production(deserialize_production(
|
|
build_spec_name,
|
|
&build_spec["production"],
|
|
))
|
|
} else if build_spec["node_production"].is_hash() {
|
|
BuildSpec::NodeProduction(deserialize_node_production(
|
|
build_spec_name,
|
|
&build_spec["node_production"],
|
|
))
|
|
} else if build_spec["polymorphic_type"].is_hash() {
|
|
BuildSpec::PolymorphicType(deserialize_polymorphic_type(
|
|
build_spec_name,
|
|
&build_spec["polymorphic_type"],
|
|
))
|
|
} else if build_spec["polymorphic_enum_loop_build"].is_hash() {
|
|
BuildSpec::PolymorphicEnumLoop(deserialize_polymorphic_enum_loop(
|
|
build_spec_name,
|
|
&build_spec["polymorphic_enum_loop_build"],
|
|
))
|
|
} else if build_spec["polymorphic_pass_through"].is_hash() {
|
|
BuildSpec::PolymorphicPassThrough(deserialize_polymorphic_pass_through(
|
|
build_spec_name,
|
|
&build_spec["polymorphic_pass_through"],
|
|
))
|
|
} else if build_spec["polymorphic_enum_inner_build"].is_hash() {
|
|
BuildSpec::PolymorphicEnumInnerBuild(deserialize_polymorphic_enum_inner_build(
|
|
build_spec_name,
|
|
&build_spec["polymorphic_enum_inner_build"],
|
|
))
|
|
} else if build_spec["polymorphic_leaf_enum"].is_hash() {
|
|
BuildSpec::PolymorphicLeafEnum(deserialize_polymorphic_leaf_enum(
|
|
build_spec_name,
|
|
&build_spec["polymorphic_leaf_enum"],
|
|
))
|
|
} else if build_spec["polymorphic_tree_enum"].is_hash() {
|
|
BuildSpec::PolymorphicTreeEnum(deserialize_polymorphic_tree_enum(
|
|
build_spec_name,
|
|
&build_spec["polymorphic_tree_enum"],
|
|
))
|
|
} else {
|
|
panic!("Missing or incorrect build type for {}", build_spec_name);
|
|
}
|
|
}
|
|
|
|
pub fn deserialize_yaml_spec(yaml: &str) -> Vec<BuildSpec> {
|
|
let docs = YamlLoader::load_from_str(yaml).unwrap();
|
|
let doc = &docs[0];
|
|
|
|
doc.as_hash()
|
|
.unwrap()
|
|
.iter()
|
|
.map(|(build_spec_name, build_spec)| {
|
|
let name_as_str = build_spec_name.as_str().unwrap();
|
|
deserialize_build_spec(name_as_str, build_spec)
|
|
})
|
|
.collect()
|
|
}
|