Skip to content

fix(parser): accept function-def name words containing unquoted $( ) (#462) - #476

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/funcdef-name-cmdsub
Oct 10, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/funcdef-name-cmdsub

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #462.

Problem

f$()g() { :; } was rejected by rubash -n with syntax error near unexpected token '(' while GNU bash parses it: function_def (parse.y:1054) admits any single WORD before (), and read_token_word folds an unquoted $( ... ) into the current word (parse.y:5513-5532 $(' branch). This broke the real-world harvest case fileRemoveWithOverwrite-dirOrFile$(useWithCaution)__hsl() { ... }in gingerpaledale/zZshFrameworkfiles.sh`.

Fix (GNU semantics: name is a WORD; the expanded name is validated at definition time)

  • parser/support.rs: mask $(/${/$[ and backquote spans before the function-name word-structure checks — bytes inside a substitution span are substitution text, not word structure.
  • parser/parse_loop.rs: admit Variable/CommandSubst tokens at the function-definition gate ($x() { :; }, $(echo f)() { :; } — the name lexes as its own token kind).
  • executor/function_calls.rs: a raw name carrying a backquote span is definition-time invalid, matching GNU's `echo f`': not a valid identifier'.

Oracle

Every expectation measured against GNU bash 5.2.37 msys (D:\Git\usr\bin\bash.exe) on 2026-10-10, corroborating the issue's WSL GNU 5.3.0 table:

construct rubash (this branch) GNU 5.2 oracle
f$()g() { :; } -n ok; runtime `f$()g': not a valid identifier' rc=1, continues same
$x() { :; } / $(echo f)() { :; } same as above same
function f$()g { :; } / backtick form same as above same
break chars outside the span (f$();g() ...) word ends, f runs, g defined same
plain/quoted controls, #453 assignment prefix unchanged same

Tests

New tests/issue462_funcdef_name_cmdsub_regressions.rs (14 tests) pins the issue boundary table, keyword/backtick forms, structure checks, and the definition-time identifier error. Existing suites green: issue443 (16), issue461 (12), issue314, parser (316), lexer (72), assign-prefix (#453) regressions. The 7 remaining failures (pwd/path, parameter_transform, pb10k interactive, upstream snapshot slice) reproduce identically on the base commit cd98dd9 — environment-dependent, unrelated.

Note: cargo fmt also reflows one pre-existing src/executor/path.rs test to satisfy the pre-commit fmt gate.

…(rubash#462)

GNU function_def (parse.y:1054) admits ANY single WORD before `()`, and
read_token_word folds an unquoted `$( ... )` into the current word
(parse.y:5513-5532), so `f$()g() { :; }` parses; the expanded name is
validated only at definition time (valid_function_word). rubash's parser
rejected such words because the substitution text's `(`/`)` tripped the
word-structure character check, breaking zZshFramework files.sh.

- parser/support.rs: mask `$(`/`${`/`$[` and backquote spans before the
  function-name structure checks (is_function_name /
  is_function_keyword_name); bytes inside a span are substitution text,
  not word structure.
- parser/parse_loop.rs: admit Variable/CommandSubst tokens at the
  function-definition gate (`$x() { :; }`, `$(echo f)() { :; }` lexes the
  name as its own token kind).
- executor/function_calls.rs: a raw name carrying a backquote span is
  definition-time invalid, matching GNU's
  `` `echo f`': not a valid identifier'``.

Runtime behavior matches the GNU 5.2.37 msys oracle byte for byte:
definitions parse (`-n` rc=0) and names containing expansions are
rejected non-fatally with `` `RAW': not a valid identifier'`` (rc=1),
execution continuing. tests/issue462_funcdef_name_cmdsub_regressions.rs
pins the issue's boundary table, the keyword/backtick forms, break
characters outside the span, and the assignment-prefix (#453) control
row. cargo fmt also reflows a pre-existing path.rs test to satisfy the
fmt gate.

Oracle: D:\Git\usr\bin\bash.exe (GNU bash 5.2.37 msys), 2026-10-10.

Closes #462
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.

[parse] function-definition name word containing unquoted $( ) rejected — GNU accepts (breaks zZshFramework files.sh)

1 participant