Repository navigation
fix(parser): match function-head parens on the operator token, not its text (Fixes #3388) - #3558
Conversation
…s text (Refs #3388) GNU parse.y:3667 read_token makes `(`/`)` operator tokens only when read unquoted; a quoted or escaped paren belongs to a WORD (parse.y:5305 read_token_word), and function_def (parse.y:1054-1056 `WORD '(' ')'`) consumes operator tokens only. rubash's lexer already emits the operator form as TokenKind::Keyword and a quoted paren as a Word with the same value, but the function-head recognizer compared the value alone, so `[ '(' ')'`, `echo '(' ')' x` and `test '(' ')'` parsed as `NAME ( )` definitions and aborted the script with a syntax error instead of running the command (`[: missing ']'`, rc 2, script continues). All paren tests on the function head (admission probe, compact/separated `()`, parenthesized body, `!!`/`<(...)` name reassembly) now go through one is_paren_operator predicate. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
队长裁决(#3388 双在途):本 PR 为 #3388 的先行实现,先合本支。 同 issue 另有外部 PR #3744(arookieofc-ai,2026-11-15 开,READY,基底为现尖):同机制(引号括号是 WORD、不是函数头算子),谓词为 kind 判定(单括号)+ 定序与后续:
|
|
【WIN-AGENT-AUDIT】s10 lane 第 3 轮 — 建议:PASS(按 S 波授权已 squash 合入) head: dba90ff base(merge-base): 8b48c16 文件: 2 个 +141/-13 定序核对(队长 2026-11-15 19:39Z 评论要求):
机制核查:
腿(逐项给数字与名字):
F 点:无 未跑/VOID 的腿:
|
The fix for #3388 landed via #3558 (same operator-token mechanism). #3744's pin file adds four coverage shapes #3558's pins lack: the closed-bracket runtime error, !/test forms, unquoted-paren parse-error preservation, and the unclosed [[ guard. Pin file taken verbatim from #3744, authorship preserved. Co-authored-by: arookieofc-ai <[email protected]>
修了什么
[ '(' ')'不再在解析期中止整脚本:变成普通简单命令,由[内建在运行时报[: missing ']'、返回 2,脚本继续——与 GNU 一致(issue 的-c形与文件形两格都对齐)。根因不在
[(issue 正文的定位):任何命令词后面跟一对加引号的括号都会中招——echo '(' ')' x、test '(' ')'、[ "(" ")"在 master 上同样报syntax error中止。src/parser/function_command.rs的函数头识别只比较 token 的文本"("/")",而 lexer 对加引号的括号产出的是TokenKind::Word(value 同为(,raw 为'('),于是NAME '(' ')'被当成NAME ( )函数定义头,下一行不是复合命令即报语法错。机制修复:新增
is_paren_operator(token, text)(要求TokenKind::Keyword运算符形),函数头上所有括号判定统一走它:入口探测、()紧凑/分离两形、name() (括号体、!!与<(...)名字重组(含其中的括号深度计数)。删了什么
function_command.rs中 9 处只看token.value的括号比较(全部替换为上述谓词)。GNU 依据
parse.y:3667 read_token():(/)只在未加引号读到时走 shellmeta 分支、作为运算符 token 返回;加引号/转义的括号属于 WORD(parse.y:5305 read_token_word())。parse.y:1054-1056function_def: WORD '(' ')' newline_list function_body | FUNCTION WORD '(' ')' ...:只消费运算符 token。test.c的[分支缺]→missing ']',返回 2(builtins/test.def)。验证
tests/issue3388_quoted_paren_function_head.rs(4 格:issue 回归种子、加引号括号对作普通词、未加引号函数头仍正常定义、-c形继续执行;期望取自 WSL GNU 5.3.20):修前 1 passed / 3 failed(仅「未加引号函数头」守门格过),修后 4/4。qp.sh(echo/test/[/case/for 中的加引号括号与花括号):修后与 GNU 分流 stdout/stderr 一致,唯一剩余差异见下方 Owed。diff --strip-trailing-cr):test.tests修前 18 / 修后 18、func.tests2 / 2,输出逐字节相同。cargo test --lib parser34/34。cargo fmt --check因 Windows 命令行过长(os error 206)无法运行,以rustfmt --edition 2021 --check检查本 PR 文件干净;hook 同样被 206 卡死,提交时走了其「cargo 不在 PATH 则跳过」分支——如实记录。Owed
'(' echo hi ')'(rubash 当子 shell 跑)与'{' echo hi '}'(rubash 报 EOF 语法错)是同类「看文本不看 kind」但在别处的缺陷(lexer 产出正确的 Word,误判发生在其后),另立 [bug] 命令位加引号的 '(' / '{' 被当作子 shell / 组命令(GNU 为普通 WORD,command not found) #3557,本 PR 未涉及。Fixes #3388