Skip to content

WIP: fix(lexer): #2227 face 2 — dquote-span bracket hunt EOF attribution (face 1 withheld) - #2373

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/2227-bracket-quote
Oct 31, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/2227-bracket-quote

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2227 — recovery delivery: face 2 only. Face 1 is withheld, with evidence (below).

What lands (face 2: EOF verdict attribution)

An unterminated $[...] hunt inside a double-quoted span used to be bounded by the span's closing quote and named the DQUOTE at the span's line. GNU runs the hunt itself — extract_delimited_string (subst.c:1361, reached for $[...] at subst.c:1303 with flags=0) recurses into quote units (subst.c:1448-1457 via skip_single_quoted subst.c:1127 / skip_double_quoted subst.c:1014) — so the span's closing quote opens a quote unit inside the hunt, and that unit's EOF names the quote at the unit's line.

  • src/lexer/skip.rs: db_scan_dquote_span delegates an in-span hunt to db_scan_bracket_hunt verbatim; the bounded-count path and db_tail_has_unclosed_quote are removed (the q6 verdict — trailing quote closes the opened unit, then the hunt names ] — now comes straight from the hunt). For echo "a $[1+<NL>2" the verdict is now " at line 2 (GNU 5.3.20), not line 1.
  • src/script_driver.rs, tests/issue543_dollar_bracket_eof_regressions.rs: verdict-attribution comments updated.
  • tests/issue2227_bracket_quote_regressions.rs (new): 4 face-2 pins + 2 control pins.

Verification (this branch, scrubbed-fd runner): issue2227 pins 6/6, issue543 pins 14/14, cargo check --tests clean, kept files 0 CR, no new warnings in kept files.

Withheld: face 1 (quote-state-aware extraction) — recovered but NOT sound yet

The recovered worktree also contained a full face-1 implementation (lexer copiers in quotes.rs, walker collectors in embedded_mutations.rs / embedded_parameters.rs, dollar_bracket_end in expand_braced_replacement.rs, all converted to the extract_delimited_string state machine). Adjudication against GNU 5.3.20 + master A/B (base 711ad72) found:

  • It correctly delimits the unquoted family and the dquoted arithmetic-error family (stdout/rc match GNU), and fixes the whole-file lexer death.
  • Regression: echo "dblbs: $[1\\]+2" prints literally. Master and GNU both produce the arithmetic error (token \). Root cause: the cooked body ends in a lone \ (from \\), and the walker collector's new escape arm consumes the closing ] as that backslash's escaped char, so the span never closes. At the cooked-word layer a source \] and a deescaped \ are indistinguishable to the collector as written — this is carrier-layer (CTLESC) territory and needs its own brief, not a drive-by patch.
  • Not delivered: the arithmetic diagnostic for an escaped bracket still shows \] where GNU shows ] (the evaluator's error token is not dequoted), and assignment-position quoted bodies (v=$["1+1"]) still error (also red on master, different shape).

Full-diff pin run for the record: 7 passed / 4 failed. The face-1 diff is preserved in the cluster workdir (face1-layers.diff, 611 lines) for the follow-up brief; the five face-1 pin drafts were removed from the pin file rather than shipped red or weakened.

#2227 stays open for face 1.

caomengxuan666 and others added 3 commits October 31, 2026 14:53
…elf (Refs #2227)

Face 2 of #2227: an unterminated dollar-bracket inside a double-quoted
span named the DQUOTE at the span's line, because db_scan_dquote_span
bounded the hunt by the span's closing quote and counted brackets
inside it. GNU runs the hunt itself: extract_delimited_string
(subst.c:1361) — reached for the bracket form at subst.c:1303 with
flags=0 — recurses into quote units (subst.c:1448-1457, via
skip_single_quoted subst.c:1127 / skip_double_quoted subst.c:1014),
so the span's closing quote OPENS a quote unit inside the hunt and
that unit's EOF names the quote at the unit's line.
db_scan_dquote_span now delegates an in-span hunt to
db_scan_bracket_hunt verbatim; the bounded-count path and
db_tail_has_unclosed_quote are gone (the q6 verdict — trailing quote
closes the opened unit, hunt names the bracket — now comes straight
from the hunt). script_driver.rs and the issue543 pin docs updated
to the new attribution. Verified: issue543 pins 14/14, issue2227
face-2 pins 4/4 (GNU bash 5.3.20 script-file probes).
Four pins for the delegated-hunt verdicts (quote unit names itself
at its own line; no closing quote names the bracket; squote unit
inside the hunt names itself; trailing quote closes the unit then
bracket EOF) plus two control pins holding GNU-agreeing shapes
(backquote/escape family, nested/subscript family). Face-1
extraction pins are deliberately absent — see the file header and
the PR body for the withheld face-1 state and its regression.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 16:02
@caomengxuan666
caomengxuan666 merged commit 8ae7e85 into master Oct 31, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 1, 2026
…r the s2 line (rubash#2227)

issue2227_nested_and_subscript_controls expected `s2: 21` for
echo "s2: $[a["1"]+1]", but GNU 5.3.20 rejects that line itself:
inside double quotes the bare " after a[ closes the segment
(subst.c:1014 skip_double_quoted has no $[...] case), extraction
over the segment `s2: $[a[` finds no ] and the command is discarded
with `bad substitution: no closing ']' in s2: $[a[` (subst.c:1505)
while the script continues — stdout s1: 21 / n: 3 / bt: 6, rc 0.
The expectation predates the #2441 segment semantics (written for
#2373). The pin now asserts the GNU outcome; no product change.
Verified byte-for-byte against GNU 5.3.20 with the pin's own script.

Refs #2227.
@caomengxuan666
caomengxuan666 deleted the fix/2227-bracket-quote branch November 2, 2026 01:08
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.

1 participant