Refactor production build fn.
This commit is contained in:
parent
f3ebcd77bd
commit
de021789c1
@ -1,19 +1,18 @@
|
||||
use crate::spec::{ProductionBuildSpec, ProductionKind, ProductionStringFrom};
|
||||
use crate::util::{make_build_fn_name, make_build_pair};
|
||||
use crate::deserialize::util::{make_build_fn_name, make_build_pair};
|
||||
use crate::spec::production_spec::{ProductionBuildSpec, ProductionKind, ProductionStringFrom};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
|
||||
pub fn make_production_build_fn(production_build_spec: &ProductionBuildSpec) -> TokenStream {
|
||||
let build_fn_ident = format_ident!("{}", make_build_fn_name(production_build_spec.rule()));
|
||||
let build_fn_ident = format_ident!("{}", make_build_fn_name(production_build_spec.name()));
|
||||
let return_type_ident = match production_build_spec.kind() {
|
||||
ProductionKind::Int => format_ident!("i32"),
|
||||
ProductionKind::Long => format_ident!("i64"),
|
||||
ProductionKind::Double => format_ident!("f64"),
|
||||
ProductionKind::String(_) => format_ident!("String"),
|
||||
ProductionKind::Boolean => format_ident!("bool"),
|
||||
ProductionKind::Node(node_type) => format_ident!("{}", node_type.kind()),
|
||||
ProductionKind::Boolean(_) => format_ident!("bool"),
|
||||
};
|
||||
let pair_ident = format_ident!("{}", make_build_pair(production_build_spec.rule()));
|
||||
let pair_ident = format_ident!("{}", make_build_pair(production_build_spec.name()));
|
||||
|
||||
let pair_mapper = match production_build_spec.kind() {
|
||||
ProductionKind::Int => quote! {
|
||||
@ -75,16 +74,9 @@ pub fn make_production_build_fn(production_build_spec: &ProductionBuildSpec) ->
|
||||
}
|
||||
}
|
||||
},
|
||||
ProductionKind::Boolean => quote! {
|
||||
ProductionKind::Boolean(_) => quote! {
|
||||
#pair_ident.as_str().parse::<bool>().unwrap()
|
||||
},
|
||||
ProductionKind::Node(node_kind) => {
|
||||
let build_fn_ident = format_ident!("{}", make_build_fn_name(node_kind.with()));
|
||||
quote! {
|
||||
let inner_pair = #pair_ident.into_inner().next().unwrap();
|
||||
#build_fn_ident(inner_pair)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
quote! {
|
||||
|
||||
@ -11,7 +11,7 @@ impl ProductionBuildSpec {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rule(&self) -> &str {
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user