summaryrefslogtreecommitdiff
path: root/pest_consume_macros/src
diff options
context:
space:
mode:
authorNadrieril2019-09-17 19:59:22 +0200
committerNadrieril2019-09-17 20:01:52 +0200
commitf8341503c778db92f46fa9f6f368a2013e4c0c1a (patch)
treefad5157c68ff56cc215bff1e9b6b9be1b6acc0a4 /pest_consume_macros/src
parentf040f12e67f4da03773c4b28934ceefeb1c5b8b8 (diff)
Change invocation syntax of pest_consume::parser macro
Diffstat (limited to '')
-rw-r--r--pest_consume_macros/src/make_parser.rs31
1 files changed, 28 insertions, 3 deletions
diff --git a/pest_consume_macros/src/make_parser.rs b/pest_consume_macros/src/make_parser.rs
index c30b12f..5bf8fe3 100644
--- a/pest_consume_macros/src/make_parser.rs
+++ b/pest_consume_macros/src/make_parser.rs
@@ -37,6 +37,8 @@ impl<Item> VecPartitionFilterExt<Item> for Vec<Item> {
mod kw {
syn::custom_keyword!(shortcut);
+ syn::custom_keyword!(rule);
+ syn::custom_keyword!(parser);
}
struct MakeParserAttrs {
@@ -72,9 +74,32 @@ struct ParsedFn<'a> {
impl Parse for MakeParserAttrs {
fn parse(input: ParseStream) -> Result<Self> {
- let parser = input.parse()?;
- let _: Token![,] = input.parse()?;
- let rule_enum = input.parse()?;
+ // By default, the pest parser is the same type as the pest_consume one
+ let mut parser = parse_quote!(Self);
+ // By default, use the `Rule` type in scope
+ let mut rule_enum = parse_quote!(Rule);
+
+ while !input.is_empty() {
+ let lookahead = input.lookahead1();
+ if lookahead.peek(kw::parser) {
+ let _: kw::parser = input.parse()?;
+ let _: Token![=] = input.parse()?;
+ parser = input.parse()?;
+ } else if lookahead.peek(kw::rule) {
+ let _: kw::rule = input.parse()?;
+ let _: Token![=] = input.parse()?;
+ rule_enum = input.parse()?;
+ } else {
+ return Err(lookahead.error());
+ }
+
+ if input.peek(Token![,]) {
+ let _: Token![,] = input.parse()?;
+ } else {
+ break;
+ }
+ }
+
Ok(MakeParserAttrs { parser, rule_enum })
}
}