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/lib.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 84a5a43..b413d2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ mod context; pub use error::{CrimError,CrimResult}; pub use position::*; -pub use context::{Context,Value,MappedStructure}; +pub use context::{Context,Value,MappedStructure,StatefulContext}; #[derive(Debug)] pub struct Crimtag { @@ -41,11 +41,12 @@ struct View { } impl View { - fn process(&self, input: &impl MappedStructure) -> CrimResult { + fn process(&self, input: &T) -> CrimResult { let mut out_vars = Context::new(); for output in &self.outputs { let mut buf = String::new(); - exec( input, &output.code, &mut buf )?; + let sc = StatefulContext::root( input ); + exec( &sc, &output.code, &mut buf )?; out_vars.insert( output.name.clone(), Value::String(buf) ); } Ok(out_vars) @@ -68,8 +69,9 @@ enum Token { Text(String), } -#[derive(Debug,Clone)] +#[derive(Debug,Clone,PartialEq)] pub enum IdentifierValue { + Root, Name(String), Index(usize), } @@ -161,7 +163,7 @@ impl Crimtag { } } - pub fn render_partial(&self, view: &str, input: &impl MappedStructure ) -> CrimResult { + pub fn render_partial(&self, view: &str, input: &T ) -> CrimResult { if let Some(view) = self.views.get(view) { return view.process( input ) } else { @@ -169,7 +171,7 @@ impl Crimtag { } } - pub fn render(&self, view: &str, input: &impl MappedStructure ) -> CrimResult { + pub fn render(&self, view: &str, input: &T ) -> CrimResult { if let Some(view) = self.views.get( view ) { //println!("::Token tree::\n{:?}", view ); let mut output = view.process( input )?; @@ -191,7 +193,7 @@ impl Crimtag { } } -fn exec(input: &impl MappedStructure, tokens: &Vec, buf: &mut String) -> CrimResult<()> { +fn exec(input: &StatefulContext, tokens: &Vec, buf: &mut String) -> CrimResult<()> { for token in tokens { match token { Token::Loop(ident,code) => { @@ -199,7 +201,7 @@ fn exec(input: &impl MappedStructure, tokens: &Vec, buf: &mut String) -> let Value::List(list) = value { for rec in &list { if let Value::Dictionary(d) = rec { - exec( d, code, buf )? + exec( &input.local(d), code, buf )? } } } -- cgit v1.2.3