From 66972b05e5996132a83332ef0c6879c3a1679dc7 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 11 Mar 2020 17:26:09 +0000 Subject: Implement record puns --- dhall/src/syntax/ast/span.rs | 1 + dhall/src/syntax/text/dhall.pest.visibility | 2 ++ dhall/src/syntax/text/parser.rs | 5 +++++ dhall/src/syntax/text/printer.rs | 2 +- dhall/tests/parser/failure/spacing/RecordTypeNoSpace.txt | 2 +- dhall/tests/parser/failure/unit/RecordLitPunDotted.txt | 6 ++++++ tests_buffer | 10 ++++++---- update-tests.sh | 13 ++++++++----- 8 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 dhall/tests/parser/failure/unit/RecordLitPunDotted.txt diff --git a/dhall/src/syntax/ast/span.rs b/dhall/src/syntax/ast/span.rs index 50985e1..153a624 100644 --- a/dhall/src/syntax/ast/span.rs +++ b/dhall/src/syntax/ast/span.rs @@ -22,6 +22,7 @@ pub(crate) enum Span { DuplicateRecordFieldsSugar, DottedFieldSugar, WithSugar, + RecordPunSugar, /// For expressions obtained from decoding binary Decoded, /// For expressions constructed during normalization/typecheck diff --git a/dhall/src/syntax/text/dhall.pest.visibility b/dhall/src/syntax/text/dhall.pest.visibility index 0ff1bfe..2a89076 100644 --- a/dhall/src/syntax/text/dhall.pest.visibility +++ b/dhall/src/syntax/text/dhall.pest.visibility @@ -184,6 +184,8 @@ non_empty_record_type record_type_entry non_empty_record_literal record_literal_entry +# record_literal_punned_entry +# record_literal_normal_entry union_type empty_union_type # non_empty_union_type diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index f59cf06..b3c2c40 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -954,6 +954,11 @@ impl DhallParser { fn record_literal_entry(input: ParseInput) -> ParseResult<(Label, Expr)> { Ok(match_nodes!(input.into_children(); + [label(name)] => { + // Desugar record pun into a variable + let expr = Expr::new(Var(name.clone().into()), Span::RecordPunSugar); + (name, expr) + }, [label(name), expression(expr)] => (name, expr), [label(first_name), label(names).., expression(expr)] => { // Desugar dotted field syntax into nested records diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs index 5bb987b..a8991b0 100644 --- a/dhall/src/syntax/text/printer.rs +++ b/dhall/src/syntax/text/printer.rs @@ -357,7 +357,7 @@ impl Display for Label { let s = String::from(self); let is_reserved = match s.as_str() { "let" | "in" | "if" | "then" | "else" | "Type" | "Kind" - | "Sort" | "True" | "False" => true, + | "Sort" | "True" | "False" | "Some" => true, _ => crate::syntax::Builtin::parse(&s).is_some(), }; if !is_reserved && s.chars().all(|c| c.is_ascii_alphanumeric()) { diff --git a/dhall/tests/parser/failure/spacing/RecordTypeNoSpace.txt b/dhall/tests/parser/failure/spacing/RecordTypeNoSpace.txt index f6427a4..b08c143 100644 --- a/dhall/tests/parser/failure/spacing/RecordTypeNoSpace.txt +++ b/dhall/tests/parser/failure/spacing/RecordTypeNoSpace.txt @@ -3,4 +3,4 @@ 1 | { x :T }␊ | ^--- | - = expected non_empty_record_type_or_literal or empty_record_literal + = expected missing, if_, merge, NaN, Some_, toMap, assert, forall, record_type_entry, or empty_record_literal diff --git a/dhall/tests/parser/failure/unit/RecordLitPunDotted.txt b/dhall/tests/parser/failure/unit/RecordLitPunDotted.txt new file mode 100644 index 0000000..2e0ac22 --- /dev/null +++ b/dhall/tests/parser/failure/unit/RecordLitPunDotted.txt @@ -0,0 +1,6 @@ + --> 1:7 + | +1 | { x.y.z }␊ + | ^--- + | + = expected missing, if_, merge, NaN, Some_, toMap, assert, or forall diff --git a/tests_buffer b/tests_buffer index de49f25..74e76bc 100644 --- a/tests_buffer +++ b/tests_buffer @@ -3,18 +3,20 @@ parser: ./"a%20b" text interpolation and escapes projection by expression unit tests -fix fakeurlencode test +x.({ a : Bool, b }) +x.({ a }) +x.{ a : Bool } s/QuotedVariable/VariableQuoted/ -binary decoding: -decode old-style optional literals ? - import: failure/ don't recover cycle don't resolve symlinks in canonicalizing normalization: +move builtins and operators in their own folder ? +RecordSortFields { b = 1, a = 0 } +RecordTypeSortFields { b : Bool, a : Natural } type-inference: something that involves destructuring a recordtype after merge diff --git a/update-tests.sh b/update-tests.sh index 7be40c4..ce5a67c 100755 --- a/update-tests.sh +++ b/update-tests.sh @@ -75,16 +75,18 @@ function generate_output_file() { file="$2" INPUT_FILE="$(${folder}_input_file "$file")" OUTPUT_FILE="$(${folder}_output_file "$file")" + if [ ! -f "$OUTPUT_FILE" ]; then echo "$OUTPUT_FILE" ${folder}_process "$INPUT_FILE" > "$tmpfile" if [ $? -eq 0 ]; then mv "$tmpfile" "$OUTPUT_FILE" - if [ "$folder" = "parser" ]; then - cat "$OUTPUT_FILE" | cbor2diag.rb > "${file}B.diag" - fi fi fi + + if [ -f "$OUTPUT_FILE" -a "$folder" = "parser" -a ! -f "${file}B.diag" ]; then + cat "$OUTPUT_FILE" | cbor2diag.rb > "${file}B.diag" + fi } if [ "$1" = "missing" ]; then @@ -94,7 +96,7 @@ if [ "$1" = "missing" ]; then # This is not robust to spaces in filenames, but hopefully there should be none fd 'A\.dhallb?$' "$root/$folder/success" \ | sed 's/A.dhallb\?$//' \ - | while read file; do + | while read -r file; do generate_output_file "$folder" "$file" done done @@ -105,10 +107,11 @@ elif [ "$1" = "add" ]; then # normalization/unit/TextShowEmpty Text/show "" # This will add a test to the local tests folder for each such line, and generate # the output using the `dhall` command in the PATH. - while read file contents; do + while read -r file contents; do folder="$(echo "$file" | cut -d/ -f1)" is_success="$(echo "$file" | cut -d/ -f2)" file="./dhall/tests/$file" + # file="./dhall-lang/tests/$file" mkdir -p "$(dirname "$file")" if [ "$is_success" = "success" ]; then -- cgit v1.2.3 From bff6c3e82ef177c683bd69e39396285e567bd38b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 12 Mar 2020 18:13:44 +0000 Subject: Upstream the `with` grammar tweak --- dhall/build.rs | 13 ------------- dhall/tests/parser/failure/spacing/MergeNoSpace2.txt | 2 +- dhall/tests/parser/failure/spacing/RecordTypeNoSpace.txt | 2 +- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/dhall/build.rs b/dhall/build.rs index 6a0a3bf..ce677e3 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -374,19 +374,6 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { rules.remove("url_path"); writeln!(&mut file, "url_path = _{{ path }}")?; - // TODO: upstream this tweak - rules.remove("with_expression"); - writeln!( - &mut file, - r#" - with_expression = {{ application_expression ~ (whsp1 ~ with ~ whsp1 ~ with_clause)* }} - with_clause = {{ - any_label_or_some ~ (whsp ~ "." ~ whsp ~ any_label_or_some)* - ~ whsp ~ "=" ~ whsp ~ application_expression - }} - "# - )?; - // Work around some greediness issue in the grammar. rules.remove("missing"); writeln!( diff --git a/dhall/tests/parser/failure/spacing/MergeNoSpace2.txt b/dhall/tests/parser/failure/spacing/MergeNoSpace2.txt index 307d873..96d937b 100644 --- a/dhall/tests/parser/failure/spacing/MergeNoSpace2.txt +++ b/dhall/tests/parser/failure/spacing/MergeNoSpace2.txt @@ -3,4 +3,4 @@ 1 | merge x(y)␊ | ^--- | - = expected missing, double_quote_literal, single_quote_literal, if_, merge, NaN, Some_, toMap, assert, forall, numeric_double_literal, minus_infinity_literal, plus_infinity_literal, natural_literal, integer_literal, import_hashed, or non_empty_list_literal + = expected missing, double_quote_literal, single_quote_literal, if_, merge, non_empty_list_literal, NaN, Some_, toMap, assert, forall, numeric_double_literal, minus_infinity_literal, plus_infinity_literal, natural_literal, integer_literal, or import_hashed diff --git a/dhall/tests/parser/failure/spacing/RecordTypeNoSpace.txt b/dhall/tests/parser/failure/spacing/RecordTypeNoSpace.txt index b08c143..0e1a879 100644 --- a/dhall/tests/parser/failure/spacing/RecordTypeNoSpace.txt +++ b/dhall/tests/parser/failure/spacing/RecordTypeNoSpace.txt @@ -3,4 +3,4 @@ 1 | { x :T }␊ | ^--- | - = expected missing, if_, merge, NaN, Some_, toMap, assert, forall, record_type_entry, or empty_record_literal + = expected missing, if_, merge, NaN, Some_, toMap, assert, forall, empty_record_literal, or record_type_entry -- cgit v1.2.3 From 7b21e068d7109a3b8d0ba81cdbd4d41ed4220d9f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 17 Mar 2020 17:55:10 +0000 Subject: Standard PR got merged --- dhall-lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhall-lang b/dhall-lang index ea3ed68..99d84e4 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit ea3ed688dfbd787c7dc998ab00fce7dca78fc4a6 +Subproject commit 99d84e47ed9c64cee9c48212ca8f2af9320cdda6 -- cgit v1.2.3 From cd30948242576e9262796d4ecd998b62619b0e8a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 17 Mar 2020 17:56:05 +0000 Subject: Update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 072dd10..6c37d4e 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ same name as the corresponding test. [???] +- Implement record puns - Add support for `with` keyword - Implement remote imports with conservative sanity checking - Implement `missing` and `env:VAR` imports -- cgit v1.2.3