Skip to content

feat(parser): print function bodies like bash and close BashBox parser gaps (45 cases) - #2599

Merged
chaliy merged 13 commits into
mainfrom
claude/project-thread-eafupr-bb-printer
Oct 7, 2026
Merged

chaliy merged 13 commits into
mainfrom
claude/project-thread-eafupr-bb-printer

Conversation

@chaliy

@chaliy chaliy commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

What changed

type f, declare -f f and declare -p now print function bodies the way bash does: a port of bash's print_cmd.c with its indentation, ; placement, redirections, here-documents, case/select/(( ))/[[ ]]/coproc and nested functions.

Parser fixes that came out of the same cases:

  • (( )) is kept as raw text, so the arithmetic prints back unchanged.
  • Here-document edge cases.
  • ]] handling inside [[ ]].
  • |&.
  • Arithmetic: a sign right after an operator is unary (3 - -1).

Why

Fourth step of adopting the BashBox corpus (#2575): function printing was a whole cluster of its bash-verified failures, and agents use type/declare -f to inspect what they defined.

Before / After

BashBox corpus cases still skipped: 420 → 375 (45 unskipped: type 25, syntax 7, lexer 4, script 4, parser 2, compound 2, line 1).

Example now passing, output identical to bash:

$ f() { echo hi; }; type f
f is a function
f () 
{ 
    echo hi
}

Risk

  • Medium
  • Parser changes touch every script. parallel_execution bench showed no regression over 10%.
  • Known gap: &>> inside a function prints as >> f 2>&1 (bash prints &>> f). Expansion errors such as $((1/0)) aborting the line are documented as a gap in knowledge/.

Checklist

  • Tests added or updated
  • Backward compatibility considered

Generated by Claude Code

chaliy added 8 commits October 7, 2026 16:35
Copies (script, stdout) pairs from shipfastlabs/bashbox (MIT) into
spec_cases/bash/bashbox-*.test.sh, keeping only cases whose recorded
output matches host bash. 624 pass and join the bash comparison gate;
420 are marked TODO skips: real gaps where bashkit differs from bash.
Attribution in NOTICE; process in knowledge/operations/testing.md.
…-eafupr-bashbox-corpus

# Conflicts:
#	THIRD_PARTY_LICENSES/README.md
…r gaps

- type / declare -f print function bodies via a print_cmd.c port
  (parser/print_cmd.rs); words keep source text while parsing function
  bodies; function bodies may be any compound command with redirections
- (( )) and for (( )) read raw up to the matching )); heredoc delimiter
  quoting decided from its source text; several heredocs per command
- ]] closes [[ only as a whole word; |& is 2>&1 |
- backquoted bodies that fail to parse error at run time (status 2)
- process substitution ends where the substitution scanner closes it
- ${x:-$(cmd)} runs operand substitutions only when the operand is used;
  quoted replacement text keeps } inside '...'
- LINENO honors local/unset; script children keep caller cwd and shared
  stdin position; command ./script runs scripts; eval/source parse
  errors exit 2
- simple-command word/redirect handling outlined so nested $( ) parsing
  uses less stack than before
…-eafupr-bb-printer

# Conflicts:
#	crates/bashkit/src/parser/mod.rs
#	crates/bashkit/tests/spec_cases/bash/bashbox-compound-syntax.test.sh
#	crates/bashkit/tests/spec_cases/bash/bashbox-lexer.test.sh
#	crates/bashkit/tests/spec_cases/bash/bashbox-line-number.test.sh
#	crates/bashkit/tests/spec_cases/bash/bashbox-parser.test.sh
#	crates/bashkit/tests/spec_cases/bash/bashbox-script-file.test.sh
#	crates/bashkit/tests/spec_cases/bash/bashbox-syntax-error.test.sh
#	crates/bashkit/tests/spec_cases/bash/bashbox-type-printer.test.sh
…-eafupr-bb-printer

# Conflicts:
#	crates/bashkit/src/parser/lexer.rs
#	crates/bashkit/src/parser/mod.rs
@chaliy chaliy self-assigned this Oct 7, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 84f7841 Commit Preview URL

Branch Preview URL
Oct 07 2026, 10:56 PM

chaliy added 5 commits October 7, 2026 21:31
A function call is the recursion path. Dispatching it from the same
future as the builtin and PATH-search arms put that whole frame on the
stack at every call level, so 16 nested calls overflowed a 2 MiB stack
in debug builds. Functions now get their own small future. Also adds
the raw field to the Word built by main's array-literal change.
The unary-sign change made 2 ** -1 parse its exponent as -1, which
the clamp turned into 2 ** 0 = 1. Keep the evaluator's error value 0.
…-eafupr-bb-printer

# Conflicts:
#	crates/bashkit/src/interpreter/mod.rs
@chaliy
chaliy merged commit b54e847 into main Oct 7, 2026
44 checks passed
@chaliy
chaliy deleted the claude/project-thread-eafupr-bb-printer branch October 7, 2026 23:18
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