From d3fcc3a5ef93d4e7f539954f1c77af58685c65b9 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 5 Sep 2019 17:40:29 +0200 Subject: Implement rule aliasing and simplify parser code --- dhall_proc_macros/src/parse_children.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'dhall_proc_macros/src/parse_children.rs') diff --git a/dhall_proc_macros/src/parse_children.rs b/dhall_proc_macros/src/parse_children.rs index b1d43fc..a35c03f 100644 --- a/dhall_proc_macros/src/parse_children.rs +++ b/dhall_proc_macros/src/parse_children.rs @@ -88,9 +88,7 @@ fn make_parser_branch( let i_variable_pattern = Ident::new("___variable_pattern", Span::call_site()); let match_pat = branch.pattern.iter().map(|item| match item { - Single { rule_name, .. } => { - quote!(<::RuleEnum>::#rule_name) - } + Single { rule_name, .. } => quote!(stringify!(#rule_name)), Multiple { .. } => quote!(#i_variable_pattern @ ..), }); let match_filter = branch.pattern.iter().map(|item| match item { @@ -101,7 +99,7 @@ fn make_parser_branch( // https://github.com/rust-lang/rust/issues/59803. let all_match = |slice: &[_]| { slice.iter().all(|r| - r == &<::RuleEnum>::#rule_name + *r == stringify!(#rule_name) ) }; all_match(#i_variable_pattern) @@ -192,6 +190,11 @@ pub fn parse_children( .clone() .into_inner() .map(|p| p.as_rule()) + .map(::rule_alias) + .collect(); + let #i_children_rules: Vec<&str> = #i_children_rules + .iter() + .map(String::as_str) .collect(); #[allow(unused_mut)] -- cgit v1.2.3