summaryrefslogtreecommitdiff
path: root/pest_consume_macros
diff options
context:
space:
mode:
authorNadrieril2019-09-10 14:51:37 +0200
committerNadrieril2019-09-10 14:51:37 +0200
commit9f41dc5a4680cba3697c64da28855c8d4f437191 (patch)
treee190bdf29be0a6cf094b8789d0567a12c43ba5b2 /pest_consume_macros
parent97f163475294a12f485a6c398df648ad0eeeca8c (diff)
Implement parsing in PestConsumer
Diffstat (limited to '')
-rw-r--r--pest_consume_macros/src/make_parser.rs19
1 files changed, 18 insertions, 1 deletions
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<AliasSrc>,
}
+impl Parse for MakeParserAttrs {
+ fn parse(input: ParseStream) -> Result<Self> {
+ 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<Self> {
let target = input.parse()?;
@@ -244,7 +258,9 @@ pub fn make_parser(
attrs: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> Result<proc_macro2::TokenStream> {
- 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)*