Skip to content

fix(parser): token-level errors preempt compound EOF reports (#3405) - #3423

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix-3405-eof-selection
Nov 15, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix-3405-eof-selection

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

What

Inside an unclosed compound at end of input, GNU's parser dies on the
first token-level error in the region (report_syntax_error,
parse.y:6833/6852-6865) and only reports the compound's
"unexpected end of file" form when the parse survives to exhaustion
(parse.y:6890-6901). rubash's compound EOF arms always preferred the
outer EOF report, so a dangling redirection inside an unclosed
compound was misreported:

  • eval 'X() { (a)>' — GNU: eval: line 1: syntax error near unexpected token \newline'; rubash: the unclosed-{` EOF form.
  • x=$( ( a) >> — GNU: syntax error near unexpected token \newline' while looking for matching `)'`; rubash: the plain
    matching-EOF form.

This change orders the verdicts by construct state, not by shape:
the brace/paren EOF arms order the mismatched-closer and
dangling-redirection candidates by offending-token position, and
the keyword EOF arm consults the dangling-redirection scan.

Deletions

None — the change is additive in parse_loop plus call-site
signature threading in the keyword EOF arm.

Fixes #3405

Part B (comsub bodies)

A command substitution body is a nested yyparse (parse.y:4549-4555),
so a token-level error inside the body — a redirect operator whose
target never arrives, a bare ( after body text — preempts the
matched-pair EOF report there too:

  • lexer/skip.rs: unclosed_comsub_eof_shape learns the
    dangling-redirect class (first redirect operator at the innermost
    unclosed comsub body's own depth whose next meaningful character is
    a newline or end of input), returned as ComsubBodyTokenError and
    ordered against the invalid-paren class by text position. The
    eval/trap consumers already render that shape with the FORCE_EOF
    abort, so eval 'x=$( ( a) >>' now exits 1 with no continuation.
  • script_driver.rs: the file-mode unclosed route's comsub arm
    consults the classifier and emits the near-token report ahead of
    the plain matching-EOF.
  • executor/public_accessors.rs: report_comsub_body_parse_error
    applies GNU's suffix rule (parse.y:6858-6859) — an operator that is
    the body's last token died on the comsub's own ) and names it
    without the suffix (x=$( ( a) >> )); an operator followed by a
    physical newline inside the body keeps `newline' with the suffix.

Verification legs (box, per-stem) are reported on the issue thread as
they land.

GNU report_syntax_error (parse.y:6833) exits at a concrete token
(parse.y:6852-6865, current_token != 0 with EOF_Reached == 0) before
the EOF branch (parse.y:6890-6901) can report an open compound, so
inside an unclosed compound the first token-level verdict in the
region precedes every "unexpected end of file from `X'" report.

The brace and paren EOF arms consulted only the mismatched closer,
and the keyword arm neither candidate, so a dangling redirection
inside an unclosed compound (`X() { (a)>`, `while true; do >`) was
reported as the compound's EOF error instead of GNU's
`syntax error near unexpected token `newline'' at the operator's
line. The brace/paren arms now order both candidates by offending
token position (preempting_token_error_node over
dangling_redirect_in_region, the scan the first W-DIAG residual
wave left unwired), and the keyword arm consults the dangling scan
(foreign closers keep their caller-side routing there).

Refs #3405
GNU bash 5.3.20 expectations for the probe matrix (lane dossier
probes.py E-series): the fail-first cells are the dangling-redirect
shapes inside unclosed compounds and command substitutions; the
controls are the clean-EOF shapes (clean comsub body, unclosed if,
complete brace group, top-level dangling redirect, the continuation
exception, the backquote counter-shape, the pending heredoc).

Refs #3405
@caomengxuan666

Copy link
Copy Markdown
Member Author

复核判词:FAIL——头编不过。首代 CI 9 腿全 fail(34s–1m50s)+ niubash 腿 fail,日志原文逐腿核对过,全部是同一对编译错,不是 flake:

  1. error[E0308],src/parser/case_command.rs:35:21:source.as_deref() 得 Option<&Rc<str>>,而 unclosed_keyword_eof_node 要 Option<&str>;rustc 建议 .map(|v| &**v)。
  2. error[E0521],src/parser/parse_loop.rs:3570:22:preempting_token_error_node 的 opener: &str 传给要求 &'static str 的 first_mismatched_closer;调用点本身传的是 "{"/"(" 字面量,错在转发侧签名,二选一收敛即可。

两处都在本次 PR 的新代码里;其余腿(回归钉双边、三方探针、lib、fmt、-D warnings、hygiene、cross-target)因头编不过依例免跑,返工新头 CI 全绿后再补全套复核。

另有一件返工须交代:issue 要求四形全钉,钉文件 19 个测试里没有 shape 4(`case x in `` 反向形)——请说明 shape 4 是否已重验、决定不钉的依据(附 GNU 实测),或补钉。

返工后请通知重审;当前头不得合入。

…port (#3405, part B)

GNU parses a command substitution body with a nested yyparse
(parse.y:4549-4555), so a token-level error inside the body - a
redirect operator whose target word never arrives, a bare ( after
body text - fails that parse BEFORE the matched-pair EOF is reached,
and report_syntax_error (parse.y:6833-6865) names the offending
token with the matching suffix. rubash classified only the bare-(
shape for eval strings and the file route never consulted the
classifier at all, so x=$( ( a) >> reported the plain matching-EOF
at the past-end line in file mode and in eval strings alike.

- lexer/skip.rs: unclosed_comsub_eof_shape learns the dangling-
  redirect class (comsub_body_dangling_redirect: first redirect
  operator at the innermost unclosed comsub body's own depth whose
  next meaningful character is a newline or the end of input),
  returned as ComsubBodyTokenError, preempting both the invalid-
  paren class when it sits earlier in the text and the ComsubEof
  tail. The eval/trap consumers already render that shape with the
  FORCE_EOF abort, so the eval face (eval 'x=$( ( a) >>' now exits
  1 with no continuation) is fixed by the classification alone.
- script_driver.rs: the file-mode unclosed route's comsub arm now
  consults the classifier and emits the near-token report (suffix +
  offending line, exit 2) ahead of the plain matching-EOF.
- executor/public_accessors.rs: report_comsub_body_parse_error
  applies GNU's suffix rule (parse.y:6858-6859) - a missing-target
  error whose operator is the body's last token died on the
  comsub's own )' (the sub-parse EOF token, parse.y:4519), so it
  names )' WITHOUT the suffix; an operator followed by a physical
  newline inside the body keeps newline' with the suffix
  (x=$( ( a) >> ) case).

Also carries two small signature refinements in the part-A helpers
left uncommitted in the lane tree (opener: &'static str, Rc<str>
deref at the case call site).

Refs #3405
@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain re-review — FAIL (dossier: review-3423/CAPTAIN-VERIFY.md §5; first-round FAIL was the uncompilable head, comment 6822595909)

The two compile errors are fixed and the head now compiles (cargo check --tests rc=0; new-head CI finished all green, goldens included). But the rework is unfinished: the head's own pin stem runs 17/19, and both reds are real divergences verified against GNU bash 5.3.20 by the captain's own oracle runs — the pin expectations are correct (GNU matches them 19/19).

Failing pins (head output vs GNU)

  1. dangling_redirect_in_subshell_names_newline — ( (a)>
  2. bare_paren_after_comsub_body_text_names_newline_with_matching_suffix — x=$(echo (

What already stands (no rework needed there)

  • Fail-first is demonstrated per name: base + top-up pin runs 8 passed / 11 failed, the 11 reds being exactly the divergence shapes, the 8 passers exactly the conservation controls.
  • Shape 4 (case x in `) is pinned as control e04 and verified on GNU/head/base alike — the EOF form stands on all three sides; nothing more is owed for it.
  • lib bilateral 1246/0/4 on both sides (failure name sets ∅); fmt / marker-literal / UTF-8 hygiene rc=0; full-target RUSTFLAGS="-D warnings" forced recheck rc=0 (1512 rustc invocations, 1505 flagged, 0 errors); intersection vs live tip ∅.
  • The Part B comsub-body mechanism is in scope for this issue (it completes the shape-3 family the pins already specified), and the two compile-error fixes are minimal one-liners.

Rework path: fix only the two reds above, push a new head, wait for CI all green, and notify the captain for a focused re-review (pin stem 19/19 + three-way probe table + lib name sets; intersection recomputed against the then-live tip).

…ken errors reach file mode (#3405, part C)

Round-2 rework for the two remaining reds in PR #3423 (re-review FAIL,
CAPTAIN-VERIFY.md §5.4):

1. `( (a)>` named the pure subshell EOF form. `parse_subshell_command`
returns None and the fallback `push_unclosed_paren_error` only knew the
two #413 pre-EOF events, while the dangling-redirect arm lived only in
`unclosed_paren_eof_node` (function-definition `()`). The left-to-right
scan now also consults `dangling_redirect_in_region` and returns
whichever event — dangling redirect, #413 (a)/(b) — its token position
reaches first ("first offender wins", parse.y:6833).

2. `x=$(echo (` reported the matched-pair EOF in file mode although the
eval face already named `newline` with the matching suffix. Root cause
is routing, not classification: the close-char scan reports the bare
`(` inside the comsub body as a command-position paren, the real parser
stays silent (the lexer swallows the body into the word token), so
`command_paren_verdict_disproved_by_parser` disproved the unclosed
route and execution fell through to the comsub-expansion EOF report.
The disproof no longer fires when `unclosed_comsub_eof_shape` yields a
ComsubBodyTokenError (parse.y:4549-4555 nested yyparse owns the
diagnostic), and the command-position branch of the unclosed route
defers to the ComsubBody arm instead of its subshell-EOF fallthrough.
The shape's own guards (#516/q1, `((` arithmetic root, `for ((`
pair) keep those families out of the class, so their reports are
unchanged.

Same family, token naming: `token_after_paren` returned an empty token
when an operator followed the invalid `(` (`x=$(echo (>` named ``).
Operators now lex maximal-munch per GNU read_token (parse.y:3630-3800);
spellings byte-verified against GNU bash 5.3.20.

GNU anchors: parse.y:532, 6833, 6858-6859, 4549-4555, 6890-6901.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3423 第3轮 — 建议:PASS
head: d28bcc0 base(merge-base): f6e8c67 文件: 7 个 +896/-23
关联 issue: #3405(状态:open,我核过的时间:2026-11-15 08:35 CST)

机制核查:

腿(逐项给数字与名字):

  • 钉自跑:stem issue3405_eof_error_selection 在 Windows 上 running 0 tests(文件级 #![cfg(unix)],本机无法跑 unix 钉)——VOID,以逐字节探针等价补跑:19 格全部 PASS(脚本 target/probes-3423/probe_3423.py,case 体逐字取自钉文件,LF 落盘,rubash.exe case.sh 比对 rc/stdout/stderr)。
  • fail-first:merge-base f6e8c67 构建的 rubash.exe 跑同一探针集 → 8 passed / 11 failed,红名 = {e01,e02,e09,e10,e11,e20,e03,e17,e08,e15,e21},恰为 11 个分歧形状、8 个守恒对照全绿——与队长「8/11、红即分歧形」口径逐名一致。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state}(1349 passed/1 failed/4 ignored)/ base 失败名集 {同一名}(1349/1/4)/ 差集 ∅。issue2084 在 base 上同样 panic(consumer_tests.rs:782 __RUBASH_CURRENT_LINE 残留),系本机既有环境失败,非本 PR 账。
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked --lib --bins rc=0;--tests 版 rc=101,唯一错误 tests/issue2473_procsub_operand_marker_regressions.rs:29 unused import std::io::Write——该文件 #![cfg(windows)] 且本 PR 未触碰(base 同字节),属 Windows 侧既有测试文件告警,非本 PR 引入。
  • 卫生:rustfmt --check(edition 2021)7 个 PR 文件全 OK;check-marker-literals.py rc=0(117 consts/268 allowlist);check-utf8-boundary-hygiene.sh clean。
  • CI:head d28bcc0 全绿——API ledger tripwire / Compatibility CLI tests / Cross-target (darwin) / Cross-target (linux/android) / GNU regression goldens and canaries / Rust tests / Rust tests (macOS) / Shell functionality tests / Windows tests compile check / niubash builds against this tree 全 pass,Bash upstream test progress skipping。无红腿。
  • GNU 对照:WSL bash = GNU bash 5.3.20(1)-release(/usr/local/bin/bash,script-file 形态,MSYS_NO_PATHCONV=1 wsl bash run_gnu.sh,LF 脚本 target/probes-3423/run_gnu.sh)。19 格 GNU 输出与钉期望逐字节一致(compare_gnu.py:19 match / 0 differ),且 head rubash 与 GNU 在 19/19 形状上逐字节一致。平台局限:无(错误消息形状平台无关)。

F 点:无

续作记录:无(本轮只审不改)

未跑/VOID 的腿:

  • cargo test --test issue3405_eof_error_selection 本机 VOID(cfg(unix));已用逐字节探针等价覆盖 19 格,且 head 的 CI「Rust tests」腿在 Linux 上真实跑了该 stem 并 pass。
  • 正文含 Fixes #3405(合入即关单口径)——按规程仅记录备查,关单口径由队长裁定。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-BATCH-SUMMARY】

Wave 2 后半 11 个 PR 审核完毕(win-agent, worktree D:/repo/rubash-devin-w6)。各 PR 报告已发至各自评论区,判词均为建议。

PR issue 建议判词 关键说明
#3423 #3405 建议 PASS 19/19 stem 全绿、GNU 逐格吻合;CI 适用任务全绿
#3451 #2642 建议 PASS env describe PATH-file 语义双侧验证
#3444 #3382 建议 PASS 17 算术格 head 全对 GNU;lib 差集 ∅
#3486 #3448 建议 PENDING(缺腿) 机制+GNU 全对,但 cfg(unix) 钉从未执行(CI 被 #2875 截停)——需 Linux 车道跑 stem
#3465 #3251 建议 PASS head 32/32,base 20 红含 c13(队长上轮唯一失格项已消除),GNU -c 32 格全验证
#3462 #3260 建议 PASS head 11/11,base 7 红实见载体泄漏,CI 全绿(钉 Linux 实跑)
#3461 #3046 建议 PENDING(缺腿) 机制+GNU 对,Linux CI head 绿;但修复面需 /dev chardev,Windows 双侧同形不可分辨,Linux fail-first 未跑
#3458 #3383 建议 PASS 钉 Linux CI 绿;Windows 等价探针实证 base 红(declare: a: not found)/ head 逐字节对 GNU
#3480 #2769 建议 PENDING(缺腿) 机制+GNU 6 形状全对;SIGXFSZ/真信号死 Windows 不可表达,Linux stem 双侧未跑(CI 被 #2875 截停)
#3136 #3102 建议 PASS 钉 Linux CI 绿;Windows 探针实证 base 粘连/mirror 损坏→head 逐字节对 GNU;正文「修法未提交」已过时(cddf4fb9 即修法)
#3126 #2900 建议 PASS 资产 sha256+上游锚点验证为真 2.14.0;eval×extglob 网格 GNU 双侧吻合;step1-3 Windows 实跑通过

阻塞项汇总:

  • 三个 PENDING 同根因:修复面只在 unix/Linux 可表达(dead-cwd fchmodat、chardev fd、真信号死亡),Windows 探针尽至等价证明,剩余腿均为「Linux 车道跑对应 stem(head 应绿 / base 应红)」——均为分钟级补腿。
  • 环境性基线:lib 全量唯一红 issue2084_session_end_restores_host_process_state 在所有 base/head 同复现;CI 红全部归因已知 issue2875(日志实证 -c 选项崩溃,nextest fail-fast 截停后续 stem)。
  • 本机 -D warnings --tests 面有既存无关 dead-code(issue2302/issue2473 测试文件,cfg(unix) 帮手在 Windows 全 dead),与本批所有 PR 无关。
  • 残差观察(非本批账,建议另案):Refs #3102 #3136 的 \x1c 字面字节在 Windows 双侧被吞(IFS_GLUE 载体在 Windows 传输路径另有解释,Linux 绿)。
  • 未动任何代码、未 push、未合并/关闭任何 PR/issue。

process 卫生:本 turn 结束自查(见下)。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 15, 2026 02:05
@caomengxuan666
caomengxuan666 merged commit 94a2643 into master Nov 15, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] at EOF inside an unclosed compound, GNU reports the innermost open construct's error; rubash reports the outer EOF error

1 participant