diff options
author | Nadrieril | 2019-03-20 22:53:18 +0100 |
---|---|---|
committer | Nadrieril | 2019-03-20 22:53:18 +0100 |
commit | 5935839881b5437eec4ea3915acbe887782d68d3 (patch) | |
tree | 66334b838e03441e5e82f3b68398ae765d5cce5a | |
parent | d6cbee16586be9013bebfa8dc9e7aa0a31c8c55f (diff) |
Reimplement shortcutting
-rw-r--r-- | dhall_core/src/parser.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index 34809b5..ef7fcc9 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -188,11 +188,19 @@ macro_rules! make_parser { let mut values_stack: Vec<ParsedValue> = vec![]; while let Some(p) = pairs_stack.pop() { match p { - Unprocessed(pair) => { - let mut pairs: Vec<_> = pair.clone().into_inner().map(StackFrame::Unprocessed).collect(); - let n_children = pairs.len(); - pairs_stack.push(Processed(pair, n_children)); - pairs_stack.append(&mut pairs); + Unprocessed(mut pair) => { + loop { + let mut pairs: Vec<_> = pair.clone().into_inner().collect(); + let n_children = pairs.len(); + if n_children == 1 && can_be_shortcutted(pair.as_rule()) { + pair = pairs.pop().unwrap(); + continue + } else { + pairs_stack.push(Processed(pair, n_children)); + pairs_stack.extend(pairs.into_iter().map(StackFrame::Unprocessed)); + break + } + } } Processed(pair, n) => { let mut parsed: Vec<_> = values_stack.split_off(values_stack.len() - n); |