From d93be73890d0db0d34afaaebd3db1b87d68fb9b7 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 16 Apr 2019 21:54:32 +0200 Subject: Prepare for nullary union variants --- dhall_core/src/visitor.rs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'dhall_core/src/visitor.rs') diff --git a/dhall_core/src/visitor.rs b/dhall_core/src/visitor.rs index 3b06f8b..1ea3fb1 100644 --- a/dhall_core/src/visitor.rs +++ b/dhall_core/src/visitor.rs @@ -106,6 +106,27 @@ where .map(|(k, x)| Ok((v.visit_label(k)?, v.visit_subexpr(x)?))) .collect() } + fn btoptmap<'a, V, SE, L, N, E, SE2, L2, N2, E2>( + x: &'a BTreeMap>, + mut v: V, + ) -> Result>, V::Error> + where + L: Ord, + L2: Ord, + V: ExprFFallibleVisitor<'a, SE, SE2, L, L2, N, N2, E, E2>, + { + x.iter() + .map(|(k, x)| { + Ok(( + v.visit_label(k)?, + match x { + Some(x) => Some(v.visit_subexpr(x)?), + None => None, + }, + )) + }) + .collect() + } let mut v = self; use crate::ExprF::*; @@ -156,10 +177,12 @@ where NEOptionalLit(e) => NEOptionalLit(v.visit_subexpr(e)?), RecordType(kts) => RecordType(btmap(kts, v)?), RecordLit(kvs) => RecordLit(btmap(kvs, v)?), - UnionType(kts) => UnionType(btmap(kts, v)?), - UnionLit(k, x, kvs) => { - UnionLit(v.visit_label(k)?, v.visit_subexpr(x)?, btmap(kvs, v)?) - } + UnionType(kts) => UnionType(btoptmap(kts, v)?), + UnionLit(k, x, kvs) => UnionLit( + v.visit_label(k)?, + v.visit_subexpr(x)?, + btoptmap(kvs, v)?, + ), Merge(x, y, t) => Merge( v.visit_subexpr(x)?, v.visit_subexpr(y)?, -- cgit v1.2.3