From e7d815c73701377ad3f370e5e5e2b3296627a7ae Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 15 Jan 2025 22:36:36 +0100 Subject: Fix error with strings containing equal operator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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à --- lib/xixanta/src/parser.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'lib/xixanta/src/parser.rs') 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\"" ); } -- cgit v1.2.3