feat: decompose parameter expansions into Word.parts#17
Merged
Conversation
Parameter expansions ($var, ${var}, ${var:-default}, ${#var}, ${!var})
were tracked as spans during lexing but not decomposed into AST nodes
in Word.parts. Downstream consumers walking Word.parts could detect
CommandSubstitution and AnsiCQuote but completely missed parameter
expansions, forcing fragile string-matching fallbacks.
Add ParamExpansion(String) and SimpleVar(String) variants to WordSegment.
Refactor segment building into build_segments() with a configurable
filter so sexp output (segments_from_spans) is unchanged while word.parts
decomposition (segments_with_params) includes parameter expansions.
The param expansion parser handles:
- Simple variables: $var, $?, $1
- Braced expansions: ${var}, ${var:-default}, ${var##pattern}
- Length: ${#var}
- Indirect: ${!var}, ${!var:-default}
- Array subscripts: ${arr[@]}
- All standard bash operators (22 operators, longest-match-first)
All 1604+ Parable tests and oracle tests pass unchanged.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mpecan
added a commit
that referenced
this pull request
Apr 7, 2026
🤖 I have created a release *beep* *boop* --- ## [0.1.9](rable-v0.1.8...rable-v0.1.9) (2026-04-07) ### Features * decompose parameter expansions into Word.parts ([b0ad648](b0ad648)) * decompose parameter expansions into Word.parts ([#17](#17)) ([ded6897](ded6897)) ### Bug Fixes * resolve clippy errors in tree-sitter comparison test ([789da4d](789da4d)) * resolve clippy errors in tree-sitter comparison test ([#15](#15)) ([26570f9](26570f9)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
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.
Summary
$var,${var},${var:-default},${#var},${!var}) are now decomposed into proper AST nodes (ParamExpansion,ParamLength,ParamIndirect) inWord.partsbuild_segments()with a configurable filter so the sexp path (segments_from_spans) stays identical while the parts path (segments_with_params) includes param expansions:-,:=,##,%%,//,^,,,@,:, etc.Motivation
Downstream consumers walking
Word.partscould detectCommandSubstitutionandAnsiCQuotebut completely missed parameter expansions. They had to fall back to string-matchingvalue.contains("${")which is fragile and can't distinguish${var:-safe}from${var}.Files changed
src/sexp/word.rsWordSegmentvariants,segments_with_params(),build_segments()refactor,is_decomposablefiltersrc/parser/word_parts.rssegment_to_nodearms, param expansion parser (10 functions), 14 new testssrc/sexp/mod.rswrite_redirect_segmentsmatch arm for new variantssrc/format/mod.rsprocess_word_valuematch arm for new variantsTest plan
cargo fmt— cleancargo clippy --all-targets -- -D warnings— no warningscargo test— 153 tests pass (99 unit + 53 integration + 1 tree-sitter comparison)just test-oracle— oracle tests pass🤖 Generated with Claude Code