diff options
Diffstat (limited to 'dhall')
-rw-r--r-- | dhall/build.rs | 2 | ||||
-rw-r--r-- | dhall/src/operations/kind.rs | 4 | ||||
-rw-r--r-- | dhall/src/syntax/ast/span.rs | 6 | ||||
-rw-r--r-- | dhall/src/syntax/text/dhall.abnf | 22 | ||||
-rw-r--r-- | dhall/src/syntax/text/parser.rs | 2 | ||||
-rw-r--r-- | dhall/tests/parser/failure/unit/WithPrecedence1.txt | 6 | ||||
-rw-r--r-- | dhall/tests/parser/failure/unit/WithPrecedence2.txt | 6 | ||||
-rw-r--r-- | dhall/tests/parser/failure/unit/WithPrecedence3.txt | 6 | ||||
-rw-r--r-- | dhall/tests/parser/success/unit/WithPrecedence1B.txt | 1 | ||||
-rw-r--r-- | dhall/tests/parser/success/unit/WithPrecedence2B.txt | 1 | ||||
-rw-r--r-- | dhall/tests/parser/success/unit/WithPrecedence3B.txt | 1 | ||||
-rw-r--r-- | dhall/tests/parser/success/unit/operators/PrecedenceEquivalenceB.txt | 1 |
12 files changed, 46 insertions, 12 deletions
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 |