From f7b0c6b9c52f65624dc765fb9eaa7d0d94eeae76 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 6 Aug 2019 23:03:01 +0200 Subject: Generalize empty list annotations --- dhall-lang | 2 +- dhall/build.rs | 2 ++ dhall/src/phase/binary.rs | 8 ++++++-- dhall_generated_parser/build.rs | 22 ++++++++++++++++++++++ dhall_syntax/src/core/expr.rs | 2 +- dhall_syntax/src/parser.rs | 10 ++++++---- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/dhall-lang b/dhall-lang index 1b587f8..4d68c57 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit 1b587f866a16ce4ae198d5ff51848a4ffc0f4cdc +Subproject commit 4d68c5708cfc5c3f5ff7e5a6c4df25c5fdfd96f4 diff --git a/dhall/build.rs b/dhall/build.rs index 2d75cbf..07da3f5 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -103,6 +103,8 @@ fn main() -> std::io::Result<()> { || path == "success/unit/import/urls/potPourri" // TODO: toMap || path == "success/toMap" + // Not a failure anymore + || path == "failure/unit/ListLitEmptyPrecedence" }, )?; diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index 66b235f..f88eee2 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -341,6 +341,10 @@ fn cbor_value_to_dhall( let y = cbor_value_to_dhall(&y)?; Annot(x, y) } + [U64(27), x] => { + let x = cbor_value_to_dhall(&x)?; + EmptyListLit(x) + } _ => Err(DecodeError::WrongFormatError(format!("{:?}", data)))?, }, _ => Err(DecodeError::WrongFormatError(format!("{:?}", data)))?, @@ -475,9 +479,9 @@ where EmptyListLit(x) => match x.as_ref() { App(f, a) => match f.as_ref() { ExprF::Builtin(Builtin::List) => ser_seq!(ser; tag(4), expr(a)), - _ => unreachable!(), + _ => ser_seq!(ser; tag(27), expr(x)), }, - _ => unreachable!(), + _ => ser_seq!(ser; tag(27), expr(x)), }, NEListLit(xs) => ser.collect_seq( once(tag(4)).chain(once(null())).chain(xs.iter().map(expr)), diff --git a/dhall_generated_parser/build.rs b/dhall_generated_parser/build.rs index 1edce9e..7eba52c 100644 --- a/dhall_generated_parser/build.rs +++ b/dhall_generated_parser/build.rs @@ -31,6 +31,7 @@ fn main() -> std::io::Result<()> { rules.remove("simple_label"); rules.remove("nonreserved_label"); rules.remove("first_application_expression"); + rules.remove("expression"); let mut file = File::create(pest_path)?; writeln!(&mut file, "// AUTO-GENERATED FILE. See build.rs.")?; @@ -65,6 +66,27 @@ fn main() -> std::io::Result<()> { | import_expression }}" )?; + // TODO: hack; we'll need to upstream a change to the grammar + writeln!( + &mut file, + r#"expression = {{ + lambda ~ whsp ~ ^"(" ~ whsp ~ nonreserved_label ~ whsp ~ ^":" ~ whsp1 ~ expression ~ whsp ~ ^")" ~ whsp ~ arrow ~ whsp ~ expression + | if_ ~ whsp1 ~ expression ~ whsp ~ then ~ whsp1 ~ expression ~ whsp ~ else_ ~ whsp1 ~ expression + | let_binding+ ~ in_ ~ whsp1 ~ expression + | forall ~ whsp ~ ^"(" ~ whsp ~ nonreserved_label ~ whsp ~ ^":" ~ whsp1 ~ expression ~ whsp ~ ^")" ~ whsp ~ arrow ~ whsp ~ expression + | operator_expression ~ whsp ~ arrow ~ whsp ~ expression + | merge ~ whsp1 ~ import_expression ~ whsp1 ~ import_expression ~ whsp ~ ^":" ~ whsp1 ~ application_expression + | empty_list_literal + | toMap ~ whsp1 ~ import_expression ~ whsp ~ ^":" ~ whsp1 ~ application_expression + | annotated_expression + }}"# + )?; + writeln!( + &mut file, + r#"empty_list_literal = {{ + ^"[" ~ whsp ~ ^"]" ~ whsp ~ ^":" ~ whsp1 ~ application_expression + }}"# + )?; // TODO: this is a cheat; properly support RFC3986 URLs instead writeln!(&mut file, "url_path = _{{ path }}")?; writeln!( diff --git a/dhall_syntax/src/core/expr.rs b/dhall_syntax/src/core/expr.rs index e33859b..14dc165 100644 --- a/dhall_syntax/src/core/expr.rs +++ b/dhall_syntax/src/core/expr.rs @@ -190,7 +190,7 @@ pub enum ExprF { DoubleLit(Double), /// `"Some ${interpolated} text"` TextLit(InterpolatedText), - /// `[] : List t` + /// `[] : t` EmptyListLit(SubExpr), /// `[x, y, z]` NEListLit(Vec), diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 0832af3..8a84b00 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -727,6 +727,12 @@ make_parser! { token_rule!(if_<()>); token_rule!(in_<()>); + rule!(empty_list_literal as expression; span; children!( + [expression(e)] => { + spanned(span, EmptyListLit(e)) + }, + )); + rule!(expression as expression; span; children!( [lambda(()), label(l), expression(typ), arrow(()), expression(body)] => { @@ -751,10 +757,6 @@ make_parser! { [merge(()), expression(x), expression(y), expression(z)] => { spanned(span, Merge(x, y, Some(z))) }, - [List(()), expression(x)] => { - let list = unspanned(Builtin(crate::Builtin::List)); - spanned(span, EmptyListLit(unspanned(App(list, x)))) - }, [expression(e)] => e, )); -- cgit v1.2.3