ast

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckNoOptional

func CheckNoOptional(ctx *Context, target Expr) bool

func PropagateOptional

func PropagateOptional(target Expr)

func RunPassChildren

func RunPassChildren[T AST](c *Context, parent AST, children []T, pass Pass)

func RunPassSlice

func RunPassSlice[T AST](c *Context, asts []T, pass Pass)

func WithPos

func WithPos[T AST](e AST, v T) T

Types

type AST

type AST interface {
	PassRunner
	Pos() token.Pos
	SetPos(pos token.Pos)
}

func Unwrap

func Unwrap(v AST) AST

type ASTs

type ASTs []AST

func (ASTs) Pos

func (asts ASTs) Pos() token.Pos

func (ASTs) RunPass

func (asts ASTs) RunPass(ctx *Context, pass Pass)

func (ASTs) SetPos

func (asts ASTs) SetPos(pos token.Pos)

type AndExpr

type AndExpr struct {
	PosImpl
	Left  Expr
	Right Expr
}

func (*AndExpr) RunPass

func (e *AndExpr) RunPass(ctx *Context, pass Pass)

type AnonFuncExpr

type AnonFuncExpr struct {
	Func
}

func (*AnonFuncExpr) RunPass

func (e *AnonFuncExpr) RunPass(ctx *Context, pass Pass)

type ArrayElement

type ArrayElement struct {
	PosImpl
	Val    Expr
	Expand bool
}

func (*ArrayElement) RunPass

func (e *ArrayElement) RunPass(ctx *Context, pass Pass)

type ArrayElementBlock

type ArrayElementBlock struct {
	PosImpl

	Elements []*ArrayElement
	// contains filtered or unexported fields
}

func (*ArrayElementBlock) RunPass

func (b *ArrayElementBlock) RunPass(ctx *Context, pass Pass)

func (*ArrayElementBlock) Scope

func (b *ArrayElementBlock) Scope() scope.Scope

type ArrayLiteral

type ArrayLiteral struct {
	PosImpl
	Block *ArrayElementBlock
	// contains filtered or unexported fields
}

func (*ArrayLiteral) RunPass

func (a *ArrayLiteral) RunPass(ctx *Context, pass Pass)

func (*ArrayLiteral) Scope

func (a *ArrayLiteral) Scope() scope.Scope

type AssignOpStmt

type AssignOpStmt struct {
	PosImpl
	Op     Operator
	LValue *LValue
	RValue Expr
	// contains filtered or unexported fields
}

func (*AssignOpStmt) RunPass

func (s *AssignOpStmt) RunPass(ctx *Context, pass Pass)

type AssignOperator

type AssignOperator int

type AssignStmt

type AssignStmt struct {
	PosImpl
	Lvalues ASTs
	Rvalues Exprs
}

func (*AssignStmt) RunPass

func (s *AssignStmt) RunPass(ctx *Context, pass Pass)

type BinaryExpr

type BinaryExpr struct {
	PosImpl
	Left  Expr
	Op    Operator
	Right Expr
}

func (*BinaryExpr) RunPass

func (e *BinaryExpr) RunPass(ctx *Context, pass Pass)

type BreakContinueEmitter

type BreakContinueEmitter interface {
	EmitBreak(pos token.Pos, emitter *vm.Emitter)
	EmitContinue(pos token.Pos, emitter *vm.Emitter)
}

type BreakStmt

type BreakStmt struct {
	PosImpl
}

func (*BreakStmt) RunPass

func (s *BreakStmt) RunPass(ctx *Context, pass Pass)

type Context

type Context struct {
	Stack
	*errlogger.ErrLoggerWrapper
	// contains filtered or unexported fields
}

func NewContext

func NewContext(
	l *errlogger.ErrLoggerWrapper,
	deps []*vm.CompiledPackage,
) *Context

func (*Context) CurrentFunc

func (c *Context) CurrentFunc() *Func

func (*Context) Emitter

func (c *Context) Emitter() *vm.Emitter

func (*Context) FindSymbol

func (c *Context) FindSymbol(symName string) symbol.Symbol

func (*Context) GetDep

func (c *Context) GetDep(packageName string) (pkg *vm.CompiledPackage, index int)

func (*Context) GetScope

func (c *Context) GetScope(typeMask scope.Type) scope.Scope

func (*Context) Imports

func (c *Context) Imports() []*vm.CompiledPackage

func (*Context) IsInRepeatableScope

func (c *Context) IsInRepeatableScope() bool

func (*Context) IsLValue

