ast

package
v0.1.36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ProgramNode                 = &Program{}
	LetStatementNode            = &LetStatement{}
	ReturnStatementNode         = &ReturnStatement{}
	ExpressionStatementNode     = &ExpressionStatement{}
	BlockStatementNode          = &BlockStatement{}
	IfStatementNode             = &IfStatement{}
	ForLoopStatementNode        = &ForLoopStatement{}
	WhileLoopStatementNode      = &WhileLoopStatement{}
	IdentifierNode              = &Identifier{}
	IntegerLiteralNode          = &IntegerLiteral{}
	BooleanNode                 = &Boolean{}
	PrefixExpressionNode        = &PrefixExpression{}
	PostfixExpressionNode       = &PostfixExpression{}
	InfixExpressionNode         = &InfixExpression{}
	CallExpressionNode          = &CallExpression{}
	IndexExpressionNode         = &IndexExpression{}
	ArrayAccessNode             = &ArrayAccess{}
	BracketExpressionNode       = &BracketExpression{}
	DoubleBracketExpressionNode = &DoubleBracketExpression{}
	CommandSubstitutionNode     = &CommandSubstitution{}
	DollarParenExpressionNode   = &DollarParenExpression{}
	SimpleCommandNode           = &SimpleCommand{}
	ConcatenatedExpressionNode  = &ConcatenatedExpression{}
	InvalidArrayAccessNode      = &InvalidArrayAccess{}
	ArrayLiteralNode            = &ArrayLiteral{}
	StringLiteralNode           = &StringLiteral{}
	GroupedExpressionNode       = &GroupedExpression{}
	SelectStatementNode         = &SelectStatement{}
	CoprocStatementNode         = &CoprocStatement{}
	DeclarationStatementNode    = &DeclarationStatement{}
	ArithmeticCommandNode       = &ArithmeticCommand{}
	RedirectionNode             = &Redirection{}
	ProcessSubstitutionNode     = &ProcessSubstitution{}
	SubshellNode                = &Subshell{}
	FunctionDefinitionNode      = &FunctionDefinition{}
	FunctionLiteralNode         = &FunctionLiteral{}
	CaseStatementNode           = &CaseStatement{}
	ShebangNode                 = &Shebang{}
)

Functions

func Walk

func Walk(node Node, f WalkFn)

Walk traverses the AST starting from the given node. It calls the walkFn for each node.

Types

type ArithmeticCommand added in v0.0.73

type ArithmeticCommand struct {
	Token      token.Token // The '((' token
	Expression Expression
}

ArithmeticCommand represents an arithmetic command (( ... )).

func (*ArithmeticCommand) String added in v0.0.73

func (ac *ArithmeticCommand) String() string

func (*ArithmeticCommand) TokenLiteral added in v0.0.73

func (ac *ArithmeticCommand) TokenLiteral() string

func (*ArithmeticCommand) TokenLiteralNode added in v0.0.73

func (ac *ArithmeticCommand) TokenLiteralNode() token.Token

type ArrayAccess

type ArrayAccess struct {
	Token token.Token // The '$' token
	Left  Expression
	Index Expression
}

ArrayAccess represents an array access expression (e.g. ${arr[0]}).

func (*ArrayAccess) String

func (aa *ArrayAccess) String() string

String returns a string representation of the ArrayAccess.

func (*ArrayAccess) TokenLiteral

func (aa *ArrayAccess) TokenLiteral() string

func (*ArrayAccess) TokenLiteralNode added in v0.0.4

func (aa *ArrayAccess) TokenLiteralNode() token.Token

type ArrayLiteral added in v0.1.1

type ArrayLiteral struct {
	Token    token.Token // The '(' token
	Elements []Expression
}

ArrayLiteral represents an array literal (e.g., (val1 val2)).

func (*ArrayLiteral) String added in v0.1.1

func (al *ArrayLiteral) String() string

func (*ArrayLiteral) TokenLiteral added in v0.1.1

func (al *ArrayLiteral) TokenLiteral() string

func (*ArrayLiteral) TokenLiteralNode added in v0.1.1

