From 7d219a98bd89dcade347c4b1adf4a1f6d5415ef6 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 21 Oct 2024 14:24:59 +0200 Subject: Allow for .byte/.address statements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/context.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'lib/xixanta/src/context.rs') diff --git a/lib/xixanta/src/context.rs b/lib/xixanta/src/context.rs index 8e77094..3fceab9 100644 --- a/lib/xixanta/src/context.rs +++ b/lib/xixanta/src/context.rs @@ -87,8 +87,10 @@ impl Context { Ok(()) } - /// Change the current context given a `node`. - pub fn change_context(&mut self, node: &PNode) -> Result<(), ContextError> { + /// Change the current context given a `node`. Returns a tuple which states: + /// 0. Whether the context has changed. + /// 1. Whether a caller can bundle nodes safely. + pub fn change_context(&mut self, node: &PNode) -> Result<(bool, bool), ContextError> { // The parser already guarantees that the control node is // from a function that we already know, so calling `unwrap` // is not dangerous. @@ -98,17 +100,25 @@ impl Context { // If the control function does not touch the context, leave early. if !control.touches_context { - return Ok(()); + return Ok((false, true)); } // And push/pop the context depending on the control being used. match node.value.value.as_str() { - ".macro" | ".proc" | ".scope" => self.context_push(&node.left.clone().unwrap()), - ".endmacro" | ".endproc" | ".endscope" => self.context_pop(&node.value)?, - _ => {} + ".macro" => { + self.context_push(&node.left.clone().unwrap()); + Ok((true, false)) + } + ".proc" | ".scope" => { + self.context_push(&node.left.clone().unwrap()); + Ok((true, true)) + } + ".endmacro" | ".endproc" | ".endscope" => { + self.context_pop(&node.value)?; + Ok((true, true)) + } + _ => Ok((false, true)), } - - Ok(()) } // Pushes a new context given a `node`, which holds the identifier of the -- cgit v1.2.3