Commit 0916080
Phase T: source positions in parser errors
Every parser error now reports the precise line:col where it occurred.
## Changes
- `Pos { line: u32, col: u32 }` — 1-indexed source position struct.
Implements Copy + Display + Debug.
- Lexer tracks line/col as it advances chars (increments line on '\n',
col otherwise).
- New `Lexer::tokenize_with_pos` returns Vec<(Token, Pos)>.
- Parser stores `VecDeque<(Token, Pos)>` instead of `VecDeque<Token>`.
- Parser exposes `current_pos()` for error sites.
- Updated 3 error-emitting sites (expect, parse_primary fallthrough,
parse_ident fallthrough) to include "at line:col".
## Before / after
Before: Error: Expected Semicolon, got Print
After: Error: at 2:1: Expected Semicolon, got Print
## Tests
141 still passing across the workspace. No regressions; the existing
tests don't depend on error-message format so they pass through
unchanged. All 6 example .omc programs still execute correctly.
## Why this matters
Every future error-quality improvement builds on this. The runtime
can now propagate source spans through values; the compiler can show
"this variable was declared at line 4, but used at line 12 where it's
out of scope"; the optimizer can blame the right source position when
something it couldn't fold reaches runtime and panics.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent b7e202b commit 0916080
2 files changed
Lines changed: 150 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
7 | 25 | | |
8 | 26 | | |
9 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
75 | 98 | | |
76 | 99 | | |
77 | 100 | | |
| 101 | + | |
| 102 | + | |
78 | 103 | | |
79 | 104 | | |
80 | 105 | | |
81 | 106 | | |
82 | 107 | | |
83 | 108 | | |
84 | 109 | | |
| 110 | + | |
| 111 | + | |
85 | 112 | | |
86 | 113 | | |
87 | 114 | | |
| |||
105 | 132 | | |
106 | 133 | | |
107 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
108 | 141 | | |
109 | 142 | | |
110 | 143 | | |
111 | 144 | | |
112 | 145 | | |
113 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
114 | 154 | | |
115 | 155 | | |
116 | 156 | | |
| |||
436 | 476 | | |
437 | 477 | | |
438 | 478 | | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
439 | 536 | | |
440 | 537 | | |
441 | 538 | | |
442 | | - | |
| 539 | + | |
443 | 540 | | |
444 | 541 | | |
445 | 542 | | |
446 | 543 | | |
447 | 544 | | |
448 | | - | |
| 545 | + | |
449 | 546 | | |
450 | 547 | | |
451 | 548 | | |
452 | 549 | | |
453 | 550 | | |
454 | 551 | | |
455 | | - | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
456 | 565 | | |
457 | 566 | | |
458 | 567 | | |
459 | | - | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
460 | 572 | | |
461 | 573 | | |
462 | 574 | | |
463 | 575 | | |
464 | 576 | | |
465 | 577 | | |
466 | 578 | | |
467 | | - | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
468 | 585 | | |
469 | 586 | | |
470 | 587 | | |
| |||
1107 | 1224 | | |
1108 | 1225 | | |
1109 | 1226 | | |
1110 | | - | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
1111 | 1232 | | |
1112 | 1233 | | |
1113 | 1234 | | |
| |||
1192 | 1313 | | |
1193 | 1314 | | |
1194 | 1315 | | |
1195 | | - | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
1196 | 1321 | | |
1197 | 1322 | | |
1198 | 1323 | | |
| |||
0 commit comments