diff options
author | Nadrieril | 2019-09-10 13:55:35 +0200 |
---|---|---|
committer | Nadrieril | 2019-09-10 13:56:07 +0200 |
commit | fc8fce6facee9bd50958e78f3b177e16ed065c19 (patch) | |
tree | 7a2dbbb7a7e550c92ef0cfdc289e2856132529bb /pest_consume_macros | |
parent | accaf45aa77099654f94319ed1fb12855dd568b4 (diff) |
Generalize parse_children and change its invocation
Diffstat (limited to '')
-rw-r--r-- | pest_consume_macros/src/parse_children.rs | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/pest_consume_macros/src/parse_children.rs b/pest_consume_macros/src/parse_children.rs index d6474a7..8feef03 100644 --- a/pest_consume_macros/src/parse_children.rs +++ b/pest_consume_macros/src/parse_children.rs @@ -175,7 +175,7 @@ pub fn parse_children( ) -> Result<proc_macro2::TokenStream> { let input: ParseChildrenInput = syn::parse(input)?; - let i_children_rules = Ident::new("___children_rules", Span::call_site()); + let i_input_rules = Ident::new("___input_rules", Span::call_site()); let i_inputs = Ident::new("___inputs", Span::call_site()); let input_expr = &input.input_expr; @@ -186,29 +186,20 @@ pub fn parse_children( .collect::<Result<Vec<_>>>()?; Ok(quote!({ - let #i_children_rules: Vec<_> = #input_expr.as_pair() - .clone() - .into_inner() - .map(|p| p.as_rule()) - .map(<Self as pest_consume::PestConsumer>::rule_alias) - .collect(); - let #i_children_rules: Vec<&str> = #i_children_rules + #[allow(unused_mut)] + let mut #i_inputs = #input_expr; + + let #i_input_rules = #i_inputs.aliased_rules::<Self>(); + let #i_input_rules: Vec<&str> = #i_input_rules .iter() .map(String::as_str) .collect(); - #[allow(unused_mut)] - let mut #i_inputs = #input_expr - .as_pair() - .clone() - .into_inner() - .map(|p| #input_expr.with_pair(p)); - #[allow(unreachable_code)] - match #i_children_rules.as_slice() { + match #i_input_rules.as_slice() { #(#branches,)* - [..] => return Err(#input_expr.error( - format!("Unexpected children: {:?}", #i_children_rules) + [..] => return Err(#i_inputs.error( + format!("Unexpected children: {:?}", #i_input_rules) )), } })) |