ast

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptExpr

func AcceptExpr[T any](expr Expr, v ExpressionVisitor) T

func AcceptStmt

func AcceptStmt[T any](stmt Statement, v StatementVisitor) T

Types

type Accessor

type Accessor interface {
	Node
	ToString() string
}

Accessor is one step in an L-value chain: either [expr] or .field

type BinaryExpr

type BinaryExpr struct {
	Left     Expr
	Operator tokens.Token
	Right    Expr
	ResolvedType
}

func (*BinaryExpr) Accept

func (b *BinaryExpr) Accept(v ExpressionVisitor) any

func (*BinaryExpr) GetSourceLocation

func (b *BinaryExpr) GetSourceLocation() interfaces.SourceLocation

func (*BinaryExpr) ToString

func (b *BinaryExpr) ToString() string

func (*BinaryExpr) Type

func (b *BinaryExpr) Type() NodeType

type BlockStmt

type BlockStmt struct {
	interfaces.SourceLocation

	Statements []Statement
}

func (BlockStmt) Accept

func (b BlockStmt) Accept(visitor StatementVisitor) any

func (BlockStmt) GetSourceLocation

func (b BlockStmt) GetSourceLocation() interfaces.SourceLocation

func (BlockStmt) ToString

func (b BlockStmt) ToString() string

func (BlockStmt) Type

func (b BlockStmt) Type() NodeType

type CallExpr

type CallExpr struct {
	interfaces.SourceLocation
	Source    Expr
	Arguments []Expr
	ResolvedType
	// contains filtered or unexported fields
}

func (*CallExpr) Accept

func (f *CallExpr) Accept(visitor ExpressionVisitor) any

func (*CallExpr) GetResolvedName

func (f *CallExpr) GetResolvedName() string

func (*CallExpr) GetSourceLocation

func (f *CallExpr) GetSourceLocation() interfaces.SourceLocation

func (*CallExpr) SetResolvedName

func (f *CallExpr) SetResolvedName(name string)

func (*CallExpr) ToString

func (f *CallExpr) ToString() string

func (*CallExpr) Type

func (f *CallExpr) Type() NodeType

type DotAccessExpr

type DotAccessExpr struct {
	interfaces.SourceLocation

	Source Expr
	Name   tokens.Token
	ResolvedType
}

func (*DotAccessExpr) Accept

func (v *DotAccessExpr) Accept(visitor ExpressionVisitor) any

func (*DotAccessExpr) GetSourceLocation

func (v *DotAccessExpr) GetSourceLocation() interfaces.SourceLocation

func (*DotAccessExpr) ToString

func (v *DotAccessExpr) ToString() string

func (*DotAccessExpr) Type

func (v *DotAccessExpr) Type() NodeType

type ExecStmt

type ExecStmt struct {
	SourceLocation interfaces.SourceLocation

	Expression Expr
	ResolvedType
}

func (ExecStmt) Accept

func (e ExecStmt) Accept(visitor StatementVisitor) any

func (ExecStmt) GetSourceLocation

func (e ExecStmt) GetSourceLocation() interfaces.SourceLocation

func (ExecStmt) ToString

func (e ExecStmt) ToString() string

func (ExecStmt) Type

func (e ExecStmt) Type() NodeType

type Expr

type Expr interface {
	Node
	Accept(v ExpressionVisitor) any
	ToString() string
	SetResolvedType(typ types.ValueType)
	GetResolvedType() types.ValueType
}

type ExpressionStmt

type ExpressionStmt struct {
	Expression Expr
}

func (ExpressionStmt) Accept

func (e ExpressionStmt) Accept(visitor StatementVisitor) any

func (ExpressionStmt) GetSourceLocation

func (e ExpressionStmt) GetSourceLocation() interfaces.SourceLocation

func (ExpressionStmt) ToString

func (e ExpressionStmt) ToString() string

func (ExpressionStmt) Type

func (e ExpressionStmt) Type() NodeType

type ExpressionVisitor

type ExpressionVisitor interface {
	VisitBinary(b *BinaryExpr) any
	VisitGrouping(g *GroupingExpr) any
	VisitLiteral(l *LiteralExpr) any
	VisitUnary(u *UnaryExpr) any
	VisitVariable(v *VariableExpr) any
	VisitDotAccess(v *DotAccessExpr) any
	VisitCall(f *CallExpr) any
	VisitLogical(l *LogicalExpr) any
	VisitSlice(s *SliceExpr) any
	VisitList(s *ListExpr) any
}

