From a342f45f820e28638e4a73a7b3a577ebf2396b0d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 4 Apr 2019 18:48:42 +0200 Subject: Factor back in some rule branches --- dhall_core/src/parser.rs | 93 ++++++++++++++++++---------------- dhall_parser/src/dhall.abnf | 64 +++++++++++------------ dhall_parser/src/dhall.pest.visibility | 22 +++----- 3 files changed, 84 insertions(+), 95 deletions(-) diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index 68796c4..f888f94 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -116,8 +116,10 @@ fn debug_pair(pair: Pair) -> String { macro_rules! make_parser { (@pattern, rule, $name:ident) => (Rule::$name); + (@pattern, token_rule, $name:ident) => (Rule::$name); (@pattern, rule_group, $name:ident) => (_); (@filter, rule) => (true); + (@filter, token_rule) => (true); (@filter, rule_group) => (false); (@body, @@ -164,6 +166,13 @@ macro_rules! make_parser { ).ok_or_else(|| -> String { unreachable!() })?; Ok(ParsedValue::$group(res)) }); + (@body, + $pair:expr, + $children:expr, + token_rule!($name:ident<$o:ty>) + ) => ({ + Ok(ParsedValue::$name(())) + }); (@body, $pair:expr, $children:expr, rule_group!( $name:ident<$o:ty> )) => ( unreachable!() ); @@ -235,7 +244,8 @@ fn do_parse<'a>(initial_pair: Pair<'a, Rule>) -> ParseResult> { fn can_be_shortcutted(rule: Rule) -> bool { use Rule::*; match rule { - import_alt_expression + expression + | import_alt_expression | or_expression | plus_expression | text_append_expression @@ -255,7 +265,7 @@ fn can_be_shortcutted(rule: Rule) -> bool { } make_parser! { - rule!(EOI<()>; captured_str!(_) => ()); + token_rule!(EOI<()>); rule!(simple_label