diff options
author | Nadrieril Feneanar | 2020-03-04 22:41:41 +0000 |
---|---|---|
committer | GitHub | 2020-03-04 22:41:41 +0000 |
commit | 2ca97e97f1718141d826a78ab3da8197b2d55c69 (patch) | |
tree | 906e09e2686356c91a3a2ea4c373ad99827c7c13 /dhall/src/semantics/nze | |
parent | 5f720252a00bf2a45fef7f4c0855b79bd3932600 (diff) | |
parent | d5874d9dcedc15eaccb942cc8f45f26b2335ed2d (diff) |
Merge pull request #133 from basile-henry/record-projection-by-expression
Record projection by expression
Diffstat (limited to 'dhall/src/semantics/nze')
-rw-r--r-- | dhall/src/semantics/nze/normalize.rs | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/dhall/src/semantics/nze/normalize.rs b/dhall/src/semantics/nze/normalize.rs index 604db8f..dedd659 100644 --- a/dhall/src/semantics/nze/normalize.rs +++ b/dhall/src/semantics/nze/normalize.rs @@ -372,11 +372,42 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind { }, _ => Ret::Expr(expr), }, + PartialExpr(ExprKind::Projection(v2, _)) => { + return normalize_one_layer( + ExprKind::Field(v2.clone(), l.clone()), + env, + ) + } _ => Ret::Expr(expr), }, - ExprKind::ProjectionByExpr(_, _) => { - unimplemented!("selection by expression") - } + + ExprKind::ProjectionByExpr(ref v, ref t) => match dbg!(v).kind() { + RecordLit(kvs) => match dbg!(t).kind() { + RecordType(kts) => Ret::NirKind(RecordLit( + kts.iter() + .filter_map(|(l, _)| { + kvs.get(l).map(|x| (l.clone(), x.clone())) + }) + .collect(), + )), + _ => Ret::Expr(expr), + }, + _ => match dbg!(t).kind() { + RecordType(kts) => { + use crate::syntax::map::DupTreeSet; + use std::iter::FromIterator; + + let ts = DupTreeSet::from_iter( + kts.iter().map(|(l, _)| l.clone()), + ); + return normalize_one_layer( + ExprKind::Projection(v.clone(), ts), + env, + ); + } + _ => Ret::Expr(expr), + }, + }, ExprKind::Merge(ref handlers, ref variant, _) => { match handlers.kind() { |