func (al *ArrayLiteral) TokenLiteralNode() token.Token

type BlockStatement

type BlockStatement struct {
	Token      token.Token // the '{' token
	Statements []Statement
}

BlockStatement represents a block of statements (e.g., in if or function bodies).

func (*BlockStatement) String

func (bs *BlockStatement) String() string

String returns a string representation of the BlockStatement.

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

func (*BlockStatement) TokenLiteralNode added in v0.0.4

func (bs *BlockStatement) TokenLiteralNode() token.Token

type Boolean

type Boolean struct {
	Token token.Token // the TRUE or FALSE token
	Value bool        // boolean value
}

Boolean represents a boolean literal.

func (*Boolean) String

func (b *Boolean) String() string

String returns a string representation of the Boolean.

func (*Boolean) TokenLiteral

func (b *Boolean) TokenLiteral() string

func (*Boolean) TokenLiteralNode added in v0.0.4

func (b *Boolean) TokenLiteralNode() token.Token

type BracketExpression

type BracketExpression struct {
	Token    token.Token // The '{' token
	Elements []Expression
}

BracketExpression represents a bracket expression (e.g. {a, b, c}).

func (*BracketExpression) String

func (be *BracketExpression) String() string

String returns a string representation of the BracketExpression.

func (*BracketExpression) TokenLiteral

func (be *BracketExpression) TokenLiteral() string

func (*BracketExpression) TokenLiteralNode added in v0.0.4

func (be *BracketExpression) TokenLiteralNode() token.Token

type CallExpression

type CallExpression struct {
	Token     token.Token // The '(' token
	Function  Expression
	Arguments []Expression
}

CallExpression represents a function call expression.

func (*CallExpression) String

func (ce *CallExpression) String() string

String returns a string representation of the CallExpression.

func (*CallExpression) TokenLiteral

func (ce *CallExpression) TokenLiteral() string

func (*CallExpression) TokenLiteralNode added in v0.0.4

func (ce *CallExpression) TokenLiteralNode() token.Token

type CaseClause added in v0.0.4

type CaseClause struct {
	Token    token.Token // The pattern token
	Patterns []Expression
	Body     *BlockStatement
}

CaseClause represents a branch in a case statement.

func (*CaseClause) String added in v0.0.4

func (cc *CaseClause) String() string

func (*CaseClause) TokenLiteral added in v0.1.1

func (cc *CaseClause) TokenLiteral() string

func (*CaseClause) TokenLiteralNode added in v0.0.4

func (cc *CaseClause) TokenLiteralNode() token.Token

type CaseStatement added in v0.0.4

type CaseStatement struct {
	Token   token.Token
	Value   Expression
	Clauses []*CaseClause
}

CaseStatement represents a case statement.

func (*CaseStatement) String added in v0.0.4

func (cs *CaseStatement) String() string

String returns a string representation of the CaseStatement.

func (*CaseStatement) TokenLiteral added in v0.0.4

func (cs *CaseStatement) TokenLiteral() string

func (*CaseStatement) TokenLiteralNode added in v0.0.4

func (cs *CaseStatement) TokenLiteralNode() token.Token

type CommandSubstitution

type CommandSubstitution struct {
	Token   token.Token // The '$(' token
	Command Node
}

CommandSubstitution represents a command substitution (e.g. $(...)).

func (*CommandSubstitution) String

func (cs *CommandSubstitution) String() string

func (*CommandSubstitution) TokenLiteral

func (cs *CommandSubstitution) TokenLiteral() string

func (*CommandSubstitution) TokenLiteralNode added in v0.0.4

func (cs *CommandSubstitution) TokenLiteralNode() token.Token

type ConcatenatedExpression added in v0.0.4

type ConcatenatedExpression struct {
	Token token.Token
	Parts []Expression
}

ConcatenatedExpression represents a concatenated expression.

func (*ConcatenatedExpression) String added in v0.0.4

func (ce *ConcatenatedExpression) String() string

String returns a string representation of the ConcatenatedExpression.

func (*ConcatenatedExpression) TokenLiteral added in v0.0.4

func (ce *ConcatenatedExpression) TokenLiteral() string

