Repository navigation
fix(parser): alias pre-pass treats quotes in comsub comments/heredocs as opaque (Refs #3813) - #3821
Merged
Merged
Conversation
…Refs #3813) Alias T='{ f() {' + $(...) holding a #-comment with an odd number of apostrophes fails to parse (rc=2, unexpected end of file from `{'); GNU is rc=0. Pins cover the issue parity table (p0-p4), comment after $(, nested/dquoted/case comsub, alias-after-comment, heredoc in comsub, nested comsub in ${...}, funsub comment/heredoc faces, and the literal-$# / mid-word-# / ${...}-# controls that must keep passing. Fail-first: expected red on base 969230b; fix follows.
… as opaque (Refs #3813) skip_dollar_paren delegated to skip_parenthesized_unit_corrected (comments at token boundaries and heredoc bodies opaque, case `)\`' resolved like the body parser); skip_dollar_brace delegates nested $(...) the same way; skip_funsub_body gains a #-comment arm (token-boundary gated) and a << heredoc arm. GNU: parse.y:3631 shell_getc, parse.y:4451 parse_comsub, make_cmd.c:512. Same defect class as #2033's pre-pass walkers; these three helpers were the residual.
rustfmt --check (X299 leg) flagged 4 hunks; whitespace-only, no semantic change: one guard join, one assert! join, one let split, two control tuples expanded (trailing commas per rustfmt).
The 4 pins (funsub comment/heredoc x3, nested comsub in brace expansion x1) need the REAL lexer layer: no-alias isolation probes show base and fixed binaries behave identically on all four, so the alias pre-scan fix in this PR cannot turn them green. They now live in rubash #3823 (pin definitions + GNU anchors + the #3808/#3797 merge gate). This stem now holds the 11 pre-scan-layer pins only (11/11 green on X299, two rounds consistent). Refs #3813, #3823
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿:
F 点:无 未跑/VOID 的腿:无(本 PR 无 fd 族面,无需 WSL 原生 fd 复核) |
caomengxuan666
marked this pull request as ready for review
November 17, 2026 03:36
This was referenced Nov 17, 2026
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.
根因
别名展开预扫描(
src/lexer/alias_stream.rs)的$(\...)/${ ... }范围扫描器把#注释与 heredoc 体内的引号字符当成了真引号:注释里的撇号(如# don't)打开一个幻影单引号,吞掉后续全部输入,连同其后的别名展开一并吞掉。alias E='}; }'永远得不到展开,别名引入的{遂无闭合,报syntax error: unexpected end of file from{'`(rc=2);偶数个撇号恰好把幻影引号重新闭合,所以奇偶表按奇偶翻转。落点(仅
src/lexer/alias_stream.rs,未碰护栏文件src/parser/process_substitution.rs/src/parser/token_actions.rs/src/executor/command_substitution.rs,未碰红线src/lexer/continuation.rs):skip_dollar_paren改为委托已修正的skip_parenthesized_unit_corrected(skip.rs):注释按 token 边界跳过、heredoc 体按不透明处理、case 模式)按体解析器判定。skip_dollar_brace增加内嵌$(\...)分支,同样委托修正扫描器(#在${...}内仍是运算符,不设注释臂)。skip_funsub_body增加#注释臂(独立的 token-boundary 状态,term回答的是另一问题)与<<heredoc 臂;;/&/|/换行与</>的边界语义与修正扫描器对齐。GNU 锚点
shell_getc:#在 token 起始位置恒为注释("Discard until EOL or EOF");词中#(a#b、$#、${x:-a # b})不是注释。parse_comsub:体用真解析器解析,注释与 heredoc 在$(\...)/${ ... }内为不透明段。make_here_document:heredoc 体按原始行读取。GNU 5.3.20 实测:除转义
\#对照(GNU 同为 rc=2,未闭合真引号)外,本 PR 全部钉用例 GNU 均为 rc=0。回归钉
tests/issue3813_alias_comsub_comment_quote_regressions.rs(新,11 格):issue 奇偶表 p0–p4、$(后紧跟注释、嵌套/双引号内/case 模式 comsub、注释后别名展开、comsub 内 heredoc、${...}内嵌 comsub,以及$#/ 词中#/${...}内#/\#/ 无别名对照。4 格 funsub /${x:-$(...)}钉(issue3813_funsub_comment_quote、issue3813_funsub_heredoc_quote、issue3813_funsub_heredoc_brace_line、issue3813_nested_comsub_in_brace_expansion)已移出本 PR,移交 rubash funsub ${ ... } 体内 # 注释/heredoc 解析死亡,${x:-$(...)} 闭合 } 漏入输出(真 lexer 层,#3813 续作) #3823(真 lexer 层残差,钉定义见该 issue 正文)。src/lexer/tests.rs:expand_aliases_in_source级单元钉(E 别名必须展开)。src/lexer/alias_stream.rsstream_tests:stream==batch 一致性钉(comsub 与 funsub 两形)。本 PR 删除了什么
4 个回归钉从钉文件移出(移交 #3823,非删除——定义见 #3823 正文):
issue3813_funsub_comment_quote、issue3813_funsub_heredoc_quote、issue3813_funsub_heredoc_brace_line、issue3813_nested_comsub_in_brace_expansion。其余无删除:仅修改src/lexer/alias_stream.rs的三处扫描器与新增回归钉;未删除任何公开 API、文档或行为面。验证(X299-2607,头 e59c8fc 腿 + 7c8d28d 拆钉;两轮一致 04:52 / 05:31)
issue3813_alias_comsub_comment_quote_regressions:基底 3/15(fail-first,红者恰为 12 机制钉)→ 修后 11/15(两轮一致)→ 拆钉后 11/11(提交 7c8d28d 移出 4 格真 lexer 钉;余 11 格在拆前两轮均已绿,未改动)。绿:全部$(...)形与对照。issue3813_funsub_comment_quote、issue3813_funsub_heredoc_quote、issue3813_funsub_heredoc_brace_line、issue3813_nested_comsub_in_brace_expansion。无别名隔离探针证明真解析器/词法器本身亦不能解析这四形——funsub${ ... }内注释/heredoc 在真 lexer 即失败(rc=2 / bad substitution,与基底二进制一致);${x:-$(...)}形 rc=0 但值多一个}(v=[hi}],基底同然)。GNU 5.3.20 四形均为 rc=0 且值正确,钉期望无误。本 PR 只修别名预扫描层;真 lexer 层由 funsub ${ ... } 体内 # 注释/heredoc 解析死亡,${x:-$(...)} 闭合 } 漏入输出(真 lexer 层,#3813 续作) #3823 续作,门控 parser:>(...)with a{ ...; }group body is rejected asambiguous redirect(GNU accepts it) #3808/fix(cd): refuse chdir into directories without the search bit (Refs #3788) #3797 合入。api::consumer_tests::issue2084_session_end_restores_host_process_state,与基底相同、为既存。RUSTFLAGS="-D warnings" cargo check --locked --lib --bins:通过(LEG_RC=0)。rustfmt --check(3 文件):提交 e59c8fc 后通过(LEG_RC=0);该提交仅空白格式调整。UNVERIFIED-BY-CAPTAIN
队长未复核。4 格真 lexer 钉已移交 rubash #3823,本 PR 钉 stem 11/11 绿,只修别名预扫描层(车道 REPORT §6 诊断 / §8 第 4 项);真 lexer 续作门控 #3808/#3797 合入,见 #3823。