type FieldAccessor

type FieldAccessor struct {
	Field tokens.Token
}

FieldAccessor holds a parsed field name (foo.bar).

func (FieldAccessor) GetSourceLocation

func (f FieldAccessor) GetSourceLocation() interfaces.SourceLocation

func (FieldAccessor) ToString

func (f FieldAccessor) ToString() string

func (FieldAccessor) Type

func (f FieldAccessor) Type() NodeType

type FunctionDeclarationStmt

type FunctionDeclarationStmt struct {
	Name          tokens.Token
	Parameters    []VariableDeclarationStmt
	Body          BlockStmt
	ReturnType    types.ValueType
	Autogenerated bool
}

func (FunctionDeclarationStmt) Accept

func (f FunctionDeclarationStmt) Accept(visitor StatementVisitor) any

func (FunctionDeclarationStmt) GetSourceLocation

func (f FunctionDeclarationStmt) GetSourceLocation() interfaces.SourceLocation

func (FunctionDeclarationStmt) HasArg

func (f FunctionDeclarationStmt) HasArg(arg string) bool

func (FunctionDeclarationStmt) ToString

func (f FunctionDeclarationStmt) ToString() string

func (FunctionDeclarationStmt) Type

type GroupingExpr

type GroupingExpr struct {
	Expression Expr
	ResolvedType
}

func (*GroupingExpr) Accept

func (g *GroupingExpr) Accept(v ExpressionVisitor) any

func (*GroupingExpr) GetSourceLocation

func (g *GroupingExpr) GetSourceLocation() interfaces.SourceLocation

func (*GroupingExpr) ToString

func (g *GroupingExpr) ToString() string

func (*GroupingExpr) Type

func (g *GroupingExpr) Type() NodeType

type IfStmt

type IfStmt struct {
	Condition  Expr
	ThenBranch BlockStmt
	ElseBranch *BlockStmt
}

func (IfStmt) Accept

func (i IfStmt) Accept(visitor StatementVisitor) any

func (IfStmt) GetSourceLocation

func (i IfStmt) GetSourceLocation() interfaces.SourceLocation

func (IfStmt) ToString

func (i IfStmt) ToString() string

func (IfStmt) Type

func (i IfStmt) Type() NodeType

type ImportStmt

type ImportStmt struct {
	interfaces.SourceLocation

	Path        string
	SymbolNames map[string]tokens.Token
}

func (ImportStmt) Accept

func (i ImportStmt) Accept(visitor StatementVisitor) any

func (ImportStmt) GetSourceLocation

func (i ImportStmt) GetSourceLocation() interfaces.SourceLocation

func (ImportStmt) ToString

func (i ImportStmt) ToString() string

func (ImportStmt) Type

func (i ImportStmt) Type() NodeType

type IndexAccessor

type IndexAccessor struct {
	Index Expr
}

IndexAccessor holds a parsed index expression (foo[expr]).

func (IndexAccessor) GetSourceLocation

func (i IndexAccessor) GetSourceLocation() interfaces.SourceLocation

func (IndexAccessor) ToString

func (i IndexAccessor) ToString() string

func (IndexAccessor) Type

func (i IndexAccessor) Type() NodeType

type ListExpr

type ListExpr struct {
	interfaces.SourceLocation

	Elements  []Expr
	ValueType types.ValueType
	ResolvedType
}

func (*ListExpr) Accept

func (l *ListExpr) Accept(v ExpressionVisitor) any

func (*ListExpr) GetSourceLocation

func (l *ListExpr) GetSourceLocation() interfaces.SourceLocation

func (*ListExpr) ToString

func (l *ListExpr) ToString() string

func (*ListExpr) Type

func (l *ListExpr) Type() NodeType

type LiteralExpr

type LiteralExpr struct {
	interfaces.SourceLocation

	Value nbt.Value
	ResolvedType
}

func NewLiteralExpr

func NewLiteralExpr(value nbt.Value, typ types.ValueType, source interfaces.SourceLocation) *LiteralExpr

func (*LiteralExpr) Accept

func (l *LiteralExpr) Accept(v ExpressionVisitor) any