func (*ConcatenatedExpression) TokenLiteralNode added in v0.0.4

func (ce *ConcatenatedExpression) TokenLiteralNode() token.Token

type CoprocStatement added in v0.0.123

type CoprocStatement struct {
	Token   token.Token // The 'coproc' token
	Name    string
	Command Statement
}

CoprocStatement represents a coproc statement.

func (*CoprocStatement) String added in v0.0.123

func (cs *CoprocStatement) String() string

func (*CoprocStatement) TokenLiteral added in v0.0.123

func (cs *CoprocStatement) TokenLiteral() string

func (*CoprocStatement) TokenLiteralNode added in v0.0.123

func (cs *CoprocStatement) TokenLiteralNode() token.Token

type DeclarationAssignment added in v0.0.123

type DeclarationAssignment struct {
	Name     *Identifier
	IsAppend bool
	Value    Expression
}

DeclarationAssignment represents an assignment in a declaration.

func (*DeclarationAssignment) String added in v0.1.1

func (da *DeclarationAssignment) String() string

type DeclarationStatement added in v0.0.123

type DeclarationStatement struct {
	Token       token.Token // The 'typeset'/'declare' token
	Command     string      // "typeset", "declare", "local", "export", "readonly"
	Flags       []string
	Assignments []*DeclarationAssignment
}

DeclarationStatement represents a typeset/declare statement.

func (*DeclarationStatement) String added in v0.0.123

func (ds *DeclarationStatement) String() string

func (*DeclarationStatement) TokenLiteral added in v0.0.123

func (ds *DeclarationStatement) TokenLiteral() string

func (*DeclarationStatement) TokenLiteralNode added in v0.0.123

func (ds *DeclarationStatement) TokenLiteralNode() token.Token

type DollarParenExpression

type DollarParenExpression struct {
	Token   token.Token // The '$(' token
	Command Node
}

DollarParenExpression represents a dollar paren expression (e.g., $(command)).

func (*DollarParenExpression) String

func (dpe *DollarParenExpression) String() string

String returns a string representation of the DollarParenExpression.

func (*DollarParenExpression) TokenLiteral

func (dpe *DollarParenExpression) TokenLiteral() string

func (*DollarParenExpression) TokenLiteralNode added in v0.0.4

func (dpe *DollarParenExpression) TokenLiteralNode() token.Token

type DoubleBracketExpression

type DoubleBracketExpression struct {
	Token    token.Token // The '[[' token
	Elements []Expression
}

DoubleBracketExpression represents a double bracket expression (e.g. [[ a ]]).

func (*DoubleBracketExpression) String

func (dbe *DoubleBracketExpression) String() string

String returns a string representation of the DoubleBracketExpression.

func (*DoubleBracketExpression) TokenLiteral

func (dbe *DoubleBracketExpression) TokenLiteral() string

func (*DoubleBracketExpression) TokenLiteralNode added in v0.0.4

func (dbe *DoubleBracketExpression) TokenLiteralNode() token.Token

type Expression

type Expression interface {
	Node
	// contains filtered or unexported methods
}

Expression represents an expression in the AST.

type ExpressionStatement

type ExpressionStatement struct {
	Token      token.Token // the first token of the expression
	Expression Expression  // expression node
}

ExpressionStatement represents an expression statement.

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

String returns a string representation of the ExpressionStatement.

func (*ExpressionStatement) TokenLiteral

func (es *ExpressionStatement) TokenLiteral() string

func (*ExpressionStatement) TokenLiteralNode added in v0.0.4

func (es *ExpressionStatement) TokenLiteralNode() token.Token

type ForLoopStatement

type ForLoopStatement struct {
	Token     token.Token // The 'for' token
	Init      Expression
	Condition Expression
	Post      Expression
	Name      *Identifier
	Items     []Expression
	Body      *BlockStatement
}

ForLoopStatement represents a for loop statement.

func (*ForLoopStatement) String

func (fls *ForLoopStatement) String() string

String returns a string representation of the ForLoopStatement.

func (*ForLoopStatement) TokenLiteral

