summaryrefslogtreecommitdiff
path: root/dhall_core
diff options
context:
space:
mode:
authorNadrieril2019-04-04 22:28:00 +0200
committerNadrieril2019-04-04 22:28:00 +0200
commite7a58d09748bd333f755a06090f378e31dc6617a (patch)
treee6a5087932b3d3dbcab90473858f6f6d02a2b860 /dhall_core
parent3e4b2dcb8c371045737901c0d49f9d9403109ea0 (diff)
Import union rules from upstream grammar
Diffstat (limited to 'dhall_core')
-rw-r--r--dhall_core/src/parser.rs30
1 files changed, 21 insertions, 9 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())
));