diff options
author | Nadrieril | 2020-06-25 14:06:24 +0100 |
---|---|---|
committer | Nadrieril | 2020-06-25 15:12:09 +0100 |
commit | e3cdf3f386b6a682981e6bdf6ca6d215b0d0788d (patch) | |
tree | a29d47ff42b1252a6ba0835707351d42af38c0b4 /dhall/src/syntax/text | |
parent | 2cb647a1af179662832fb978b90f0b1df6e3dc18 (diff) |
spec: not all ABNF parsers like empty rules
Diffstat (limited to 'dhall/src/syntax/text')
-rw-r--r-- | dhall/src/syntax/text/dhall.abnf | 20 | ||||
-rw-r--r-- | dhall/src/syntax/text/dhall.pest.visibility | 8 | ||||
-rw-r--r-- | dhall/src/syntax/text/parser.rs | 37 |
3 files changed, 21 insertions, 44 deletions
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<UnspannedExpr> { - Ok(RecordLit(Default::default())) - } - - #[alias(record_type_or_literal)] - fn empty_record_type(input: ParseInput) -> ParseResult<UnspannedExpr> { - Ok(RecordType(Default::default())) - } - - #[alias(record_type_or_literal)] - fn non_empty_record_type_or_literal( - input: ParseInput, - ) -> ParseResult<UnspannedExpr> { + fn record_type_or_literal(input: ParseInput) -> ParseResult<UnspannedExpr> { 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<BTreeMap<Label, Expr>> { @@ -997,8 +990,7 @@ impl DhallParser { } fn union_type(input: ParseInput) -> ParseResult<UnspannedExpr> { - 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<Expr> { } #[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"); |