JustBash.Parser (JustBash v0.4.0)
View SourceRecursive 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 commandsParser.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
@type t() :: %JustBash.Parser{ parse_iterations: non_neg_integer(), pending_heredocs: list(), pos: non_neg_integer(), tokens: [JustBash.Parser.Lexer.Token.t()] }
Functions
@spec parse(String.t()) :: {:ok, JustBash.AST.Script.t()} | {:error, JustBash.Parser.ParseError.t() | JustBash.Parser.Lexer.Error.t()}
Parse a bash script string into an AST.
@spec parse!(String.t()) :: JustBash.AST.Script.t()
Parse a bash script string into an AST, raising on error.