diff options
author | Nadrieril | 2019-04-17 01:22:28 +0200 |
---|---|---|
committer | Nadrieril | 2019-04-17 01:22:28 +0200 |
commit | 63d3356f40ef48a7735a2151a14ad9952fc245db (patch) | |
tree | baa79551653585fa3288f810bb6c2a0b906484cd /dhall_core | |
parent | 7389cbce9ab7c26ce23be24a5c3e57c9d86a716b (diff) |
Normalize union constructors
Diffstat (limited to 'dhall_core')
-rw-r--r-- | dhall_core/src/core.rs | 2 | ||||
-rw-r--r-- | dhall_core/src/printer.rs | 14 | ||||
-rw-r--r-- | dhall_core/src/visitor.rs | 7 |
3 files changed, 19 insertions, 4 deletions
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<SubExpr, Label, Note, Embed> { UnionType(BTreeMap<Label, Option<SubExpr>>), /// `< k1 = t1, k2 : t2, k3 >` UnionLit(Label, SubExpr, BTreeMap<Label, Option<SubExpr>>), + /// `< k1 : t1, k2 >.k1` + UnionConstructor(Label, BTreeMap<Label, Option<SubExpr>>), /// `merge x y : t` Merge(SubExpr, SubExpr, Option<SubExpr>), /// `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<SE: Display + Clone, N, E: Display> Display for ExprF<SE, Label, N, E> { 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<SE: Display + Clone, N, E: Display> Display for ExprF<SE, Label, N, E> { } 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)?, |