Fix five defects the port uncovered in the reference parser and scanner

Chained subtraction and exponentiation fold left instead of abandoning the
rest of the line -- `1 - 2 - 3` gave -1 and dropped the `- 3`. A unary leaf's
operand moves to .left, so a negative literal is one argument again and a
second argument no longer overwrites it. An operator in a line's final column
survives. Hex literals reach the parser whole. A leading zero is padding, not
a radix.

Item 16 stays pinned: the fix works and costs an upstream golden case, which
is a decision rather than a defect.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-31 11:35:14 -04:00
parent f24201fdef
commit 1eb8f9ffaa
14 changed files with 272 additions and 167 deletions

View File

@@ -36,14 +36,20 @@ int main(void)
TEST_REQUIRE_INT(LEAVES[1].literal_int, 255);
/*
* A leading zero selects base 8, so 010 is 8 and 08 will not parse.
* Commodore BASIC has no octal literals; this is TODO.md section 12 item 10,
* reproduced deliberately and pinned here so the eventual fix is a
* deliberate change to this assertion.
* A leading zero is padding, not a radix -- TODO.md section 6 item 10's
* regression test. The reference selects base 8 for any lexeme starting with
* '0' (basicgrammar.go:224), so 010 was 8 and 08 would not parse at all.
* Commodore BASIC has no octal literals.
*/
TEST_REQUIRE_OK(akbasic_leaf_new_literal_int(&LEAVES[1], "010"));
TEST_REQUIRE_INT(LEAVES[1].literal_int, 10);
TEST_REQUIRE_OK(akbasic_leaf_new_literal_int(&LEAVES[1], "08"));
TEST_REQUIRE_INT(LEAVES[1].literal_int, 8);
TEST_REQUIRE_ANY_ERROR(akbasic_leaf_new_literal_int(&LEAVES[1], "08"));
TEST_REQUIRE_OK(akbasic_leaf_new_literal_int(&LEAVES[1], "0"));
TEST_REQUIRE_INT(LEAVES[1].literal_int, 0);
/* 0x still selects base 16, which is the one prefix that means anything. */
TEST_REQUIRE_OK(akbasic_leaf_new_literal_int(&LEAVES[1], "0x10"));
TEST_REQUIRE_INT(LEAVES[1].literal_int, 16);
TEST_REQUIRE_OK(akbasic_leaf_new_literal_float(&LEAVES[2], "2.5"));
TEST_REQUIRE_FEQ(LEAVES[2].literal_float, 2.5);