From 193b8956ba2b8373ffbd34046ae57e42eca82387 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 20 Mar 2019 21:33:46 +0100 Subject: Change syntax of parser macros --- dhall_core/src/parser.rs | 296 +++++++++++++++++++++++------------------------ 1 file changed, 148 insertions(+), 148 deletions(-) diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index 52e8c64..34b6a13 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -72,10 +72,10 @@ fn debug_pair(pair: Pair) -> String { } macro_rules! match_pair { - (@make_child_match, $pair:expr, ($($outer_acc:tt)*), ($($acc:tt)*), ($(,)* $x:ident : $ty:ident $($rest_of_match:tt)*) => $body:expr, $($rest:tt)*) => { + (@make_child_match, $pair:expr, ($($outer_acc:tt)*), ($($acc:tt)*), ($(,)* $ty:ident ($x:ident) $($rest_of_match:tt)*) => $body:expr, $($rest:tt)*) => { match_pair!(@make_child_match, $pair, ($($outer_acc)*), ($($acc)*, ParsedValue::$ty($x)), ($($rest_of_match)*) => $body, $($rest)*) }; - (@make_child_match, $pair:expr, ($($outer_acc:tt)*), ($($acc:tt)*), ($(,)* $x:ident.. : $ty:ident $($rest_of_match:tt)*) => $body:expr, $($rest:tt)*) => { + (@make_child_match, $pair:expr, ($($outer_acc:tt)*), ($($acc:tt)*), ($(,)* $ty:ident ($x:ident..) $($rest_of_match:tt)*) => $body:expr, $($rest:tt)*) => { match_pair!(@make_child_match, $pair, ($($outer_acc)*), ($($acc)*, x..), ($($rest_of_match)*) => { let $x = x.map(|x| x.$ty()); $body @@ -88,7 +88,7 @@ macro_rules! match_pair { match_pair!(@make_matches, $pair, ([] => { $body }, $($outer_acc)*), $($rest)*) }; - (@make_matches, $pair:expr, ($($acc:tt)*), children!($($args:tt)*) => $body:expr, $($rest:tt)*) => { + (@make_matches, $pair:expr, ($($acc:tt)*), [$($args:tt)*] => $body:expr, $($rest:tt)*) => { match_pair!(@make_child_match, $pair, ($($acc)*), (), ($($args)*) => $body, $($rest)*) }; (@make_matches, $pair:expr, ($($acc:tt)*) $(,)*) => { @@ -104,8 +104,8 @@ macro_rules! match_pair { } }; - ($pair:expr; $( $submac:ident!($($args:tt)*) => $body:expr ),* $(,)*) => { - match_pair!(@make_matches, $pair, (), $( $submac!($($args)*) => $body ),* ,) + ($pair:expr; $( [$($args:tt)*] => $body:expr ),* $(,)*) => { + match_pair!(@make_matches, $pair, (), $( [$($args)*] => $body ),* ,) }; } @@ -128,7 +128,7 @@ macro_rules! make_parser { let res: $o = $body; Ok(ParsedValue::$group(res)) }); - (@body, $pair:expr, rule_in_group!( $name:ident<$o:ty>; $group:ident; $($args:tt)* )) => ( { + (@body, $pair:expr, rule_in_group!( $name:ident<$o:ty>; $group:ident; children!( $($args:tt)* ) )) => ( { let res: $o = match_pair!($pair; $($args)*)?; Ok(ParsedValue::$group(res)) }); @@ -254,23 +254,23 @@ rule!(EOI<()>; raw_pair!(_) => ()); rule!(label_raw