From 9f41dc5a4680cba3697c64da28855c8d4f437191 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 10 Sep 2019 14:51:37 +0200 Subject: Implement parsing in PestConsumer --- pest_consume_macros/src/make_parser.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'pest_consume_macros/src') diff --git a/pest_consume_macros/src/make_parser.rs b/pest_consume_macros/src/make_parser.rs index 9de2f6f..0638c19 100644 --- a/pest_consume_macros/src/make_parser.rs +++ b/pest_consume_macros/src/make_parser.rs @@ -13,6 +13,11 @@ mod kw { syn::custom_keyword!(shortcut); } +struct MakeParserAttrs { + parser: Ident, + rule_enum: Ident, +} + struct AliasArgs { target: Ident, is_shortcut: bool, @@ -39,6 +44,15 @@ struct ParsedFn<'a> { alias_srcs: Vec, } +impl Parse for MakeParserAttrs { + fn parse(input: ParseStream) -> Result { + let parser = input.parse()?; + let _: Token![,] = input.parse()?; + let rule_enum = input.parse()?; + Ok(MakeParserAttrs { parser, rule_enum }) + } +} + impl Parse for AliasArgs { fn parse(input: ParseStream) -> Result { let target = input.parse()?; @@ -244,7 +258,9 @@ pub fn make_parser( attrs: proc_macro::TokenStream, input: proc_macro::TokenStream, ) -> Result { - let rule_enum: Ident = syn::parse(attrs)?; + let attrs: MakeParserAttrs = syn::parse(attrs)?; + let parser = &attrs.parser; + let rule_enum = &attrs.rule_enum; let mut imp: ItemImpl = syn::parse(input)?; let mut alias_map = collect_aliases(&mut imp)?; @@ -322,6 +338,7 @@ pub fn make_parser( Ok(quote!( impl #impl_generics pest_consume::PestConsumer for #ty #where_clause { type Rule = #rule_enum; + type Parser = #parser; fn rule_alias(rule: Self::Rule) -> String { match rule { #(#rule_alias_branches)* -- cgit v1.2.3