From 72ad56209fe10e3120c19ca5b820ff267423ab1d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 11 Apr 2020 15:41:21 +0100 Subject: spec: fix precedence of `===` and `with` --- CHANGELOG.md | 1 + README.md | 2 +- dhall-lang | 2 +- dhall/build.rs | 2 +- dhall/src/operations/kind.rs | 4 ++-- dhall/src/syntax/ast/span.rs | 6 ++++++ dhall/src/syntax/text/dhall.abnf | 22 ++++++++++++++-------- dhall/src/syntax/text/parser.rs | 2 +- .../tests/parser/failure/unit/WithPrecedence1.txt | 6 ++++++ .../tests/parser/failure/unit/WithPrecedence2.txt | 6 ++++++ .../tests/parser/failure/unit/WithPrecedence3.txt | 6 ++++++ .../tests/parser/success/unit/WithPrecedence1B.txt | 1 + .../tests/parser/success/unit/WithPrecedence2B.txt | 1 + .../tests/parser/success/unit/WithPrecedence3B.txt | 1 + .../unit/operators/PrecedenceEquivalenceB.txt | 1 + tests_buffer | 1 - 16 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 dhall/tests/parser/failure/unit/WithPrecedence1.txt create mode 100644 dhall/tests/parser/failure/unit/WithPrecedence2.txt create mode 100644 dhall/tests/parser/failure/unit/WithPrecedence3.txt create mode 100644 dhall/tests/parser/success/unit/WithPrecedence1B.txt create mode 100644 dhall/tests/parser/success/unit/WithPrecedence2B.txt create mode 100644 dhall/tests/parser/success/unit/WithPrecedence3B.txt create mode 100644 dhall/tests/parser/success/unit/operators/PrecedenceEquivalenceB.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 457c346..23997c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ #### [Unreleased] +- Adjust precedence of `===` and `with` - Fix running tests on Windows. Developing on this lib should now be possible on Windows. #### [0.5.3] - 2020-05-30 diff --git a/README.md b/README.md index ab32536..cad82f8 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ same name as the corresponding test. I try to keep commit messages somewhat in the style of [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0). That means the commit -message should start with `feat:`, `test:`, `doc:`, `fix:`, `style:`, +message should start with `feat:`, `test:`, `spec:`, `doc:`, `fix:`, `style:`, `refactor:`, `chore:`, `perf:` or similar prefixes. A breaking change should be indicated with `!` before the `:`. diff --git a/dhall-lang b/dhall-lang index a53a620..b788d6d 160000 --- a/dhall-lang +++ b/dhall-lang @@ -1 +1 @@ -Subproject commit a53a620df888b97fe23598356be7157bda0c8e21 +Subproject commit b788d6dd2150eec49b6bdd0cc7de50e403fad889 diff --git a/dhall/build.rs b/dhall/build.rs index 4fc8545..3dcdd5e 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -95,7 +95,7 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { bool_or | import_alt }} - operator_expression = {{ with_expression ~ (whsp ~ operator ~ whsp ~ with_expression)* }} + operator_expression = {{ application_expression ~ (whsp ~ operator ~ whsp ~ application_expression)* }} "## )?; diff --git a/dhall/src/operations/kind.rs b/dhall/src/operations/kind.rs index 5415637..0ee9671 100644 --- a/dhall/src/operations/kind.rs +++ b/dhall/src/operations/kind.rs @@ -6,6 +6,8 @@ use crate::syntax::{trivial_result, Label}; // pretty-printing to work correctly #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum BinOp { + /// x === y + Equivalence, /// `x ? y` ImportAlt, /// `x || y` @@ -30,8 +32,6 @@ pub enum BinOp { BoolEQ, /// `x != y` BoolNE, - /// x === y - Equivalence, } /// Operations diff --git a/dhall/src/syntax/ast/span.rs b/dhall/src/syntax/ast/span.rs index e250602..ab3279b 100644 --- a/dhall/src/syntax/ast/span.rs +++ b/dhall/src/syntax/ast/span.rs @@ -66,6 +66,12 @@ impl Span { end: max(x.end, y.end), }) } + (Parsed(_), Parsed(_)) => panic!( + "Tried to union incompatible spans: {:?} and {:?}", + self, other + ), + (Parsed(x), _) => Parsed(x.clone()), + (_, Parsed(x)) => Parsed(x.clone()), _ => panic!( "Tried to union incompatible spans: {:?} and {:?}", self, other diff --git a/dhall/src/syntax/text/dhall.abnf b/dhall/src/syntax/text/dhall.abnf index 1c3a980..861f7b3 100644 --- a/dhall/src/syntax/text/dhall.abnf +++ b/dhall/src/syntax/text/dhall.abnf @@ -757,6 +757,11 @@ expression = ; NOTE: Backtrack if parsing this alternative fails / operator-expression whsp arrow whsp expression + ; "a with x = b" + ; + ; NOTE: Backtrack if parsing this alternative fails + / with-expression + ; "merge e1 e2 : t" ; ; NOTE: Backtrack if parsing this alternative fails since we can't tell @@ -792,9 +797,16 @@ let-binding = let whsp1 nonreserved-label whsp [ ":" whsp1 expression whsp ] "=" empty-list-literal = "[" whsp [ "," whsp ] "]" whsp ":" whsp1 application-expression -operator-expression = import-alt-expression +with-expression = + import-expression 1*(whsp1 with whsp1 with-clause) + +with-clause = + any-label-or-some *(whsp "." whsp any-label-or-some) whsp "=" whsp operator-expression + +operator-expression = equivalent-expression ; Nonempty-whitespace to disambiguate `http://a/a?a` +equivalent-expression = import-alt-expression *(whsp equivalent whsp import-alt-expression) import-alt-expression = or-expression *(whsp "?" whsp1 or-expression) or-expression = plus-expression *(whsp "||" whsp plus-expression) ; Nonempty-whitespace to disambiguate `f +2` @@ -807,13 +819,7 @@ prefer-expression = combine-types-expression *(whsp prefer whsp combine-t combine-types-expression = times-expression *(whsp combine-types whsp times-expression) times-expression = equal-expression *(whsp "*" whsp equal-expression) equal-expression = not-equal-expression *(whsp "==" whsp not-equal-expression) -not-equal-expression = equivalent-expression *(whsp "!=" whsp equivalent-expression) -equivalent-expression = with-expression *(whsp equivalent whsp with-expression) - -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 +not-equal-expression = application-expression *(whsp "!=" whsp application-expression) ; Import expressions need to be separated by some whitespace, otherwise there diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index 1e1449c..e870db3 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -130,6 +130,7 @@ lazy_static::lazy_static! { use Rule::*; // In order of precedence let operators = vec![ + equivalent, import_alt, bool_or, natural_plus, @@ -142,7 +143,6 @@ lazy_static::lazy_static! { natural_times, bool_eq, bool_ne, - equivalent, ]; PrecClimber::new( operators diff --git a/dhall/tests/parser/failure/unit/WithPrecedence1.txt b/dhall/tests/parser/failure/unit/WithPrecedence1.txt new file mode 100644 index 0000000..a1dfd31 --- /dev/null +++ b/dhall/tests/parser/failure/unit/WithPrecedence1.txt @@ -0,0 +1,6 @@ + --> 1:24 + | +1 | { x = 0 } // { y = 1 } with x = 1␊ + | ^--- + | + = expected EOI, import_alt, bool_or, natural_plus, text_append, list_append, bool_and, natural_times, bool_eq, bool_ne, combine, combine_types, equivalent, prefer, arrow, import_hashed, or primitive_expression diff --git a/dhall/tests/parser/failure/unit/WithPrecedence2.txt b/dhall/tests/parser/failure/unit/WithPrecedence2.txt new file mode 100644 index 0000000..fefd172 --- /dev/null +++ b/dhall/tests/parser/failure/unit/WithPrecedence2.txt @@ -0,0 +1,6 @@ + --> 1:15 + | +1 | foo { x = 0 } with x = 1␊ + | ^--- + | + = expected EOI, import_alt, bool_or, natural_plus, text_append, list_append, bool_and, natural_times, bool_eq, bool_ne, combine, combine_types, equivalent, prefer, arrow, import_hashed, or primitive_expression diff --git a/dhall/tests/parser/failure/unit/WithPrecedence3.txt b/dhall/tests/parser/failure/unit/WithPrecedence3.txt new file mode 100644 index 0000000..418c669 --- /dev/null +++ b/dhall/tests/parser/failure/unit/WithPrecedence3.txt @@ -0,0 +1,6 @@ + --> 1:22 + | +1 | { x = 0 } with x = 1 : T␊ + | ^--- + | + = expected EOI, import_alt, bool_or, natural_plus, text_append, list_append, bool_and, natural_times, bool_eq, bool_ne, combine, combine_types, equivalent, prefer, import_hashed, or primitive_expression diff --git a/dhall/tests/parser/success/unit/WithPrecedence1B.txt b/dhall/tests/parser/success/unit/WithPrecedence1B.txt new file mode 100644 index 0000000..5f22335 --- /dev/null +++ b/dhall/tests/parser/success/unit/WithPrecedence1B.txt @@ -0,0 +1 @@ +{ a = Some 1 } ⫽ { a = Some 2 } ⫽ { a = Some 3 } diff --git a/dhall/tests/parser/success/unit/WithPrecedence2B.txt b/dhall/tests/parser/success/unit/WithPrecedence2B.txt new file mode 100644 index 0000000..f945cc9 --- /dev/null +++ b/dhall/tests/parser/success/unit/WithPrecedence2B.txt @@ -0,0 +1 @@ +{ x = 0 } ⫽ { x = 1 + 1 } diff --git a/dhall/tests/parser/success/unit/WithPrecedence3B.txt b/dhall/tests/parser/success/unit/WithPrecedence3B.txt new file mode 100644 index 0000000..a801b24 --- /dev/null +++ b/dhall/tests/parser/success/unit/WithPrecedence3B.txt @@ -0,0 +1 @@ +foo::{ x = 0 } ⫽ { x = 1 } diff --git a/dhall/tests/parser/success/unit/operators/PrecedenceEquivalenceB.txt b/dhall/tests/parser/success/unit/operators/PrecedenceEquivalenceB.txt new file mode 100644 index 0000000..717c108 --- /dev/null +++ b/dhall/tests/parser/success/unit/operators/PrecedenceEquivalenceB.txt @@ -0,0 +1 @@ +2 + 3 * 4 ≡ 4 * 3 + 2 diff --git a/tests_buffer b/tests_buffer index 3240b41..e01d7a7 100644 --- a/tests_buffer +++ b/tests_buffer @@ -11,7 +11,6 @@ From https://github.com/dhall-lang/dhall-lang/issues/280 : "${ not_really_an_expression ;-) }" ''${ not_an_expression ;-) }'' {- {- -} 1 -{ x = 0 } with x = 1 + 1 import: failure/ -- cgit v1.2.3