Repository navigation
fix(hook): keep case terminators intact when rewriting (#3197) - #4130
Merged
Merged
Conversation
📊 Automated PR Analysis
SummaryThis PR fixes the shell command lexer so that Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
2 tasks done
KuSh
marked this pull request as ready for review
September 19, 2026 16:22
KuSh
force-pushed
the
lex/02-case-terminators
branch
from
September 20, 2026 23:23
f0fe86b to
4173c33
Compare
KuSh
force-pushed
the
lex/02-case-terminators
branch
from
September 25, 2026 22:55
4173c33 to
8cc2de9
Compare
KuSh
force-pushed
the
lex/02-case-terminators
branch
2 times, most recently
from
September 25, 2026 23:29
ef75dea to
6a9fbaf
Compare
KuSh
force-pushed
the
lex/02-case-terminators
branch
from
September 26, 2026 17:55
6a9fbaf to
ec2696c
Compare
2 tasks done
KuSh
force-pushed
the
lex/02-case-terminators
branch
3 times, most recently
from
October 2, 2026 15:04
150f73c to
935d467
Compare
KuSh
force-pushed
the
lex/02-case-terminators
branch
2 times, most recently
from
October 2, 2026 15:07
1dc3d6d to
57f52b8
Compare
10 tasks done
KuSh
force-pushed
the
lex/02-case-terminators
branch
2 times, most recently
from
October 7, 2026 07:16
f64f271 to
d0ba176
Compare
aeppling
approved these changes
Oct 9, 2026
aeppling
left a comment
Contributor
There was a problem hiding this comment.
LGTM
Nit: discover/README.md:24 and the split_on_operators / split_for_permissions doc comments still list only &&, ||, ; as split points. Please add ;;, ;&, ;;&.
KuSh
force-pushed
the
lex/02-case-terminators
branch
from
October 9, 2026 11:07
d0ba176 to
dde81ea
Compare
`;;`, `;&` and `;;&` each terminate a `case` arm, but the lexer emitted a
separate `Operator(";")` per character. `rewrite_compound` splits on every
operator and rebuilds the text around it, so the second half of a terminator
came back as its own empty segment and the arm was re-emitted with the two
halves apart:
case x in a) echo 1;; esac -> case x in a) echo 1; ; esac
case x in a) echo 1;& esac -> case x in a) echo 1; & esac
The first is a bash syntax error, so any command mixing a `case` statement
with a rewritable command never ran at all. The second is worse than an
error: `; &` is valid, and turns a fall-through into a background job.
The `;` arm now folds `;;`, `;&` and `;;&` into one operator token, matching
bash's own maximal munch — `;;;` is `;;` then `;`, and `;&&` is `;&` then
`&`, which bash's syntax errors name explicitly. The emitter's existing
no-padding branch for `;` covers every terminator starting with one, so the
terminator itself is reproduced verbatim instead of being padded to ` ;; `.
Whitespace after a terminator is not preserved: that branch appends a space
when the operator is not the last token, so `echo 1;;esac` comes back as
`echo 1;; esac`. Both parse identically, and the behaviour predates this
change — it applied to bare `;` already.
No existing test changes: the old two-token form produced an empty segment
between the halves, which the segmenters already dropped.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review follow-up: the segmenter doc comments and the discover README still named only `&&`, `||` and `;` as split points; `;;`, `;&` and `;;&` are now one operator token each and split the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
force-pushed
the
lex/02-case-terminators
branch
from
October 9, 2026 16:27
b06d637 to
b295eb7
Compare
Merged
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.
;;,;∧;&each terminate acasearm, but the lexer emitted aseparate
Operator(";")per character.rewrite_compoundsplits on everyoperator and rebuilds the text around it, so the second half of a terminator
came back as its own empty segment and the arm was re-emitted with the two
halves apart:
The first is a bash syntax error, so any command mixing a
casestatementwith a rewritable command never ran at all. The second is worse than an
error:
; &is valid, and turns a fall-through into a background job.The
;arm now folds;;,;∧;&into one operator token, matchingbash's own maximal munch —
;;;is;;then;, and;&&is;&then&, which bash's syntax errors name explicitly. The emitter's existingno-padding branch for
;covers every terminator starting with one, so theterminator itself is reproduced verbatim instead of being padded to
;;.Whitespace after a terminator is not preserved: that branch appends a space
when the operator is not the last token, so
echo 1;;esaccomes back asecho 1;; esac. Both parse identically, and the behaviour predates thischange — it applied to bare
;already.No existing test changes: the old two-token form produced an empty segment
between the halves, which the segmenters already dropped.
Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test --all— 3852 passing, clippy clean, at this commit rather than only at the tip of the stackrtk rewrite 'ls /tmp; case x in a) echo 1;; *) echo 2;; esac'leaves;;intact, and;&is no longer split into; &Part of stack #4139 (#4129 → #4138). Based on #4129. Each commit gates green on its own, so the stack is bisectable.
🤖 Generated with Claude Code