Skip to content

feat(bashkit): Phase 5 - Array support#6

Merged
chaliy merged 1 commit intomainfrom
claude/bash-filesystem-library-cYGoo
Jan 31, 2026
Merged

feat(bashkit): Phase 5 - Array support#6
chaliy merged 1 commit intomainfrom
claude/bash-filesystem-library-cYGoo

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Jan 31, 2026

Summary

Add indexed array support to the bash interpreter.

Features

Array Declaration

  • arr=(a b c) - Array literal assignment
  • arr[0]=value - Indexed element assignment

Array Access

  • ${arr[0]} - Single element access
  • ${arr[@]} and ${arr[*]} - All elements
  • ${#arr[@]} - Array length (number of elements)

Implementation

AST Changes

  • Assignment now has optional index field for arr[n]=value
  • New AssignmentValue enum: Scalar(Word) vs Array(Vec<Word>)
  • New WordPart::ArrayAccess { name, index } for ${arr[...]}
  • New WordPart::ArrayLength(name) for ${#arr[@]}

Parser Changes

  • Handle arr=(...) syntax where ( is a separate token
  • Parse array subscripts in assignments
  • Parse ${arr[...]} access patterns in words
  • Avoid treating arr=( as function definition

Interpreter Changes

  • Added arrays: HashMap<String, HashMap<usize, String>> storage
  • Expand array access with @ or * to all elements
  • Evaluate arithmetic expressions in array indices

Test plan

  • 104 tests passing (+4 new array tests)
  • Basic array declaration and access
  • All elements expansion
  • Array length
  • Indexed assignment
  • Clippy clean

Add indexed array support:
- Array literal assignment: arr=(a b c)
- Indexed assignment: arr[0]=value
- Element access: ${arr[0]}
- All elements: ${arr[@]} ${arr[*]}
- Array length: ${#arr[@]}

AST changes:
- Assignment now has optional index for arr[n]=value
- AssignmentValue enum: Scalar vs Array
- WordPart::ArrayAccess for ${arr[index]}
- WordPart::ArrayLength for ${#arr[@]}

Parser changes:
- Handle arr=(...) syntax with separate tokens
- Parse array subscripts in assignments
- Parse ${arr[...]} access patterns
- Don't treat arr=( as function definition

Interpreter changes:
- HashMap<String, HashMap<usize, String>> for array storage
- Expand array access with @/* for all elements
- Evaluate arithmetic in array indices

Tests: 104 passing (+4 array tests)

https://claude.ai/code/session_01A16cD8ztbTJs2PB2iHe1Ua
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@chaliy chaliy merged commit 57b6915 into main Jan 31, 2026
1 check passed
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