ast

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 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
	Range Range
}

AnyLiteral defines a struct for a literal any value.

func (*AnyLiteral) Expr added in v0.1.1

func (e *AnyLiteral) Expr() string

Expr returns the expression of the any literal.

func (*AnyLiteral) GetRange added in v0.1.2

func (e *AnyLiteral) GetRange() Range

GetRange returns the range 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
	Range  Range
}

ArrayLiteral defines a struct for a literal array value.

func (*ArrayLiteral) Expr added in v0.1.1

func (e *ArrayLiteral) Expr() string

Expr returns the expression of the array literal.

func (*ArrayLiteral) GetRange added in v0.1.2

func (e *ArrayLiteral) GetRange() Range

GetRange returns the range 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
	Range Range
}

AssignmentStatement represents an assignment statement.

func (*AssignmentStatement) Expr

func (a *AssignmentStatement) Expr() string

Expr returns the expression of the assignment statement.

func (*AssignmentStatement) GetRange added in v0.1.2

func (a *AssignmentStatement) GetRange() Range

GetRange returns the range 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
	Range    Range
}

BinaryExpr defines a struct for a binary expression.

func (*BinaryExpr) Expr

func (e *BinaryExpr) Expr() string

Expr returns the expression of the binary expression.

func (*BinaryExpr) GetRange added in v0.1.2

func (e *BinaryExpr) GetRange() Range

GetRange returns the range 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
	Range      Range
}

BlockStatement defines a struct for a block statement.

func (*BlockStatement) Expr

func (e *BlockStatement) Expr() string

Expr returns the expression of the block statement.

func (*BlockStatement) GetRange added in v0.1.2

func (e *BlockStatement) GetRange() Range

GetRange returns the range 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
	Range Range
}

BoolLiteral defines a struct for a literal boolean value.

func (*BoolLiteral) Expr

func (e *BoolLiteral) Expr() string

Expr returns the expression of the boolean literal.

func (*BoolLiteral) GetRange added in v0.1.2

func (e *BoolLiteral) GetRange() Range

GetRange returns the range 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
	Range Range
}

BreakStatement represents a break statement.

func (*BreakStatement) Expr

func (b *BreakStatement) Expr() string

Expr returns the expression of the break statement.

func (*BreakStatement) GetRange added in v0.1.2

func (b *BreakStatement) GetRange() Range

GetRange returns the range of the break statement.

func (*BreakStatement) Walk

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

Walk walks the break statement.

type CommentLiteral added in v0.1.2

type CommentLiteral struct {
	Value string
	Range Range
}

CommentLiteral defines a struct for a comment literal.

func (*CommentLiteral) Expr added in v0.1.2

func (e *CommentLiteral) Expr() string

Expr returns the expression of the comment literal.

func (*CommentLiteral) GetRange added in v0.1.2

func (e *CommentLiteral) GetRange() Range

GetRange returns the range of the comment literal.

func (*CommentLiteral) Walk added in v0.1.2

func (e *CommentLiteral) Walk(_ func(node ExprNode) bool)

Walk walks the comment literal.

type ConstantDeclaration

type ConstantDeclaration struct {
	Name  string
	Type  string
	Value ExprNode
	Range Range
}

ConstantDeclaration represents a constant declaration.

func (*ConstantDeclaration) Expr

func (c *ConstantDeclaration) Expr() string

Expr returns the expression of the constant declaration.

func (*ConstantDeclaration) GetRange added in v0.1.2

func (c *ConstantDeclaration) GetRange() Range

GetRange returns the range 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
	Range Range
}

ContinueStatement represents a continue statement.

func (*ContinueStatement) Expr

func (c *ContinueStatement) Expr() string

Expr returns the expression of the continue statement.

func (*ContinueStatement) GetRange added in v0.1.2

func (c *ContinueStatement) GetRange() Range

GetRange returns the range 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
	GetRange() Range
	Walk(func(node ExprNode) bool)
}

ExprNode defines a common interface signature for expression structs.

type ForStatement

type ForStatement struct {
	Condition        ExprNode
	Body             *BlockStatement
	Range            Range
	DeclaredVariable string
	RangeVariable    string
	RangeFrom        ExprNode
	RangeTo          ExprNode
	IsRange          bool
	HasExplicitFrom  bool
}

ForStatement represents a for statement.

func (*ForStatement) Expr

func (f *ForStatement) Expr() string

Expr returns the expression of the for statement.

func (*ForStatement) GetRange added in v0.1.2

func (f *ForStatement) GetRange() Range

GetRange returns the range 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
	Range           Range
}

FuncDeclarationStatement represents a 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) GetRange added in v0.1.2

func (b *FuncDeclarationStatement) GetRange() Range

GetRange returns the range 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
	Range        Range
}

FunctionCall defines a struct for a function call.

func (*FunctionCall) Expr

func (fc *FunctionCall) Expr() string

Expr returns the expression of the function call.

func (*FunctionCall) GetRange added in v0.1.2

func (fc *FunctionCall) GetRange() Range

GetRange returns the range 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
	Range Range
}

Identifier defines a struct for an identifier.

func (*Identifier) Expr

func (e *Identifier) Expr() string

Expr returns the expression of the identifier.

func (*Identifier) GetRange added in v0.1.2

