Fail calculator parsers without a unary minus

SK
34m ago
+171-1

The Budget Sheet Formulas contract in problem-bank/variants.json allows a minus before a number or a parenthesized group, and Jim's clarification gives -(2+3) as an example, but none of the seven cases in problem-bank/judges.json had a minus without a left operand. A parser that reads every minus as binary therefore passed all seven.

Five cases now cover where a unary minus can stand and what it reads: -(2+3) expecting -5 (minus before a group), 1-(-2) expecting 3 (minus inside a group), -2+3 expecting 1 (minus on the first number only), - 7 expecting -7 (space after a leading minus) and -12 expecting -12 (minus before a two-digit number). The labels join the tricky-case list in tests/web/contract.rs. python3 scripts/gen-problems.py regenerated web/judges/budget-sheet-formulas.json, and the basic-calculator digest in tests/golden/task-posed.json is recomputed the way tests/test_task_package.py computes it.

A test in tests/browser/compiler-explorer.test.js, in the style of the valid-anagram one, runs six wrong parsers by name over the built-in cases and fails when no case rejects one of them. They share one recursive-descent parser and differ only in when a - that starts a term is read as a sign and what it negates: never (every minus is binary), only after a 0 is prepended to a leading minus, always and over the rest of the expression, only before a digit, only when it touches its operand with spaces kept, and always but over a single digit. That parser checks the ) that closes a group and fails on input left unread. Each case is the only one that rejects one of the last five parsers, so removing any case fails the test; I checked this by deleting each case from the generated judge in turn. The test also fails against the seven cases on main. The same test checks every expected value with evaluate from web/calculator.js, the task workspace's calculator, instead of a second parser of its own; the wrong parsers keep their own because that calculator has no switch for when a minus is a sign. The calculator refuses an unclosed group or input left unread, so a wrong expected value (such as - 7 expecting 7) or a malformed input (such as 1-(-2(, -(2+3( or -12)) fails the test too. It also reads *, ^, decimals, functions and a plus sign of its own, which the contract leaves out, so each input is first held to the contract's characters (digits, +, -, parentheses and spaces) with no plus sign of its own: 2*3, 1.5+1, +(2+3) or 1-(+2) fails the test.

The whitespace case is - 7 rather than - (2 + 3): every parser but one strips spaces, so - (2 + 3) would reject the same parser as -(2+3) and leave minus before a group unprotected. The two-digit case is -12 rather than -12+3 or 1-(-12): those also reject the parser that negates the rest or the one that prepends 0, so -2+3 or 1-(-2) would no longer be the only case that rejects it.

Each expected value was also checked against a sign-stack solution, which passes all twelve cases.

Verification on Ubuntu 26.04 in WSL2, Node v26.13.1, at this head on main bfadc5ee: ./scripts/test.sh rust has no failed gates; node --test tests/browser/compiler-explorer.test.js passes 107/107; python3 -m unittest -k test_posed_bank_golden tests/test_task_package.py passes; python3 scripts/gen-problems.py --check is clean. The full ./scripts/test.sh run reports rust-style, review-memory-tests and git-hooks, and all three fail identically on main at 288a0c99 on this machine: rust-style measures against a stale origin/main in my clone and passes with --baseline upstream/main, and the other two fail the same tests without this change. Not run here: desktop clippy and tests (no libwebkit2gtk), cargo-audit, cargo-deny, ruff, shfmt and shellcheck.

Close #776