func (*LiteralExpr) GetSourceLocation

func (l *LiteralExpr) GetSourceLocation() interfaces.SourceLocation

func (*LiteralExpr) ToString

func (l *LiteralExpr) ToString() string

func (*LiteralExpr) Type

func (l *LiteralExpr) Type() NodeType

type LogicalExpr

type LogicalExpr struct {
	Left     Expr
	Operator tokens.Token
	Right    Expr
	ResolvedType
}

func (*LogicalExpr) Accept

func (l *LogicalExpr) Accept(v ExpressionVisitor) any

func (*LogicalExpr) GetSourceLocation

func (l *LogicalExpr) GetSourceLocation() interfaces.SourceLocation

func (*LogicalExpr) ToString

func (l *LogicalExpr) ToString() string

func (*LogicalExpr) Type

func (l *LogicalExpr) Type() NodeType

type Node

type Node interface {
	Type() NodeType
	GetSourceLocation() interfaces.SourceLocation
}

type NodeType

type NodeType string
const (
	BinaryExpression       NodeType = "BinaryExpression"
	GroupingExpression     NodeType = "GroupingExpression"
	LiteralExpression      NodeType = "LiteralExpression"
	UnaryExpression        NodeType = "UnaryExpression"
	FieldAccessExpression  NodeType = "FieldAccessExpression"
	VariableExpression     NodeType = "VariableExpression"
	FunctionCallExpression NodeType = "FunctionCallExpression"
	LogicalExpression      NodeType = "LogicalExpression"
	SliceExpression        NodeType = "SliceExpression"
	ListExpression         NodeType = "ListExpression"

	ExpressionStatement          NodeType = "ExpressionStatement"
	VariableDeclarationStatement NodeType = "VariableDeclarationStatement"
	FunctionDeclarationStatement NodeType = "FunctionDeclarationStatement"
	StructDeclarationStatement   NodeType = "StructDeclarationStatement"
	VariableAssignmentStatement  NodeType = "VariableAssignmentStatement"
	BlockStatement               NodeType = "BlockStatement"
	WhileStatement               NodeType = "WhileStatement"
	IfStatement                  NodeType = "IfStatement"
	ReturnStatement              NodeType = "ReturnStatement"
	SetReturnFlagStatement       NodeType = "SetReturnFlagStatement"
	ImportStatement              NodeType = "ImportStatement"
	ExecStatement                NodeType = "ExecStatement"

	IndexAccessorType NodeType = "IndexAccessorType"
	FieldAccessorType NodeType = "FieldAccessorType"
)

type ResolvedType

type ResolvedType struct {
	// contains filtered or unexported fields
}

func (*ResolvedType) GetResolvedType

func (r *ResolvedType) GetResolvedType() types.ValueType

func (*ResolvedType) SetResolvedType

func (r *ResolvedType) SetResolvedType(typ types.ValueType)

type ReturnStmt

type ReturnStmt struct {
	interfaces.SourceLocation

	Expression Expr
}

func (ReturnStmt) Accept

func (s ReturnStmt) Accept(v StatementVisitor) any

func (ReturnStmt) GetSourceLocation

func (s ReturnStmt) GetSourceLocation() interfaces.SourceLocation

func (ReturnStmt) ToString

func (s ReturnStmt) ToString() string

func (ReturnStmt) Type

func (s ReturnStmt) Type() NodeType

type SetReturnFlagStmt

type SetReturnFlagStmt struct {
}

func (SetReturnFlagStmt) Accept

func (SetReturnFlagStmt) GetSourceLocation

func (s SetReturnFlagStmt) GetSourceLocation() interfaces.SourceLocation

func (SetReturnFlagStmt) ToString

func (s SetReturnFlagStmt) ToString() string

func (SetReturnFlagStmt) Type

func (s SetReturnFlagStmt) Type() NodeType

type SliceExpr

type SliceExpr struct {
	StartIndex Expr
	EndIndex   Expr
	TargetExpr Expr

	interfaces.SourceLocation
	ResolvedType
}

func (*SliceExpr) Accept

func (s *SliceExpr) Accept(v ExpressionVisitor) any

func (*SliceExpr) GetSourceLocation

func (s *SliceExpr) GetSourceLocation() interfaces.SourceLocation

func (*SliceExpr) ToString

