Skip to content

lexer: join lines while a word-attached procsub body is open (fixes #463) - #483

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/multiline-procsub-word
Oct 10, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/multiline-procsub-word

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #463

Problem

word<( NEWLINE ... NEWLINE ) — a process substitution attached directly to a word (no space), with its body spanning physical lines — was rejected by rubash with syntax error near unexpected token ')', while GNU accepts it. This breaks the h4l/json.bash jb-cli nesting example:

jb menu:json@<(
  jb id=file value=File popup:json@<(
    ...
  )
)

The word scanner itself already consumes the body (skip_cmd_subst spans newlines, rubash#339's <(/>( word arm), but the tokenizer's logical-line join gate had no signal for an open word-attached body: the line echo outer<( looked complete, and the body lines were parsed as fresh commands.

Fix

GNU folds word<( into the word (read_token fall-through parse.y:3793-3797; shellexp arm parse.y:5494-5524) and reads the (...) body under parse_matched_pair's LEX_GTLT discipline (parse.y:4147-4153), where newlines are ordinary body characters. Mirror that at the join gate:

  • word_ends_in_open_process_substitution (src/lexer/continuation.rs): quote/escape/backtick-aware scan of the last word token's raw span; true iff the word ended inside an unclosed word-attached <(/>(.
  • GroupScanFeeder::push_main_line (src/lexer/mod.rs): when the pass's last token is that word, hold the logical line open for the next physical line (full re-lex — the pass ended mid-word, so the tail-resume checkpoint is invalid).
  • GroupScanFeeder::token_level_needs_more: report the held join so the incremental group reader (script-file and -c execution) keeps appending physical lines too.

Untouched by design: bare <( at word start (the parser's own procsub bridge already spans lines there), #424's extglob redirect rejections, the #339/#355/#468 procsub behavior.

Oracle

GNU bash 5.2.37 msys (D:\Git\usr\bin\bash.exe): bash -n rc=0 on every accepted shape of the issue's boundary table; executed shapes (echo outer<( NL ... NL), comsub-wrapped) byte-identical stdout (outer/dev/fd/63).

Tests

tests/issue463_multiline_procsub_word_regressions.rs — 9 cases: minimal repro (-n + execution), parsing continues after the closing ), the jb-cli nesting shape, output procsub >(, comsub-wrapped, single-line attached forms unchanged, #424 rejections intact, quoted opener does not join, body executes once.

Known pre-existing gaps (out of scope, unchanged on master)

  • Interactive/stdin-source completeness (stdin_source_text_needs_more) has no arm for either form, so piped echo outer<( + lines still errors at ).
  • The space-separated multi-line form still mis-parses under -c/script execution (parse-only via -n is fine).
  • Truncated-EOF diagnostics (echo outer<( with no body) stay accepted where GNU reports unexpected EOF while looking for matching )'`.

GNU folds `word<(` into the word via read_token's fall-through
(parse.y:3793-3797) and read_token_word's shellexp arm
(parse.y:5494-5524), with the `(...)` body consumed under
parse_matched_pair's LEX_GTLT discipline (parse.y:4147-4153) where
newlines are ordinary body characters. rubash's word scanner already
spans the body (skip_cmd_subst), but the tokenizer's logical-line join
gate had no signal for it, so `echo outer<(` NL `echo inner` NL `)` —
and the h4l/json.bash jb-cli `jb menu:json@<(...)' nesting example —
died with `syntax error near unexpected token `)'`.

- word_ends_in_open_process_substitution (continuation.rs): quote/
  escape/backtick-aware scan of the last word token's raw span; answers
  whether the word ended inside an unclosed word-attached `<(`/`>(`.
- GroupScanFeeder join gate (lexer/mod.rs): when the pass's last token
  is that word, hold the logical line open for the next physical line,
  clear the tail-resume checkpoint (the pass ended mid-word), and let
  token_level_needs_more report it so the incremental group reader
  (script/`-c` execution) keeps appending too.
- Bare `<(` (word-initial) is untouched — the parser's own procsub
  bridge handles it; #424's extglob redirect rejections stay green;
  #339/#355/#468 procsub suites pass.

Oracle: GNU bash 5.2.37 msys (D:\Git\usr\bin\bash.exe) — rc=0 on every
accepted shape, byte-identical stdout on executed shapes. Known
out-of-scope gap, pre-existing on master: interactive/stdin-source
completeness (stdin_source_text_needs_more) and the `-c` space-form
body still lack their own arms; truncated-EOF diagnostics unchanged.

Tests: tests/issue463_multiline_procsub_word_regressions.rs (9 cases:
minimal repro, line-spanning continue, jb-cli nesting, output procsub,
comsub-wrapped, single-line forms, #424 rejections, quoted opener).
src/executor/path.rs is cargo fmt reformat of pre-existing test code.

Closes #463
@caomengxuan666
caomengxuan666 merged commit 2ebb1aa into master Oct 10, 2026
7 of 8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/multiline-procsub-word branch October 10, 2026 03:17
caomengxuan666 added a commit that referenced this pull request Oct 21, 2026
… and windows_drive.rs

The two `bytes[0] as char` drive-letter folds added for niubash#481/#483
each sit behind a `bytes[0].is_ascii_alphabetic()` condition, pinning the
widened byte to ASCII — never a UTF-8 continuation byte. Same reviewed-safe
class as the existing path.rs/cd/paths.rs/pwd.rs entries.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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] word-attached multi-line process substitution word<( NL ... NL ) rejected — GNU accepts (breaks json.bash jb-cli example)

1 participant