From 92ea98da2f89348c3dfdc7d49594a4d876d06ba2 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 18 Mar 2019 05:27:17 +0100 Subject: Split List literal between empty and non-empty --- dhall_core/src/core.rs | 25 ++++++++++++------------- dhall_core/src/parser.rs | 4 ++-- 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'dhall_core') diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index a3236eb..722506b 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -307,8 +307,10 @@ pub enum Expr { DoubleLit(Double), /// `TextLit t ~ t` TextLit(InterpolatedText), - /// `ListLit t [x, y, z] ~ [x, y, z] : List t` - ListLit(Option>, Vec>), + /// [] : List t` + EmptyListLit(SubExpr), + /// [x, y, z] + NEListLit(Vec>), /// `OptionalLit t [e] ~ [e] : Optional t` /// `OptionalLit t [] ~ [] : Optional t` OptionalLit(Option>, Option>), @@ -543,16 +545,12 @@ impl Expr { write!(f, ") → ")?; d.fmt_b(f) } - &ListLit(ref t, ref es) => { - fmt_list("[", "]", es, f, |e, f| e.fmt(f))?; - match t { - Some(t) => { - write!(f, " : List ")?; - t.fmt_e(f)? - } - None => {} - } - Ok(()) + &EmptyListLit(ref t) => { + write!(f, "[] : List ")?; + t.fmt_e(f) + } + &NEListLit(ref es) => { + fmt_list("[", "]", es, f, |e, f| e.fmt(f)) } &OptionalLit(ref t, ref es) => { match es { @@ -902,7 +900,8 @@ where DoubleLit(n) => DoubleLit(*n), TextLit(t) => TextLit(t.map(&map)), BinOp(o, x, y) => BinOp(*o, map(x), map(y)), - ListLit(t, es) => ListLit(opt(t), vec(es)), + EmptyListLit(t) => EmptyListLit(map(t)), + NEListLit(es) => NEListLit(vec(es)), OptionalLit(t, es) => OptionalLit(opt(t), opt(es)), Record(kts) => Record(btmap(kts)), RecordLit(kvs) => RecordLit(btmap(kvs)), diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index 9487ebc..6809aa2 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -650,7 +650,7 @@ rule!(empty_collection; children!(x: str, y: expression) => { match x { "Optional" => bx(Expr::OptionalLit(Some(y), None)), - "List" => bx(Expr::ListLit(Some(y), vec![])), + "List" => bx(Expr::EmptyListLit(y)), _ => unreachable!(), } } @@ -871,7 +871,7 @@ rule!(union_type_entry<(Label, RcExpr)>; rule!(non_empty_list_literal_raw; children!(items*: expression) => { - bx(Expr::ListLit(None, items.collect())) + bx(Expr::NEListLit(items.collect())) } ); -- cgit v1.2.3