From 68745e87a73ed7cfa305ee5319b85aeef85eb088 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 14 Jun 2026 07:09:59 -0700 Subject: In progress... --- src/context.rs | 46 +++++++++++++++++++++++++++++++++++++++++++++- src/lib.rs | 2 +- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/context.rs b/src/context.rs index d322411..2f12ea9 100644 --- a/src/context.rs +++ b/src/context.rs @@ -6,7 +6,10 @@ pub type Context = HashMap; pub trait MappedStructure { fn get_value(&self, id: &[IdentifierValue]) -> Option; - + fn get_iterable(&self, id: &[IdentifierValue]) -> Option + where + T: IntoIterator, + T::Item: MappedStructure; } impl MappedStructure for Context { @@ -36,6 +39,40 @@ impl MappedStructure for Context { return cur_val.cloned(); } + + fn get_iter(&self, id: &[IdentifierValue]) -> Option + where + T: IntoIterator, + T::Item: MappedStructure, { + if id.len() == 0 { + return None; + } + let mut cur_val : Option<&Value> = if let IdentifierValue::Name(s) = &id[0] { + self.get(s) + } else { + return None; + }; + if cur_val.is_none() { + return None; + } + + for idx in 1..id.len() { + if let IdentifierValue::Name(s) = &id[idx] && + let Some(Value::Dictionary(d)) = &cur_val { + cur_val.replace( if let Some(v) = d.get(s) { + v + } else { + return None; + }); + } + } + + if let Some(Value::List(l)) = cur_val { + return l.into + } + + return cur_val.cloned(); + } } pub struct StatefulContext<'a, T: MappedStructure> { @@ -75,6 +112,13 @@ impl<'a, T: MappedStructure> MappedStructure for StatefulContext<'a,T> { self.local.get_value( id ) } } + + fn get_iter(&self, id: &[IdentifierValue]) -> Option + where + U: IntoIterator, + U::Item: MappedStructure, { + None + } } #[derive(Debug,Clone)] diff --git a/src/lib.rs b/src/lib.rs index 1ecd3b8..362e017 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -208,7 +208,7 @@ fn exec(input: &StatefulContext, tokens: &Vec, buf println!("Doesn't match."); } - exec( &StatefulContext::full(input.root,d), code, buf )? + exec( &StatefulContext::root(d), code, buf )? } } } -- cgit v1.2.3