From 6188fa4c32160846908e4ff7654c4ff7bc177797 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 13 Jun 2026 00:21:12 -0700 Subject: Adding root access in identifiers. There's an issue, it doesn't compile yet. --- src/context.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/context.rs') diff --git a/src/context.rs b/src/context.rs index e4cd5c2..7484a1f 100644 --- a/src/context.rs +++ b/src/context.rs @@ -5,11 +5,12 @@ use crate::{Identifier,IdentifierValue}; pub type Context = HashMap; pub trait MappedStructure { - fn get_value(&self, id: &Identifier) -> Option; + fn get_value(&self, id: &[IdentifierValue]) -> Option; + } impl MappedStructure for Context { - fn get_value(&self, id: &Identifier) -> Option { + fn get_value(&self, id: &[IdentifierValue]) -> Option { if id.len() == 0 { return None; } @@ -37,6 +38,39 @@ impl MappedStructure for Context { } } +pub struct StatefulContext<'a, T: MappedStructure> { + root: &'a T, + current: &'a T, +} + +impl<'a, T: MappedStructure> StatefulContext<'a, T> { + pub fn root( root: &'a T ) -> Self { + Self { + root, current: root, + } + } + + pub fn local(&self, current: &'a T ) -> Self { + Self { + root: self.root, + current + } + } +} + +impl<'a, T: MappedStructure> MappedStructure for StatefulContext<'a,T> { + fn get_value(&self, id: &[IdentifierValue]) -> Option { + if id.is_empty() { + return None; + } + if id[0] == IdentifierValue::Root { + self.root.get_value( &id[1..] ) + } else { + self.current.get_value( id ) + } + } +} + #[derive(Debug,Clone)] pub enum Value { Dictionary(Context), -- cgit v1.2.3