Bash.Parser (Bash v0.6.0)

Copy Markdown View Source

Recursive descent parser for Bash scripts.

Converts tokens from the Tokenizer into AST nodes.

Grammar Overview

The parser follows Bash's grammar from parse.y:

script       → statement_list EOF
statement    → simple_command
             | compound_command
             | pipeline
             | control_flow
pipeline     → command ('|' command)*
command      → simple_command redirect*
simple_cmd   → assignment* name word* redirect*
compound_cmd → '{' list '}'
             | '(' list ')'
             | if_clause
             | for_clause
             | while_clause
             | case_clause
             | function_def

Summary

Functions

Parse a Bash script string into an AST.

Types

state()

@type state() :: %{tokens: [token()], pos: non_neg_integer()}

token()

@type token() :: Bash.Tokenizer.token()

Functions

parse(input)

@spec parse(String.t()) ::
  {:ok, Bash.Script.t()} | {:error, String.t(), pos_integer(), pos_integer()}

Parse a Bash script string into an AST.