diff options
Diffstat (limited to '')
| -rw-r--r-- | pest_consume_macros/src/lib.rs | 2 | ||||
| -rw-r--r-- | pest_consume_macros/src/make_parser.rs | 8 | ||||
| -rw-r--r-- | pest_consume_macros/src/match_inputs.rs | 27 | 
3 files changed, 18 insertions, 19 deletions
diff --git a/pest_consume_macros/src/lib.rs b/pest_consume_macros/src/lib.rs index db21f37..7f9f464 100644 --- a/pest_consume_macros/src/lib.rs +++ b/pest_consume_macros/src/lib.rs @@ -11,7 +11,7 @@ mod match_inputs;  use proc_macro::TokenStream;  #[proc_macro_attribute] -pub fn make_parser(attrs: TokenStream, input: TokenStream) -> TokenStream { +pub fn parser(attrs: TokenStream, input: TokenStream) -> TokenStream {      TokenStream::from(match make_parser::make_parser(attrs, input) {          Ok(tokens) => tokens,          Err(err) => err.to_compile_error(), diff --git a/pest_consume_macros/src/make_parser.rs b/pest_consume_macros/src/make_parser.rs index e8d861f..2ed3271 100644 --- a/pest_consume_macros/src/make_parser.rs +++ b/pest_consume_macros/src/make_parser.rs @@ -64,7 +64,7 @@ struct ParsedFn<'a> {      function: &'a mut ImplItemMethod,      // Name of the function.      fn_name: Ident, -    // Name of the first argument of the function, which should be of type `ParseInput`. +    // Name of the first argument of the function, which should be of type `Node`.      input_arg: Ident,      // List of aliases pointing to this function      alias_srcs: Vec<AliasSrc>, @@ -255,14 +255,14 @@ fn apply_special_attrs(f: &mut ParsedFn, rule_enum: &Path) -> Result<()> {              .map(|src| &src.ident)              .filter(|i| i != &fn_name);          let block = &function.block; -        let self_ty = quote!(<Self as ::pest_consume::PestConsumer>); +        let self_ty = quote!(<Self as ::pest_consume::Parser>);          function.block = parse_quote!({              let mut #input_arg = #input_arg;              // While the current rule allows shortcutting, and there is a single child, and the              // child can still be parsed by the current function, then skip to that child.              while #self_ty::allows_shortcut(#input_arg.as_rule()) {                  if let Some(child) = #input_arg.single_child() { -                    if child.as_rule_alias::<Self>() == #self_ty::AliasedRule::#fn_name { +                    if child.as_aliased_rule::<Self>() == #self_ty::AliasedRule::#fn_name {                          #input_arg = child;                          continue;                      } @@ -375,7 +375,7 @@ pub fn make_parser(              #(#aliased_rule_variants,)*          } -        impl #impl_generics ::pest_consume::PestConsumer for #ty #where_clause { +        impl #impl_generics ::pest_consume::Parser for #ty #where_clause {              type Rule = #rule_enum;              type AliasedRule = AliasedRule;              type Parser = #parser; diff --git a/pest_consume_macros/src/match_inputs.rs b/pest_consume_macros/src/match_inputs.rs index 34bfd38..773f806 100644 --- a/pest_consume_macros/src/match_inputs.rs +++ b/pest_consume_macros/src/match_inputs.rs @@ -23,7 +23,7 @@ enum ChildrenBranchPatternItem {  #[derive(Debug, Clone)]  struct ParseChildrenInput { -    consumer: Type, +    parser: Type,      input_expr: Expr,      branches: Punctuated<ChildrenBranch, Token![,]>,  } @@ -66,12 +66,12 @@ impl Parse for ChildrenBranchPatternItem {  impl Parse for ParseChildrenInput {      fn parse(input: ParseStream) -> Result<Self> { -        let consumer = if input.peek(token::Lt) { +        let parser = if input.peek(token::Lt) {              let _: token::Lt = input.parse()?; -            let consumer = input.parse()?; +            let parser = input.parse()?;              let _: token::Gt = input.parse()?;              let _: Token![;] = input.parse()?; -            consumer +            parser          } else {              parse_quote!(Self)          }; @@ -80,7 +80,7 @@ impl Parse for ParseChildrenInput {          let branches = Punctuated::parse_terminated(input)?;          Ok(ParseChildrenInput { -            consumer, +            parser,              input_expr,              branches,          }) @@ -90,13 +90,12 @@ impl Parse for ParseChildrenInput {  fn make_parser_branch(      branch: &ChildrenBranch,      i_inputs: &Ident, -    consumer: &Type, +    parser: &Type,  ) -> Result<TokenStream> {      use ChildrenBranchPatternItem::{Multiple, Single};      let body = &branch.body; -    let aliased_rule = -        quote!(<#consumer as ::pest_consume::PestConsumer>::AliasedRule); +    let aliased_rule = quote!(<#parser as ::pest_consume::Parser>::AliasedRule);      // Convert the input pattern into a pattern-match on the Rules of the children. This uses      // slice_patterns. @@ -156,7 +155,7 @@ fn make_parser_branch(      let mut parses = Vec::new();      for (rule_name, binder) in singles_before_multiple.into_iter() {          parses.push(quote!( -            let #binder = #consumer::#rule_name( +            let #binder = #parser::#rule_name(                  #i_inputs.next().unwrap()              )?;          )) @@ -165,7 +164,7 @@ fn make_parser_branch(      // 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 = #consumer::#rule_name( +            let #binder = #parser::#rule_name(                  #i_inputs.next_back().unwrap()              )?;          )) @@ -173,7 +172,7 @@ fn make_parser_branch(      if let Some((rule_name, binder)) = multiple {          parses.push(quote!(              let #binder = #i_inputs -                .map(|i| #consumer::#rule_name(i)) +                .map(|i| #parser::#rule_name(i))                  .collect::<Result<Vec<_>, _>>()?                  .into_iter();          )) @@ -196,17 +195,17 @@ pub fn match_inputs(      let i_inputs = Ident::new("___inputs", Span::call_site());      let input_expr = &input.input_expr; -    let consumer = &input.consumer; +    let parser = &input.parser;      let branches = input          .branches          .iter() -        .map(|br| make_parser_branch(br, &i_inputs, consumer)) +        .map(|br| make_parser_branch(br, &i_inputs, parser))          .collect::<Result<Vec<_>>>()?;      Ok(quote!({          #[allow(unused_mut)]          let mut #i_inputs = #input_expr; -        let #i_input_rules = #i_inputs.aliased_rules::<#consumer>(); +        let #i_input_rules = #i_inputs.aliased_rules::<#parser>();          #[allow(unreachable_code)]          match #i_input_rules.as_slice() {  | 
