mirror of
https://github.com/rohitg00/ai-engineering-from-scratch.git
synced 2026-09-19 02:42:50 +08:00
771df0fe7a
* fix(phase-11/09): calculator got the operator token, not the expression The per-token scan ran before whole-expression extraction, so for a spaced expression the first token merely containing an operator won - the bare '+'. The whole-expression branch below it was unreachable, so the demo query from docs/en.md returned a syntax error instead of a result. Extract the expression first, keep the token scan as the fallback. The TypeScript port already does whole-match extraction (code/main.ts). 'Calculate (100 + 250) * 0.15' -> 52.5 (was: unexpected EOF while parsing) 'What is 2+2' -> 4.0 'how much is 7 * 6' -> 42.0 'calculate 10/4' -> 2.5 'compute the total' -> 0.0 (unchanged fallback) * fix(phase-11/09): extract a contiguous expression and validate it Review feedback: filtering allowed characters out of the whole message concatenated unrelated numbers - 'calculate 10/4 with precision 2' produced '10/4 2', which contains '/' so it was returned and then failed to parse. Match contiguous arithmetic runs instead, and validate each candidate through calculator() before returning it, so a malformed run falls through to the token scan rather than being handed to the tool. 'calculate 10/4 with precision 2' -> '10/4' -> 2.5 'Calculate (100 + 250) * 0.15' -> '(100 + 250) * 0.15' -> 52.5 'What is 2+2' -> '2+2' -> 4.0 'how much is 7 * 6' -> '7 * 6' -> 42.0 'compute the total' -> '0' -> 0.0 'what is 5 apples plus 3 oranges' -> '0' -> 0.0 --------- Co-authored-by: thejesh23 <thejesh23@users.noreply.github.com>