func (e *Identifier) GetRange() Range

GetRange returns the range 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
	Range     Range
}

IfStatement defines a struct for an if statement.

func (*IfStatement) Expr

func (e *IfStatement) Expr() string

Expr returns the expression of the if statement.

func (*IfStatement) GetRange added in v0.1.2

func (e *IfStatement) GetRange() Range

GetRange returns the range 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
	Range     Range
}

ImportStatement represents an import statement in the AST.

func (*ImportStatement) Expr added in v0.1.1

func (i *ImportStatement) Expr() string

Expr returns the expression of the import statement.

func (*ImportStatement) GetRange added in v0.1.2

func (i *ImportStatement) GetRange() Range

GetRange returns the range 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
	Range Range
}

IndexAssignmentStatement represents an assignment to an array index.

func (*IndexAssignmentStatement) Expr added in v0.1.1

func (a *IndexAssignmentStatement) Expr() string

Expr returns the expression of the index assignment statement.

func (*IndexAssignmentStatement) GetRange added in v0.1.2

func (a *IndexAssignmentStatement) GetRange() Range

GetRange returns the range 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
	Range Range
}

IndexExpr defines a struct for an 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) GetRange added in v0.1.2

func (e *IndexExpr) GetRange() Range

GetRange returns the range 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 NewlineLiteral added in v0.1.2

type NewlineLiteral struct {
	Range Range
}

NewlineLiteral defines a struct for a literal newline value.

func (*NewlineLiteral) Expr added in v0.1.2

func (e *NewlineLiteral) Expr() string

Expr returns the expression of the newline literal.

func (*NewlineLiteral) GetRange added in v0.1.2

func (e *NewlineLiteral) GetRange() Range

GetRange returns the range of the newline literal.

func (*NewlineLiteral) Walk added in v0.1.2

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

Walk walks the newline literal.

type NullLiteral

type NullLiteral struct {
	Range Range
}

NullLiteral defines a struct for a literal null value.

func (*NullLiteral) Expr

func (e *NullLiteral) Expr() string

Expr returns the expression of the null literal.

func (*NullLiteral) GetRange added in v0.1.2

func (e *NullLiteral) GetRange() Range

GetRange returns the range 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
	Range Range
}

NumberLiteral defines a struct for a literal number value.

func (*NumberLiteral) Expr

func (e *NumberLiteral) Expr() string

Expr returns the expression of the number literal.

func (*NumberLiteral) GetRange added in v0.1.2

func (e *NumberLiteral) GetRange() Range

GetRange returns the range of the number literal.

func (*NumberLiteral) Walk

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

Walk walks the number literal.

type Position added in v0.1.2

type Position struct {
	Offset int
	Line   int
	Column int
}

Position represents a position in the source code.

type PrefixExpr

type PrefixExpr struct {
	Operator token.Token
	Operand  ExprNode
	Range    Range
}

PrefixExpr defines a struct for a prefix expression.

func (*PrefixExpr) Expr

func (e *PrefixExpr) Expr() string

Expr returns the expression of the prefix expression.

func (*PrefixExpr) GetRange added in v0.1.2

func (e *PrefixExpr) GetRange() Range

GetRange returns the range 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 Range added in v0.1.2

type Range struct {
	Start Position
	End   Position
}

Range represents a range in the source code.

func (*Range) IsMultiLine added in v0.1.2

func (r *Range) IsMultiLine() bool

IsMultiLine returns true if the range is multi-line.

func (*Range) LineSpan added in v0.1.2

func (r *Range) LineSpan() int

LineSpan returns the number of lines in the range.

func (*Range) String added in v0.1.2

func (r *Range) String() string

String returns the string representation of the range.

type ReturnStatement added in v0.1.1

type ReturnStatement struct {
	Values    []ExprNode
	NumValues int
	Range     Range
}

ReturnStatement represents a 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) GetRange added in v0.1.2

func (b *ReturnStatement) GetRange() Range

GetRange returns the range 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
	Range    Range
}

ShorthandAssignmentExpr represents a 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) GetRange added in v0.1.2

func (s *ShorthandAssignmentExpr) GetRange() Range

GetRange returns the range 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
	Range      Range
}

SpreadExpr represents a 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) GetRange added in v0.1.2

func (s *SpreadExpr) GetRange() Range

GetRange returns the range 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
	Range      Range
}

StatementList represents multiple statements separated by newlines.

func (*StatementList) Expr

func (sl *StatementList) Expr() string

Expr returns the expression in the statement list.

func (*StatementList) GetRange added in v0.1.2

func (sl *StatementList) GetRange() Range

GetRange returns the range 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
	Range Range
}

StringLiteral defines a struct for a literal string value.

func (*StringLiteral) Expr

func (e *StringLiteral) Expr() string

Expr returns the expression of the string literal.

func (*StringLiteral) GetRange added in v0.1.2

func (e *StringLiteral) GetRange() Range

GetRange returns the range 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
	Range Range
}

VariableDeclaration represents a variable declaration.

func (*VariableDeclaration) Expr

func (v *VariableDeclaration) Expr() string

Expr returns the expression of the variable declaration.

func (*VariableDeclaration) GetRange added in v0.1.2

func (v *VariableDeclaration) GetRange() Range

GetRange returns the range 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