func (fls *ForLoopStatement) TokenLiteral() string

func (*ForLoopStatement) TokenLiteralNode added in v0.0.4

func (fls *ForLoopStatement) TokenLiteralNode() token.Token

type FunctionDefinition added in v0.0.4

type FunctionDefinition struct {
	Token token.Token
	Name  *Identifier
	Body  Statement
}

FunctionDefinition represents a function definition statement.

func (*FunctionDefinition) String added in v0.0.4

func (fd *FunctionDefinition) String() string

func (*FunctionDefinition) TokenLiteral added in v0.0.4

func (fd *FunctionDefinition) TokenLiteral() string

func (*FunctionDefinition) TokenLiteralNode added in v0.0.4

func (fd *FunctionDefinition) TokenLiteralNode() token.Token

type FunctionLiteral

type FunctionLiteral struct {
	Token  token.Token // The 'fn' token
	Name   *Identifier
	Params []*Identifier
	Body   *BlockStatement
}

FunctionLiteral represents a function literal.

func (*FunctionLiteral) String

func (fl *FunctionLiteral) String() string

String returns a string representation of the FunctionLiteral.

func (*FunctionLiteral) TokenLiteral

func (fl *FunctionLiteral) TokenLiteral() string

func (*FunctionLiteral) TokenLiteralNode added in v0.0.4

func (fl *FunctionLiteral) TokenLiteralNode() token.Token

type GroupedExpression added in v0.0.4

type GroupedExpression struct {
	Token      token.Token // The '(' token
	Expression Expression
}

GroupedExpression represents a grouped expression (e.g. (1 + 2)).

func (*GroupedExpression) String added in v0.0.4

func (ge *GroupedExpression) String() string

func (*GroupedExpression) TokenLiteral added in v0.0.4

func (ge *GroupedExpression) TokenLiteral() string

func (*GroupedExpression) TokenLiteralNode added in v0.0.4

func (ge *GroupedExpression) TokenLiteralNode() token.Token

type Identifier

type Identifier struct {
	Token token.Token // the IDENT token
	Value string      // identifier name
}

Identifier represents an identifier.

func (*Identifier) String

func (i *Identifier) String() string

String returns a string representation of the Identifier.

func (*Identifier) TokenLiteral

func (i *Identifier) TokenLiteral() string

func (*Identifier) TokenLiteralNode added in v0.0.4

func (i *Identifier) TokenLiteralNode() token.Token

type IfStatement

type IfStatement struct {
	Token       token.Token // The 'if' token
	Condition   Expression
	Consequence *BlockStatement
	Alternative Statement // Statement, could be *BlockStatement or *ExpressionStatement
}

IfStatement represents an if statement.

func (*IfStatement) String

func (is *IfStatement) String() string

String returns a string representation of the IfStatement.

func (*IfStatement) TokenLiteral

func (is *IfStatement) TokenLiteral() string

func (*IfStatement) TokenLiteralNode added in v0.0.4

func (is *IfStatement) TokenLiteralNode() token.Token

type IndexExpression added in v0.0.4

type IndexExpression struct {
	Token token.Token // The '[' token
	Left  Expression
	Index Expression
}

IndexExpression represents an index expression (e.g., arr[0]).

func (*IndexExpression) String added in v0.0.4

func (ie *IndexExpression) String() string

String returns a string representation of the IndexExpression.

func (*IndexExpression) TokenLiteral added in v0.0.4

func (ie *IndexExpression) TokenLiteral() string

func (*IndexExpression) TokenLiteralNode added in v0.0.4

func (ie *IndexExpression) TokenLiteralNode() token.Token

type InfixExpression

type InfixExpression struct {
	Token    token.Token // The operator token
	Left     Expression  // Left operand
	Operator string      // Infix operator
	Right    Expression  // Right operand
}

InfixExpression represents an infix expression (e.g. 5 + 5).

func (*InfixExpression) String

func (ie *InfixExpression) String() string

String returns a string representation of the InfixExpression.

func (*InfixExpression) TokenLiteral

func (ie *InfixExpression) TokenLiteral() string

func (*InfixExpression) TokenLiteralNode added in v0.0.4

