Skip to content

fix(parser): attribute diagnostics to the token GNU blames (deep-audit F4) - #2778

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/f4-diag-attribution
Nov 3, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/f4-diag-attribution

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Deep-audit lane F4 — parser diagnostic attribution (which token/line an error blames, source echo and suffix fidelity). UNVERIFIED-BY-CAPTAIN: code + regression pins only; captain compiles/verifies/merges centrally.

Mechanism (one root): error-position bookkeeping at reduction points. GNU's yyerror blames the parser's current lookahead (parse.y report_syntax_error → error_token_from_token / error_token_from_text), echoes the offending physical line, and inside $( re-presents the error at the body boundary with shell_eof_token = `)' (parse.y:4519). Rubash's construct parsers validated at collection boundaries and its renderers covered only some error encodings, so blame landed on neighbours, echoes dropped, and comsub errors escalated once per nesting level.

Per finding (GNU citation, mechanism, state):

Verification (lane-local, debug build):

  • Differential probe corpus vs the GNU bash 5.3.20 oracle binary: 102 SAME; every remaining DIFF is one of the documented residuals above (fragment echo, -c status, single-) arith headers, route pre-emption shapes).
  • New pins: 85 tests across 8 files (exact stderr bytes + exit status), all passing.
  • Neighbouring diagnostics targets: 138 tests across 21 stems, all passing (3 stems platform-gated to 0 tests on Linux, compile-verified).
  • cargo check --all-targets clean; cargo fmt applied (my files check-clean). src/lexer/continuation.rs untouched.

Refs #2739
Refs #2740
Refs #2741
Refs #2742
Refs #2743
Refs #2747
Refs #2749
Refs #2750
Refs #2751
Refs #2754
Refs #2679

…t F4)

Error-position bookkeeping at reduction points, per finding:

- #2739 (R1): a list operator opening a line goes through the shared
  unexpected-token production (line + source echo), not a hand-rolled
  line-less message node.
- #2740/#2743/#2679 (R2/R5/A1-F05): the case parser fails at the
  first non-continuing token — subject scan ends at the first
  non-`in` token, pattern clauses check clause terminators, list
  operators and second words at the pattern boundary, final `esac`
  check names the token found.
- #2741 (R3): reserved words carry force only at command position
  (parse.y CHECK_FOR_RESERVED_WORD) — `if true then ...` blames
  `fi`; a `then` dangling after a connector is at command position
  and is blamed itself, with the condition's latched error winning.
- #2742 (R4): loop-head scan names a boundary keyword sitting in
  `do`'s place (`while do done` blames `do`).
- #2747 (R9): the function-body fallthrough names the body token;
  `time` is removed from the body dispatch — a timed pipeline is not
  a compound command, so `f() time ...` is rejected at `time`.
- #2749 (R11): the arith-for scan reports in reduction order —
  post-header junk names the junk token, a closed header without a
  body is the compound-EOF form, an unclosed header is the
  matched-pair EOF (parse.y:3908-3915), including through the script
  driver's unclosed-input route (an arith-for `((` is not a comsub
  paren) and via eval.
- #2750 (R12): the conditional's follow-on walk (parse.y
  error_token_from_text) — the token glued to `]]` is named, doubled
  operators contribute one character, redirects one byte, a newline
  is not glued; `]]` closes only as an exact token (parse.y
  special_case_tokens), word fragments are ordinary arguments, and
  the first error stands against later stray terminators and
  separator-less words (the walk sees every error encoding, not
  just the message marker).
- #2751 (R13): comsub body errors are reported once, in GNU's
  read-time shape (parse.y:4519 shell_eof_token `)'): the matching
  suffix for near errors, the `)' named for bodies that ran into
  their end, the conditional walk extended over a glued paren; the
  per-level "syntax error in command substitution" escalation
  stands down. Both body routes (typed + run_ast) share one screen.
  report_command_parse_error gains the COND/NEAR/EOF arms it lacked
  (backtick child reports dropped the offender's name). The `-c`
  status face (127 vs 2) is unchanged — owner decision pending.
- #2754 (R17): dangling-list EOF markers ride the LAST command of
  the list (multi-command dangling lists fold too), so the report
  names the end-of-input line.

Regression pins: tests/issue2739_*, issue2740_2743_2679_*,
issue2741_2742_*, issue2747_*, issue2749_*, issue2750_*,
issue2751_*, issue2754_* — exact stderr bytes + exit status,
GNU bash 5.3.20 oracle. UNVERIFIED-BY-CAPTAIN.

Refs #2739, #2740, #2741, #2742, #2743, #2747, #2749, #2750,
#2751, #2754, #2679
…tion

# Conflicts:
#	src/parser/case_command.rs
#	src/parser/parse_loop.rs
PR #2778 verification caught a regression the lane's differential
corpus missed: `for (( i=0; i<1; i++ ); do :; done` fell into the new
matched-pair EOF form ("unexpected EOF while looking for matching
`)'"), where master reported the header-validation syntax error —
breaking cli_tests' malformed_pipeline_and_if_are_syntax_errors.

GNU's parse_dparen stops inside the header on this shape. The close
scan now treats a lone `)' at header depth, once the three header
sections are complete, as a (malformed) close: the shape routes to
the continuation + header validation and is reported as the syntax
error it is. A header whose sections never completed (`for ((i=0;)`)
keeps the matched-pair EOF form, as does a header no `)' reaches.
Exact GNU token attribution for single-`)' headers is tracked in
#2781. New pin: issue2749_single_paren_header_with_body_is_a_syntax_error.

Captain-verified: issue2749 stem 13/0, issue2754 stem 5/0,
cli_tests malformed_pipeline_and_if_are_syntax_errors ok.
@caomengxuan666
caomengxuan666 merged commit b1dac38 into master Nov 3, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/f4-diag-attribution branch November 6, 2026 03:20
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.

1 participant