Skip to content

test(parser): pin GNU semantics for tokens on the function-definition brace line (rubash#443) - #459

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/func-line-comment
Oct 9, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/func-line-comment

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #443

What #443 reported

Any trailing token on the f() { line — a # comment, or the first body
word with the } closing on a later line — was rejected on the reported
build (rubash b4cbcad / niu 1.1.2) with
syntax error near unexpected token ('against a mangledf ( ) {`
re-rendering, rc=2, before any execution.

Findings on current master

Every row of the issue's measured scope table already matches GNU bash
5.x on this branch. The underlying lexer faults (the brace-group token
swallowing trailing comment text, and has_unclosed_brace_group not
continuing the logical line across a function header) were fixed with
the niubash #120 follow-up; tests/issue120_fndef_inline_comment.rs
already pins the comment-after-brace shapes. No parser change is needed.

What this PR adds

Black-box regression pins (tests/issue443_func_line_trailing_tokens.rs,
CARGO_BIN_EXE_rubash) for the rest of the #443 scope that was not yet
covered:

  • bodies that open on the brace line and close on a later line, including
    f() { echo hi # c and f() { x=1 # c (assignment + comment);
  • one-liner f() { :; } with and without a trailing comment, and the
    comment not swallowing following lines;
  • } followed by a # comment (legal) vs a bare word (rc=2, error names
    THAT word, physical offending line echoed verbatim — not f ( ) {);
  • control rows the issue measured as already correct (brace alone, brace
    on its own line, complete one-liner);
  • no interference with the rubash#453 assignment-prefix + subshell parse
    inside a body whose brace line carries a comment.

Verification

  • New suite: 16/16 green.
  • cargo fmt --check clean.
  • Related suites green: issue120_fndef_inline_comment (13),
    assign_prefix_subshell_regressions (fix(parser): 赋值前缀 + 子 shell — GNU 形态(审计语料 #452 集群1) #453, 3),
    issue314_nested_funcdef_loop_regressions (12), lib tests 623 passed.
  • Pre-existing, unrelated environment failures noted (not touched by this
    PR): one pwd lib test and the cli_tests bashdb/examples rows that
    require the absent third_party/bash vendored tree.

… brace line (rubash#443)

#443 reported that any trailing token on the `f() {` line
— a `# comment`, or the first body word with the `}` closing on a later
line — was rejected with "syntax error near unexpected token `('" on the
b4cbcad build, against a mangled `f ( ) {` re-rendering.

On current master every row of the issue's measured scope table already
behaves like GNU bash 5.x: the underlying lexer faults (the brace-group
token swallowing trailing comment text, and has_unclosed_brace_group not
continuing the logical line across a function header) were fixed with
the niubash #120 follow-up whose regressions live in
tests/issue120_fndef_inline_comment.rs.

This adds the missing black-box pins for the rest of the #443 scope:
- bodies that open on the brace line and close on a later line, including
  body + trailing comment and assignment + comment shapes;
- one-liner `f() { :; }` definitions with and without a trailing
  comment, and the comment not swallowing following lines;
- `}` followed by a comment (legal) vs a bare word (rc=2 syntax error
  naming THAT word, with the physical offending line echoed verbatim —
  not the mangled `f ( ) {` rendering);
- control rows the issue measured as already correct;
- no interference with the rubash#453 assignment-prefix + subshell parse
  inside a body whose brace line carries a comment.

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

parser: trailing comment (or body) on the f() { line -> "syntax error near unexpected token ("

1 participant