Commit 58aae9a
fix(awk): stop number lexer swallowing following +/- operators (#2392)
## What changed
awk's number lexer no longer folds a following `+`/`-` into numeric
literals. Unspaced arithmetic like `awk 'BEGIN{print 1+2}'` and `awk
'{print $1+$2}'` now parses, while exponents with explicit signs
(`1e+5`, `1.5e-3`) still lex as single tokens. A lone `.` is still
rejected as an invalid number.
## Why
Fixes #2389. `+`/`-` are the two chars legal after `e`/`E`, and the old
lexer consumed them unconditionally — turning `1+2` into one invalid
token. Hard error (not wrong value), and unspaced `a+b` is the form LLMs
reach for first, so agents burned extra calls before abandoning awk.
## Before / After
Before (`1+2` regression test fails: `awk: invalid number: 1+2`):
| expression | before | after |
| --- | --- | --- |
| `BEGIN{print 1+2}` | `invalid number: 1+2` | `3` |
| `BEGIN{print 1+ 2}` | `invalid number: 1+` | `3` |
| `BEGIN{print 3-1}` | `invalid number: 3-1` | `2` |
| `BEGIN{print 1e5+2}` | `invalid number: 1e5+2` | `100002` |
| `{print $1+$2}` on `1 2` | `invalid number: 1+` | `3` |
| `BEGIN{print 1e+5}` | `100000` | `100000` (unchanged) |
| `BEGIN{print 1.5e-3}` | `0.0015` | `0.0015` (unchanged) |
After verified end-to-end via CLI; outputs match system awk (`3 2 100002
100000 0.0015`). New `test_awk_unspaced_plus_minus_after_number` covers
all rows plus a lone-dot negative case; full awk suite (105 tests)
green, fmt + clippy clean.
## Risk
- Low. Change is confined to awk's `parse_number`; sibling lexers
audited (`bc`, shell arithmetic, `expr`, `jq`) — none share the pattern.
- One local-only `just pre-pr` failure in
`malformed_command_substitution_aborts_like_bash`, unrelated: it asserts
on real system-bash output and this Mac ships bash 3.2 (`echo a$(|)b`
prints `ab` here). CI on Linux is the arbiter.
## Checklist
- [x] Tests added or updated
- [x] Backward compatibility considered (no compat needed — internal
code; behavior now matches real awk)
Closes #2389.
Produced by [yolop](https://everruns.com/yolop)
Co-authored-by: yolop <yolop@everruns.com>1 parent 16727ff commit 58aae9a
2 files changed
Lines changed: 55 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1536 | 1536 | | |
1537 | 1537 | | |
1538 | 1538 | | |
1539 | | - | |
1540 | | - | |
1541 | | - | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
1542 | 1548 | | |
1543 | | - | |
1544 | | - | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
1545 | 1566 | | |
1546 | 1567 | | |
1547 | 1568 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
412 | 441 | | |
413 | 442 | | |
414 | 443 | | |
| |||
0 commit comments