func (ie *InfixExpression) TokenLiteralNode() token.Token

type IntegerLiteral

type IntegerLiteral struct {
	Token token.Token // the INT token
	Value int64       // integer value
}

IntegerLiteral represents an integer literal.

func (*IntegerLiteral) String

func (il *IntegerLiteral) String() string

String returns a string representation of the IntegerLiteral.

func (*IntegerLiteral) TokenLiteral

func (il *IntegerLiteral) TokenLiteral() string

func (*IntegerLiteral) TokenLiteralNode added in v0.0.4

func (il *IntegerLiteral) TokenLiteralNode() token.Token

type InvalidArrayAccess

type InvalidArrayAccess struct {
	Token token.Token
	Left  Expression
	Index Expression
}

InvalidArrayAccess represents an invalid array access.

func (*InvalidArrayAccess) String

func (ia *InvalidArrayAccess) String() string

func (*InvalidArrayAccess) TokenLiteral

func (ia *InvalidArrayAccess) TokenLiteral() string

func (*InvalidArrayAccess) TokenLiteralNode added in v0.0.4

func (ia *InvalidArrayAccess) TokenLiteralNode() token.Token

type LetStatement

type LetStatement struct {
	Token token.Token // the 'let' token
	Name  *Identifier // identifier node
	Value Expression  // expression node
}

LetStatement represents a let statement.

func (*LetStatement) String

func (ls *LetStatement) String() string

String returns a string representation of the LetStatement.

func (*LetStatement) TokenLiteral

func (ls *LetStatement) TokenLiteral() string

func (*LetStatement) TokenLiteralNode added in v0.0.4

func (ls *LetStatement) TokenLiteralNode() token.Token

type Node

type Node interface {
	TokenLiteral() string // literal value of the node
	TokenLiteralNode() token.Token
	String() string // string representation of the node
}

Node represents a node in the AST.

type PostfixExpression

type PostfixExpression struct {
	Token    token.Token // The postfix operator token (-- or ++)
	Operator string      // Postfix operator
	Left     Expression  // Left operand
}

PostfixExpression represents a postfix expression (e.g. --i, ++i).

func (*PostfixExpression) String

func (pe *PostfixExpression) String() string

String returns a string representation of the PostfixExpression.

func (*PostfixExpression) TokenLiteral

func (pe *PostfixExpression) TokenLiteral() string

func (*PostfixExpression) TokenLiteralNode added in v0.0.4

func (pe *PostfixExpression) TokenLiteralNode() token.Token

type PrefixExpression

type PrefixExpression struct {
	Token    token.Token // The prefix operator token (! or -)
	Operator string      // Prefix operator
	Right    Expression  // Right operand
}

PrefixExpression represents a prefix expression (e.g., -5, !true).

func (*PrefixExpression) String

func (pe *PrefixExpression) String() string

String returns a string representation of the PrefixExpression.

func (*PrefixExpression) TokenLiteral

func (pe *PrefixExpression) TokenLiteral() string

func (*PrefixExpression) TokenLiteralNode added in v0.0.4

func (pe *PrefixExpression) TokenLiteralNode() token.Token

type ProcessSubstitution added in v0.0.123

type ProcessSubstitution struct {
	Token   token.Token
	Command Node
}

ProcessSubstitution represents <(...) or >(...).

func (*ProcessSubstitution) String added in v0.0.123

func (ps *ProcessSubstitution) String() string

func (*ProcessSubstitution) TokenLiteral added in v0.0.123

func (ps *ProcessSubstitution) TokenLiteral() string

func (*ProcessSubstitution) TokenLiteralNode added in v0.0.123

func (ps *ProcessSubstitution) TokenLiteralNode() token.Token

type Program

type Program struct {
	Statements []Statement
}

Program represents the root of the AST.

func (*Program) String

func (p *Program) String() string

String returns a string representation of the Program.

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

func (*Program) TokenLiteralNode added in v0.0.4

func (p *Program) TokenLiteralNode() token.Token

type Redirection added in v0.0.4

type Redirection struct {
	Token    token.Token
	Operator string
	Left     Expression
	Right    Expression
}

