summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dhall_syntax/src/parser.rs2
-rw-r--r--pest_consume/examples/csv/main.rs2
-rw-r--r--pest_consume/src/lib.rs2
-rw-r--r--pest_consume_macros/src/make_parser.rs31
4 files changed, 31 insertions, 6 deletions
diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs
index 8f6f423..2af2d92 100644
--- a/dhall_syntax/src/parser.rs
+++ b/dhall_syntax/src/parser.rs
@@ -149,7 +149,7 @@ lazy_static::lazy_static! {
struct DhallParser;
-#[pest_consume::parser(dgp::DhallParser, dgp::Rule)]
+#[pest_consume::parser(parser = dgp::DhallParser, rule = dgp::Rule)]
impl DhallParser {
fn EOI(_input: ParseInput) -> ParseResult<()> {
Ok(())
diff --git a/pest_consume/examples/csv/main.rs b/pest_consume/examples/csv/main.rs
index a045eb4..88621db 100644
--- a/pest_consume/examples/csv/main.rs
+++ b/pest_consume/examples/csv/main.rs
@@ -15,7 +15,7 @@ type Node<'i> = pest_consume::Node<'i, Rule, ()>;
#[grammar = "../examples/csv/csv.pest"]
struct CSVParser;
-#[pest_consume::parser(CSVParser, Rule)]
+#[pest_consume::parser]
impl CSVParser {
fn EOI(_input: Node) -> Result<()> {
Ok(())
diff --git a/pest_consume/src/lib.rs b/pest_consume/src/lib.rs
index a161d3f..c1d62e5 100644
--- a/pest_consume/src/lib.rs
+++ b/pest_consume/src/lib.rs
@@ -32,7 +32,7 @@
//! struct CSVParser;
//!
//! // This is the other half of the parser, using pest_consume.
-//! #[pest_consume::parser(CSVParser, Rule)]
+//! #[pest_consume::parser]
//! impl CSVParser {
//! fn EOI(_input: Node) -> Result<()> {
//! Ok(())
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 })
}
}