Skip to main content

Module shell

Module shell 

Source
Expand description

Shell command parsing backed by tree-sitter-bash.

Public API:

The parser uses tree-sitter-bash for a full AST, then walks it to produce segments joined by operators. Substitutions ($(), backticks, <(), >()) are recursively parsed into nested pipelines — the result is a tree that can be evaluated bottom-up (catamorphism).

§Control flow handling

Shell keywords (for, if, while, case) are grammar structure, not commands. The walker recurses into their bodies and extracts the actual commands as segments.

§Redirection propagation

When a control flow construct has output redirection (e.g. for ... done > file), it propagates to inner segments via ShellSegment::redirection.

Functions§

dump_ast
Diagnostic: dump the tree-sitter AST and parsed pipeline.
has_output_redirection
Check whether command contains output redirection.
parse_with_substitutions
Parse a shell command into a recursive pipeline tree.