diff options
author | Nadrieril | 2019-04-04 22:28:00 +0200 |
---|---|---|
committer | Nadrieril | 2019-04-04 22:28:00 +0200 |
commit | e7a58d09748bd333f755a06090f378e31dc6617a (patch) | |
tree | e6a5087932b3d3dbcab90473858f6f6d02a2b860 | |
parent | 3e4b2dcb8c371045737901c0d49f9d9403109ea0 (diff) |
Import union rules from upstream grammar
-rw-r--r-- | dhall_core/src/parser.rs | 30 | ||||
-rw-r--r-- | dhall_parser/src/dhall.abnf | 17 |
2 files changed, 30 insertions, 17 deletions
diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index 60ab6ef..c569918 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -841,29 +841,41 @@ make_parser! { rule!(non_empty_union_type_or_literal <(Option<(Label, ParsedSubExpr)>, BTreeMap<Label, ParsedSubExpr>)>; children!( - [label(l), expression(e), union_type_entries(entries)] => { + [label(l), union_literal_variant_value((e, entries))] => { (Option::Some((l, rc(e))), entries) }, - [label(l), expression(e), non_empty_union_type_or_literal(rest)] => { + [label(l), union_type_or_literal_variant_type((e, rest))] => { let (x, mut entries) = rest; entries.insert(l, rc(e)); (x, entries) }, - [label(l), expression(e)] => { - let mut entries = BTreeMap::new(); - entries.insert(l, rc(e)); - (Option::None, entries) - }, )); - rule!(union_type_entries<BTreeMap<Label, ParsedSubExpr>>; children!( - [union_type_entry(entries)..] => entries.collect() + rule!(union_literal_variant_value + <(ParsedExpr, BTreeMap<Label, ParsedSubExpr>)>; + children!( + [expression(e), union_type_entry(entries)..] => { + (e, entries.collect()) + }, )); rule!(union_type_entry<(Label, ParsedSubExpr)>; children!( [label(name), expression(expr)] => (name, rc(expr)) )); + // TODO: unary union variants + rule!(union_type_or_literal_variant_type + <(ParsedExpr, + (Option<(Label, ParsedSubExpr)>, BTreeMap<Label, ParsedSubExpr>))>; + children!( + [expression(e), non_empty_union_type_or_literal(rest)] => { + (e, rest) + }, + [expression(e)] => { + (e, (Option::None, BTreeMap::new())) + }, + )); + rule!(non_empty_list_literal<ParsedExpr> as expression; children!( [expression(items)..] => Expr::NEListLit(items.map(rc).collect()) )); diff --git a/dhall_parser/src/dhall.abnf b/dhall_parser/src/dhall.abnf index 01ec6d8..7ad0b24 100644 --- a/dhall_parser/src/dhall.abnf +++ b/dhall_parser/src/dhall.abnf @@ -688,17 +688,18 @@ union-type-or-literal = empty-union-type = ""
non-empty-union-type-or-literal =
- any-label whsp
- ( "=" whsp expression union-type-entries
- / ":" whsp1 expression [ whsp "|" whsp non-empty-union-type-or-literal ]
- )
-union-type-entries = *(whsp "|" whsp union-type-entry)
+ any-label [ whsp ( union-literal-variant-value / union-type-or-literal-variant-type) ]
+
+; = True | ...
+union-literal-variant-value = "=" whsp expression *(whsp "|" whsp union-type-entry)
union-type-entry = any-label whsp ":" whsp1 expression
-; "[1, 2, 3]"
-; `empty-list-or-optional` handles empty lists
-non-empty-list-literal = "[" whsp expression whsp *("," whsp expression whsp) "]"
+; : Integer | ...
+; | ...
+union-type-or-literal-variant-type = [ ":" whsp1 expression ] [ whsp "|" whsp non-empty-union-type-or-literal ]
+non-empty-list-literal = "[" whsp expression whsp *("," whsp expression whsp) "]"
+
; This just adds surrounding whitespace for the top-level of the program
complete-expression = whsp expression whsp
|