ast

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ast defines structs and methods to handle AST creation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyLiteral added in v0.1.1

type AnyLiteral struct {
	Value    ExprNode
	StartPos int
	EndPos   int
}

AnyLiteral defines a struct for a literal any value.

func (*AnyLiteral) EndPosition added in v0.1.1

func (e *AnyLiteral) EndPosition() int

EndPosition returns the end position of the any literal.

func (*AnyLiteral) Expr added in v0.1.1

func (e *AnyLiteral) Expr() string

Expr returns the expression of the any literal.

func (*AnyLiteral) StartPosition added in v0.1.1

func (e *AnyLiteral) StartPosition() int

StartPosition returns the start position of the any literal.

func (*AnyLiteral) Walk added in v0.1.1

func (e *AnyLiteral) Walk(fn func(node ExprNode) bool)

Walk walks the any literal.

type ArrayLiteral added in v0.1.1

type ArrayLiteral struct {
	Values   []ExprNode
	StartPos int
	EndPos   int
}

ArrayLiteral defines a struct for a literal array value.

func (*ArrayLiteral) EndPosition added in v0.1.1

func (e *ArrayLiteral) EndPosition() int

EndPosition returns the end position of the array literal.

func (*ArrayLiteral) Expr added in v0.1.1

func (e *ArrayLiteral) Expr() string

Expr returns the expression of the array literal.

func (*ArrayLiteral) StartPosition added in v0.1.1

func (e *ArrayLiteral) StartPosition() int

StartPosition returns the start position of the array literal.

func (*ArrayLiteral) Walk added in v0.1.1

func (e *ArrayLiteral) Walk(fn func(node ExprNode) bool)

Walk walks the array literal and its values.

type AssignmentStatement

type AssignmentStatement struct {
	Left     *Identifier
	Right    ExprNode
	StartPos int
	EndPos   int
}

AssignmentStatement represents an assignment statement.

func (*AssignmentStatement) EndPosition

func (a *AssignmentStatement) EndPosition() int

EndPosition returns the end position of the assignment statement.

func (*AssignmentStatement) Expr

func (a *AssignmentStatement) Expr() string

Expr returns the expression of the assignment statement.

func (*AssignmentStatement) StartPosition

func (a *AssignmentStatement) StartPosition() int

StartPosition returns the start position of the assignment statement.

func (*AssignmentStatement) Walk

func (a *AssignmentStatement) Walk(fn func(node ExprNode) bool)

Walk walks the assignment statement and its left and right nodes.

type BinaryExpr

type BinaryExpr struct {
	Left     ExprNode
	Right    ExprNode
	Operator token.Token
	StartPos int
	EndPos   int
}

BinaryExpr defines a struct for a binary expression.

func (*BinaryExpr) EndPosition

func (e *BinaryExpr) EndPosition() int

EndPosition returns the end position of the binary expression.

func (*BinaryExpr) Expr

func (e *BinaryExpr) Expr() string

Expr returns the expression of the binary expression.

func (*BinaryExpr) StartPosition

func (e *BinaryExpr) StartPosition() int

StartPosition returns the start position of the binary expression.

func (*BinaryExpr) Walk

func (e *BinaryExpr) Walk(fn func(node ExprNode) bool)

Walk walks the binary expression and its left and right nodes.

type BlockStatement

type BlockStatement struct {
	Statements []ExprNode
	StartPos   int
	EndPos     int
}

BlockStatement defines a struct for a block statement.

func (*BlockStatement) EndPosition

func (e *BlockStatement) EndPosition() int

EndPosition returns the end position of the block statement.

func (*BlockStatement) Expr

func (e *BlockStatement) Expr() string

Expr returns the expression of the block statement.

func (*BlockStatement) StartPosition

func (e *BlockStatement) StartPosition() int

StartPosition returns the start position of the block statement.

func (*BlockStatement) Walk

func (e *BlockStatement) Walk(fn func(node ExprNode) bool)

Walk walks the block statement and its statements.

type BoolLiteral

type BoolLiteral struct {
	Value    string
	StartPos int
	EndPos   int
}

BoolLiteral defines a struct for a literal boolean value.

func (*BoolLiteral) EndPosition