func (c *Context) IsLValue() bool

func (*Context) Len

func (c *Context) Len() int

func (*Context) Package

func (c *Context) Package() *Package

func (*Context) Parent

func (c *Context) Parent() AST

func (*Context) Peek

func (c *Context) Peek(n int) AST

func (*Context) RunPassChild

func (c *Context) RunPassChild(parent AST, child AST, pass Pass)

type ContinueStmt

type ContinueStmt struct {
	PosImpl
}

func (*ContinueStmt) RunPass

func (s *ContinueStmt) RunPass(ctx *Context, pass Pass)

type DeferStmt

type DeferStmt struct {
	PosImpl
	// contains filtered or unexported fields
}

func NewDeferStmt

func NewDeferStmt(callExpr *FuncCallExpr) *DeferStmt

func (*DeferStmt) RunPass

func (s *DeferStmt) RunPass(ctx *Context, pass Pass)

type ExecExpand

type ExecExpand struct {
	PosImpl
	Expr Expr
}

func (*ExecExpand) RunPass

func (e *ExecExpand) RunPass(ctx *Context, pass Pass)

type ExecHome

type ExecHome struct {
	PosImpl
	// contains filtered or unexported fields
}

func (*ExecHome) RunPass

func (e *ExecHome) RunPass(ctx *Context, pass Pass)

type ExecWS

type ExecWS struct {
	PosImpl
}

func (*ExecWS) RunPass

func (e *ExecWS) RunPass(ctx *Context, pass Pass)

type Expr

type Expr interface {
	AST
	// contains filtered or unexported methods
}

type ExprStmt

type ExprStmt struct {
	PosImpl
	Expr Expr
}

func (*ExprStmt) RunPass

func (c *ExprStmt) RunPass(ctx *Context, pass Pass)

type Exprs

type Exprs []Expr

func (Exprs) Pos

func (exprs Exprs) Pos() token.Pos

func (Exprs) RunPass

func (exprs Exprs) RunPass(ctx *Context, pass Pass)

func (Exprs) SetPos

func (exprs Exprs) SetPos(pos token.Pos)

type ForStmt

type ForStmt struct {
	PosImpl
	ForVars  []*ForVar
	IterExpr Expr
	Block    *StmtBlock
}

func (*ForStmt) RunPass

func (s *ForStmt) RunPass(ctx *Context, pass Pass)

type ForVar

type ForVar struct {
	PosImpl
	VarName token.Token
	// contains filtered or unexported fields
}

func (*ForVar) RunPass

func (s *ForVar) RunPass(ctx *Context, pass Pass)

type FormatExpr

type FormatExpr struct {
	PosImpl
	Target Expr
	Format string
}

func (*FormatExpr) RunPass

func (e *FormatExpr) RunPass(ctx *Context, pass Pass)

type FormattedStringLiteral

type FormattedStringLiteral struct {
	PosImpl

	Parts []Expr
}

func (*FormattedStringLiteral) RunPass

func (e *FormattedStringLiteral) RunPass(ctx *Context, pass Pass)

type Func

type Func struct {
	PosImpl

	Params    []*FuncParam
	Block     *StmtBlock
	IsClosure bool
	DebugName string
	// contains filtered or unexported fields
}

func (*Func) IdxFunc

func (f *Func) IdxFunc() int

func (*Func) IsIter

func (f *Func) IsIter() bool

func (*Func) IterNRet

func (f *Func) IterNRet() int

func (*Func) NewCapture

func (f *Func) NewCapture(sym symbol.Symbol) *symbol.CaptureSymbol

func (*Func) NewLocal

func (f *Func) NewLocal() *symbol.LocalVarSymbol

func (*Func) NewParam

func (f *Func) NewParam() *symbol.ParamSymbol

func (*Func) RunPass

func (f *Func) RunPass(ctx *Context, pass Pass)

func (*Func) Scope

func (f *Func) Scope() scope.Scope

func (*Func) SetIterNRet

func (f *Func) SetIterNRet(nret int)

type FuncCallExpr

type FuncCallExpr struct {
	PosImpl
	Target   Expr
	Args     Exprs
	RetN     int
	Expand   bool
	Pipeline bool
}

func (*FuncCallExpr) RunPass

func (c *FuncCallExpr) RunPass(ctx *Context, pass Pass)

func (*FuncCallExpr) SetRetN

func (c *FuncCallExpr) SetRetN(logger errlogger.ErrLogger, n int)

type FuncParam

