diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-10-21 14:24:59 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-12 07:48:30 +0100 |
| commit | 7d219a98bd89dcade347c4b1adf4a1f6d5415ef6 (patch) | |
| tree | 589da7e23069b113e552ecfe2c22f7d18b3a51f4 /lib/xixanta/src/context.rs | |
| parent | ef22c6f29db80fd6daf3f14e516ddf190b0a1783 (diff) | |
| download | tools.nes-7d219a98bd89dcade347c4b1adf4a1f6d5415ef6.tar.gz tools.nes-7d219a98bd89dcade347c4b1adf4a1f6d5415ef6.zip | |
Allow for .byte/.address statements
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/context.rs')
| -rw-r--r-- | lib/xixanta/src/context.rs | 26 |
1 files changed, 18 insertions, 8 deletions
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 |
