From 47d5dbcfffa7842466187197513ffa403a0fdb59 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 16 Apr 2019 22:06:01 +0200 Subject: Handle nullary union variants Closes #36 --- dhall/src/normalize.rs | 10 +++++----- dhall/src/typecheck.rs | 2 +- dhall_core/src/parser.rs | 9 ++++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs index fa669d8..7f56669 100644 --- a/dhall/src/normalize.rs +++ b/dhall/src/normalize.rs @@ -667,12 +667,12 @@ mod spec_tests { norm!(success_unit_True, "unit/True"); norm!(success_unit_Type, "unit/Type"); norm!(success_unit_TypeAnnotation, "unit/TypeAnnotation"); - // norm!(success_unit_UnionNormalizeAlternatives, "unit/UnionNormalizeAlternatives"); + norm!(success_unit_UnionNormalizeAlternatives, "unit/UnionNormalizeAlternatives"); norm!(success_unit_UnionNormalizeArguments, "unit/UnionNormalizeArguments"); - // norm!(success_unit_UnionProjectConstructor, "unit/UnionProjectConstructor"); - // norm!(success_unit_UnionSortAlternatives, "unit/UnionSortAlternatives"); - // norm!(success_unit_UnionType, "unit/UnionType"); + norm!(success_unit_UnionProjectConstructor, "unit/UnionProjectConstructor"); + norm!(success_unit_UnionSortAlternatives, "unit/UnionSortAlternatives"); + norm!(success_unit_UnionType, "unit/UnionType"); norm!(success_unit_UnionTypeEmpty, "unit/UnionTypeEmpty"); - // norm!(success_unit_UnionTypeNormalizeArguments, "unit/UnionTypeNormalizeArguments"); + norm!(success_unit_UnionTypeNormalizeArguments, "unit/UnionTypeNormalizeArguments"); norm!(success_unit_Variable, "unit/Variable"); } diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index d9566d0..ffa149b 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -1021,7 +1021,7 @@ mod spec_tests { // tc_success!(tc_success_simple_kindParameter, "simple/kindParameter"); // tc_success!(tc_success_simple_mergeEquivalence, "simple/mergeEquivalence"); // tc_success!(tc_success_simple_mixedFieldAccess, "simple/mixedFieldAccess"); - // tc_success!(tc_success_simple_unionsOfTypes, "simple/unionsOfTypes"); + tc_success!(tc_success_simple_unionsOfTypes, "simple/unionsOfTypes"); // tc_failure!(tc_failure_combineMixedRecords, "combineMixedRecords"); // tc_failure!(tc_failure_duplicateFields, "duplicateFields"); diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index a335ccc..b463073 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -895,7 +895,8 @@ make_parser! { )); rule!(union_type_entry<(Label, Option>)>; children!( - [label(name), expression(expr)] => (name, Option::Some(rc(expr))) + [label(name), expression(expr)] => (name, Option::Some(rc(expr))), + [label(name)] => (name, Option::None), )); // TODO: unary union variants @@ -910,6 +911,12 @@ make_parser! { [expression(e)] => { (Option::Some(rc(e)), (Option::None, BTreeMap::new())) }, + [non_empty_union_type_or_literal(rest)] => { + (Option::None, rest) + }, + [] => { + (Option::None, (Option::None, BTreeMap::new())) + }, )); rule!(non_empty_list_literal> as expression; span; -- cgit v1.2.3