type FuncParam struct {
	PosImpl

	Name string
	// contains filtered or unexported fields
}

func (*FuncParam) RunPass

func (p *FuncParam) RunPass(ctx *Context, pass Pass)

type FuncStmt

type FuncStmt struct {
	Func

	Name string
	// contains filtered or unexported fields
}

func (*FuncStmt) RunPass

func (s *FuncStmt) RunPass(ctx *Context, pass Pass)

type GraphPrinter

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

func NewGraphPrinter

func NewGraphPrinter(out io.Writer) *GraphPrinter

func (*GraphPrinter) PrintGraph

func (p *GraphPrinter) PrintGraph(root Printer)

func (*GraphPrinter) PrintNode

func (p *GraphPrinter) PrintNode(label string, children ...Printer)

type IfSection

type IfSection struct {
	PosImpl
	Pred  Expr
	Block AST
	// contains filtered or unexported fields
}

func (*IfSection) RunPass

func (b *IfSection) RunPass(ctx *Context, pass Pass)

type IfStmt

type IfStmt struct {
	PosImpl
	Sections []*IfSection
	// contains filtered or unexported fields
}

func (*IfStmt) RunPass

func (s *IfStmt) RunPass(ctx *Context, pass Pass)

type Import

type Import struct {
	PosImpl

	Alias           string
	Package         string
	ExpandedPackage string
}

func (*Import) RunPass

func (i *Import) RunPass(ctx *Context, pass Pass)

type IncDecOp

type IncDecOp int
const (
	IncDecOpUndefined IncDecOp = iota
	IncDecOpInc
	IncDecOpDec
)

type IncDecStmt

type IncDecStmt struct {
	PosImpl
	LValue *LValue
	Op     IncDecOp
	// contains filtered or unexported fields
}

func (*IncDecStmt) RunPass

func (s *IncDecStmt) RunPass(ctx *Context, pass Pass)

type IndexExpr

type IndexExpr struct {
	PosImpl

	Target   Expr
	Index    Expr
	Optional bool
}

func (*IndexExpr) RunPass

func (e *IndexExpr) RunPass(ctx *Context, pass Pass)

type LValue

type LValue struct {
	PosImpl

	Expr Expr
}

func (*LValue) RunPass

func (v *LValue) RunPass(ctx *Context, pass Pass)

type LiteralExpr

type LiteralExpr struct {
	PosImpl
	Val token.Token
}

func (*LiteralExpr) RunPass

func (e *LiteralExpr) RunPass(ctx *Context, pass Pass)

type Loop

type Loop struct {
	PosImpl

	Predicate     Expr
	Block         AST
	ContinueBlock AST
	// contains filtered or unexported fields
}

func (*Loop) EmitBreak

func (l *Loop) EmitBreak(pos token.Pos, e *vm.Emitter)

func (*Loop) EmitContinue

func (l *Loop) EmitContinue(pos token.Pos, e *vm.Emitter)

func (*Loop) IsRepeatableScope

func (l *Loop) IsRepeatableScope()

func (*Loop) RunPass

func (l *Loop) RunPass(ctx *Context, pass Pass)

type MemberAccess

type MemberAccess struct {
	PosImpl

	Target   Expr
	Member   token.Token
	Optional bool

	ModuleMember symbol.Symbol
}

func (*MemberAccess) RunPass

func (a *MemberAccess) RunPass(ctx *Context, pass Pass)

type MetaAttrib

type MetaAttrib struct {
	PosImpl

	Name  string
	Value vm.Value
}

func (*MetaAttrib) RunPass

func (a *MetaAttrib) RunPass(ctx *Context, pass Pass)

type MetaParam

type MetaParam struct {
	PosImpl

	Name    string
	IsFlag  bool
	Default Expr
	Attribs ASTs
	// contains filtered or unexported fields
}

func (*MetaParam) RunPass

func (p *MetaParam) RunPass(ctx *Context, pass Pass)

type MetaParamInit

type MetaParamInit struct {
	PosImpl
	Default   Expr
	GlobalSym *symbol.GlobalVarSymbol
}

func (*MetaParamInit) RunPass

func (p *MetaParamInit) RunPass(ctx *Context, pass Pass)

type MultiValueExpr

type MultiValueExpr interface {
	SetRetN(logger errlogger.ErrLogger, n int)
}

type Nop

type Nop struct {
	PosImpl
}

func (*Nop) RunPass

func (n *Nop) RunPass(ctx *Context, pass Pass)

type ObjectField

