From 5692bf2c8a7acfb90a5d03d0bd360c105ba2a72b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 16 Mar 2019 00:18:50 +0100 Subject: Store an Option in OptionalLit instead of a vec Closes #21 --- dhall_core/src/core.rs | 18 +++++++++--------- dhall_core/src/parser.rs | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'dhall_core') diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index 197907a..a7b6b53 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -339,7 +339,10 @@ pub enum Expr { ListLit(Option>>, Vec>), /// `OptionalLit t [e] ~ [e] : Optional t` /// `OptionalLit t [] ~ [] : Optional t` - OptionalLit(Option>>, Vec>), + OptionalLit( + Option>>, + Option>>, + ), /// `Record [(k1, t1), (k2, t2)] ~ { k1 : t1, k2 : t1 }` Record(BTreeMap>), /// `RecordLit [(k1, v1), (k2, v2)] ~ { k1 = v1, k2 = v2 }` @@ -576,7 +579,7 @@ impl Expr { Ok(()) } &OptionalLit(ref t, ref es) => { - match es.iter().next() { + match es { None => { write!(f, "None ")?; t.as_ref().unwrap().fmt_e(f)?; @@ -925,10 +928,7 @@ where let es = es.iter().map(&map).collect(); ListLit(opt(t), es) } - OptionalLit(ref t, ref es) => { - let es = es.iter().map(&map).collect(); - OptionalLit(opt(t), es) - } + OptionalLit(ref t, ref es) => OptionalLit(opt(t), opt(es)), Record(ref kts) => { Record(map_record_value_and_keys(kts, map, map_label)) } @@ -1112,9 +1112,9 @@ pub fn shift(d: isize, v: &V, e: &Expr) -> Expr { t.as_ref().map(|t| bx(shift(d, v, t))), es.iter().map(|e| shift(d, v, e)).collect(), ), - OptionalLit(t, es) => OptionalLit( + OptionalLit(t, e) => OptionalLit( t.as_ref().map(|t| bx(shift(d, v, t))), - es.iter().map(|e| shift(d, v, e)).collect(), + e.as_ref().map(|t| bx(shift(d, v, t))), ), Record(a) => Record(map_record_value(a, |val| shift(d, v, val))), RecordLit(a) => RecordLit(map_record_value(a, |val| shift(d, v, val))), @@ -1218,7 +1218,7 @@ where } OptionalLit(a, b) => { let a2 = a.as_ref().map(|a| bx(subst(v, e, a))); - let b2 = b.iter().map(|be| subst(v, e, be)).collect(); + let b2 = b.as_ref().map(|a| bx(subst(v, e, a))); OptionalLit(a2, b2) } Record(kts) => Record(map_record_value(kts, |t| subst(v, e, t))), diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index 02242bf..9cbd878 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -648,7 +648,7 @@ rule!(merge_expression; rule!(empty_collection; children!(x: str, y: expression) => { match x { - "Optional" => bx(Expr::OptionalLit(Some(y), vec![])), + "Optional" => bx(Expr::OptionalLit(Some(y), None)), "List" => bx(Expr::ListLit(Some(y), vec![])), _ => unreachable!(), } @@ -657,7 +657,7 @@ rule!(empty_collection; rule!(non_empty_optional; children!(x: expression, _y: str, z: expression) => { - bx(Expr::OptionalLit(Some(z), vec![*x])) + bx(Expr::OptionalLit(Some(z), Some(x))) } ); -- cgit v1.2.3