Redirection represents a redirection.

func (*Redirection) String added in v0.0.4

func (r *Redirection) String() string

func (*Redirection) TokenLiteral added in v0.0.4

func (r *Redirection) TokenLiteral() string

func (*Redirection) TokenLiteralNode added in v0.0.4

func (r *Redirection) TokenLiteralNode() token.Token

type ReturnStatement

type ReturnStatement struct {
	Token       token.Token // the 'return' token
	ReturnValue Expression  // expression node
}

ReturnStatement represents a return statement.

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

String returns a string representation of the ReturnStatement.

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

func (*ReturnStatement) TokenLiteralNode added in v0.0.4

func (rs *ReturnStatement) TokenLiteralNode() token.Token

type SelectStatement added in v0.0.123

type SelectStatement struct {
	Token token.Token // The 'select' token
	Name  *Identifier
	Items []Expression
	Body  *BlockStatement
}

SelectStatement represents a select loop.

func (*SelectStatement) String added in v0.0.123

func (ss *SelectStatement) String() string

func (*SelectStatement) TokenLiteral added in v0.0.123

func (ss *SelectStatement) TokenLiteral() string

func (*SelectStatement) TokenLiteralNode added in v0.0.123

func (ss *SelectStatement) TokenLiteralNode() token.Token

type Shebang

type Shebang struct {
	Token token.Token // The '#!' token
	Path  string
}

Shebang represents a shebang comment (e.g., #!/bin/zsh).

func (*Shebang) String

func (s *Shebang) String() string

String returns a string representation of the Shebang.

func (*Shebang) TokenLiteral

func (s *Shebang) TokenLiteral() string

func (*Shebang) TokenLiteralNode added in v0.0.4

func (s *Shebang) TokenLiteralNode() token.Token

type SimpleCommand

type SimpleCommand struct {
	Token     token.Token
	Name      Expression
	Arguments []Expression
}

SimpleCommand represents a simple command (e.g., ls -l).

func (*SimpleCommand) String

func (sc *SimpleCommand) String() string

String returns a string representation of the SimpleCommand.

func (*SimpleCommand) TokenLiteral

func (sc *SimpleCommand) TokenLiteral() string

func (*SimpleCommand) TokenLiteralNode added in v0.0.4

func (sc *SimpleCommand) TokenLiteralNode() token.Token

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

Statement represents a statement in the AST.

type StringLiteral

type StringLiteral struct {
	Token token.Token
	Value string
}

StringLiteral represents a string literal.

func (*StringLiteral) String

func (sl *StringLiteral) String() string

func (*StringLiteral) TokenLiteral

func (sl *StringLiteral) TokenLiteral() string

func (*StringLiteral) TokenLiteralNode added in v0.0.4

func (sl *StringLiteral) TokenLiteralNode() token.Token

type Subshell added in v0.0.121

type Subshell struct {
	Token   token.Token
	Command Node
}

Subshell represents ( ... ).

func (*Subshell) String added in v0.0.121

func (s *Subshell) String() string

func (*Subshell) TokenLiteral added in v0.0.121

func (s *Subshell) TokenLiteral() string

func (*Subshell) TokenLiteralNode added in v0.0.121

func (s *Subshell) TokenLiteralNode() token.Token

type WalkFn

type WalkFn func(node Node) bool

WalkFn is a function that will be called for each node in the AST. It returns true if the children of the node should be visited.

type WhileLoopStatement added in v0.0.4

type WhileLoopStatement struct {
	Token     token.Token // The 'while' token
	Condition Expression
	Body      *BlockStatement
}

WhileLoopStatement represents a while loop statement.

func (*WhileLoopStatement) String added in v0.0.4

func (wls *WhileLoopStatement) String() string

String returns a string representation of the WhileLoopStatement.

func (*WhileLoopStatement) TokenLiteral added in v0.0.4

func (wls *WhileLoopStatement) TokenLiteral() string

func (*WhileLoopStatement) TokenLiteralNode added in v0.0.4

func (wls *WhileLoopStatement) TokenLiteralNode() token.Token

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL