summaryrefslogtreecommitdiff
path: root/dhall_core
diff options
context:
space:
mode:
authorNadrieril2019-03-12 00:14:50 +0100
committerNadrieril2019-03-12 00:23:39 +0100
commit4cd6c39d6d61c1d5a2670fe52c79bce4f11facdb (patch)
tree6dc184feea444d901993d9f8f4956844e8122cda /dhall_core
parentf1f292f5b7ed12b5b8d4a568b9db6bdbbcb23d83 (diff)
Handle Some and None builtins
Closes #19
Diffstat (limited to 'dhall_core')
-rw-r--r--dhall_core/src/core.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs
index 9c96b2a..9f4beb3 100644
--- a/dhall_core/src/core.rs
+++ b/dhall_core/src/core.rs
@@ -257,6 +257,8 @@ pub enum Builtin {
Text,
List,
Optional,
+ OptionalSome,
+ OptionalNone,
NaturalBuild,
NaturalFold,
NaturalIsZero,
@@ -462,13 +464,19 @@ impl<S, A: Display> Expr<S, A> {
Ok(())
}
&OptionalLit(ref t, ref es) => {
- fmt_list("[", "]", es, f, |e, f| e.fmt(f))?;
- match t {
- Some(t) => {
- write!(f, " : Optional ")?;
- t.fmt_e(f)?
+ match es.iter().next() {
+ None => {
+ write!(f, "None ")?;
+ t.as_ref().unwrap().fmt_e(f)?;
+ }
+ Some(e) => {
+ write!(f, "Some ")?;
+ e.fmt_e(f)?;
+ if let Some(t) = t {
+ write!(f, " : Optional ")?;
+ t.fmt_e(f)?;
+ }
}
- None => {}
}
Ok(())
}
@@ -624,6 +632,8 @@ impl Display for Builtin {
Text => "Text",
List => "List",
Optional => "Optional",
+ OptionalSome => "Some",
+ OptionalNone => "None",
NaturalBuild => "Natural/build",
NaturalFold => "Natural/fold",
NaturalIsZero => "Natural/isZero",
@@ -659,6 +669,8 @@ impl Builtin {
"Text" => Some(Text),
"List" => Some(List),
"Optional" => Some(Optional),
+ "Some" => Some(OptionalSome),
+ "None" => Some(OptionalNone),
"Natural/build" => Some(NaturalBuild),
"Natural/fold" => Some(NaturalFold),
"Natural/isZero" => Some(NaturalIsZero),