func (e *BoolLiteral) EndPosition() int

EndPosition returns the end position of the boolean literal.

func (*BoolLiteral) Expr

func (e *BoolLiteral) Expr() string

Expr returns the expression of the boolean literal.

func (*BoolLiteral) StartPosition

func (e *BoolLiteral) StartPosition() int

StartPosition returns the start position of the boolean literal.

func (*BoolLiteral) Walk

func (e *BoolLiteral) Walk(fn func(node ExprNode) bool)

Walk walks the boolean literal.

type BreakStatement

type BreakStatement struct {
	Count    int
	StartPos int
	EndPos   int
}

BreakStatement represents a break statement.

func (*BreakStatement) EndPosition

func (b *BreakStatement) EndPosition() int

EndPosition returns the end position of the break statement.

func (*BreakStatement) Expr

func (b *BreakStatement) Expr() string

Expr returns the expression of the break statement.

func (*BreakStatement) StartPosition

func (b *BreakStatement) StartPosition() int

StartPosition returns the start position of the break statement.

func (*BreakStatement) Walk

func (b *BreakStatement) Walk(fn func(node ExprNode) bool)

Walk walks the break statement.

type ConstantDeclaration

type ConstantDeclaration struct {
	Name     string
	Type     string
	Value    ExprNode
	StartPos int
	EndPos   int
}

ConstantDeclaration represents a constant declaration.

func (*ConstantDeclaration) EndPosition

func (c *ConstantDeclaration) EndPosition() int

EndPosition returns the end position of the constant declaration.

func (*ConstantDeclaration) Expr

func (c *ConstantDeclaration) Expr() string

Expr returns the expression of the constant declaration.

func (*ConstantDeclaration) StartPosition

func (c *ConstantDeclaration) StartPosition() int

StartPosition returns the start position of the constant declaration.

func (*ConstantDeclaration) Walk

func (c *ConstantDeclaration) Walk(fn func(node ExprNode) bool)

Walk walks the constant declaration and its value.

type ContinueStatement

type ContinueStatement struct {
	Count    int
	StartPos int
	EndPos   int
}

ContinueStatement represents a continue statement.

func (*ContinueStatement) EndPosition

func (c *ContinueStatement) EndPosition() int

EndPosition returns the end position of the continue statement.

func (*ContinueStatement) Expr

func (c *ContinueStatement) Expr() string

Expr returns the expression of the continue statement.

func (*ContinueStatement) StartPosition

func (c *ContinueStatement) StartPosition() int

StartPosition returns the start position of the continue statement.

func (*ContinueStatement) Walk

func (c *ContinueStatement) Walk(fn func(node ExprNode) bool)

Walk walks the continue statement.

type ExprNode

type ExprNode interface {
	Expr() string
	StartPosition() int
	EndPosition() int
	Walk(func(node ExprNode) bool)
}

ExprNode defines a common interface signature for expression structs.

type ForStatement

type ForStatement struct {
	Condition        ExprNode
	Body             *BlockStatement
	StartPos         int
	EndPos           int
	DeclaredVariable string
	RangeVariable    string
	RangeFrom        ExprNode
	RangeTo          ExprNode
	IsRange          bool
}

ForStatement represents a for statement.

func (*ForStatement) EndPosition

func (f *ForStatement) EndPosition() int

EndPosition returns the end position of the for statement.

func (*ForStatement) Expr

func (f *ForStatement) Expr() string

Expr returns the expression of the for statement.

func (*ForStatement) StartPosition

func (f *ForStatement) StartPosition() int

StartPosition returns the start position of the for statement.

func (*ForStatement) Walk

func (f *ForStatement) Walk(fn func(node ExprNode) bool)

Walk walks the for statement and its condition and body.

type FuncDeclarationStatement added in v0.1.1

type FuncDeclarationStatement struct {
	Name            string
	Args            []FuncParameter
	Body            ExprNode
	ReturnValues    []string
	NumReturnValues int
	StartPos        int
	EndPos          int
}

FuncDeclarationStatement represents a function declaration statement.

func (*FuncDeclarationStatement) EndPosition added in v0.1.1

func (b *FuncDeclarationStatement) EndPosition() int

