Documentation
¶
Overview ¶
Package ast defines the typed Go AST that mirrors the just-bash TypeScript shape in src/ast/types.ts. It is the public AST surface produced by parser.Parse / parser.ParseString and consumed by the (future, Phase 13) transform plugin pipeline.
Stability ¶
Add new node types freely; renaming or removing exported fields is a breaking change. Each compound-command type leaves room for parity-only fields that are not yet populated by the translator — Phase 4 ships the public shape; later phases (transform plugins in Phase 13, interpreter bridge in Phase 5) drive incremental fills.
Origin pointer ¶
Script carries an Origin field pointing back at the mvdan.cc/sh/v3/syntax.File the parser produced. transform.Serialize uses Origin to byte-faithfully render the script back to bash source. Origin is nil for plugin-synthesized scripts (Phase 13+); the inverse translator in the transform package handles that case via best-effort reconstruction with default positions.
Index ¶
- type Alternative
- type AnsiCQuoted
- type ArithCmd
- type ArithmeticExpansion
- type ArrayElement
- type ArrayInit
- type Assign
- type Assignment
- type CStyleFor
- type CaseItem
- type CaseModify
- type CaseStmt
- type Command
- type CommandSubstitution
- type CondCmd
- type DBracket
- type DefaultValue
- type DoubleQuoted
- type ErrorOp
- type ExtGlob
- type ForStmt
- type FunctionDef
- type Group
- type Heredoc
- type IfBranch
- type IfStmt
- type Keys
- type Literal
- type Names
- type Node
- type ParamOp
- type ParameterExpansion
- type PatternRemove
- type Pipeline
- type ProcessSubstitution
- type Redirection
- type Replace
- type Script
- type SimpleCommand
- type SingleQuoted
- type Statement
- type Subshell
- type SubstringRange
- type Transform
- type WhileStmt
- type Word
- type WordPart
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alternative ¶
Alternative: ${var+word} (or ${var:+word} when ColonNull).
type AnsiCQuoted ¶
type AnsiCQuoted struct{ Value string }
AnsiCQuoted is the $'...' bash-specific quote form with C-style escapes. We keep the raw inner text and let the runtime decode.
type ArithmeticExpansion ¶
type ArithmeticExpansion struct {
Expr string
}
ArithmeticExpansion captures $((expr)). We keep the expression source verbatim and let the interpreter (or a runtime transform) evaluate it.
type ArrayElement ¶
ArrayElement is one element of an array literal. Index is "" for positional entries.
type ArrayInit ¶
type ArrayInit struct {
Elements []*ArrayElement
}
ArrayInit holds an array literal: `(a b c)` or `([k]=v ...)`.
type Assignment ¶
Assignment is a `NAME=value` or `NAME+=value` (Append) shell assignment. Array is non-nil for `NAME=(elem ...)` form.
type CaseModify ¶
CaseModify: ${var^}, ${var^^}, ${var,}, ${var,,}.
type Command ¶
type Command interface {
Node
// contains filtered or unexported methods
}
Command is one element of a Pipeline. Every command type also implements Node.
type CommandSubstitution ¶
CommandSubstitution is $(...) or `...` (Backtick).
type CondCmd ¶
CondCmd: [[ expr ]]. The Expr text is kept verbatim for Phase 4 — a proper CondExpr tree lands when we wire conditional evaluation in Phase 5/6.
type DBracket ¶
type DBracket = CondCmd
DBracket is the spec's alternate spelling for CondCmd. Defined as a type alias for API parity with src/ast/types.ts.
type DefaultValue ¶
DefaultValue: ${var-word} (or ${var:-word} when ColonNull).
type DoubleQuoted ¶
type DoubleQuoted struct{ Parts []WordPart }
DoubleQuoted holds the inner parts of a "..." word part.
type ExtGlob ¶
ExtGlob captures bash extended glob patterns: ?(pat), *(pat), +(pat), @(pat), !(pat). Op is one of "?", "*", "+", "@", "!".
type FunctionDef ¶
FunctionDef: name() { ... } or function name { ... }.
type Group ¶
type Group struct {
Body []*Statement
Redirections []*Redirection
Line int
}
Group: { cmds; }.
type Heredoc ¶
type Heredoc struct {
Tag string
Body string
StripTabs bool // true for <<-
Expand bool // false when tag was quoted
}
Heredoc carries the body of a here-document.
type Names ¶
type Names struct {
SplitWords bool // true for @, false for *
}
Names: ${!prefix*} / ${!prefix@}.
type Node ¶
type Node interface {
// contains filtered or unexported methods
}
Node is the closed type implemented by every AST node. The nodeMarker method is unexported to prevent external implementations.
type ParamOp ¶
type ParamOp interface {
Node
// contains filtered or unexported methods
}
ParamOp is the closed interface implemented by every parameter expansion modifier.
type ParameterExpansion ¶
type ParameterExpansion struct {
Parameter string
Operation ParamOp
Indirect bool // ${!var}
Length bool // ${#var}
Index string // raw text inside subscript [...]; "" if none
}
ParameterExpansion captures $var, ${var}, ${var-default}, etc. Parameter is the variable name (or special parameter like "?", "0", "@"). Operation is one of the concrete *ParamOp* types below, or nil for a bare ${var} reference.
type PatternRemove ¶
PatternRemove: ${var#pat} ${var##pat} ${var%pat} ${var%%pat}.
type Pipeline ¶
type Pipeline struct {
Commands []Command
PipeStderr []bool // length = len(Commands) - 1
Negated bool
Line int
}
Pipeline is a sequence of Commands connected by | (or |& when the corresponding PipeStderr entry is true). Negated is true when the leftmost pipeline element carries a leading `!`.
type ProcessSubstitution ¶
ProcessSubstitution captures <(cmds) and >(cmds).
type Redirection ¶
type Redirection struct {
FD int // -1 when not specified
Op string // ">", ">>", "<", "<<", "<<-", "<<<", "<>", ">|", "&>", "&>>", "<&", ">&"
Word *Word // target word
Heredoc *Heredoc // non-nil for <<, <<-
}
Redirection is a single input/output redirection attached to a command.
type Script ¶
type Script struct {
Statements []*Statement
Line int
// Origin is the back-reference to the original mvdan.cc/sh/v3
// *syntax.File the parser walked. transform.Serialize uses it for
// byte-identical round-trips. Nil for plugin-synthesized scripts.
Origin *syntax.File
}
Script is the root of a parsed bash file.
type SimpleCommand ¶
type SimpleCommand struct {
Assignments []*Assignment
Name *Word // may be nil for assignment-only statements
Args []*Word
Redirections []*Redirection
Line int
}
SimpleCommand is a leaf command: zero or more inline assignments followed by a command name and its arguments, plus any redirections.
type SingleQuoted ¶
type SingleQuoted struct{ Value string }
SingleQuoted holds a single-quoted string: '...'.
type Statement ¶
type Statement struct {
Pipelines []*Pipeline
Operators []string // each "&&" or "||"; len = len(Pipelines)-1
Background bool
Line int
}
Statement is one and-or list: a sequence of pipelines joined by && or || (Operators), optionally terminated with & (Background).
Note: the just-bash AST overloads Operators to include ";" for in-source separators between pipelines on the same line; the Go port reserves Operators for "&&" and "||" and represents ";"-separated commands as distinct top-level Statements. This preserves the natural 1:1 mapping with mvdan.cc/sh/v3's *syntax.Stmt and is a deliberate resolved decision.
type Subshell ¶
type Subshell struct {
Body []*Statement
Redirections []*Redirection
Line int
}
Subshell: (cmds).
type SubstringRange ¶
SubstringRange: ${var:offset:length}. Length is "" when omitted.