From 7822c00e8689c99ded0a360026f4e7ace1f2c87f Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 16 Jul 2024 11:12:26 +0200 Subject: Add support for branching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a bare bones implementation of it, and there's a lot of nuance that it's being missed, but at least the fundamentals have been implemented already. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/context.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib/xixanta/src/context.rs') diff --git a/lib/xixanta/src/context.rs b/lib/xixanta/src/context.rs index 62ec7e0..aade200 100644 --- a/lib/xixanta/src/context.rs +++ b/lib/xixanta/src/context.rs @@ -3,10 +3,17 @@ use std::collections::HashMap; const GLOBAL_CONTEXT: &str = "Global"; +#[derive(Debug)] +pub struct PValue { + pub node: PString, + pub value: usize, + pub label: bool, +} + #[derive(Debug)] pub struct Context { stack: Vec, - map: HashMap>, + map: HashMap>, } impl Default for Context { @@ -27,18 +34,18 @@ impl Context { self.stack = vec![]; } - pub fn find(&self, name: &str) -> Option<&HashMap> { + pub fn find(&self, name: &str) -> Option<&HashMap> { self.map.get(name) } - pub fn current(&self) -> Option<&HashMap> { + pub fn current(&self) -> Option<&HashMap> { match self.stack.last() { Some(name) => self.map.get(name), None => self.map.get(GLOBAL_CONTEXT), } } - pub fn current_mut(&mut self) -> Option<&mut HashMap> { + pub fn current_mut(&mut self) -> Option<&mut HashMap> { match self.stack.last() { Some(name) => self.map.get_mut(name), None => self.map.get_mut(GLOBAL_CONTEXT), -- cgit v1.2.3