Moving things around and cargo fmt.
This commit is contained in:
parent
2176d0eb8d
commit
aff2fe2a2b
@ -8,7 +8,8 @@ pub fn make_leaf_enum_build_fn(leaf_enum_build_spec: &LeafEnumBuildSpec) -> Toke
|
||||
let pair_ident = format_ident!("{}", make_build_pair(leaf_enum_build_spec.build()));
|
||||
let return_type_ident = format_ident!("{}", leaf_enum_build_spec.build());
|
||||
|
||||
let rule_branches = leaf_enum_build_spec.rules()
|
||||
let rule_branches = leaf_enum_build_spec
|
||||
.rules()
|
||||
.map(|leaf_enum_rule| {
|
||||
let rule_ident = format_ident!("{}", leaf_enum_rule.rule());
|
||||
quote! {
|
||||
8
ast-generator/src/build_fn/mod.rs
Normal file
8
ast-generator/src/build_fn/mod.rs
Normal file
@ -0,0 +1,8 @@
|
||||
pub(crate) mod enum_build_fn;
|
||||
pub(crate) mod leaf_enum_build_fn;
|
||||
pub(crate) mod leaf_struct_build_fn;
|
||||
pub(crate) mod polymorphic_build_build_fn;
|
||||
pub(crate) mod polymorphic_build_fn;
|
||||
pub(crate) mod polymorphic_enum_build_fn;
|
||||
pub(crate) mod production_build_fn;
|
||||
pub(crate) mod struct_build_fn;
|
||||
@ -1,6 +1,9 @@
|
||||
use convert_case::{Case, Casing};
|
||||
use crate::spec::{AlternativeAction, AlternativeBuild, AlternativeBuildChild, AlternativeChild, AlternativeTest, PolymorphicBuildBuildSpec};
|
||||
use crate::spec::{
|
||||
AlternativeAction, AlternativeBuild, AlternativeBuildChild, AlternativeChild, AlternativeTest,
|
||||
PolymorphicBuildBuildSpec,
|
||||
};
|
||||
use crate::util::{make_build_fn_name, make_build_pair};
|
||||
use convert_case::{Case, Casing};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
|
||||
@ -25,16 +28,14 @@ fn make_build_action(
|
||||
|
||||
let child_holders = alternative_build
|
||||
.children()
|
||||
.map(|child| {
|
||||
match child {
|
||||
AlternativeChild::Skip => None,
|
||||
AlternativeChild::Build(build_child) => {
|
||||
let child_ident = format_ident!("{}", build_child.name());
|
||||
let child_type_ident = format_ident!("{}", build_child.kind());
|
||||
Some(quote! {
|
||||
let mut #child_ident: Option<#child_type_ident> = None
|
||||
})
|
||||
}
|
||||
.map(|child| match child {
|
||||
AlternativeChild::Skip => None,
|
||||
AlternativeChild::Build(build_child) => {
|
||||
let child_ident = format_ident!("{}", build_child.name());
|
||||
let child_type_ident = format_ident!("{}", build_child.kind());
|
||||
Some(quote! {
|
||||
let mut #child_ident: Option<#child_type_ident> = None
|
||||
})
|
||||
}
|
||||
})
|
||||
.filter(Option::is_some)
|
||||
@ -45,13 +46,9 @@ fn make_build_action(
|
||||
|
||||
let rule_matchers = alternative_build
|
||||
.children()
|
||||
.map(|child| {
|
||||
match child {
|
||||
AlternativeChild::Skip => None,
|
||||
AlternativeChild::Build(build_child) => {
|
||||
Some(make_build_child(build_child))
|
||||
}
|
||||
}
|
||||
.map(|child| match child {
|
||||
AlternativeChild::Skip => None,
|
||||
AlternativeChild::Build(build_child) => Some(make_build_child(build_child)),
|
||||
})
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
@ -59,22 +56,21 @@ fn make_build_action(
|
||||
|
||||
let built_ident = format_ident!("{}", spec.name().to_case(Case::Snake));
|
||||
let inner_type_ident = format_ident!("{}", spec.name());
|
||||
let child_args = alternative_build.children()
|
||||
.map(|child| {
|
||||
match child {
|
||||
AlternativeChild::Skip => None,
|
||||
AlternativeChild::Build(child_build) => {
|
||||
let child_ident = format_ident!("{}", child_build.name());
|
||||
Some(quote! {
|
||||
Box::new(#child_ident.unwrap())
|
||||
})
|
||||
}
|
||||
let child_args = alternative_build
|
||||
.children()
|
||||
.map(|child| match child {
|
||||
AlternativeChild::Skip => None,
|
||||
AlternativeChild::Build(child_build) => {
|
||||
let child_ident = format_ident!("{}", child_build.name());
|
||||
Some(quote! {
|
||||
Box::new(#child_ident.unwrap())
|
||||
})
|
||||
}
|
||||
})
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
||||
quote! {
|
||||
#(#child_holders;)*
|
||||
|
||||
@ -86,7 +82,7 @@ fn make_build_action(
|
||||
}
|
||||
|
||||
let #built_ident = #inner_type_ident::new(#(#child_args),*);
|
||||
|
||||
|
||||
#enum_type_ident::#enum_variant_ident(#built_ident)
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,13 @@
|
||||
use crate::spec::{PolymorphicEnumBuildSpec, PolymorphicEnumRule};
|
||||
use crate::util::{make_build_fn_name, make_build_pair};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use crate::util::{make_build_fn_name, make_build_pair};
|
||||
|
||||
pub fn make_polymorphic_enum_build_fn(spec: &PolymorphicEnumBuildSpec) -> TokenStream {
|
||||
let build_fn_ident = format_ident!("{}", make_build_fn_name(spec.name()));
|
||||
let pair_ident = format_ident!("{}", make_build_pair(spec.name()));
|
||||
let return_type_ident = format_ident!("{}", spec.return_type());
|
||||
|
||||
|
||||
let match_arms = spec.rules()
|
||||
.map(|rule| {
|
||||
match rule {
|
||||
@ -29,7 +29,7 @@ pub fn make_polymorphic_enum_build_fn(spec: &PolymorphicEnumBuildSpec) -> TokenS
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
||||
quote! {
|
||||
fn #build_fn_ident(#pair_ident: Pair<Rule>) -> #return_type_ident {
|
||||
let inner_pair = #pair_ident.into_inner().next().unwrap();
|
||||
@ -11,7 +11,7 @@ pub fn make_production_build_fn(production_build_spec: &ProductionBuildSpec) ->
|
||||
ProductionKind::Double => format_ident!("f64"),
|
||||
ProductionKind::String(_) => format_ident!("String"),
|
||||
ProductionKind::Boolean => format_ident!("bool"),
|
||||
ProductionKind::Node(node_type) => format_ident!("{}", node_type),
|
||||
ProductionKind::Node(node_type) => format_ident!("{}", node_type.kind()),
|
||||
};
|
||||
let pair_ident = format_ident!("{}", make_build_pair(production_build_spec.rule()));
|
||||
|
||||
@ -78,8 +78,8 @@ pub fn make_production_build_fn(production_build_spec: &ProductionBuildSpec) ->
|
||||
ProductionKind::Boolean => quote! {
|
||||
#pair_ident.as_str().parse::<bool>().unwrap()
|
||||
},
|
||||
ProductionKind::Node(node_type) => {
|
||||
let build_fn_ident = format_ident!("{}", make_build_fn_name(node_type));
|
||||
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)
|
||||
@ -1,4 +1,7 @@
|
||||
use crate::spec::{BooleanChildToBuild, MemberChildToBuild, NodeChildToBuild, StructBuildSpec, StructChildSpec, VecChild, VecChildToBuild};
|
||||
use crate::spec::{
|
||||
BooleanChildToBuild, MemberChildToBuild, NodeChildToBuild, StructBuildSpec, StructChildSpec,
|
||||
VecChild, VecChildToBuild,
|
||||
};
|
||||
use crate::util::{make_build_fn_name, make_build_pair};
|
||||
use convert_case::{Case, Casing};
|
||||
use proc_macro2::TokenStream;
|
||||
@ -16,16 +19,16 @@ fn make_vec_child_holder(vec_child: &VecChild) -> TokenStream {
|
||||
quote! {
|
||||
let mut #child_ident: Vec<Box<#child_type_ident >> = vec![]
|
||||
}
|
||||
},
|
||||
}
|
||||
VecChildToBuild::String => quote! {
|
||||
let mut #child_ident: Vec<String> = vec![]
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn make_node_child_holder(name: &str, node_child: &NodeChildToBuild) -> TokenStream {
|
||||
let child_ident = format_ident!("{}", name);
|
||||
let child_type_ident = format_ident!("{}", node_child.build());
|
||||
let child_type_ident = format_ident!("{}", node_child.kind());
|
||||
quote! {
|
||||
let mut #child_ident: Option<Box<#child_type_ident>> = None
|
||||
}
|
||||
@ -61,7 +64,7 @@ fn make_vec_child_match_action(vec_child: &VecChild) -> TokenStream {
|
||||
quote! {
|
||||
#child_name_ident.push(Box::new(#build_fn_ident(inner_pair)))
|
||||
}
|
||||
},
|
||||
}
|
||||
VecChildToBuild::String => {
|
||||
let build_fn_ident = format_ident!("{}", make_build_fn_name(vec_child.rule()));
|
||||
quote! {
|
||||
@ -73,7 +76,7 @@ fn make_vec_child_match_action(vec_child: &VecChild) -> TokenStream {
|
||||
|
||||
fn make_node_member_child_match_action(name: &str, node_child: &NodeChildToBuild) -> TokenStream {
|
||||
let child_name_ident = format_ident!("{}", name);
|
||||
let build_fn_ident = format_ident!("{}", make_build_fn_name(node_child.build()));
|
||||
let build_fn_ident = format_ident!("{}", make_build_fn_name(node_child.kind()));
|
||||
quote! {
|
||||
#child_name_ident = Some(Box::new(#build_fn_ident(inner_pair)))
|
||||
}
|
||||
@ -89,9 +92,7 @@ fn make_boolean_member_child_match_action(boolean_child: &BooleanChildToBuild) -
|
||||
fn make_match_action(child_spec: &StructChildSpec) -> TokenStream {
|
||||
match child_spec {
|
||||
StructChildSpec::SkipChild(_) => quote! {},
|
||||
StructChildSpec::VecChild(vec_child) => {
|
||||
make_vec_child_match_action(vec_child)
|
||||
}
|
||||
StructChildSpec::VecChild(vec_child) => make_vec_child_match_action(vec_child),
|
||||
StructChildSpec::MemberChild(member_child) => match member_child.build() {
|
||||
MemberChildToBuild::Node(node_child) => {
|
||||
make_node_member_child_match_action(member_child.name(), node_child)
|
||||
@ -128,7 +129,7 @@ fn make_node_member_child_arg(name: &str, node_child: &NodeChildToBuild) -> Toke
|
||||
if node_child.optional() {
|
||||
quote! { #child_ident }
|
||||
} else if let Some(or_else) = node_child.or_else() {
|
||||
let child_type_ident = format_ident!("{}", node_child.build());
|
||||
let child_type_ident = format_ident!("{}", node_child.kind());
|
||||
let or_else_ident = format_ident!("{}", or_else);
|
||||
quote! {
|
||||
#child_ident.unwrap_or_else(|| Box::new(#child_type_ident::#or_else_ident()))
|
||||
@ -146,13 +147,12 @@ fn make_boolean_member_child_arg(boolean_child: &BooleanChildToBuild) -> TokenSt
|
||||
fn make_child_arg(child_spec: &StructChildSpec) -> Option<TokenStream> {
|
||||
match child_spec {
|
||||
StructChildSpec::SkipChild(_) => None,
|
||||
StructChildSpec::VecChild(vec_child) => {
|
||||
Some(make_vec_child_arg(vec_child))
|
||||
}
|
||||
StructChildSpec::VecChild(vec_child) => Some(make_vec_child_arg(vec_child)),
|
||||
StructChildSpec::MemberChild(member_child) => match member_child.build() {
|
||||
MemberChildToBuild::Node(single_type_child) => {
|
||||
Some(make_node_member_child_arg(member_child.name(), single_type_child))
|
||||
}
|
||||
MemberChildToBuild::Node(single_type_child) => Some(make_node_member_child_arg(
|
||||
member_child.name(),
|
||||
single_type_child,
|
||||
)),
|
||||
MemberChildToBuild::Boolean(boolean_child) => {
|
||||
Some(make_boolean_member_child_arg(boolean_child))
|
||||
}
|
||||
@ -213,4 +213,4 @@ pub fn make_struct_build_fn(build_spec: &StructBuildSpec) -> TokenStream {
|
||||
#new_stream
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,14 @@
|
||||
use crate::spec::{AlternativeAction, AlternativeBuild, AlternativeBuildChild, AlternativeChild, AlternativeTest, BooleanChildToBuild, BuildSpec, EnumBuildSpec, EnumRule, EnumRuleChild, EnumRuleChildKind, EnumRuleNodeChild, LeafEnumBuildSpec, LeafEnumRule, LeafStructBuildSpec, LeafStructMember, LeafStructMemberKind, MemberChild, MemberChildToBuild, NameAndKind, NodeChildToBuild, PolymorphicBuildAlternative, PolymorphicBuildBuildSpec, PolymorphicEnumBuildSpec, PolymorphicEnumMember, PolymorphicEnumRule, PolymorphicTypeBuildSpec, ProductionBuildSpec, ProductionKind, ProductionStringFrom, SkipChild, StructBuildSpec, StructChildSpec, VecChild, VecChildToBuild, VecNodeChildToBuild};
|
||||
use crate::spec::{
|
||||
AlternativeAction, AlternativeBuild, AlternativeBuildChild, AlternativeChild, AlternativeTest,
|
||||
BooleanChildToBuild, BuildSpec, EnumBuildSpec, EnumRule, EnumRuleChild, EnumRuleChildKind,
|
||||
EnumRuleNodeChild, LeafEnumBuildSpec, LeafEnumRule, LeafStructBuildSpec, LeafStructMember,
|
||||
LeafStructMemberKind, MemberChild, MemberChildToBuild, NameAndKind, NodeChildToBuild,
|
||||
PolymorphicBuildAlternative, PolymorphicBuildBuildSpec, PolymorphicEnumBuildSpec,
|
||||
PolymorphicEnumMember, PolymorphicEnumRule, PolymorphicTypeBuildSpec, ProductionBuildSpec,
|
||||
ProductionKind, ProductionNodeKind, ProductionStringFrom, SkipChild, StructBuildSpec,
|
||||
StructChildSpec, VecChild, VecChildToBuild, VecNodeChildToBuild,
|
||||
};
|
||||
use crate::util::make_build_fn_name;
|
||||
use convert_case::{Case, Casing};
|
||||
use yaml_rust2::{Yaml, YamlLoader};
|
||||
|
||||
@ -18,7 +28,10 @@ fn unwrap_single_member_hash(hash: &Yaml) -> (String, &Yaml) {
|
||||
(key_as_string, member_value)
|
||||
}
|
||||
|
||||
fn deserialize_polymorphic_enum_build_spec(name: &str, build_spec: &Yaml) -> PolymorphicEnumBuildSpec {
|
||||
fn deserialize_polymorphic_enum_build_spec(
|
||||
name: &str,
|
||||
build_spec: &Yaml,
|
||||
) -> PolymorphicEnumBuildSpec {
|
||||
let return_type = build_spec["return_type"].as_str().unwrap();
|
||||
let rules = build_spec["rules"]
|
||||
.as_vec()
|
||||
@ -29,12 +42,12 @@ fn deserialize_polymorphic_enum_build_spec(name: &str, build_spec: &Yaml) -> Pol
|
||||
if props["wrap"].is_hash() {
|
||||
PolymorphicEnumRule::Wrap(NameAndKind::new(
|
||||
&rule_name,
|
||||
props["wrap"]["enum_variant"].as_str().unwrap()
|
||||
props["wrap"]["enum_variant"].as_str().unwrap(),
|
||||
))
|
||||
} else if props["return_build"].is_hash() {
|
||||
PolymorphicEnumRule::ReturnBuild(NameAndKind::new(
|
||||
&rule_name,
|
||||
props["return_build"]["kind"].as_str().unwrap()
|
||||
props["return_build"]["kind"].as_str().unwrap(),
|
||||
))
|
||||
} else {
|
||||
panic!()
|
||||
@ -76,7 +89,7 @@ fn deserialize_polymorphic_action(action_yaml: &Yaml) -> AlternativeAction {
|
||||
|
||||
fn deserialize_polymorphic_build_build_spec(
|
||||
name: &str,
|
||||
polymorphic_build_yaml: &Yaml
|
||||
polymorphic_build_yaml: &Yaml,
|
||||
) -> PolymorphicBuildBuildSpec {
|
||||
let return_type = polymorphic_build_yaml["return_type"].as_str().unwrap();
|
||||
let alternatives = polymorphic_build_yaml["alternatives"]
|
||||
@ -84,11 +97,13 @@ fn deserialize_polymorphic_build_build_spec(
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|alternative_yaml| {
|
||||
let number_of_pairs = alternative_yaml["test"]["number_of_pairs"].as_i64().unwrap();
|
||||
let number_of_pairs = alternative_yaml["test"]["number_of_pairs"]
|
||||
.as_i64()
|
||||
.unwrap();
|
||||
let action = deserialize_polymorphic_action(&alternative_yaml["action"]);
|
||||
PolymorphicBuildAlternative::new(
|
||||
AlternativeTest::NumberOfPairs(number_of_pairs),
|
||||
action
|
||||
action,
|
||||
)
|
||||
})
|
||||
.map(Box::new)
|
||||
@ -119,10 +134,11 @@ fn deserialize_polymorphic_spec(name: &str, spec_props: &Yaml) -> PolymorphicTyp
|
||||
}
|
||||
|
||||
fn deserialize_production_spec(rule: &str, production_yaml: &Yaml) -> ProductionBuildSpec {
|
||||
let kind = if production_yaml["kind"].is_hash() {
|
||||
let node = production_yaml["kind"]["node"].as_str().unwrap();
|
||||
ProductionKind::Node(node.to_string())
|
||||
} else {
|
||||
let kind = if production_yaml["node"].is_hash() {
|
||||
let kind = production_yaml["node"]["kind"].as_str().unwrap();
|
||||
let with = production_yaml["node"]["with"].as_str().unwrap();
|
||||
ProductionKind::Node(ProductionNodeKind::new(kind, with))
|
||||
} else {
|
||||
match production_yaml["kind"].as_str().unwrap() {
|
||||
"int" => ProductionKind::Int,
|
||||
"long" => ProductionKind::Long,
|
||||
@ -249,8 +265,18 @@ fn deserialize_member_node_to_build(
|
||||
})
|
||||
.map(ToString::to_string);
|
||||
|
||||
let kind = build_props["kind"]
|
||||
.as_str()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_else(|| make_build_fn_name(rule));
|
||||
|
||||
let with = build_props["with"]
|
||||
.as_str()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_else(|| make_build_fn_name(rule));
|
||||
|
||||
Box::new(MemberChildToBuild::Node(NodeChildToBuild::new(
|
||||
rule, or_else, optional,
|
||||
&kind, &with, or_else, optional,
|
||||
)))
|
||||
}
|
||||
|
||||
@ -276,8 +302,13 @@ fn deserialize_member_child_to_build(
|
||||
}
|
||||
} else {
|
||||
let optional = get_as_bool(&props["optional"]);
|
||||
let with = props["with"]
|
||||
.as_str()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_else(|| make_build_fn_name(rule));
|
||||
|
||||
Box::new(MemberChildToBuild::Node(NodeChildToBuild::new(
|
||||
rule, None, optional,
|
||||
rule, &with, None, optional,
|
||||
)))
|
||||
}
|
||||
}
|
||||
@ -356,6 +387,7 @@ fn deserialize_struct_string_child(child: &Yaml) -> Box<StructChildSpec> {
|
||||
&child_name_pascal,
|
||||
Box::new(MemberChildToBuild::Node(NodeChildToBuild::new(
|
||||
&child_name_pascal,
|
||||
&make_build_fn_name(&child_name_pascal),
|
||||
None,
|
||||
false,
|
||||
))),
|
||||
@ -409,7 +441,7 @@ fn deserialize_build_spec(build_spec_name: &str, build_spec: &Yaml) -> BuildSpec
|
||||
BuildSpec::PolymorphicEnum(deserialize_polymorphic_enum_build_spec(
|
||||
build_spec_name,
|
||||
&build_spec["polymorphic_enum"],
|
||||
))
|
||||
))
|
||||
} else {
|
||||
panic!(
|
||||
"Expected a node spec for either a struct, leaf_struct, enum, leaf_enum node type, production, polymorphic type, or polymorphic build type."
|
||||
|
||||
@ -1,26 +1,19 @@
|
||||
mod build_fn;
|
||||
pub mod deserialize;
|
||||
mod enum_build_fn;
|
||||
mod leaf_enum_build_fn;
|
||||
mod leaf_struct_build_fn;
|
||||
mod polymorphic_build_build_fn;
|
||||
mod polymorphic_build_fn;
|
||||
mod polymorphic_enum_build_fn;
|
||||
mod pretty_print;
|
||||
mod production_build_fn;
|
||||
mod spec;
|
||||
mod struct_build_fn;
|
||||
mod type_gen;
|
||||
mod util;
|
||||
|
||||
use crate::enum_build_fn::make_enum_build_fn;
|
||||
use crate::leaf_enum_build_fn::make_leaf_enum_build_fn;
|
||||
use crate::leaf_struct_build_fn::make_leaf_struct_build_fn;
|
||||
use crate::polymorphic_build_build_fn::make_polymorphic_build_build_fn;
|
||||
use crate::polymorphic_build_fn::make_polymorphic_build_fn;
|
||||
use crate::polymorphic_enum_build_fn::make_polymorphic_enum_build_fn;
|
||||
use crate::build_fn::enum_build_fn::make_enum_build_fn;
|
||||
use crate::build_fn::leaf_enum_build_fn::make_leaf_enum_build_fn;
|
||||
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::production_build_fn::make_production_build_fn;
|
||||
use crate::struct_build_fn::make_struct_build_fn;
|
||||
use crate::type_gen::make_type;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
@ -168,7 +161,7 @@ fn generate_pretty_print_file(build_specs: &[BuildSpec]) -> AstGeneratedFile {
|
||||
stream
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
||||
let combined = quote! {
|
||||
use crate::ast::node::*;
|
||||
#(#impls)*
|
||||
|
||||
@ -293,23 +293,29 @@ pub enum MemberChildToBuild {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NodeChildToBuild {
|
||||
build: String,
|
||||
kind: String,
|
||||
with: String,
|
||||
or_else: Option<String>,
|
||||
optional: bool,
|
||||
}
|
||||
|
||||
impl NodeChildToBuild {
|
||||
pub fn new(build: &str, or_else: Option<String>, optional: bool) -> Self {
|
||||
pub fn new(kind: &str, with: &str, or_else: Option<String>, optional: bool) -> Self {
|
||||
Self {
|
||||
build: build.to_string(),
|
||||
kind: kind.to_string(),
|
||||
with: with.to_string(),
|
||||
or_else,
|
||||
optional,
|
||||
}
|
||||
}
|
||||
|
||||
/// The type to build, in Pascal case.
|
||||
pub fn build(&self) -> &str {
|
||||
&self.build
|
||||
pub fn kind(&self) -> &str {
|
||||
&self.kind
|
||||
}
|
||||
|
||||
pub fn with(&self) -> &str {
|
||||
&self.with
|
||||
}
|
||||
|
||||
/// The default fn to call when unwrapping the child (before passing as arg to new).
|
||||
@ -418,7 +424,29 @@ pub enum ProductionKind {
|
||||
Double,
|
||||
String(ProductionStringFrom),
|
||||
Boolean,
|
||||
Node(String),
|
||||
Node(ProductionNodeKind),
|
||||
}
|
||||
|
||||
pub struct ProductionNodeKind {
|
||||
kind: String,
|
||||
with: String,
|
||||
}
|
||||
|
||||
impl ProductionNodeKind {
|
||||
pub fn new(kind: &str, with: &str) -> Self {
|
||||
Self {
|
||||
kind: kind.to_string(),
|
||||
with: with.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> &str {
|
||||
&self.kind
|
||||
}
|
||||
|
||||
pub fn with(&self) -> &str {
|
||||
&self.with
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ProductionStringFrom {
|
||||
@ -232,7 +232,7 @@ fn handle_node_child(
|
||||
) {
|
||||
let child_ident = format_ident!("{}", name);
|
||||
let child_ident_mut = format_ident!("{}_mut", name);
|
||||
let child_type_ident = format_ident!("{}", node_child.build());
|
||||
let child_type_ident = format_ident!("{}", node_child.kind());
|
||||
|
||||
member_names.push(child_ident.clone());
|
||||
|
||||
@ -48,7 +48,7 @@ pub mod build {
|
||||
use pest::iterators::Pairs;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/src/ast/build.rs"));
|
||||
|
||||
|
||||
pub fn build_ast(parsed_pairs: &mut Pairs<Rule>) -> Box<CompilationUnit> {
|
||||
let compilation_unit_pair = parsed_pairs.next().unwrap();
|
||||
Box::new(build_compilation_unit(compilation_unit_pair))
|
||||
@ -138,6 +138,6 @@ pub mod pretty_print {
|
||||
pub trait PrettyPrint {
|
||||
fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()>;
|
||||
}
|
||||
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/src/ast/pretty_print.rs"));
|
||||
}
|
||||
|
||||
@ -50,6 +50,6 @@ fn main() {
|
||||
// eprintln!("{}", e)
|
||||
// }
|
||||
// }
|
||||
_ => todo!()
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// use crate::name_analysis::symbol::{FunctionSymbol, ParameterSymbol};
|
||||
// use crate::name_analysis::symbol_table::{SymbolInsertError, SymbolTable};
|
||||
//
|
||||
//
|
||||
// pub fn add_std_core_symbols(symbol_table: &mut SymbolTable) -> Result<(), SymbolInsertError> {
|
||||
// symbol_table.insert_function_symbol(
|
||||
// FunctionSymbol::new("std::core::println", "println", true, true, None)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user