From 588127bf4105d8d4629304521abc3d992326a63a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 18 Apr 2019 19:34:38 +0200 Subject: subst_shift in a single pass --- dhall_core/src/context.rs | 14 +++++++++++ dhall_core/src/core.rs | 62 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 5 deletions(-) (limited to 'dhall_core/src') diff --git a/dhall_core/src/context.rs b/dhall_core/src/context.rs index 877843d..b500226 100644 --- a/dhall_core/src/context.rs +++ b/dhall_core/src/context.rs @@ -43,6 +43,20 @@ impl Context { .collect(), ) } + + pub fn lookup_all<'a>(&'a self, k: &K) -> impl Iterator { + self.0.get(k).into_iter().flat_map(|v| v.iter()) + } + + pub fn iter<'a>(&'a self) -> impl Iterator { + self.0 + .iter() + .flat_map(|(k, vs)| vs.iter().map(move |v| (k, v))) + } + + pub fn iter_keys<'a>(&'a self) -> impl Iterator)> { + self.0.iter() + } } impl Context { diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index aeb6f23..56ab66c 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -1,7 +1,9 @@ #![allow(non_snake_case)] use std::collections::BTreeMap; +use std::collections::HashMap; use std::rc::Rc; +use crate::context::Context; use crate::visitor; use crate::*; @@ -486,6 +488,7 @@ fn shift_var(delta: isize, var: &V