aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/parser.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-01-15 22:36:36 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-01-15 22:36:36 +0100
commite7d815c73701377ad3f370e5e5e2b3296627a7ae (patch)
tree0dfb48bcb913a7f967ea04a49a2b34916cffcfdd /lib/xixanta/src/parser.rs
parente27a1593c8d819b275b4e6da284e0cd39f12b5ac (diff)
downloadtools.nes-e7d815c73701377ad3f370e5e5e2b3296627a7ae.tar.gz
tools.nes-e7d815c73701377ad3f370e5e5e2b3296627a7ae.zip
Fix error with strings containing equal operator
As with e27a1593c8d8 ("Allow semicolons inside of strings"), the parser was too naive and regarded any '=' operator as part of an assignment, despite that it could be art of string literal. Luckily the fix was already done inside of the parsing of assignments, we just needed to move it up. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/parser.rs')
-rw-r--r--lib/xixanta/src/parser.rs17
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs
index 37a5931..a91ce8f 100644
--- a/lib/xixanta/src/parser.rs
+++ b/lib/xixanta/src/parser.rs
@@ -388,7 +388,10 @@ impl Parser {
match INSTRUCTIONS.get(&id.value) {
Some(_) => Ok(self.parse_instruction(line, id)?),
None => {
- if line.contains('=') {
+ // Skip whitespaces and check if we have a '=' sign. If that's
+ // the case, then it's an assignment.
+ self.skip_whitespace(line);
+ if line.chars().nth(self.offset).unwrap_or_default() == '=' {
Ok(self.parse_assignment(line, id)?)
} else {
self.parse_other(line, id)
@@ -538,12 +541,6 @@ impl Parser {
return Err(self.parser_error(&msg));
}
- // Skip whitespaces and make sure that we have a '=' sign.
- self.skip_whitespace(line);
- if line.chars().nth(self.offset).unwrap_or_default() != '=' {
- return Err(self.parser_error(format!("unknown instruction '{}'", id.value).as_str()));
- }
-
// Skip the '=' sign and any possible whitespaces.
self.next();
self.skip_whitespace(line);
@@ -1621,17 +1618,17 @@ mod tests {
#[test]
fn parse_string() {
let mut parser = Parser::default();
- let line = ".asciiz \"a: b, c; d\" ; Comment";
+ let line = ".asciiz \"=a: b, c; d\" ; Comment";
assert!(parser.parse(line.as_bytes(), SourceInfo::default()).is_ok());
let stmt = parser.nodes.last().unwrap().last().unwrap();
let inner = stmt.args.as_ref().unwrap().first().unwrap();
assert_eq!(inner.node_type, NodeType::Value);
- assert_eq!(inner.value.value, "\"a: b, c; d\"");
+ assert_eq!(inner.value.value, "\"=a: b, c; d\"");
assert_eq!(
line.get(inner.value.start..inner.value.end).unwrap(),
- "\"a: b, c; d\""
+ "\"=a: b, c; d\""
);
}