From ec8b709fa24c3386dae919cf0c33a51468efbae5 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Sun, 5 Jan 2025 08:57:26 +0100 Subject: Implement block bodies inside of the assembler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Following 1f8a6becc7cd ("parser: Implement block bodies"), the support for the new way of managing block bodies have also been added into the assembler. There are still some things to iron out, but they will be fixed in later commits. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/parser.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'lib/xixanta/src/parser.rs') diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs index bcc4b4e..0de0bd8 100644 --- a/lib/xixanta/src/parser.rs +++ b/lib/xixanta/src/parser.rs @@ -313,6 +313,7 @@ impl Parser { if line.contains('=') { self.parse_assignment(line, id) } else { + // TODO: move out into its own thing... let node = self.parse_expression_with_identifier(id, line)?; let node_type = node.node_type.clone(); let body_type = node.body_type(); @@ -342,17 +343,18 @@ impl Parser { )); } + // Note that empty bodies are possible. This is left + // to the caller (e.g. assembler) to decide whether + // it makes sense or not. let nodes = self.nodes.pop().unwrap(); - if !nodes.is_empty() { - self.nodes.last_mut().unwrap().last_mut().unwrap().right = - Some(Box::new(PNode { - node_type: NodeType::ControlBody, - value: PString::default(), - left: None, - right: None, - args: Some(nodes), - })); - } + self.nodes.last_mut().unwrap().last_mut().unwrap().right = + Some(Box::new(PNode { + node_type: NodeType::ControlBody, + value: PString::default(), + left: None, + right: None, + args: Some(nodes), + })); self.nodes.last_mut().unwrap().push(node); } NodeBodyType::None => self.nodes.last_mut().unwrap().push(node), @@ -1806,7 +1808,7 @@ mod tests { line, ".scope", ); - assert!(node.right.is_none()); + assert!(node.right.is_some()); assert!(node.args.is_none()); let left = node.left.clone().unwrap(); @@ -1840,7 +1842,7 @@ mod tests { line, ".macro", ); - assert!(node.right.is_none()); + assert!(node.right.is_some()); let left = node.left.clone().unwrap(); assert_node(&left, NodeType::Value, line, "Macro"); @@ -1877,7 +1879,7 @@ mod tests { line, ".macro", ); - assert!(node.right.is_none()); + assert!(node.right.is_some()); let left = node.left.clone().unwrap(); assert_node(&left, NodeType::Value, line, "Macro"); -- cgit v1.2.3