From d3fcc3a5ef93d4e7f539954f1c77af58685c65b9 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 5 Sep 2019 17:40:29 +0200 Subject: Implement rule aliasing and simplify parser code --- dhall_syntax/src/parser.rs | 423 +++++++++++++++++++-------------------------- 1 file changed, 177 insertions(+), 246 deletions(-) (limited to 'dhall_syntax/src/parser.rs') diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index c2ba19a..bd29a27 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -66,11 +66,15 @@ impl<'input> ParseInput<'input, Rule> { fn as_str(&self) -> &'input str { self.pair.as_str() } + fn as_rule(&self) -> Rule { + self.pair.as_rule() + } } -// Used to retrieve the `Rule` enum associated with the `Self` type in `parse_children`. +// Used by the macros. trait PestConsumer { - type RuleEnum: pest::RuleType; + type Rule: pest::RuleType; + fn rule_alias(rule: Self::Rule) -> String; } fn debug_pair(pair: Pair) -> String { @@ -231,21 +235,17 @@ struct Parsers; #[make_parser(Rule)] impl Parsers { - fn EOI(_: ParseInput) -> ParseResult<()> { + fn EOI(_input: ParseInput) -> ParseResult<()> { Ok(()) } + #[alias(label)] fn simple_label(input: ParseInput) -> ParseResult