EndPosition returns the end position of the function declaration statement.

func (*FuncDeclarationStatement) Expr added in v0.1.1

func (b *FuncDeclarationStatement) Expr() string

Expr returns the expression of the function declaration statement.

func (*FuncDeclarationStatement) StartPosition added in v0.1.1

func (b *FuncDeclarationStatement) StartPosition() int

StartPosition returns the start position of the function declaration statement.

func (*FuncDeclarationStatement) Walk added in v0.1.1

func (b *FuncDeclarationStatement) Walk(fn func(node ExprNode) bool)

Walk walks the function declaration statement.

type FuncParameter added in v0.1.1

type FuncParameter struct {
	Name string
	Type string
}

FuncParameter represents a function parameter.

type FunctionCall

type FunctionCall struct {
	Namespace    string
	FunctionName string
	Arguments    []ExprNode
	StartPos     int
	EndPos       int
}

FunctionCall defines a struct for a function call.

func (*FunctionCall) EndPosition

func (fc *FunctionCall) EndPosition() int

EndPosition returns the end position of the function call.

func (*FunctionCall) Expr

func (fc *FunctionCall) Expr() string

Expr returns the expression of the function call.

func (*FunctionCall) StartPosition

func (fc *FunctionCall) StartPosition() int

StartPosition returns the start position of the function call.

func (*FunctionCall) Walk

func (fc *FunctionCall) Walk(fn func(node ExprNode) bool)

Walk walks the function call and its arguments.

type Identifier

type Identifier struct {
	Value    string
	StartPos int
	EndPos   int
}

Identifier defines a struct for an identifier.

func (*Identifier) EndPosition

func (e *Identifier) EndPosition() int

EndPosition returns the end position of the identifier.

func (*Identifier) Expr

func (e *Identifier) Expr() string

Expr returns the expression of the identifier.

func (*Identifier) StartPosition

func (e *Identifier) StartPosition() int

StartPosition returns the start position of the identifier.

func (*Identifier) Walk

func (e *Identifier) Walk(fn func(node ExprNode) bool)

Walk walks the identifier.

type IfStatement

type IfStatement struct {
	Condition ExprNode
	ThenBlock *BlockStatement
	ElseBlock *BlockStatement
	StartPos  int
	EndPos    int
}

IfStatement defines a struct for an if statement.

func (*IfStatement) EndPosition

func (e *IfStatement) EndPosition() int

EndPosition returns the end position of the if statement.

func (*IfStatement) Expr

func (e *IfStatement) Expr() string

Expr returns the expression of the if statement.

func (*IfStatement) StartPosition

func (e *IfStatement) StartPosition() int

StartPosition returns the start position of the if statement.

func (*IfStatement) Walk

func (e *IfStatement) Walk(fn func(node ExprNode) bool)

Walk walks the if statement and its condition and body.

type ImportStatement added in v0.1.1

type ImportStatement struct {
	Path      *StringLiteral
	Namespace string
	Alias     string
	StartPos  int
	EndPos    int
}

ImportStatement represents an import statement in the AST.

func (*ImportStatement) EndPosition added in v0.1.1

func (i *ImportStatement) EndPosition() int

EndPosition returns the end position of the import statement.

func (*ImportStatement) Expr added in v0.1.1

func (i *ImportStatement) Expr() string

Expr returns the expression of the import statement.

func (*ImportStatement) StartPosition added in v0.1.1

func (i *ImportStatement) StartPosition() int

StartPosition returns the start position of the import statement.

func (*ImportStatement) Walk added in v0.1.1

func (i *ImportStatement) Walk(fn func(node ExprNode) bool)

Walk walks the import statement.

type IndexAssignmentStatement added in v0.1.1

type IndexAssignmentStatement struct {
	Array    ExprNode
	Index    ExprNode
	Right    ExprNode
	StartPos int
	EndPos   int
}

IndexAssignmentStatement represents an assignment to an array index.

func (*IndexAssignmentStatement) EndPosition added in v0.1.1

func (a *IndexAssignmentStatement) EndPosition() int

EndPosition returns the end position of the index assignment statement.

func (*IndexAssignmentStatement) Expr added in v0.1.1

