Skip to content

feat: decompose parameter expansions into Word.parts#17

Merged
mpecan merged 1 commit intomainfrom
feat/param-expansion-word-parts
Apr 7, 2026
Merged

feat: decompose parameter expansions into Word.parts#17
mpecan merged 1 commit intomainfrom
feat/param-expansion-word-parts

Conversation

@mpecan
Copy link
Copy Markdown
Owner

@mpecan mpecan commented Apr 7, 2026

Summary

  • Parameter expansions ($var, ${var}, ${var:-default}, ${#var}, ${!var}) are now decomposed into proper AST nodes (ParamExpansion, ParamLength, ParamIndirect) in Word.parts
  • S-expression output is unchanged — refactored build_segments() with a configurable filter so the sexp path (segments_from_spans) stays identical while the parts path (segments_with_params) includes param expansions
  • 22 bash operators supported via longest-match-first parsing: :-, :=, ##, %%, //, ^, ,, @, :, etc.
  • 14 new unit tests covering simple vars, braced expansions, length, indirect, special params, array subscripts, and mixed text

Motivation

Downstream consumers walking Word.parts could detect CommandSubstitution and AnsiCQuote but completely missed parameter expansions. They had to fall back to string-matching value.contains("${") which is fragile and can't distinguish ${var:-safe} from ${var}.

Files changed

File Changes
src/sexp/word.rs WordSegment variants, segments_with_params(), build_segments() refactor, is_decomposable filter
src/parser/word_parts.rs segment_to_node arms, param expansion parser (10 functions), 14 new tests
src/sexp/mod.rs write_redirect_segments match arm for new variants
src/format/mod.rs process_word_value match arm for new variants

Test plan

  • cargo fmt — clean
  • cargo clippy --all-targets -- -D warnings — no warnings
  • cargo test — 153 tests pass (99 unit + 53 integration + 1 tree-sitter comparison)
  • just test-oracle — oracle tests pass
  • All 1604+ Parable S-expression tests unchanged

🤖 Generated with Claude Code

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 mpecan merged commit ded6897 into main Apr 7, 2026
5 checks passed
@mpecan mpecan deleted the feat/param-expansion-word-parts branch April 7, 2026 07:31
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).
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