From 29b62de572ba756d162671e3cd16eb8b11408b00 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 5 Mar 2019 12:19:15 +0100 Subject: Allow empty match in match_children! --- dhall/src/lib.rs | 1 + dhall/src/parser.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'dhall/src') 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> = 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 ),* $(,)*) => { -- cgit v1.2.3