Repository navigation
fix(parser): attribute diagnostics to the token GNU blames (deep-audit F4) - #2778
Merged
Merged
Conversation
…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
This was referenced Nov 3, 2026
conditional follow-on walk truncates a glued redirect item to its first byte (F4/R12 residual)
#2782
Closed
Closed
caomengxuan666
marked this pull request as ready for review
November 3, 2026 18:27
…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.
This was referenced Nov 3, 2026
Closed
[B6-R5] Case-clause error resync blames the resync token (esac) instead of the offending token
#2743
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
&&: the And|Or token action now uses the shared unexpected-token production (line + source echo). Fixed.case in esac(missing subject) blames the previous line and drops the source echo #2740 / [B6-R5] Case-clause error resync blames the resync token (esac) instead of the offending token #2743 / [A1-F05] Case-header parse errors blame the wrong token and drop file:line source context #2679 (R2/R5/A1-F05) — case: fail at the first non-continuing token (subject scan, pattern-boundary checks for terminators/operators/second words, finalesaccheck). Fixed.if true then ...: GNU blames the closing keywordfi(then is consumed as a condition argument); rubash blamesthen#2741 (R3) — reserved words carry force only at command position (parse.y CHECK_FOR_RESERVED_WORD):if true then …blamesfi; a connector-danglingthenis at command position and is blamed itself, and the section-stop no longer treats it as the frame boundary mid-list. Fixed.while do done/until do done: GNU blamesdo, rubash blamesdone#2742 (R4) — loop-head scan names a boundary keyword indo's place:while do doneblamesdo. Fixed.(instead of the token after()#2747 (R9) — function-body fallthrough names the body token (NEAR at that token); thetimebody arm is removed (a timed pipeline is not a compound command —f() time …is rejected attime). Fixed.src/lexer/skip.rs: an arith-for((after a command-positionforis not a comsub paren) and via eval. Header validation is unchanged for malformed headers with complete bodies. Fixed; residual: single-)header shapes (for ((i=0;i<3;i++); …) keep the matched-pair form where GNU's parse_dparen splitting names the inner token — documented in the lane report.[[ ]]error resync: the follow-onsyntax error nearnames]]instead of the following token #2750 (R12) — conditional follow-on walk (parse.y error_token_from_text): the glued token after]]is named (;, single char of&&/||, first byte of redirects,)walked over, case terminators as operators, newline not glued);]]closes only as an exact token (parse.y special_case_tokens) — word fragments are arguments, operator fragments fail in stream order with the follow-on offered; the FIRST error stands (any-encoding checkCommandNode::has_parse_error_marker) against stray terminators and separator-less words. Fixed; residual:[[ a ==]]2>f— GNU's walk runs over the whole redirect item (]]2>f), rubash names the operator's first byte only.while looking for matching ')'suffix, fragment echo, per-level escalation lines,-cstatus 2 vs GNU 127 #2751 (R13) — comsub bodies: one shared screen (report_comsub_body_error_if_any) on both execution routes (typed + run_ast) reports a body error exactly once in GNU's read-time shape (suffix for near errors,)' named for end-of-body shapes, conditional walk over a glued paren); the execute_command escalation stands down when the body was already reported.report_command_parse_errorgains the missing COND/NEAR/EOF arms (backtick child reports dropped the offender's name entirely). **Not changed**: the-cexit status (GNU 127 vs ours 2) — owner-decision pending. **Remaining**: the$(offending-line echo is the body fragment, not the enclosing line (no driver→executor source-line channel exists);$(case x in)is intercepted by the comsub extractor's case-aware scan before the body parser runs; a space before the closing paren still extends a conditional's near by)` (the dispatcher trims the body text first).Verification (lane-local, debug build):
-cstatus, single-)arith headers, route pre-emption shapes).cargo check --all-targetsclean;cargo fmtapplied (my files check-clean).src/lexer/continuation.rsuntouched.Refs #2739
Refs #2740
Refs #2741
Refs #2742
Refs #2743
Refs #2747
Refs #2749
Refs #2750
Refs #2751
Refs #2754
Refs #2679