Skip to content

Comments

feat(bash): arithmetic exponentiation, base literals, mapfile#241

Merged
chaliy merged 6 commits intomainfrom
claude/bashkit-bash-compatibility-BsDKD
Feb 24, 2026
Merged

feat(bash): arithmetic exponentiation, base literals, mapfile#241
chaliy merged 6 commits intomainfrom
claude/bashkit-bash-compatibility-BsDKD

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Feb 24, 2026

Summary

  • Implement arithmetic ** (exponentiation) operator with correct precedence over *
  • Add base#value literal support (16#ff, 2#1010, 8#77) and 0x/077 prefix literals
  • Add unary operators (!, ~, -) in arithmetic expressions
  • Implement mapfile/readarray builtin with -t flag and custom array names
  • Fix expand_arithmetic_vars to track numeric literal context, preventing hex digits from being expanded as variable names

Test plan

  • 10 new arithmetic spec tests (exponentiation, base literals, hex/octal, unary ops)
  • 3 new mapfile spec tests (basic, readarray alias, default MAPFILE name)
  • All 757 bash spec tests pass (752 pass, 5 skip)
  • Bash comparison tests pass (mapfile pipe tests marked bash_diff)
  • Full test suite passes (cargo test --all-features)
  • Clippy clean

jaq's built-in `env` function reads from std::env::vars() which
doesn't see bashkit's virtual environment. Fix: temporarily expose
ctx.env and ctx.variables to the process environment before running
jaq, with an RAII drop guard for cleanup on all return paths.

- Unskip jq_env spec test
- Add jq_env_missing and jq_env_in_pipeline spec tests
- Add test_jq_env_access and test_jq_env_missing_var unit tests

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
Replace per-value empty inputs iterator with a shared RcIter over
all parsed JSON values.  Main loop and filter's input/inputs functions
consume from the same source, matching real jq behavior.

- Unskip jq_input and jq_inputs spec tests
- Add jq_input_with_dot, jq_inputs_empty spec tests
- Add 3 unit tests (input_reads_next, inputs_collects_remaining,
  inputs_single_value)

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
- Arithmetic ** (power) operator with correct precedence over *
- Base#value literals (16#ff, 2#1010, 8#77) and 0x/077 prefixes
- Unary operators: !, ~, - in arithmetic expressions
- mapfile/readarray builtin with -t flag and custom array name
- expand_arithmetic_vars tracks numeric literal context to avoid
  expanding hex digits as variable names
- 13 new spec tests (10 arithmetic, 3 mapfile)

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
…n, heredoc <<-

Arithmetic evaluation:
- Bitwise XOR (^), left/right shift (<<, >>)
- Compound assignments (+=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=)
- Pre/post increment/decrement (++x, x++, --x, x--)
- Comma operator for multi-expression evaluation
- Fix C-style for loop with <= and >= conditions

Shell features:
- trap builtin with EXIT handler support
- PIPESTATUS array tracking per-command exit codes in pipelines
- Subshell (...) variable isolation (changes don't leak to parent)
- Heredoc tab-stripping with <<- syntax
- ${!prefix*} / ${!prefix@} variable name prefix matching

Parser fixes:
- HereDocStrip token for <<- heredocs
- Fix arithmetic for-loop condition reconstruction (<=, >= operators)
- PrefixMatch WordPart for ${!prefix*} expansion

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
@chaliy chaliy force-pushed the claude/bashkit-bash-compatibility-BsDKD branch from 29312c2 to 1e40756 Compare February 24, 2026 04:24
- set -o pipefail: pipeline returns rightmost non-zero exit code
- trap ERR: fires on non-zero exit from semicolon-separated commands
- ${var@Q/@U/@u/@L/@A/@a/@e}: parameter transformation operators
- printf -v varname: assign formatted output to variable
- read -a arr: read words into indexed array
- read -n N: read at most N characters
- read -d delim: custom delimiter
- set -o/+o long option names (pipefail, errexit, nounset, etc.)
- Fix cargo vet exemption versions for dependency bumps
- Update 009-implementation-status.md: trap partially implemented,
  800 bash test cases (up from 744)
Variable assignments now check call_stack frames before writing to
globals, matching bash's dynamic scoping. Also uses set_variable() in
all arithmetic assignment paths (=, +=, ++, -- etc).

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
@chaliy chaliy merged commit 4807416 into main Feb 24, 2026
16 checks 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