diff options
author | Nadrieril | 2019-04-15 12:22:02 +0200 |
---|---|---|
committer | Nadrieril | 2019-04-15 12:22:02 +0200 |
commit | 63aa21c581933a10b2b1ab96c632c72834cf2115 (patch) | |
tree | 9e534d7a4107fae5aae33637a5ea7c8a2f58c873 /dhall_core | |
parent | 75420d0822652d6592b74199ea35281dbdf84efb (diff) |
Handle empty optionals correctly
Closes #78
Diffstat (limited to 'dhall_core')
-rw-r--r-- | dhall_core/src/core.rs | 4 | ||||
-rw-r--r-- | dhall_core/src/parser.rs | 8 | ||||
-rw-r--r-- | dhall_core/src/printer.rs | 8 | ||||
-rw-r--r-- | dhall_core/src/visitor.rs | 4 |
4 files changed, 18 insertions, 6 deletions
diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index 7859c73..c0e04ed 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -174,6 +174,10 @@ pub enum ExprF<SubExpr, Label, Note, Embed> { EmptyListLit(SubExpr), /// [x, y, z] NEListLit(Vec<SubExpr>), + /// Deprecated Optional literal form + /// [] : Optional a + /// [x] : Optional a + OldOptionalLit(Option<SubExpr>, SubExpr), /// None t EmptyOptionalLit(SubExpr), /// Some e diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index cea7cea..c4ae2e5 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -641,13 +641,13 @@ make_parser! { spanned(span, EmptyListLit(rc(t))) }, [Optional(_), expression(t)] => { - spanned(span, EmptyOptionalLit(rc(t))) + spanned(span, OldOptionalLit(None, rc(t))) }, )); rule!(non_empty_optional<ParsedExpr<'a>> as expression; span; children!( [expression(x), Optional(_), expression(t)] => { - spanned(span, Annot(rc(NEOptionalLit(rc(x))), rc(t))) + spanned(span, OldOptionalLit(Option::Some(rc(x)), rc(t))) } )); @@ -747,10 +747,6 @@ make_parser! { rule!(application_expression<ParsedExpr<'a>> as expression; span; children!( [expression(e)] => e, - [expression(Builtin(crate::Builtin::OptionalNone)), - expression(e), expression(rest)..] => { - spanned(span, app(EmptyOptionalLit(rc(e)), rest.map(rc).collect())) - }, [Some(()), expression(e), expression(rest)..] => { spanned(span, app(NEOptionalLit(rc(e)), rest.map(rc).collect())) }, diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index e53c1ec..bb094de 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -32,6 +32,12 @@ impl<SE: Display + Clone, N, E: Display> Display for ExprF<SE, Label, N, E> { NEListLit(es) => { fmt_list("[", ", ", "]", es, f, Display::fmt)?; } + OldOptionalLit(None, t) => { + write!(f, "[] : Optional {}", t)?; + } + OldOptionalLit(Some(x), t) => { + write!(f, "[{}] : Optional {}", x, t)?; + } EmptyOptionalLit(t) => { write!(f, "None {}", t)?; } @@ -149,6 +155,7 @@ impl<S: Clone, A: Display + Clone> Expr<S, A> { | Let(_, _, _, _) | EmptyListLit(_) | NEListLit(_) + | OldOptionalLit(_, _) | EmptyOptionalLit(_) | NEOptionalLit(_) | Merge(_, _, _) @@ -189,6 +196,7 @@ impl<S: Clone, A: Display + Clone> Expr<S, A> { b.phase(PrintPhase::BinOp(op)), ), EmptyListLit(t) => EmptyListLit(t.phase(Import)), + OldOptionalLit(x, t) => OldOptionalLit(x, t.phase(Import)), EmptyOptionalLit(t) => EmptyOptionalLit(t.phase(Import)), NEOptionalLit(e) => NEOptionalLit(e.phase(Import)), ExprF::App(a, args) => ExprF::App( diff --git a/dhall_core/src/visitor.rs b/dhall_core/src/visitor.rs index b0424ac..3b06f8b 100644 --- a/dhall_core/src/visitor.rs +++ b/dhall_core/src/visitor.rs @@ -148,6 +148,10 @@ where ), EmptyListLit(t) => EmptyListLit(v.visit_subexpr(t)?), NEListLit(es) => NEListLit(vec(es, |e| v.visit_subexpr(e))?), + OldOptionalLit(x, t) => OldOptionalLit( + opt(x, |e| v.visit_subexpr(e))?, + v.visit_subexpr(t)?, + ), EmptyOptionalLit(t) => EmptyOptionalLit(v.visit_subexpr(t)?), NEOptionalLit(e) => NEOptionalLit(v.visit_subexpr(e)?), RecordType(kts) => RecordType(btmap(kts, v)?), |