summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadrieril2020-04-11 15:41:21 +0100
committerNadrieril2020-06-25 15:12:09 +0100
commit72ad56209fe10e3120c19ca5b820ff267423ab1d (patch)
tree4728152ca9b5af25c293b3b16f921b5bcf32a1b8
parent4c80de149200a86f7fc13c725160dafb35d0ac08 (diff)
spec: fix precedence of `===` and `with`
Diffstat (limited to '')
-rw-r--r--CHANGELOG.md1
-rw-r--r--README.md2
m---------dhall-lang0
-rw-r--r--dhall/build.rs2
-rw-r--r--dhall/src/operations/kind.rs4
-rw-r--r--dhall/src/syntax/ast/span.rs6
-rw-r--r--dhall/src/syntax/text/dhall.abnf22
-rw-r--r--dhall/src/syntax/text/parser.rs2
-rw-r--r--dhall/tests/parser/failure/unit/WithPrecedence1.txt6
-rw-r--r--dhall/tests/parser/failure/unit/WithPrecedence2.txt6
-rw-r--r--dhall/tests/parser/failure/unit/WithPrecedence3.txt6
-rw-r--r--dhall/tests/parser/success/unit/WithPrecedence1B.txt1
-rw-r--r--dhall/tests/parser/success/unit/WithPrecedence2B.txt1
-rw-r--r--dhall/tests/parser/success/unit/WithPrecedence3B.txt1
-rw-r--r--dhall/tests/parser/success/unit/operators/PrecedenceEquivalenceB.txt1
-rw-r--r--tests_buffer1
16 files changed, 48 insertions, 14 deletions
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
-Subproject a53a620df888b97fe23598356be7157bda0c8e2
+Subproject b788d6dd2150eec49b6bdd0cc7de50e403fad88
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/