diff options
author | Nadrieril | 2019-03-05 12:19:15 +0100 |
---|---|---|
committer | Nadrieril | 2019-03-05 12:19:15 +0100 |
commit | 29b62de572ba756d162671e3cd16eb8b11408b00 (patch) | |
tree | 6ffad0317aab87962098c7e18436139e9991890f /dhall | |
parent | 4314421924c256ab13f5a630aff2596c480f6a66 (diff) |
Allow empty match in match_children!
Diffstat (limited to 'dhall')
-rw-r--r-- | dhall/src/lib.rs | 1 | ||||
-rw-r--r-- | dhall/src/parser.rs | 10 |
2 files changed, 8 insertions, 3 deletions
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 9dbd3a6..7cc96e1 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -1,4 +1,5 @@ #![feature(box_patterns)] +#![feature(trace_macros)] pub mod context; mod core; diff --git a/dhall/src/parser.rs b/dhall/src/parser.rs index 6c7c0c5..ba96a09 100644 --- a/dhall/src/parser.rs +++ b/dhall/src/parser.rs @@ -135,7 +135,7 @@ macro_rules! match_iter { }; // Check no elements remain - (@match 0, $iter:expr) => { + (@match 0, $iter:expr $(,)*) => { match $iter.next() { Some(_) => break Err(IterMatchError::TooManyItems), None => {}, @@ -190,7 +190,11 @@ macro_rules! match_children { (@collect, $pairs:expr, ($($args:tt)*), $body:expr, ($($acc:tt)*), ($x:ident* : $ty:ident, $($rest:tt)*)) => { match_children!(@collect, $pairs, ($($args)*), $body, ($($acc)*, $x??), ($($rest)*)) }; - (@collect, $pairs:expr, ($($args:tt)*), $body:expr, (,$($acc:tt)*), ()) => { + // Catch extra comma if exists + (@collect, $pairs:expr, ($($args:tt)*), $body:expr, (,$($acc:tt)*), ($(,)*)) => { + match_children!(@collect, $pairs, ($($args)*), $body, ($($acc)*), ()) + }; + (@collect, $pairs:expr, ($($args:tt)*), $body:expr, ($($acc:tt)*), ($(,)*)) => { let matched: Result<_, IterMatchError<ParseError>> = match_iter!(@get_err, $pairs; ($($acc)*) => { match_children!(@parse, $pairs, $($args)*); @@ -228,7 +232,7 @@ macro_rules! match_children { }; match_children!(@parse, $pairs $($rest)*); }; - (@parse, $pairs:expr) => {}; + (@parse, $pairs:expr $(,)*) => {}; // Entrypoint ($pair:expr; $( ($($args:tt)*) => $body:expr ),* $(,)*) => { |