func (a *IndexAssignmentStatement) Expr() string

Expr returns the expression of the index assignment statement.

func (*IndexAssignmentStatement) StartPosition added in v0.1.1

func (a *IndexAssignmentStatement) StartPosition() int

StartPosition returns the start position of the index assignment statement.

func (*IndexAssignmentStatement) Walk added in v0.1.1

func (a *IndexAssignmentStatement) Walk(fn func(node ExprNode) bool)

Walk walks the index assignment statement and its array, index, and right nodes.

type IndexExpr added in v0.1.1

type IndexExpr struct {
	Array    ExprNode
	Index    ExprNode
	StartPos int
	EndPos   int
}

IndexExpr defines a struct for an index expression.

func (*IndexExpr) EndPosition added in v0.1.1

func (e *IndexExpr) EndPosition() int

EndPosition returns the end position of the index expression.

func (*IndexExpr) Expr added in v0.1.1

func (e *IndexExpr) Expr() string

Expr returns the expression of the index expression.

func (*IndexExpr) StartPosition added in v0.1.1

func (e *IndexExpr) StartPosition() int

StartPosition returns the start position of the index expression.

func (*IndexExpr) Walk added in v0.1.1

func (e *IndexExpr) Walk(fn func(node ExprNode) bool)

Walk walks the index expression and its array and index nodes.

type NullLiteral

type NullLiteral struct {
	StartPos int
	EndPos   int
}

NullLiteral defines a struct for a literal null value.

func (*NullLiteral) EndPosition

func (e *NullLiteral) EndPosition() int

EndPosition returns the end position of the null literal.

func (*NullLiteral) Expr

func (e *NullLiteral) Expr() string

Expr returns the expression of the null literal.

func (*NullLiteral) StartPosition

func (e *NullLiteral) StartPosition() int

StartPosition returns the start position of the null literal.

func (*NullLiteral) Walk

func (e *NullLiteral) Walk(fn func(node ExprNode) bool)

Walk walks the null literal.

type NumberLiteral

type NumberLiteral struct {
	Value    string
	StartPos int
	EndPos   int
}

NumberLiteral defines a struct for a literal number value.

func (*NumberLiteral) EndPosition

func (e *NumberLiteral) EndPosition() int

EndPosition returns the end position of the number literal.

func (*NumberLiteral) Expr

func (e *NumberLiteral) Expr() string

Expr returns the expression of the number literal.

func (*NumberLiteral) StartPosition

func (e *NumberLiteral) StartPosition() int

StartPosition returns the start position of the number literal.

func (*NumberLiteral) Walk

func (e *NumberLiteral) Walk(fn func(node ExprNode) bool)

Walk walks the number literal.

type PrefixExpr

type PrefixExpr struct {
	Operator token.Token
	Operand  ExprNode
	StartPos int
	EndPos   int
}

PrefixExpr defines a struct for a prefix expression.

func (*PrefixExpr) EndPosition

func (e *PrefixExpr) EndPosition() int

EndPosition returns the end position of the prefix expression.

func (*PrefixExpr) Expr

func (e *PrefixExpr) Expr() string

Expr returns the expression of the prefix expression.

func (*PrefixExpr) StartPosition

func (e *PrefixExpr) StartPosition() int

StartPosition returns the start position of the prefix expression.

func (*PrefixExpr) Walk

func (e *PrefixExpr) Walk(fn func(node ExprNode) bool)

Walk walks the prefix expression and its operand.

type ReturnStatement added in v0.1.1

type ReturnStatement struct {
	Values    []ExprNode
	NumValues int
	StartPos  int
	EndPos    int
}

ReturnStatement represents a return statement.

func (*ReturnStatement) EndPosition added in v0.1.1

func (b *ReturnStatement) EndPosition() int

EndPosition returns the end position of the return statement.

func (*ReturnStatement) Expr added in v0.1.1

func (b *ReturnStatement) Expr() string

Expr returns the expression of the return statement.

func (*ReturnStatement) StartPosition added in v0.1.1

func (b *ReturnStatement) StartPosition() int

StartPosition returns the start position of the return statement.

func (*ReturnStatement) Walk added in v0.1.1

