diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-05 08:57:26 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-05 08:57:26 +0100 |
| commit | ec8b709fa24c3386dae919cf0c33a51468efbae5 (patch) | |
| tree | 846b5354e75efb776eac66e5c781662c1800f01c /lib/xixanta/src/parser.rs | |
| parent | 1f8a6becc7cdca285333d51b4548373974df7dd3 (diff) | |
| download | tools.nes-ec8b709fa24c.tar.gz tools.nes-ec8b709fa24c.zip | |
Implement block bodies inside of the assembler
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à <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/parser.rs')
| -rw-r--r-- | lib/xixanta/src/parser.rs | 28 |
1 files changed, 15 insertions, 13 deletions
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"); |
