JustBash.Parser (JustBash v0.4.0)

View Source

Recursive Descent Parser for Bash Scripts.

This parser consumes tokens from the lexer and produces an AST. It follows the bash grammar structure for correctness.

Complex functionality is delegated to submodules:

  • Parser.Compound - if/for/while/case and other compound commands
  • Parser.Redirection - File redirections (>, >>, <, etc.)
  • Parser.Heredoc - Heredoc content handling (parser-level, fills heredoc body into AST)

Grammar (simplified): script ::= statement statement ::= pipeline ((&&|'||') pipeline) [&] pipeline ::= [!] command (| command) command ::= simple_command | compound_command | function_def simple_cmd ::= (assignment) [word] (word) (redirection) compound_cmd ::= if | for | while | until | case | subshell | group | (( | [[

Summary

Functions

Parse a bash script string into an AST.

Parse a bash script string into an AST, raising on error.

Types

t()

@type t() :: %JustBash.Parser{
  parse_iterations: non_neg_integer(),
  pending_heredocs: list(),
  pos: non_neg_integer(),
  tokens: [JustBash.Parser.Lexer.Token.t()]
}

Functions

parse(input)

Parse a bash script string into an AST.

parse!(input)

@spec parse!(String.t()) :: JustBash.AST.Script.t()

Parse a bash script string into an AST, raising on error.