type ObjectField struct {
	PosImpl

	NameID   string
	NameExpr Expr
	Val      Expr
}

func (*ObjectField) RunPass

func (s *ObjectField) RunPass(ctx *Context, pass Pass)

type ObjectFieldBlock

type ObjectFieldBlock struct {
	PosImpl

	Fields []*ObjectField
	// contains filtered or unexported fields
}

func (*ObjectFieldBlock) RunPass

func (b *ObjectFieldBlock) RunPass(ctx *Context, pass Pass)

func (*ObjectFieldBlock) Scope

func (b *ObjectFieldBlock) Scope() scope.Scope

type ObjectLiteral

type ObjectLiteral struct {
	PosImpl
	FieldBlock *ObjectFieldBlock
	// contains filtered or unexported fields
}

func (*ObjectLiteral) RunPass

func (s *ObjectLiteral) RunPass(ctx *Context, pass Pass)

func (*ObjectLiteral) Scope

func (s *ObjectLiteral) Scope() scope.Scope

type Operator

type Operator int
const (
	BinOpPlus Operator = iota
	BinOpMinus
	BinOpMult
	BinOpDiv
	BinOpMod
	BinOpLT
	BinOpLE
	BinOpGT
	BinOpGE
	BinOpEq
	BinOpNE
)

type OrExpr

type OrExpr struct {
	PosImpl
	Left  Expr
	Right Expr
}

func (*OrExpr) RunPass

func (e *OrExpr) RunPass(ctx *Context, pass Pass)

type Package

type Package struct {
	PosImpl

	IsMain      bool
	AutoImports ASTs
	Units       ASTs
	// contains filtered or unexported fields
}

func (*Package) AddGlobalParam

func (m *Package) AddGlobalParam(ctx *Context, name string, param *meta.Param, pos token.Pos) *symbol.GlobalVarSymbol

func (*Package) AddInitStmt

func (p *Package) AddInitStmt(initStmt AST)

func (*Package) GetImports

func (p *Package) GetImports() []string

func (*Package) Metadata

func (m *Package) Metadata() *meta.Metadata

func (*Package) NewGlobal

func (m *Package) NewGlobal() *symbol.GlobalVarSymbol

func (*Package) RunPass

func (p *Package) RunPass(ctx *Context, pass Pass)

func (*Package) Scope

func (p *Package) Scope() scope.Scope

type Pass

type Pass int
const (
	Print Pass = iota

	Rewrite
	CreateGlobals
	Check
	Emit
)

type PassRunner

type PassRunner interface {
	RunPass(ctx *Context, pass Pass)
}

type PipeExpr

type PipeExpr struct {
	PosImpl

	Left  Expr
	Right Expr
	// contains filtered or unexported fields
}

func (*PipeExpr) RunPass

func (e *PipeExpr) RunPass(ctx *Context, pass Pass)

func (*PipeExpr) SetRetN

func (e *PipeExpr) SetRetN(logger errlogger.ErrLogger, n int)

type PosImpl

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

func (*PosImpl) Pos

func (b *PosImpl) Pos() token.Pos

func (*PosImpl) SetPos

func (b *PosImpl) SetPos(pos token.Pos)

type PreResolvedReference

type PreResolvedReference struct {
	PosImpl

	// TODO: for consistency, rename every `sym` everywhere to `symbol`.
	Symbol symbol.Symbol
}

func (*PreResolvedReference) RunPass

func (r *PreResolvedReference) RunPass(ctx *Context, pass Pass)

type Printer

type Printer interface {
	Print(p *GraphPrinter)
}

type RegexLiteral

type RegexLiteral struct {
	PosImpl

	RegexDef string
}

func (*RegexLiteral) RunPass

func (l *RegexLiteral) RunPass(ctx *Context, pass Pass)

type Repeatable

type Repeatable struct {
	PosImpl

	Stmt AST
}

func (*Repeatable) RunPass

func (r *Repeatable) RunPass(ctx *Context, pass Pass)

type ReturnStmt

type ReturnStmt struct {
	PosImpl
	Values Exprs
}

func (*ReturnStmt) RunPass

func (s *ReturnStmt) RunPass(ctx *Context, pass Pass)

type RootExpr

type RootExpr struct {
	PosImpl

	Type RootExprType

	Target *RootExpr

	Member token.Token

	Index Expr

	Begin Expr
	End   Expr

	Optional bool
	// contains filtered or unexported fields
}

func (*RootExpr) RunPass

func (e *RootExpr) RunPass(ctx *Context, pass Pass)

