Repository navigation
fix(lexer): record argument-position ! as Word in reader history (Refs #3639) - #3646
Merged
Merged
Conversation
UNVERIFIED-BY-CAPTAIN
…efs #3639) GNU parse.y:3168 CHECK_FOR_RESERVED_WORD + :2378 word_token_alist ({"!", BANG}): `!` is BANG only where reserved_word_acceptable (parse.y:5899) holds; elsewhere the reader returns a WORD and it is the PRODUCED token that last_read_token names. Rubash recorded the dedicated-branch `!` as Keyword in history unconditionally, so reserved_word_position() armed the `{` fold after an argument `!` and `printf "! { }"` saw one "{ }" word. Demote `!` to Word in history exactly when it was not read in a reserved position; a genuine BANG keeps Keyword history, so `! { ...; }` still folds. UNVERIFIED-BY-CAPTAIN
This was referenced Nov 14, 2026
caomengxuan666
marked this pull request as ready for review
November 16, 2026 12:07
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿:
F 点:无 |
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #3639 (P3-low, area:parser).
What this fixes
Trailing unquoted
{ }after an argument-position!was folded intoone word
"{ }"; GNU keeps three separate words (printf '[%s]\n' ! { }prints[!],[{],[}]).Root cause
GNU parse.y:3168
CHECK_FOR_RESERVED_WORD+ :2378 word_token_alist(
{"!", BANG}):!is the BANG token only wherereserved_word_acceptable(parse.y:5899) holds; elsewhere the readerreturns a plain WORD, and it is the PRODUCED token that
last_read_tokenthen names. Rubash recorded the dedicated-branch!as Keyword in the reader history unconditionally, so
reserved_word_position()armed the{fold after an argument!.The same chain explains the second trigger shape: in
! { } { }thefirst
{'s}is rejected as a group close (followed by{), sothe first
{is emitted as a bare Keyword{, which makes the}aKeyword, which arms the fold for the LAST pair only.
Fix
In
record_token(src/lexer/scanner.rs), demote!to Word in thereader history exactly when it was not read in a reserved-word
position — the
!exception to the verbatim-history rule forstructural tokens. A genuine BANG (command position, after
time,after
(/;/etc.) keeps its Keyword history, so! { ...; }stillfolds and negates. Stream token kind is untouched; only the history
classification changes.
Pins
tests/issue3639_brace_fold_after_bang_regressions.rs, 13 cells:
fail-first 5 passed / 8 failed on the base; head 13/13. Issue seed
9/9 on head (base 2/9). GNU-oracle matrix 27/29 — the 2 remaining
cells are pre-existing divergences in paths this change cannot affect
(
echo hi | ! trueomits the source-line echo;! } { }runs}as a command instead of a syntax error); both have the
!in areserved position, so no demotion fires and the token stream is
identical to base.
Legs run by this lane
stems 36/36 (issue1625 3/3, issue1652 6/6, issue1721 8/8,
issue1046 1/1, issue1128 1/1, array_compound_quote 17/17).
RUSTFLAGS="-D warnings" cargo check --lib --bins: rc=0.本 PR 删除了什么
demotion 规则的例外说明(
!从 verbatim 结构 token 表中移出,另立一臂说明)。
UNVERIFIED-BY-CAPTAIN