func (b *ReturnStatement) Walk(fn func(node ExprNode) bool)

Walk walks the return statement.

type ShorthandAssignmentExpr added in v0.1.1

type ShorthandAssignmentExpr struct {
	Left     ExprNode
	Right    ExprNode
	Operator token.Token
	StartPos int
	EndPos   int
}

ShorthandAssignmentExpr represents a shorthand assignment expression.

func (*ShorthandAssignmentExpr) EndPosition added in v0.1.1

func (s *ShorthandAssignmentExpr) EndPosition() int

EndPosition returns the end position of the shorthand assignment expression.

func (*ShorthandAssignmentExpr) Expr added in v0.1.1

func (s *ShorthandAssignmentExpr) Expr() string

Expr returns the expression of the shorthand assignment expression.

func (*ShorthandAssignmentExpr) StartPosition added in v0.1.1

func (s *ShorthandAssignmentExpr) StartPosition() int

StartPosition returns the start position of the shorthand assignment expression.

func (*ShorthandAssignmentExpr) Walk added in v0.1.1

func (s *ShorthandAssignmentExpr) Walk(fn func(node ExprNode) bool)

Walk walks the shorthand assignment expreession.

type SpreadExpr added in v0.1.1

type SpreadExpr struct {
	Expression ExprNode
	StartPos   int
	EndPos     int
}

SpreadExpr represents a spread expression.

func (*SpreadExpr) EndPosition added in v0.1.1

func (s *SpreadExpr) EndPosition() int

EndPosition returns the end position of the spread expression.

func (*SpreadExpr) Expr added in v0.1.1

func (s *SpreadExpr) Expr() string

Expr returns the expression of the spread expression.

func (*SpreadExpr) StartPosition added in v0.1.1

func (s *SpreadExpr) StartPosition() int

StartPosition returns the start position of the spread expression.

func (*SpreadExpr) Walk added in v0.1.1

func (s *SpreadExpr) Walk(fn func(node ExprNode) bool)

Walk walks the spread expression.

type StatementList

type StatementList struct {
	Statements []ExprNode
	StartPos   int
	EndPos     int
}

StatementList represents multiple statements separated by newlines.

func (*StatementList) EndPosition

func (sl *StatementList) EndPosition() int

EndPosition returns the end position of the statement list.

func (*StatementList) Expr

func (sl *StatementList) Expr() string

Expr returns the expression in the statement list.

func (*StatementList) StartPosition

func (sl *StatementList) StartPosition() int

StartPosition returns the start position of the statement list.

func (*StatementList) Walk

func (sl *StatementList) Walk(fn func(node ExprNode) bool)

Walk walks the statement list and its statements.

type StringLiteral

type StringLiteral struct {
	Value    string
	StartPos int
	EndPos   int
}

StringLiteral defines a struct for a literal string value.

func (*StringLiteral) EndPosition

func (e *StringLiteral) EndPosition() int

EndPosition returns the end position of the string literal.

func (*StringLiteral) Expr

func (e *StringLiteral) Expr() string

Expr returns the expression of the string literal.

func (*StringLiteral) StartPosition

func (e *StringLiteral) StartPosition() int

StartPosition returns the start position of the string literal.

func (*StringLiteral) Walk

func (e *StringLiteral) Walk(fn func(node ExprNode) bool)

Walk walks the string literal.

type VariableDeclaration

type VariableDeclaration struct {
	Name     string
	Type     string
	Value    ExprNode
	StartPos int
	EndPos   int
}

VariableDeclaration represents a variable declaration.

func (*VariableDeclaration) EndPosition

func (v *VariableDeclaration) EndPosition() int

EndPosition returns the end position of the variable declaration.

func (*VariableDeclaration) Expr

func (v *VariableDeclaration) Expr() string

Expr returns the expression of the variable declaration.

func (*VariableDeclaration) StartPosition

func (v *VariableDeclaration) StartPosition() int

StartPosition returns the start position of the variable declaration.

func (*VariableDeclaration) Walk

func (v *VariableDeclaration) Walk(fn func(node ExprNode) bool)

Walk walks the variable declaration and its value.

Jump to

Keyboard shortcuts

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