Skip to content

feat: implement brace expansion as strict subset of bash#273

Merged
wolfv merged 4 commits intomainfrom
claude/brace-expansion-strict-011CV1cr6ktJxfkeuQT8X25D
Mar 17, 2026
Merged

feat: implement brace expansion as strict subset of bash#273
wolfv merged 4 commits intomainfrom
claude/brace-expansion-strict-011CV1cr6ktJxfkeuQT8X25D

Conversation

@wolfv
Copy link
Member

@wolfv wolfv commented Nov 11, 2025

This commit adds brace expansion support to the shell, implementing a strict subset of bash's brace expansion functionality.

Supported features:

  • Comma-separated lists: {a,b,c} → a b c
  • Numeric sequences: {1..10} → 1 2 3 4 5 6 7 8 9 10
  • Character sequences: {a..z} → a b c ... z
  • Reverse sequences: {10..1} → 10 9 8 7 6 5 4 3 2 1
  • Step sequences: {1..10..2} → 1 3 5 7 9
  • Reverse step sequences: {10..1..2} → 10 8 6 4 2
  • Empty elements: {a,,b} → a b
  • Quoted braces don't expand: "{a,b,c}" → {a,b,c}

Implementation details:

  • Added BRACE_EXPANSION grammar rule to grammar.pest
  • Added BraceExpansion enum to parser.rs with List and Sequence variants
  • Added WordPart::BraceExpansion variant
  • Implemented expand_braces() and expand_sequence() functions
  • Added comprehensive test suite in brace_expansion.sh

The implementation is a strict subset of bash, ensuring compatibility while keeping the implementation simple and maintainable.

Fixes #242

claude and others added 4 commits November 11, 2025 06:37
This commit adds brace expansion support to the shell, implementing
a strict subset of bash's brace expansion functionality.

Supported features:
- Comma-separated lists: {a,b,c} → a b c
- Numeric sequences: {1..10} → 1 2 3 4 5 6 7 8 9 10
- Character sequences: {a..z} → a b c ... z
- Reverse sequences: {10..1} → 10 9 8 7 6 5 4 3 2 1
- Step sequences: {1..10..2} → 1 3 5 7 9
- Reverse step sequences: {10..1..2} → 10 8 6 4 2
- Empty elements: {a,,b} → a  b
- Quoted braces don't expand: "{a,b,c}" → {a,b,c}

Implementation details:
- Added BRACE_EXPANSION grammar rule to grammar.pest
- Added BraceExpansion enum to parser.rs with List and Sequence variants
- Added WordPart::BraceExpansion variant
- Implemented expand_braces() and expand_sequence() functions
- Added comprehensive test suite in brace_expansion.sh

The implementation is a strict subset of bash, ensuring compatibility
while keeping the implementation simple and maintainable.

Fixes #242
- Resolve merge conflicts with upstream import reorganization and new tests
- Fix prefix/suffix combining with brace elements (pre{a,b}post now works)
- Fix operator precedence bug in character sequence step direction
- Fix grammar to allow dots in brace elements ({foo.txt,bar.txt})
- Extract shared generate_range() to deduplicate numeric/char sequences
- Use char::from_u32 instead of lossy u8 cast for char sequences
- Expand braces at word level before evaluation for correct semantics
- Add 16 new brace expansion tests covering prefix/suffix, cartesian
  product, dots, hyphens, steps, and quoted braces

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wolfv wolfv merged commit 7c932fa into main Mar 17, 2026
8 checks passed
@wolfv wolfv deleted the claude/brace-expansion-strict-011CV1cr6ktJxfkeuQT8X25D branch March 17, 2026 13:12
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.

2 participants