From a86088505de38c9b3d4c4bb8feecab28055514d8 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 10 Sep 2019 13:57:43 +0200 Subject: Rename parse_children to match_inputs --- dhall_syntax/src/parser.rs | 74 +++++------ pest_consume/src/lib.rs | 2 +- pest_consume_macros/src/lib.rs | 6 +- pest_consume_macros/src/match_inputs.rs | 206 ++++++++++++++++++++++++++++++ pest_consume_macros/src/parse_children.rs | 206 ------------------------------ 5 files changed, 247 insertions(+), 247 deletions(-) create mode 100644 pest_consume_macros/src/match_inputs.rs delete mode 100644 pest_consume_macros/src/parse_children.rs diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index d86e35a..761795a 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -6,7 +6,7 @@ use pest::Parser; use std::rc::Rc; use dhall_generated_parser::{DhallParser, Rule}; -use pest_consume::{make_parser, parse_children}; +use pest_consume::{make_parser, match_inputs}; use crate::map::{DupTreeMap, DupTreeSet}; use crate::ExprF::*; @@ -168,7 +168,7 @@ impl Parsers { fn double_quote_literal( input: ParseInput, ) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [double_quote_chunk(chunks)..] => { chunks.collect() } @@ -178,7 +178,7 @@ impl Parsers { fn double_quote_chunk( input: ParseInput, ) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [expression(e)] => { InterpolatedTextContents::Expr(e) }, @@ -265,7 +265,7 @@ impl Parsers { fn single_quote_literal( input: ParseInput, ) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [single_quote_continue(lines)] => { let newline: ParsedText = "\n".to_string().into(); @@ -308,7 +308,7 @@ impl Parsers { fn single_quote_continue( input: ParseInput, ) -> ParseResult>>> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [expression(e), single_quote_continue(lines)] => { let c = InterpolatedTextContents::Expr(e); let mut lines = lines; @@ -393,7 +393,7 @@ impl Parsers { #[alias(expression, shortcut = true)] fn identifier(input: ParseInput) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [variable(v)] => { spanned(input, Var(v)) }, @@ -402,7 +402,7 @@ impl Parsers { } fn variable(input: ParseInput) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [label(l), natural_literal(idx)] => { V(l, idx) }, @@ -444,7 +444,7 @@ impl Parsers { .collect()) } fn path(input: ParseInput) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [path_component(components)..] => { components.collect() } @@ -455,7 +455,7 @@ impl Parsers { fn local( input: ParseInput, ) -> ParseResult>> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [local_path((prefix, p))] => ImportLocation::Local(prefix, p), )) } @@ -464,19 +464,19 @@ impl Parsers { fn parent_path( input: ParseInput, ) -> ParseResult<(FilePrefix, Vec)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [path(p)] => (FilePrefix::Parent, p) )) } #[alias(local_path)] fn here_path(input: ParseInput) -> ParseResult<(FilePrefix, Vec)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [path(p)] => (FilePrefix::Here, p) )) } #[alias(local_path)] fn home_path(input: ParseInput) -> ParseResult<(FilePrefix, Vec)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [path(p)] => (FilePrefix::Home, p) )) } @@ -484,7 +484,7 @@ impl Parsers { fn absolute_path( input: ParseInput, ) -> ParseResult<(FilePrefix, Vec)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [path(p)] => (FilePrefix::Absolute, p) )) } @@ -498,7 +498,7 @@ impl Parsers { } fn http_raw(input: ParseInput) -> ParseResult>> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [scheme(sch), authority(auth), path(p)] => URL { scheme: sch, authority: auth, @@ -528,7 +528,7 @@ impl Parsers { fn http( input: ParseInput, ) -> ParseResult>> { - Ok(ImportLocation::Remote(parse_children!(input.children(); + Ok(ImportLocation::Remote(match_inputs!(input.children(); [http_raw(url)] => url, [http_raw(url), expression(e)] => URL { headers: Some(e), ..url }, ))) @@ -538,7 +538,7 @@ impl Parsers { fn env( input: ParseInput, ) -> ParseResult>> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [environment_variable(v)] => ImportLocation::Env(v), )) } @@ -548,7 +548,7 @@ impl Parsers { } #[alias(environment_variable)] fn posix_environment_variable(input: ParseInput) -> ParseResult { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [posix_environment_variable_character(chars)..] => { chars.collect() }, @@ -593,7 +593,7 @@ impl Parsers { ) -> ParseResult>> { use crate::Import; let mode = ImportMode::Code; - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [import_type(location)] => Import { mode, location, hash: None }, [import_type(location), hash(h)] => Import { mode, location, hash: Some(h) }, )) @@ -611,7 +611,7 @@ impl Parsers { #[alias(expression)] fn import(input: ParseInput) -> ParseResult> { use crate::Import; - let import = parse_children!(input.children(); + let import = match_inputs!(input.children(); [import_hashed(imp)] => { Import { mode: ImportMode::Code, ..imp } }, @@ -646,13 +646,13 @@ impl Parsers { #[alias(expression)] fn empty_list_literal(input: ParseInput) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [expression(e)] => spanned(input, EmptyListLit(e)), )) } fn expression(input: ParseInput) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [lambda(()), label(l), expression(typ), arrow(()), expression(body)] => { spanned(input, Lam(l, typ, body)) @@ -699,7 +699,7 @@ impl Parsers { fn let_binding( input: ParseInput, ) -> ParseResult<(Label, Option>, Expr, Span)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [label(name), expression(annot), expression(expr)] => (name, Some(annot), expr, input_to_span(input)), [label(name), expression(expr)] => @@ -749,7 +749,7 @@ impl Parsers { fn application_expression( input: ParseInput, ) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [expression(e)] => e, [expression(first), expression(rest)..] => { rest.fold( @@ -770,7 +770,7 @@ impl Parsers { fn first_application_expression( input: ParseInput, ) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [Some_(()), expression(e)] => { spanned(input, SomeLit(e)) }, @@ -788,7 +788,7 @@ impl Parsers { fn selector_expression( input: ParseInput, ) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [expression(e)] => e, [expression(first), selector(rest)..] => { rest.fold( @@ -811,7 +811,7 @@ impl Parsers { fn selector( input: ParseInput, ) -> ParseResult<(Either>, Span)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [label(l)] => (Either::Left(l), input_to_span(input)), [labels(ls)] => (Either::Right(ls), input_to_span(input)), // [expression(_e)] => unimplemented!("selection by expression"), // TODO @@ -819,7 +819,7 @@ impl Parsers { } fn labels(input: ParseInput) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [label(ls)..] => ls.collect(), )) } @@ -828,7 +828,7 @@ impl Parsers { fn primitive_expression( input: ParseInput, ) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [double_literal(n)] => spanned(input, DoubleLit(n)), [natural_literal(n)] => spanned(input, NaturalLit(n)), [integer_literal(n)] => spanned(input, IntegerLit(n)), @@ -854,7 +854,7 @@ impl Parsers { fn non_empty_record_type_or_literal( input: ParseInput, ) -> ParseResult> { - let e = parse_children!(input.children(); + let e = match_inputs!(input.children(); [label(first_label), non_empty_record_type(rest)] => { let (first_expr, mut map) = rest; map.insert(first_label, first_expr); @@ -872,7 +872,7 @@ impl Parsers { fn non_empty_record_type( input: ParseInput, ) -> ParseResult<(Expr, DupTreeMap>)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [expression(expr), record_type_entry(entries)..] => { (expr, entries.collect()) } @@ -882,7 +882,7 @@ impl Parsers { fn record_type_entry( input: ParseInput, ) -> ParseResult<(Label, Expr)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [label(name), expression(expr)] => (name, expr) )) } @@ -890,7 +890,7 @@ impl Parsers { fn non_empty_record_literal( input: ParseInput, ) -> ParseResult<(Expr, DupTreeMap>)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [expression(expr), record_literal_entry(entries)..] => { (expr, entries.collect()) } @@ -900,14 +900,14 @@ impl Parsers { fn record_literal_entry( input: ParseInput, ) -> ParseResult<(Label, Expr)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [label(name), expression(expr)] => (name, expr) )) } #[alias(expression)] fn union_type(input: ParseInput) -> ParseResult> { - let map = parse_children!(input.children(); + let map = match_inputs!(input.children(); [empty_union_type(_)] => Default::default(), [union_type_entry(entries)..] => entries.collect(), ); @@ -921,7 +921,7 @@ impl Parsers { fn union_type_entry( input: ParseInput, ) -> ParseResult<(Label, Option>)> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [label(name), expression(expr)] => (name, Some(expr)), [label(name)] => (name, None), )) @@ -931,7 +931,7 @@ impl Parsers { fn non_empty_list_literal( input: ParseInput, ) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [expression(items)..] => spanned( input, NEListLit(items.collect()) @@ -940,7 +940,7 @@ impl Parsers { } fn final_expression(input: ParseInput) -> ParseResult> { - Ok(parse_children!(input.children(); + Ok(match_inputs!(input.children(); [expression(e), EOI(_)] => e )) } diff --git a/pest_consume/src/lib.rs b/pest_consume/src/lib.rs index 70aee56..7e2c1ca 100644 --- a/pest_consume/src/lib.rs +++ b/pest_consume/src/lib.rs @@ -2,7 +2,7 @@ use pest::error::{Error, ErrorVariant}; use pest::iterators::Pair; use pest::Span; -pub use pest_consume_macros::{make_parser, parse_children}; +pub use pest_consume_macros::{make_parser, match_inputs}; /// Carries a pest Pair alongside custom user data. #[derive(Debug)] diff --git a/pest_consume_macros/src/lib.rs b/pest_consume_macros/src/lib.rs index dd437f6..b5368ec 100644 --- a/pest_consume_macros/src/lib.rs +++ b/pest_consume_macros/src/lib.rs @@ -7,7 +7,7 @@ extern crate proc_macro; mod make_parser; -mod parse_children; +mod match_inputs; use proc_macro::TokenStream; @@ -20,8 +20,8 @@ pub fn make_parser(attrs: TokenStream, input: TokenStream) -> TokenStream { } #[proc_macro] -pub fn parse_children(input: TokenStream) -> TokenStream { - TokenStream::from(match parse_children::parse_children(input) { +pub fn match_inputs(input: TokenStream) -> TokenStream { + TokenStream::from(match match_inputs::match_inputs(input) { Ok(tokens) => tokens, Err(err) => err.to_compile_error(), }) diff --git a/pest_consume_macros/src/match_inputs.rs b/pest_consume_macros/src/match_inputs.rs new file mode 100644 index 0000000..3a325a6 --- /dev/null +++ b/pest_consume_macros/src/match_inputs.rs @@ -0,0 +1,206 @@ +use proc_macro2::{Span, TokenStream}; +use quote::quote; +use syn::parse::{Parse, ParseStream, Result}; +use syn::punctuated::Punctuated; +use syn::spanned::Spanned; +use syn::{bracketed, parenthesized, token, Error, Expr, Ident, Pat, Token}; + +#[derive(Debug, Clone)] +struct ChildrenBranch { + pattern_span: Span, + pattern: Punctuated, + body: Expr, +} + +#[derive(Debug, Clone)] +enum ChildrenBranchPatternItem { + Single { rule_name: Ident, binder: Pat }, + Multiple { rule_name: Ident, binder: Ident }, +} + +#[derive(Debug, Clone)] +struct ParseChildrenInput { + input_expr: Expr, + branches: Punctuated, +} + +impl Parse for ChildrenBranch { + fn parse(input: ParseStream) -> Result { + let contents; + let _: token::Bracket = bracketed!(contents in input); + let pattern_unparsed: TokenStream = contents.fork().parse()?; + let pattern_span = pattern_unparsed.span(); + let pattern = Punctuated::parse_terminated(&contents)?; + let _: Token![=>] = input.parse()?; + let body = input.parse()?; + + Ok(ChildrenBranch { + pattern_span, + pattern, + body, + }) + } +} + +impl Parse for ChildrenBranchPatternItem { + fn parse(input: ParseStream) -> Result { + let contents; + let rule_name = input.parse()?; + parenthesized!(contents in input); + if input.peek(Token![..]) { + let binder = contents.parse()?; + let _: Token![..] = input.parse()?; + Ok(ChildrenBranchPatternItem::Multiple { rule_name, binder }) + } else if input.is_empty() || input.peek(Token![,]) { + let binder = contents.parse()?; + Ok(ChildrenBranchPatternItem::Single { rule_name, binder }) + } else { + Err(input.error("expected `..` or nothing")) + } + } +} + +impl Parse for ParseChildrenInput { + fn parse(input: ParseStream) -> Result { + let input_expr = input.parse()?; + let _: Token![;] = input.parse()?; + let branches = Punctuated::parse_terminated(input)?; + + Ok(ParseChildrenInput { + input_expr, + branches, + }) + } +} + +fn make_parser_branch( + branch: &ChildrenBranch, + i_inputs: &Ident, +) -> Result { + use ChildrenBranchPatternItem::{Multiple, Single}; + + let body = &branch.body; + + // Convert the input pattern into a pattern-match on the Rules of the children. This uses + // slice_patterns. + // A single pattern just checks that the rule matches; a variable-length pattern binds the + // subslice and checks, in the if-guard, that its elements all match the chosen Rule. + 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!(stringify!(#rule_name)), + Multiple { .. } => quote!(#i_variable_pattern @ ..), + }); + let match_filter = branch.pattern.iter().map(|item| match item { + Single { .. } => quote!(), + Multiple { rule_name, .. } => quote!( + { + // We can't use .all() directly in the pattern guard; see + // https://github.com/rust-lang/rust/issues/59803. + let all_match = |slice: &[_]| { + slice.iter().all(|r| + *r == stringify!(#rule_name) + ) + }; + all_match(#i_variable_pattern) + } && + ), + }); + + // Once we have found a branch that matches, we need to parse the children. + let mut singles_before_multiple = Vec::new(); + let mut multiple = None; + let mut singles_after_multiple = Vec::new(); + for item in &branch.pattern { + match item { + Single { + rule_name, binder, .. + } => { + if multiple.is_none() { + singles_before_multiple.push((rule_name, binder)) + } else { + singles_after_multiple.push((rule_name, binder)) + } + } + Multiple { + rule_name, binder, .. + } => { + if multiple.is_none() { + multiple = Some((rule_name, binder)) + } else { + return Err(Error::new( + branch.pattern_span.clone(), + "multiple variable-length patterns are not allowed", + )); + } + } + } + } + let mut parses = Vec::new(); + for (rule_name, binder) in singles_before_multiple.into_iter() { + parses.push(quote!( + let #binder = Self::#rule_name( + #i_inputs.next().unwrap() + )?; + )) + } + // Note the `rev()`: we are taking inputs from the end of the iterator in reverse order, so that + // only the unmatched inputs are left for the variable-length pattern, if any. + for (rule_name, binder) in singles_after_multiple.into_iter().rev() { + parses.push(quote!( + let #binder = Self::#rule_name( + #i_inputs.next_back().unwrap() + )?; + )) + } + if let Some((rule_name, binder)) = multiple { + parses.push(quote!( + let #binder = #i_inputs + .map(|i| Self::#rule_name(i)) + .collect::, _>>()? + .into_iter(); + )) + } + + Ok(quote!( + [#(#match_pat),*] if #(#match_filter)* true => { + #(#parses)* + #body + } + )) +} + +pub fn match_inputs( + input: proc_macro::TokenStream, +) -> Result { + let input: ParseChildrenInput = syn::parse(input)?; + + 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; + let branches = input + .branches + .iter() + .map(|br| make_parser_branch(br, &i_inputs)) + .collect::>>()?; + + Ok(quote!({ + #[allow(unused_mut)] + let mut #i_inputs = #input_expr; + + let #i_input_rules = #i_inputs.aliased_rules::(); + let #i_input_rules: Vec<&str> = #i_input_rules + .iter() + .map(String::as_str) + .collect(); + + #[allow(unreachable_code)] + match #i_input_rules.as_slice() { + #(#branches,)* + [..] => return Err(#i_inputs.error( + format!("Unexpected children: {:?}", #i_input_rules) + )), + } + })) +} diff --git a/pest_consume_macros/src/parse_children.rs b/pest_consume_macros/src/parse_children.rs deleted file mode 100644 index 8feef03..0000000 --- a/pest_consume_macros/src/parse_children.rs +++ /dev/null @@ -1,206 +0,0 @@ -use proc_macro2::{Span, TokenStream}; -use quote::quote; -use syn::parse::{Parse, ParseStream, Result}; -use syn::punctuated::Punctuated; -use syn::spanned::Spanned; -use syn::{bracketed, parenthesized, token, Error, Expr, Ident, Pat, Token}; - -#[derive(Debug, Clone)] -struct ChildrenBranch { - pattern_span: Span, - pattern: Punctuated, - body: Expr, -} - -#[derive(Debug, Clone)] -enum ChildrenBranchPatternItem { - Single { rule_name: Ident, binder: Pat }, - Multiple { rule_name: Ident, binder: Ident }, -} - -#[derive(Debug, Clone)] -struct ParseChildrenInput { - input_expr: Expr, - branches: Punctuated, -} - -impl Parse for ChildrenBranch { - fn parse(input: ParseStream) -> Result { - let contents; - let _: token::Bracket = bracketed!(contents in input); - let pattern_unparsed: TokenStream = contents.fork().parse()?; - let pattern_span = pattern_unparsed.span(); - let pattern = Punctuated::parse_terminated(&contents)?; - let _: Token![=>] = input.parse()?; - let body = input.parse()?; - - Ok(ChildrenBranch { - pattern_span, - pattern, - body, - }) - } -} - -impl Parse for ChildrenBranchPatternItem { - fn parse(input: ParseStream) -> Result { - let contents; - let rule_name = input.parse()?; - parenthesized!(contents in input); - if input.peek(Token![..]) { - let binder = contents.parse()?; - let _: Token![..] = input.parse()?; - Ok(ChildrenBranchPatternItem::Multiple { rule_name, binder }) - } else if input.is_empty() || input.peek(Token![,]) { - let binder = contents.parse()?; - Ok(ChildrenBranchPatternItem::Single { rule_name, binder }) - } else { - Err(input.error("expected `..` or nothing")) - } - } -} - -impl Parse for ParseChildrenInput { - fn parse(input: ParseStream) -> Result { - let input_expr = input.parse()?; - let _: Token![;] = input.parse()?; - let branches = Punctuated::parse_terminated(input)?; - - Ok(ParseChildrenInput { - input_expr, - branches, - }) - } -} - -fn make_parser_branch( - branch: &ChildrenBranch, - i_inputs: &Ident, -) -> Result { - use ChildrenBranchPatternItem::{Multiple, Single}; - - let body = &branch.body; - - // Convert the input pattern into a pattern-match on the Rules of the children. This uses - // slice_patterns. - // A single pattern just checks that the rule matches; a variable-length pattern binds the - // subslice and checks, in the if-guard, that its elements all match the chosen Rule. - 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!(stringify!(#rule_name)), - Multiple { .. } => quote!(#i_variable_pattern @ ..), - }); - let match_filter = branch.pattern.iter().map(|item| match item { - Single { .. } => quote!(), - Multiple { rule_name, .. } => quote!( - { - // We can't use .all() directly in the pattern guard; see - // https://github.com/rust-lang/rust/issues/59803. - let all_match = |slice: &[_]| { - slice.iter().all(|r| - *r == stringify!(#rule_name) - ) - }; - all_match(#i_variable_pattern) - } && - ), - }); - - // Once we have found a branch that matches, we need to parse the children. - let mut singles_before_multiple = Vec::new(); - let mut multiple = None; - let mut singles_after_multiple = Vec::new(); - for item in &branch.pattern { - match item { - Single { - rule_name, binder, .. - } => { - if multiple.is_none() { - singles_before_multiple.push((rule_name, binder)) - } else { - singles_after_multiple.push((rule_name, binder)) - } - } - Multiple { - rule_name, binder, .. - } => { - if multiple.is_none() { - multiple = Some((rule_name, binder)) - } else { - return Err(Error::new( - branch.pattern_span.clone(), - "multiple variable-length patterns are not allowed", - )); - } - } - } - } - let mut parses = Vec::new(); - for (rule_name, binder) in singles_before_multiple.into_iter() { - parses.push(quote!( - let #binder = Self::#rule_name( - #i_inputs.next().unwrap() - )?; - )) - } - // Note the `rev()`: we are taking inputs from the end of the iterator in reverse order, so that - // only the unmatched inputs are left for the variable-length pattern, if any. - for (rule_name, binder) in singles_after_multiple.into_iter().rev() { - parses.push(quote!( - let #binder = Self::#rule_name( - #i_inputs.next_back().unwrap() - )?; - )) - } - if let Some((rule_name, binder)) = multiple { - parses.push(quote!( - let #binder = #i_inputs - .map(|i| Self::#rule_name(i)) - .collect::, _>>()? - .into_iter(); - )) - } - - Ok(quote!( - [#(#match_pat),*] if #(#match_filter)* true => { - #(#parses)* - #body - } - )) -} - -pub fn parse_children( - input: proc_macro::TokenStream, -) -> Result { - let input: ParseChildrenInput = syn::parse(input)?; - - 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; - let branches = input - .branches - .iter() - .map(|br| make_parser_branch(br, &i_inputs)) - .collect::>>()?; - - Ok(quote!({ - #[allow(unused_mut)] - let mut #i_inputs = #input_expr; - - let #i_input_rules = #i_inputs.aliased_rules::(); - let #i_input_rules: Vec<&str> = #i_input_rules - .iter() - .map(String::as_str) - .collect(); - - #[allow(unreachable_code)] - match #i_input_rules.as_slice() { - #(#branches,)* - [..] => return Err(#i_inputs.error( - format!("Unexpected children: {:?}", #i_input_rules) - )), - } - })) -} -- cgit v1.2.3