Expand description
Typed AST for bash, mirroring tree-sitter-bash’s node-types.json 1:1.
Every named node kind in the grammar has a representation here. The three
supertypes (_statement, _expression, _primary_expression) become Rust
enums; the 12 nodes with named fields become structs with field-named
members; everything else gets a leaf struct carrying its text and span.
Where the grammar allows a wider type set than a supertype enum covers
(e.g. binary_expression.left permits subscript and variable_name in
addition to _expression), we define small ad-hoc operand enums rather
than widening Expression itself — keeps the mapping faithful.
@yah:ticket(R155-T1, “Add Deserialize + PartialEq to bash-ast::ast::Program + BashShape; round-trip JSON test”) @yah:assignee(agent:claude) @yah:at(2026-05-13T00:20:06Z) @yah:status(review) @yah:phase(P1) @yah:parent(R155) @arch:see(.yah/docs/working/W113-yah-bash-snapshot-and-permissions.md)
Structs§
- AnsiC
String - Arithmetic
Expansion - Array
- Binary
Expression - Binary
Operator - All operators the grammar lists for
binary_expression. We keep the rawtextalongside so callers can pretty-print without a table lookup. - Brace
Expression - CStyle
ForStatement - Case
Item - Case
Statement - Command
- Command
Name - Command
Substitution - Comment
- Compound
Statement - Concatenation
- Declaration
Command - DoGroup
- Elif
Clause - Else
Clause - Expansion
- Expansion
Operator - Extglob
Pattern - File
Descriptor - File
Redirect - ForStatement
- Function
Definition - Heredoc
Body - Heredoc
Content - Heredoc
End - Heredoc
Redirect - Heredoc
Start - Herestring
Redirect - IfStatement
- List
- Negated
Command - Number
- Parenthesized
Expression - Pipeline
- Point
- Postfix
Expression - Process
Substitution - Program
- RawString
- Redirected
Statement - Regex
- Simple
Expansion - Span
- Source byte + (row, column) span. Owned (no lifetime) so the AST can be passed around freely.
- Special
Variable Name - String
Content - String
Node - Subscript
- Subshell
- Ternary
Expression - Test
Command - Test
Operator - Translated
String - Unary
Expression - Unary
Operator - Unset
Command - Variable
Assignment - Variable
Assignments a=1 b=2 c=3as a free-standing prefix without a command.- Variable
Name - While
Statement - Word
Enums§
- Array
Element - Assignment
Target - Name slot of
variable_assignment— either a plain name or a subscript. - Assignment
Value - What appears in
variable_assignment.value. - Binary
Extra - Binary
Operator Kind - Binary
Right Operand - Permitted on
binary_expression.right— addsextglob_patternandregex. - CStyle
ForPart - Element inside the parenthesized header of a C-style
for ((..;..;..)). - Case
Fallthrough - Case
Pattern - Permitted in the
valuefield ofcase_statementandcase_item.value. - Case
Termination - Command
Argument - Argument list slot of
command— adds$,==,=~,regexas bare tokens. - Command
Name Inner - Condition
Part - Single condition step in
if_statement.condition/while_statement.condition(the grammar admits a statement plus a terminator token). - Declaration
Part - Expansion
Element - Element inside an
expansionbody. - Expression
- Function
Body - Permitted as the body of a
function_definition. - Heredoc
Operator - Herestring
Value - List
Operator - Loop
Body - Body of a
for/whileloop. - Postfix
Operator - Primary
Expression - Redirect
- Permitted in a
redirected_statement.redirectslot. - Redirect
Destination - Simple
Expansion Element - Simple
Redirect - Restricted redirect set used by
command.redirectandfunction_definition.redirect. - Statement
- String
Part - Subscript
Index - What
subscript.indexmay contain. - Test
Operand - Permitted operand at
binary_expression.left,unary_expression,postfix_expression,ternary_expression.{condition,consequence,alternative}. - Unary
Operator Kind - Unset
Part
Type Aliases§
- Command
SubBody - What
command_substitutionwraps: a sequence of statements.