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` --- dhall/src/syntax/ast/span.rs | 6 ++++++ dhall/src/syntax/text/dhall.abnf | 22 ++++++++++++++-------- dhall/src/syntax/text/parser.rs | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'dhall/src/syntax') 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 -- cgit v1.2.3 From 2cb647a1af179662832fb978b90f0b1df6e3dc18 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 25 Jun 2020 13:55:49 +0100 Subject: spec: allow quoted labels to be empty --- dhall/src/syntax/text/dhall.abnf | 2 +- dhall/src/syntax/text/printer.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'dhall/src/syntax') diff --git a/dhall/src/syntax/text/dhall.abnf b/dhall/src/syntax/text/dhall.abnf index 861f7b3..05d76e6 100644 --- a/dhall/src/syntax/text/dhall.abnf +++ b/dhall/src/syntax/text/dhall.abnf @@ -206,7 +206,7 @@ quoted-label-char = ; %x60 = '`' / %x61-7E -quoted-label = 1*quoted-label-char +quoted-label = *quoted-label-char ; NOTE: Dhall does not support Unicode labels, mainly to minimize the potential ; for code obfuscation diff --git a/dhall/src/syntax/text/printer.rs b/dhall/src/syntax/text/printer.rs index ccba385..8815d69 100644 --- a/dhall/src/syntax/text/printer.rs +++ b/dhall/src/syntax/text/printer.rs @@ -154,7 +154,9 @@ fn fmt_label(label: &Label, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { | "True" | "False" | "Some" => true, _ => Builtin::parse(&s).is_some(), }; - if !is_reserved && s.chars().all(|c| c.is_ascii_alphanumeric()) { + if s.is_empty() { + write!(f, "``") + } else if !is_reserved && s.chars().all(|c| c.is_ascii_alphanumeric()) { write!(f, "{}", s) } else { write!(f, "`{}`", s) -- cgit v1.2.3 From e3cdf3f386b6a682981e6bdf6ca6d215b0d0788d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 25 Jun 2020 14:06:24 +0100 Subject: spec: not all ABNF parsers like empty rules --- dhall/src/syntax/text/dhall.abnf | 20 ++++++---------- dhall/src/syntax/text/dhall.pest.visibility | 8 ++----- dhall/src/syntax/text/parser.rs | 37 ++++++++++------------------- 3 files changed, 21 insertions(+), 44 deletions(-) (limited to 'dhall/src/syntax') diff --git a/dhall/src/syntax/text/dhall.abnf b/dhall/src/syntax/text/dhall.abnf index 05d76e6..362a436 100644 --- a/dhall/src/syntax/text/dhall.abnf +++ b/dhall/src/syntax/text/dhall.abnf @@ -896,11 +896,9 @@ primitive-expression = record-type-or-literal = empty-record-literal - / non-empty-record-type-or-literal - / empty-record-type + / [non-empty-record-type-or-literal] empty-record-literal = "=" -empty-record-type = "" non-empty-record-type-or-literal = (non-empty-record-type / non-empty-record-literal) @@ -913,22 +911,18 @@ record-type-entry = any-label-or-some whsp ":" whsp1 expression non-empty-record-literal = record-literal-entry *(whsp "," whsp record-literal-entry) +; If the `record-literal-normal-entry` is absent, that represents a punned +; record entry, such as in `{ x }`, which is a short-hand for `{ x = x }` record-literal-entry = - any-label-or-some (record-literal-normal-entry / record-literal-punned-entry) + any-label-or-some [record-literal-normal-entry] record-literal-normal-entry = *(whsp "." whsp any-label-or-some) whsp "=" whsp expression -record-literal-punned-entry = "" - +; If the `union-type-entry` is absent, that represents an empty union +; alternative, such as in `< Heads | Tails >` union-type = - non-empty-union-type - / empty-union-type - -empty-union-type = "" - -non-empty-union-type = - union-type-entry *(whsp "|" whsp union-type-entry) + [union-type-entry *(whsp "|" whsp union-type-entry)] ; x : Natural ; x diff --git a/dhall/src/syntax/text/dhall.pest.visibility b/dhall/src/syntax/text/dhall.pest.visibility index b2114ce..2fee160 100644 --- a/dhall/src/syntax/text/dhall.pest.visibility +++ b/dhall/src/syntax/text/dhall.pest.visibility @@ -178,19 +178,15 @@ selector labels # type_selector primitive_expression -# record_type_or_literal +record_type_or_literal empty_record_literal -empty_record_type -non_empty_record_type_or_literal +# non_empty_record_type_or_literal 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 union_type_entry non_empty_list_literal # complete_expression diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index e870db3..1c51ca2 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -909,26 +909,19 @@ impl DhallParser { )) } - #[alias(record_type_or_literal)] - fn empty_record_literal(input: ParseInput) -> ParseResult { - Ok(RecordLit(Default::default())) - } - - #[alias(record_type_or_literal)] - fn empty_record_type(input: ParseInput) -> ParseResult { - Ok(RecordType(Default::default())) - } - - #[alias(record_type_or_literal)] - fn non_empty_record_type_or_literal( - input: ParseInput, - ) -> ParseResult { + fn record_type_or_literal(input: ParseInput) -> ParseResult { Ok(match_nodes!(input.children(); + [empty_record_literal(_)] => RecordLit(Default::default()), [non_empty_record_type(map)] => RecordType(map), [non_empty_record_literal(map)] => RecordLit(map), + [] => RecordType(Default::default()), )) } + fn empty_record_literal(input: ParseInput) -> ParseResult<()> { + Ok(()) + } + fn non_empty_record_type( input: ParseInput, ) -> ParseResult> { @@ -997,8 +990,7 @@ impl DhallParser { } fn union_type(input: ParseInput) -> ParseResult { - let map = match_nodes!(input.children(); - [empty_union_type(_)] => Default::default(), + Ok(match_nodes!(input.children(); [union_type_entry(entries)..] => { let mut map = BTreeMap::default(); for (l, t) in entries { @@ -1015,14 +1007,9 @@ impl DhallParser { } } } - map + UnionType(map) }, - ); - Ok(UnionType(map)) - } - - fn empty_union_type(_input: ParseInput) -> ParseResult<()> { - Ok(()) + )) } fn union_type_entry( @@ -1065,7 +1052,7 @@ pub fn parse_expr(input_str: &str) -> ParseResult { } #[test] -#[ignore] +#[cfg_attr(windows, ignore)] // Check that the local copy of the grammar file is in sync with the one from dhall-lang. fn test_grammar_files_in_sync() { use std::process::Command; @@ -1079,8 +1066,8 @@ fn test_grammar_files_in_sync() { .arg("--ignore-space-change") .arg("--color") .arg("--") - .arg(spec_abnf_path) .arg(local_abnf_path) + .arg(spec_abnf_path) .output() .expect("failed to run `git diff` command"); -- cgit v1.2.3 From 812fb88102082493d1176aab7ee61b5339821492 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 25 Jun 2020 14:09:24 +0100 Subject: spec: ensure `keyword` rule only matches keywords --- dhall/src/syntax/text/dhall.abnf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'dhall/src/syntax') diff --git a/dhall/src/syntax/text/dhall.abnf b/dhall/src/syntax/text/dhall.abnf index 362a436..26f6eab 100644 --- a/dhall/src/syntax/text/dhall.abnf +++ b/dhall/src/syntax/text/dhall.abnf @@ -370,7 +370,9 @@ NaN = %x4e.61.4e Some = %x53.6f.6d.65 toMap = %x74.6f.4d.61.70 assert = %x61.73.73.65.72.74 -forall = %x2200 / %x66.6f.72.61.6c.6c ; "∀" / "forall" +forall-keyword = %x66.6f.72.61.6c.6c ; "forall" +forall-symbol = %x2200 ; "∀" +forall = forall-symbol / forall-keyword with = %x77.69.74.68 ; Unused rule that could be used as negative lookahead in the @@ -382,7 +384,7 @@ keyword = / assert / as / Infinity / NaN / merge / Some / toMap - / forall + / forall-keyword / with builtin = -- cgit v1.2.3 From 8fd2fb4871335c72b9448da4a66144fd7f986f09 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 25 Jun 2020 14:21:02 +0100 Subject: spec!: remove the ability to quote paths in URLs --- dhall/src/syntax/text/dhall.abnf | 9 ++------- dhall/src/syntax/text/dhall.pest.visibility | 2 +- dhall/src/syntax/text/parser.rs | 11 +++++------ 3 files changed, 8 insertions(+), 14 deletions(-) (limited to 'dhall/src/syntax') diff --git a/dhall/src/syntax/text/dhall.abnf b/dhall/src/syntax/text/dhall.abnf index 26f6eab..4061de2 100644 --- a/dhall/src/syntax/text/dhall.abnf +++ b/dhall/src/syntax/text/dhall.abnf @@ -582,7 +582,6 @@ scheme = %x68.74.74.70 [ %x73 ] ; "http" [ "s" ] ; NOTE: This does not match the official grammar for a URI. Specifically: ; -; * path segments may be quoted instead of using percent-encoding ; * this does not support fragment identifiers, which have no meaning within ; Dhall expressions and do not affect import resolution ; * the characters "(" ")" and "," are not included in the `sub-delims` rule: @@ -595,13 +594,9 @@ scheme = %x68.74.74.70 [ %x73 ] ; "http" [ "s" ] ; ; Reserved characters in quoted path components should be percent-encoded ; according to https://tools.ietf.org/html/rfc3986#section-2 -http-raw = scheme "://" authority url-path [ "?" query ] +http-raw = scheme "://" authority path-abempty [ "?" query ] -; Temporary rule to allow old-style `path-component`s and RFC3986 `segment`s in -; the same grammar. Eventually we can just use `path-abempty` from the same -; RFC. See issue #581 - -url-path = *(path-component / "/" segment) +path-abempty = *( "/" segment ) ; NOTE: Backtrack if parsing the optional user info prefix fails authority = [ userinfo "@" ] host [ ":" port ] diff --git a/dhall/src/syntax/text/dhall.pest.visibility b/dhall/src/syntax/text/dhall.pest.visibility index 2fee160..6de7dd2 100644 --- a/dhall/src/syntax/text/dhall.pest.visibility +++ b/dhall/src/syntax/text/dhall.pest.visibility @@ -120,7 +120,7 @@ home_path absolute_path scheme http_raw -url_path +path_abempty authority # userinfo # host diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index 1c51ca2..06c1ac3 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -514,14 +514,14 @@ impl DhallParser { fn http_raw(input: ParseInput) -> ParseResult> { Ok(match_nodes!(input.into_children(); - [scheme(sch), authority(auth), url_path(p)] => URL { + [scheme(sch), authority(auth), path_abempty(p)] => URL { scheme: sch, authority: auth, path: p, query: None, headers: None, }, - [scheme(sch), authority(auth), url_path(p), query(q)] => URL { + [scheme(sch), authority(auth), path_abempty(p), query(q)] => URL { scheme: sch, authority: auth, path: p, @@ -531,10 +531,10 @@ impl DhallParser { )) } - fn url_path(input: ParseInput) -> ParseResult { + fn path_abempty(input: ParseInput) -> ParseResult { Ok(match_nodes!(input.into_children(); - [path_component(components)..] => { - let mut file_path: Vec<_> = components.collect(); + [segment(segments)..] => { + let mut file_path: Vec<_> = segments.collect(); // An empty path normalizes to "/" if file_path.is_empty() { file_path = vec!["".to_owned()]; @@ -548,7 +548,6 @@ impl DhallParser { Ok(input.as_str().to_owned()) } - #[alias(path_component)] fn segment(input: ParseInput) -> ParseResult { Ok(input.as_str().to_string()) } -- cgit v1.2.3 From ba61655649f4dd6117125430e49aba5ce4f92392 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 25 Jun 2020 14:22:48 +0100 Subject: spec: remove Unicode character from `dhall.abnf` --- dhall/src/syntax/text/dhall.abnf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dhall/src/syntax') diff --git a/dhall/src/syntax/text/dhall.abnf b/dhall/src/syntax/text/dhall.abnf index 4061de2..173209c 100644 --- a/dhall/src/syntax/text/dhall.abnf +++ b/dhall/src/syntax/text/dhall.abnf @@ -371,7 +371,7 @@ Some = %x53.6f.6d.65 toMap = %x74.6f.4d.61.70 assert = %x61.73.73.65.72.74 forall-keyword = %x66.6f.72.61.6c.6c ; "forall" -forall-symbol = %x2200 ; "∀" +forall-symbol = %x2200 ; Unicode FOR ALL forall = forall-symbol / forall-keyword with = %x77.69.74.68 -- cgit v1.2.3 From ac7e39a752c41c06155e27e84404c67c1341065d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 25 Jun 2020 14:28:48 +0100 Subject: spec!: remove Optional/build and Optional/fold --- dhall/src/syntax/text/dhall.abnf | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'dhall/src/syntax') diff --git a/dhall/src/syntax/text/dhall.abnf b/dhall/src/syntax/text/dhall.abnf index 173209c..37ec43b 100644 --- a/dhall/src/syntax/text/dhall.abnf +++ b/dhall/src/syntax/text/dhall.abnf @@ -387,6 +387,9 @@ keyword = / forall-keyword / with +; Note that there is a corresponding parser test in +; `tests/parser/success/builtinsA.dhall`. Please update it when +; you modify this `builtin` rule. builtin = Natural-fold / Natural-build @@ -408,8 +411,6 @@ builtin = / List-last / List-indexed / List-reverse - / Optional-fold - / Optional-build / Text-show / Bool / True @@ -462,8 +463,6 @@ List-head = %x4c.69.73.74.2f.68.65.61.64 List-last = %x4c.69.73.74.2f.6c.61.73.74 List-indexed = %x4c.69.73.74.2f.69.6e.64.65.78.65.64 List-reverse = %x4c.69.73.74.2f.72.65.76.65.72.73.65 -Optional-fold = %x4f.70.74.69.6f.6e.61.6c.2f.66.6f.6c.64 -Optional-build = %x4f.70.74.69.6f.6e.61.6c.2f.62.75.69.6c.64 Text-show = %x54.65.78.74.2f.73.68.6f.77 ; Operators -- cgit v1.2.3