summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-06-13 09:26:56 -0700
committerMike Buland <mike@xagasoft.com>2026-06-13 09:26:56 -0700
commit038884232b6efbabb414cb011fa0fc4e3b4c8fd6 (patch)
treef960400d8733c50eb13d9a04986ed6e896d50542
parent6188fa4c32160846908e4ff7654c4ff7bc177797 (diff)
downloadcrimtag-038884232b6efbabb414cb011fa0fc4e3b4c8fd6.tar.gz
crimtag-038884232b6efbabb414cb011fa0fc4e3b4c8fd6.tar.bz2
crimtag-038884232b6efbabb414cb011fa0fc4e3b4c8fd6.tar.xz
crimtag-038884232b6efbabb414cb011fa0fc4e3b4c8fd6.zip
I did some silly things. This one doesn't build.
-rw-r--r--src/context.rs18
-rw-r--r--src/lib.rs11
2 files changed, 21 insertions, 8 deletions
diff --git a/src/context.rs b/src/context.rs
index 7484a1f..d322411 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -39,21 +39,27 @@ impl MappedStructure for Context {
39} 39}
40 40
41pub struct StatefulContext<'a, T: MappedStructure> { 41pub struct StatefulContext<'a, T: MappedStructure> {
42 root: &'a T, 42 pub root: &'a T,
43 current: &'a T, 43 local: &'a T,
44} 44}
45 45
46impl<'a, T: MappedStructure> StatefulContext<'a, T> { 46impl<'a, T: MappedStructure> StatefulContext<'a, T> {
47 pub fn root( root: &'a T ) -> Self { 47 pub fn root( root: &'a T ) -> Self {
48 Self { 48 Self {
49 root, current: root, 49 root, local: root,
50 } 50 }
51 } 51 }
52 52
53 pub fn local(&self, current: &'a T ) -> Self { 53 pub fn local(&self, local: &'a T ) -> Self {
54 Self { 54 Self {
55 root: self.root, 55 root: self.root,
56 current 56 local
57 }
58 }
59
60 pub fn full( root: &'a T, local: &'a T ) -> Self {
61 Self {
62 root, local
57 } 63 }
58 } 64 }
59} 65}
@@ -66,7 +72,7 @@ impl<'a, T: MappedStructure> MappedStructure for StatefulContext<'a,T> {
66 if id[0] == IdentifierValue::Root { 72 if id[0] == IdentifierValue::Root {
67 self.root.get_value( &id[1..] ) 73 self.root.get_value( &id[1..] )
68 } else { 74 } else {
69 self.current.get_value( id ) 75 self.local.get_value( id )
70 } 76 }
71 } 77 }
72} 78}
diff --git a/src/lib.rs b/src/lib.rs
index b413d2a..1ecd3b8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -46,7 +46,7 @@ impl View {
46 for output in &self.outputs { 46 for output in &self.outputs {
47 let mut buf = String::new(); 47 let mut buf = String::new();
48 let sc = StatefulContext::root( input ); 48 let sc = StatefulContext::root( input );
49 exec( &sc, &output.code, &mut buf )?; 49 exec::<T>( &sc, &output.code, &mut buf )?;
50 out_vars.insert( output.name.clone(), Value::String(buf) ); 50 out_vars.insert( output.name.clone(), Value::String(buf) );
51 } 51 }
52 Ok(out_vars) 52 Ok(out_vars)
@@ -201,7 +201,14 @@ fn exec<T: MappedStructure>(input: &StatefulContext<T>, tokens: &Vec<Token>, buf
201 let Value::List(list) = value { 201 let Value::List(list) = value {
202 for rec in &list { 202 for rec in &list {
203 if let Value::Dictionary(d) = rec { 203 if let Value::Dictionary(d) = rec {
204 exec( &input.local(d), code, buf )? 204 if matches!(d, Context) &&
205 matches!(input.root, Context) {
206 println!("Matches.");
207 } else {
208 println!("Doesn't match.");
209
210 }
211 exec( &StatefulContext::full(input.root,d), code, buf )?
205 } 212 }
206 } 213 }
207 } 214 }