ast

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AST

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

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 ASTs
	// 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 added in v0.2.0

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

func (*AssignOpStmt) RunPass added in v0.2.0

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

type AssignOperator added in v0.2.0

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 added in v0.5.0

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

func (*Context) GetScope added in v0.5.0

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

func (*Context) Imports added in v0.5.0

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

func (*Context) IsInRepeatableScope added in v0.3.0

func (c *Context) IsInRepeatableScope() bool

func (*Context) IsLValue added in v0.5.0

func (c *Context) IsLValue() bool

func (*Context) Len

func (c *Context) Len() int

func (*Context) Package added in v0.3.0

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 added in v0.5.0

type ExecExpand struct {
	PosImpl
	Expr Expr
}

func (*ExecExpand) RunPass added in v0.5.0

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

type ExecHome added in v0.5.0

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

func (*ExecHome) RunPass added in v0.5.0

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

type ExecWS added in v0.5.0

type ExecWS struct {
	PosImpl
}

func (*ExecWS) RunPass added in v0.5.0

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  ASTs
	IterExpr Expr
	Block    AST
	// contains filtered or unexported fields
}

func (*ForStmt) EmitBreak

func (s *ForStmt) EmitBreak(pos token.Pos, e *vm.Emitter)

func (*ForStmt) EmitContinue

func (s *ForStmt) EmitContinue(pos token.Pos, e *vm.Emitter)

func (*ForStmt) IsRepeatableScope added in v0.3.0

func (s *ForStmt) IsRepeatableScope()

func (*ForStmt) RunPass

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

func (*ForStmt) Scope

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

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 Func

type Func struct {
	PosImpl

	Params    ASTs
	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)

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 IfBlock

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

func (*IfBlock) RunPass

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

type IfStmt

type IfStmt struct {
	PosImpl
	Sections ASTs
	// 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 added in v0.2.0

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

type IncDecStmt added in v0.2.0

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

func (*IncDecStmt) RunPass added in v0.2.0

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

type IndexExpr

type IndexExpr struct {
	PosImpl
	Target Expr
	Index  Expr
}

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 MemberAccess

type MemberAccess struct {
	PosImpl
	Target Expr
	Member token.Token

	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 added in v0.3.0

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

func (*MetaParamInit) RunPass added in v0.3.0

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

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 ASTs
	// 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 added in v0.3.0

type Package struct {
	PosImpl

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

func (*Package) AddGlobalParam added in v0.5.0

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

func (*Package) AddInitStmt added in v0.3.0

func (p *Package) AddInitStmt(initStmt AST)

func (*Package) GetImports added in v0.3.0

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

func (*Package) Metadata added in v0.5.0

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

func (*Package) NewGlobal added in v0.5.0

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

func (*Package) RunPass added in v0.3.0

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

func (*Package) Scope added in v0.3.0

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 PosImpl added in v0.3.0

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

func (*PosImpl) Pos added in v0.3.0

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

func (*PosImpl) SetPos added in v0.3.0

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

type PreResolvedReference added in v0.5.0

type PreResolvedReference struct {
	PosImpl

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

func (*PreResolvedReference) RunPass added in v0.5.0

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 RepeatableScope added in v0.3.0

type RepeatableScope interface {
	Scope
	IsRepeatableScope()
}

type ReturnStmt

type ReturnStmt struct {
	PosImpl
	Values Exprs
}

func (*ReturnStmt) RunPass

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

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) 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 added in v0.2.0

type Unit struct {
	PosImpl

	Meta    ASTs
	Imports ASTs
	Block   ASTs
	// contains filtered or unexported fields
}

func (*Unit) ConvertSimple added in v0.5.0

func (u *Unit) ConvertSimple()

func (*Unit) RunPass added in v0.2.0

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

func (*Unit) Scope added in v0.2.0

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

type Value

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

type VarDeclInit added in v0.3.0

type VarDeclInit struct {
	PosImpl

	Syms       []symbol.Symbol
	InitValues Exprs
}

func (*VarDeclInit) RunPass added in v0.3.0

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) EmitBreak

func (s *WhileStmt) EmitBreak(pos token.Pos, e *vm.Emitter)

func (*WhileStmt) EmitContinue

func (s *WhileStmt) EmitContinue(pos token.Pos, e *vm.Emitter)

func (*WhileStmt) IsRepeatableScope added in v0.3.0

func (s *WhileStmt) IsRepeatableScope()

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