func (s *SliceExpr) ToString() string

func (*SliceExpr) Type

func (s *SliceExpr) Type() NodeType

type Source

type Source []Statement

type Statement

type Statement interface {
	Node
	Accept(StatementVisitor) any
	ToString() string
}

type StatementVisitor

type StatementVisitor interface {
	VisitExpression(ExpressionStmt) any
	VisitVariableDeclaration(VariableDeclarationStmt) any
	VisitFunctionDeclaration(FunctionDeclarationStmt) any
	VisitVariableAssignment(VariableAssignmentStmt) any
	VisitStructDeclaration(StructDeclarationStmt) any
	VisitBlock(BlockStmt) any
	VisitWhile(WhileStmt) any
	VisitIf(IfStmt) any
	VisitReturn(ReturnStmt) any
	VisitSetReturnFlag(SetReturnFlagStmt) any
	VisitImport(ImportStmt) any
	VisitExec(ExecStmt) any
}

type StructDeclarationStmt

type StructDeclarationStmt struct {
	Name       tokens.Token
	StructType types.StructTypeStruct
}

func (StructDeclarationStmt) Accept

func (s StructDeclarationStmt) Accept(visitor StatementVisitor) any

func (StructDeclarationStmt) GetSourceLocation

func (s StructDeclarationStmt) GetSourceLocation() interfaces.SourceLocation

func (StructDeclarationStmt) ToString

func (s StructDeclarationStmt) ToString() string

func (StructDeclarationStmt) Type

type UnaryExpr

type UnaryExpr struct {
	Operator   tokens.Token
	Expression Expr
	ResolvedType
}

func (*UnaryExpr) Accept

func (u *UnaryExpr) Accept(v ExpressionVisitor) any

func (*UnaryExpr) GetSourceLocation

func (u *UnaryExpr) GetSourceLocation() interfaces.SourceLocation

func (*UnaryExpr) ReturnType

func (u *UnaryExpr) ReturnType() types.ValueType

func (*UnaryExpr) ToString

func (u *UnaryExpr) ToString() string

func (*UnaryExpr) Type

func (u *UnaryExpr) Type() NodeType

type VariableAssignmentStmt

type VariableAssignmentStmt struct {
	Name      tokens.Token
	Accessors []Accessor
	Value     Expr
}

func (VariableAssignmentStmt) Accept

func (v VariableAssignmentStmt) Accept(visitor StatementVisitor) any

func (VariableAssignmentStmt) GetSourceLocation

func (v VariableAssignmentStmt) GetSourceLocation() interfaces.SourceLocation

func (VariableAssignmentStmt) ToString

func (v VariableAssignmentStmt) ToString() string

func (VariableAssignmentStmt) Type

type VariableDeclarationStmt

type VariableDeclarationStmt struct {
	Name        tokens.Token
	Initializer Expr
	ValueType   types.ValueType
}

func (VariableDeclarationStmt) Accept

func (v VariableDeclarationStmt) Accept(visitor StatementVisitor) any

func (VariableDeclarationStmt) GetSourceLocation

func (v VariableDeclarationStmt) GetSourceLocation() interfaces.SourceLocation

func (VariableDeclarationStmt) ToString

func (v VariableDeclarationStmt) ToString() string

func (VariableDeclarationStmt) Type

type VariableExpr

type VariableExpr struct {
	Name tokens.Token
	ResolvedType
}

func (*VariableExpr) Accept

func (v *VariableExpr) Accept(visitor ExpressionVisitor) any

func (*VariableExpr) GetSourceLocation

func (v *VariableExpr) GetSourceLocation() interfaces.SourceLocation

func (*VariableExpr) ToString

func (v *VariableExpr) ToString() string

func (*VariableExpr) Type

func (v *VariableExpr) Type() NodeType

type WhileStmt

type WhileStmt struct {
	Condition Expr
	Body      BlockStmt
}

func (WhileStmt) Accept

func (w WhileStmt) Accept(v StatementVisitor) any

func (WhileStmt) GetSourceLocation

func (w WhileStmt) GetSourceLocation() interfaces.SourceLocation

func (WhileStmt) ToString

func (w WhileStmt) ToString() string

func (WhileStmt) Type

func (w WhileStmt) Type() NodeType

Jump to

Keyboard shortcuts

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