type RootExprType

type RootExprType int
const (
	RootExprMemberAccess RootExprType = iota
	RootExprIndex
)

type Scope

type Scope interface {
	Scope() scope.Scope
}

type SimpleRef

type SimpleRef struct {
	PosImpl
	ID token.Token

	Import *symbol.Import
	// contains filtered or unexported fields
}

func (*SimpleRef) RunPass

func (r *SimpleRef) RunPass(ctx *Context, pass Pass)

type SliceExpr

type SliceExpr struct {
	PosImpl

	Target Expr
	Begin  Expr
	End    Expr
}

func (*SliceExpr) RunPass

func (e *SliceExpr) RunPass(ctx *Context, pass Pass)

type Stack

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

func (*Stack) All

func (s *Stack) All() iter.Seq[AST]

func (*Stack) Pop

func (s *Stack) Pop()

func (*Stack) Push

func (s *Stack) Push(ast AST)

type StmtBlock

type StmtBlock struct {
	PosImpl

	Stmts ASTs
	// contains filtered or unexported fields
}

func (*StmtBlock) RunPass

func (b *StmtBlock) RunPass(ctx *Context, pass Pass)

func (*StmtBlock) Scope

func (b *StmtBlock) Scope() scope.Scope

type TernaryExpr

type TernaryExpr struct {
	PosImpl

	Condition Expr
	Then      Expr
	Else      Expr
}

func (*TernaryExpr) RunPass

func (e *TernaryExpr) RunPass(ctx *Context, pass Pass)

type ThrowStmt

type ThrowStmt struct {
	PosImpl

	Expr Expr
}

func (*ThrowStmt) RunPass

func (s *ThrowStmt) RunPass(ctx *Context, pass Pass)

type TryCatchStmt

type TryCatchStmt struct {
	PosImpl
	// contains filtered or unexported fields
}

func NewTryCatchStmt

func NewTryCatchStmt(
	tryBlock AST,
	catchVar *token.Token,
	catchStmts AST,
) *TryCatchStmt

func (*TryCatchStmt) RunPass

func (s *TryCatchStmt) RunPass(ctx *Context, pass Pass)

type Type

type Type int
const (
	Number Type = iota
	String
	Bool
)

type UnaryExpr

type UnaryExpr struct {
	PosImpl
	Term Expr
	Op   UnaryOp
}

func (*UnaryExpr) RunPass

func (e *UnaryExpr) RunPass(ctx *Context, pass Pass)

type UnaryOp

type UnaryOp int
const (
	UnaryOpUndefined UnaryOp = iota
	UnaryOpNot
	UnaryOpPlus
	UnaryOpMinus
)

type Unit

type Unit struct {
	PosImpl

	Meta    ASTs
	Imports []*Import
	Block   ASTs
	// contains filtered or unexported fields
}

func (*Unit) ConvertSimple

func (u *Unit) ConvertSimple()

func (*Unit) RunPass

func (u *Unit) RunPass(ctx *Context, pass Pass)

func (*Unit) Scope

func (u *Unit) Scope() scope.Scope

type Unwrapper

type Unwrapper interface {
	Unwrap() AST
}

type Value

type Value struct {
	Type   Type
	Number float64
	String string
	Bool   bool
}

type VarDeclInit

type VarDeclInit struct {
	PosImpl

	Syms       []symbol.Symbol
	InitValues Exprs
}

func (*VarDeclInit) RunPass

func (v *VarDeclInit) RunPass(ctx *Context, pass Pass)

type VarDeclStmt

type VarDeclStmt struct {
	PosImpl
	Vars       []token.Token
	InitValues Exprs
	// contains filtered or unexported fields
}

func (*VarDeclStmt) RunPass

func (s *VarDeclStmt) RunPass(ctx *Context, pass Pass)

type WhileStmt

type WhileStmt struct {
	PosImpl

	Predicate Expr
	Block     *StmtBlock
	// contains filtered or unexported fields
}

func (*WhileStmt) RunPass

func (s *WhileStmt) RunPass(ctx *Context, pass Pass)

type YieldStmt

type YieldStmt struct {
	PosImpl
	Values Exprs
}

func (*YieldStmt) RunPass

func (s *YieldStmt) RunPass(ctx *Context, pass Pass)

type ZeroExpr

type ZeroExpr struct {
	PosImpl
}

func (*ZeroExpr) RunPass

func (e *ZeroExpr) RunPass(ctx *Context, pass Pass)

Jump to

Keyboard shortcuts

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