From 7c01c29cec6f5fcc94abcd154c47d2c78f765a78 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 23 Apr 2026 22:17:23 +0200 Subject: Ensure expressions in arguments are fully parsed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Imagine the following scenario: lda #.lobyte(@address + 1) Here we have an immediate which comes from the .lobyte call. That being said, since this is using the '#' symbol, we look ahead after noticing it just in case we need to disambiguate some scenarios. When a parenthesis is found, in extract_paren_expression() we temporarily discard the looking ahead status as expressions inside of parenthesis are no longer affected by any hypothetical external ambiguity. This, though, was not being done in parse_arguments(), which is the function that would be called in the above scenario. Hence, ensure that we temporarily decrease the look ahead status for the inner arguments, and then increase it back when we are done. This way, when the parser finds '@address', it will no longer go the "we have found a 'value', refrain from ambiguities and return early" route, and it will check for any binary expression. Note that all this dance actually applied here, as binary operations are a source of ambiguities, and the look ahead mechanism was brought about because of these kinds of expressions. Hence, it's not like the look ahead mechanism is troublesome in on itself, we just missed the special handling on this specific scenario. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/assembler.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/xixanta/src/assembler.rs') diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 2f0292e..54ba4c3 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -4629,6 +4629,19 @@ JAL procedure } } + #[test] + fn lobyte_with_arithmetic() { + let res = just_bundles( + r#"lda #.lobyte(@address - 1) +@address: +nop + "#, + ); + + assert_eq!(res[0].bytes[0], 0xA9); + assert_eq!(res[0].bytes[1], 0x01); + } + #[test] fn warnings_on_empty_proc_scope_macro() { let res = just_assemble( -- cgit v1.2.3