diff options
author | Nadrieril | 2019-04-16 22:06:01 +0200 |
---|---|---|
committer | Nadrieril | 2019-04-16 22:06:01 +0200 |
commit | 47d5dbcfffa7842466187197513ffa403a0fdb59 (patch) | |
tree | 9fb5c54ae85957c259cddf8bf81aeb3f51f731b4 | |
parent | d93be73890d0db0d34afaaebd3db1b87d68fb9b7 (diff) |
Handle nullary union variants
Closes #36
-rw-r--r-- | dhall/src/normalize.rs | 10 | ||||
-rw-r--r-- | dhall/src/typecheck.rs | 2 | ||||
-rw-r--r-- | 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<ParsedSubExpr<'a>>)>; 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<ParsedExpr<'a>> as expression; span; |