From 63d3356f40ef48a7735a2151a14ad9952fc245db Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 17 Apr 2019 01:22:28 +0200 Subject: Normalize union constructors --- dhall_core/src/core.rs | 2 ++ dhall_core/src/printer.rs | 14 ++++++++++++-- dhall_core/src/visitor.rs | 7 +++++-- 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'dhall_core') diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index 075ef81..2dfa4d8 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -190,6 +190,8 @@ pub enum ExprF { UnionType(BTreeMap>), /// `< k1 = t1, k2 : t2, k3 >` UnionLit(Label, SubExpr, BTreeMap>), + /// `< k1 : t1, k2 >.k1` + UnionConstructor(Label, BTreeMap>), /// `merge x y : t` Merge(SubExpr, SubExpr, Option), /// `e.x` diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index bb3c427..4d1ae2d 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -92,9 +92,9 @@ impl Display for ExprF { write!(f, "{} = {}", k, v) })?, UnionType(a) => fmt_list("< ", " | ", " >", a, f, |(k, v), f| { - write!(f, "{} : ", k)?; + write!(f, "{}", k)?; if let Some(v) = v { - v.fmt(f)? + write!(f, ": {}", v)?; } Ok(()) })?, @@ -108,6 +108,16 @@ impl Display for ExprF { } f.write_str(" >")? } + UnionConstructor(x, map) => { + fmt_list("< ", " | ", " >", map, f, |(k, v), f| { + write!(f, "{}", k)?; + if let Some(v) = v { + write!(f, ": {}", v)?; + } + Ok(()) + })?; + write!(f, ".{}", x)? + } Embed(a) => a.fmt(f)?, Note(_, b) => b.fmt(f)?, } diff --git a/dhall_core/src/visitor.rs b/dhall_core/src/visitor.rs index 1ea3fb1..c123275 100644 --- a/dhall_core/src/visitor.rs +++ b/dhall_core/src/visitor.rs @@ -178,11 +178,14 @@ where RecordType(kts) => RecordType(btmap(kts, v)?), RecordLit(kvs) => RecordLit(btmap(kvs, v)?), UnionType(kts) => UnionType(btoptmap(kts, v)?), - UnionLit(k, x, kvs) => UnionLit( + UnionLit(k, x, kts) => UnionLit( v.visit_label(k)?, v.visit_subexpr(x)?, - btoptmap(kvs, v)?, + btoptmap(kts, v)?, ), + UnionConstructor(x, kts) => { + UnionConstructor(v.visit_label(x)?, btoptmap(kts, v)?) + } Merge(x, y, t) => Merge( v.visit_subexpr(x)?, v.visit_subexpr(y)?, -- cgit v1.2.3