Commit d8782b3
fix(parser): handle heredoc pipe ordering and edge cases (#379)
## Summary
- Fix heredoc pipe ordering: `cat <<EOF | sort` now correctly pipes
heredoc content to the next command in the pipeline
- Fix pipe continuation: `cat <<EOF |\nsort` works via rest-of-line
re-injection
- Handle partial quote delimiters: `<<'EOF'"2"` correctly combines to
delimiter `EOF2` with quoting preventing expansion
- Fix multiple heredocs on one line: `while cat <<E1 && cat <<E2; do ...
done` parses and executes correctly
- Fix heredoc followed by multiline dquote: `cat <<EOF; echo
"two\nthree"` handles quoted strings spanning lines
- Capture while/until condition stdout so heredocs in loop conditions
produce visible output
All 6 previously-skipped heredoc-edge spec tests are now enabled and
passing.
## Approach
**Lexer**: Added a `VecDeque<char>` re-injection buffer. `read_heredoc`
saves the rest of the command line (after the heredoc delimiter token)
instead of discarding it, then re-injects it after reading the heredoc
body. `peek_char`/`advance` check the buffer first.
**Lexer**: `read_continuation_into` concatenates adjacent
quoted/unquoted segments after a single-quoted string, enabling
partial-quote heredoc delimiters.
**Interpreter**: `execute_while` and `execute_until` now capture and
emit condition command stdout/stderr.
## Test plan
- [x] All 6 heredoc-edge skipped tests enabled and passing
- [x] 2 new parser unit tests (heredoc pipe, multiple heredocs)
- [x] Full spec test suite passes (1305 tests, 1192 passed, 0 failed,
113 skipped)
- [x] bash_comparison_tests pass (identical output to real bash)
- [x] All 1017 lib unit tests pass
- [x] `cargo fmt --check` clean
- [x] No new clippy warnings (pre-existing `resolve_redirect_url`
dead_code only)
Closes #359
Co-authored-by: Claude <noreply@anthropic.com>1 parent ef0c02d commit d8782b3
File tree
4 files changed
+204
-70
lines changed- crates/bashkit
- src
- interpreter
- parser
- tests/spec_cases/bash
4 files changed
+204
-70
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1462 | 1462 | | |
1463 | 1463 | | |
1464 | 1464 | | |
| 1465 | + | |
1465 | 1466 | | |
1466 | 1467 | | |
1467 | 1468 | | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
1468 | 1477 | | |
1469 | 1478 | | |
1470 | 1479 | | |
| |||
1547 | 1556 | | |
1548 | 1557 | | |
1549 | 1558 | | |
| 1559 | + | |
1550 | 1560 | | |
1551 | 1561 | | |
1552 | 1562 | | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
1553 | 1571 | | |
1554 | 1572 | | |
1555 | 1573 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | | - | |
23 | | - | |
24 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
50 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
51 | 57 | | |
52 | 58 | | |
53 | 59 | | |
54 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
55 | 65 | | |
56 | 66 | | |
57 | 67 | | |
| |||
708 | 718 | | |
709 | 719 | | |
710 | 720 | | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
711 | 725 | | |
712 | 726 | | |
713 | 727 | | |
714 | 728 | | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
715 | 782 | | |
716 | 783 | | |
717 | 784 | | |
| |||
1212 | 1279 | | |
1213 | 1280 | | |
1214 | 1281 | | |
1215 | | - | |
1216 | | - | |
1217 | | - | |
1218 | | - | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
1219 | 1291 | | |
1220 | 1292 | | |
1221 | | - | |
| 1293 | + | |
1222 | 1294 | | |
1223 | 1295 | | |
1224 | | - | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
1225 | 1310 | | |
1226 | 1311 | | |
1227 | 1312 | | |
| |||
1254 | 1339 | | |
1255 | 1340 | | |
1256 | 1341 | | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
1257 | 1351 | | |
1258 | 1352 | | |
1259 | 1353 | | |
| |||
1370 | 1464 | | |
1371 | 1465 | | |
1372 | 1466 | | |
1373 | | - | |
1374 | 1467 | | |
1375 | 1468 | | |
1376 | 1469 | | |
1377 | 1470 | | |
1378 | 1471 | | |
1379 | 1472 | | |
1380 | 1473 | | |
1381 | | - | |
1382 | 1474 | | |
1383 | 1475 | | |
1384 | 1476 | | |
| |||
1394 | 1486 | | |
1395 | 1487 | | |
1396 | 1488 | | |
1397 | | - | |
1398 | 1489 | | |
1399 | 1490 | | |
1400 | 1491 | | |
1401 | 1492 | | |
| 1493 | + | |
1402 | 1494 | | |
1403 | 1495 | | |
1404 | 1496 | | |
1405 | 1497 | | |
1406 | 1498 | | |
1407 | 1499 | | |
1408 | | - | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
1409 | 1506 | | |
1410 | 1507 | | |
1411 | 1508 | | |
| |||
0 commit comments