Skip to content

fix(parser): report first offending reserved word in case-in-comsub syntax errors (Refs #3628) - #3901

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3628-case-in-comsub-token
Nov 18, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3628-case-in-comsub-token

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #3628. Adds in to command-position reserved-word rejection and replaces case_body_end silent break with first-offender detection matching GNU parse.y.

caomengxuan666 and others added 2 commits November 18, 2026 18:38
…rs (#3628)

`case' inside a command substitution (and plain case clause bodies)
reported the wrong unexpected token: GNU names the token that actually
arrived where the grammar expected something else, but rubash blamed a
later `esac'/`;;'/`)'/EOF.

Two cooperating defects:

- src/parser/token_actions.rs: the command-position reserved-word
  rejection (command_is_pending_pipeline_prefix) omitted `in', so a bare
  `in' at command position became a command word instead of the token
  yyerror names. GNU parse.y CHECK_FOR_RESERVED_WORD (parse.y:3168-3187)
  and the compound_list grammar (parse.y:1262) admit no production for
  it; `in' is the only member of reserved_word_acceptable's complement
  (parse.y:5899-5937) that is not itself a boundary predecessor.
  Argument/command-name position is preserved: `x=1 in a' and `>f in a'
  still run `in' -> `in: command not found' (rc 127), and `echo in' /
  `echo done' stay legal.

- src/parser/case_command.rs case_body_end: a lexical
  `done|fi|then|else|elif` break stopped the clause-body walk at those
  keywords without reporting them, swallowing the real offender so a
  later token was blamed (and misfiring on argument-position
  same-spellings like `echo done fi'). Removed the break so the real
  body parser judges command position, and added command-position
  offender detection (flat && at_command_start && structural_keyword)
  that reports the FIRST can't-start-command keyword like GNU's yyerror
  (parse.y:6724/6833/6850-6865) — fixing `in esac' (whose `esac' the
  boundary scan cannot see) and first-offender-beats-stray-`)'.

Regression coverage in tests/issue3628_case_in_comsub_token.rs (12
tests): the comsub reproducer (`v=$(case x in x) done ;; esac)' ->
`done' while looking for matching `)', `in' likewise, `esac ;;' -> `;;'),
the shared clause-body root cause, `in' command-position rejection, and
argument-position preservation.

Verified against WSL GNU Bash 5.3.20 (script-file probes): every probed
case-body/comsub keyword now names the same token with the same rc.
Known pre-existing limitation (unchanged): the NEAR-channel source echo
for a case nested inside while/if echoes the clause span, not the full
physical line — same as the existing stray-`)`/`|' offenders.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit 21a6f69 into master Nov 18, 2026
9 of 12 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 18, 2026
队长复核 PASS 并合入(钉期望对齐,无产品代码变更,chore 类豁免删除节)。

头 CI 裁定:census 78,issue3833 茎 8 PASS / 0 FAIL(对齐生效),与现尖 census 逐名零新增;goldens 基线二名;CLI 全绿。fail-first 即现尖 census 的原红格(旧期望在 #3901 后的产品上必红);期望本身由 GNU 5.3.20 oracle 实测背书(`! in` / 裸 `in` / `| in` 皆 rc 2)。
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.

case-in-comsub: syntax-error diagnostics report the wrong unexpected token (GNU names the token)

1 participant