node

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(n Coder, opt ...CodeOption) string

func CodeStmtsW

func CodeStmtsW(w io.Writer, n Stmts, opt ...CodeOption)

func CodeW

func CodeW(w io.Writer, n Coder, opt ...CodeOption)

func IsExpr

func IsExpr(n Node) (ok bool)

func IsStatement

func IsStatement(v Node) (ok bool)

IsStatement returns true if given value is implements interface{ StmtNode() }.

func Lit

func Lit(value string, pos source.Pos) ast.Literal

Types

type ArgVarLit

type ArgVarLit struct {
	TokenPos source.Pos
	Value    Expr
}

ArgVarLit represents an variadic of argument.

func ArgVar

func ArgVar(pos source.Pos, value Expr) *ArgVarLit

func (*ArgVarLit) End

func (e *ArgVarLit) End() source.Pos

func (*ArgVarLit) ExprNode

func (e *ArgVarLit) ExprNode()

func (*ArgVarLit) Pos

func (e *ArgVarLit) Pos() source.Pos

func (*ArgVarLit) String

func (e *ArgVarLit) String() string

func (*ArgVarLit) WriteCode

func (e *ArgVarLit) WriteCode(ctx *CodeWriteContext)

type ArgsKeywordExpr

type ArgsKeywordExpr struct {
	TokenPos source.Pos
	Literal  string
}

func ArgsKW

func ArgsKW(pos source.Pos) *ArgsKeywordExpr

func (*ArgsKeywordExpr) End

func (c *ArgsKeywordExpr) End() source.Pos

func (*ArgsKeywordExpr) ExprNode

func (c *ArgsKeywordExpr) ExprNode()

func (*ArgsKeywordExpr) Pos

func (c *ArgsKeywordExpr) Pos() source.Pos

func (*ArgsKeywordExpr) String

func (c *ArgsKeywordExpr) String() string

func (*ArgsKeywordExpr) WriteCode

func (c *ArgsKeywordExpr) WriteCode(ctx *CodeWriteContext)

type ArgsList

type ArgsList struct {
	Var    *TypedIdentExpr
	Values []*TypedIdentExpr
}

ArgsList represents a list of identifiers.

func Args

func Args(vari *TypedIdentExpr, names ...Expr) ArgsList

func (*ArgsList) End

func (n *ArgsList) End() source.Pos

End returns the position of first character immediately after the node.

func (*ArgsList) NumFields

func (n *ArgsList) NumFields() int

NumFields returns the number of fields.

func (*ArgsList) Pos

func (n *ArgsList) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ArgsList) PrependValue

func (n *ArgsList) PrependValue(v ...*TypedIdentExpr)

func (*ArgsList) String

func (n *ArgsList) String() string

type ArrayExpr

type ArrayExpr struct {
	Elements []Expr
	LBrack   source.Pos
	RBrack   source.Pos
}

ArrayExpr represents an array literal.

func Array

func Array(lbracket, rbracket source.Pos, list ...Expr) *ArrayExpr

func (*ArrayExpr) End

func (e *ArrayExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*ArrayExpr) ExprNode

func (e *ArrayExpr) ExprNode()

func (*ArrayExpr) Pos

func (e *ArrayExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ArrayExpr) String

func (e *ArrayExpr) String() string

func (*ArrayExpr) WriteCode

func (e *ArrayExpr) WriteCode(ctx *CodeWriteContext)

type AssignStmt

type AssignStmt struct {
	LHS      []Expr
	RHS      []Expr
	Token    token.Token
	TokenPos source.Pos
}

AssignStmt represents an assignment statement.

func SAssign

func SAssign(
	lhs, rhs []Expr,
	token token.Token,
	pos source.Pos,
) *AssignStmt

func (*AssignStmt) End

func (s *AssignStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*AssignStmt) Pos

func (s *AssignStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*AssignStmt) StmtNode

func (s *AssignStmt) StmtNode()

func (*AssignStmt) String

func (s *AssignStmt) String() string

func (*AssignStmt) WriteCode

func (s *AssignStmt) WriteCode(ctx *CodeWriteContext)

type BadDecl

type BadDecl struct {
	From, To source.Pos // position range of bad declaration
}

A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.

func (*BadDecl) End

func (d *BadDecl) End() source.Pos

End returns the position of first character immediately after the node.

func (*BadDecl) Pos

func (d *BadDecl) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BadDecl) String

func (*BadDecl) String() string

func (*BadDecl) WriteCode

func (d *BadDecl) WriteCode(ctx *CodeWriteContext)

type BadExpr

type BadExpr struct {
	From source.Pos
	To   source.Pos
}

BadExpr represents a bad expression.

func (*BadExpr) End

func (e *BadExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*BadExpr) ExprNode

func (e *BadExpr) ExprNode()

func (*BadExpr) Pos

func (e *BadExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BadExpr) String

func (e *BadExpr) String() string

func (*BadExpr) WriteCode

func (e *BadExpr) WriteCode(ctx *CodeWriteContext)

type BadStmt

type BadStmt struct {
	From source.Pos
	To   source.Pos
}

BadStmt represents a bad statement.

func (*BadStmt) End

func (s *BadStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*BadStmt) Pos

func (s *BadStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BadStmt) StmtNode

func (s *BadStmt) StmtNode()

func (*BadStmt) String

func (s *BadStmt) String() string

func (*BadStmt) WriteCode

func (s *BadStmt) WriteCode(ctx *CodeWriteContext)

type BinaryExpr

type BinaryExpr struct {
	LHS      Expr
	RHS      Expr
	Token    token.Token
	TokenPos source.Pos
}

BinaryExpr represents a binary operator expression.

func EBinary

func EBinary(
	x, y Expr,
	op token.Token,
	pos source.Pos,
) *BinaryExpr

func (*BinaryExpr) End

func (e *BinaryExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*BinaryExpr) ExprNode

func (e *BinaryExpr) ExprNode()

func (*BinaryExpr) Pos

func (e *BinaryExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BinaryExpr) String

func (e *BinaryExpr) String() string

func (*BinaryExpr) WriteCode

func (e *BinaryExpr) WriteCode(ctx *CodeWriteContext)

type BlockExpr

type BlockExpr struct {
	*BlockStmt
}

func EBlock

func EBlock(lbrace, rbrace source.Pos, list ...Stmt) *BlockExpr

func (BlockExpr) ExprNode

func (b BlockExpr) ExprNode()

type BlockStmt

type BlockStmt struct {
	Stmts  Stmts
	LBrace ast.Literal
	RBrace ast.Literal
	Scoped bool
}

BlockStmt represents a block statement.

func SBlock

func SBlock(lbrace, rbrace source.Pos, list ...Stmt) *BlockStmt

func SBlockLit

func SBlockLit(lbrace, rbrace ast.Literal, list ...Stmt) *BlockStmt

func (*BlockStmt) End

func (s *BlockStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*BlockStmt) LeftBrace

func (s *BlockStmt) LeftBrace() string

func (*BlockStmt) Pos

func (s *BlockStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BlockStmt) RightBrace

func (s *BlockStmt) RightBrace() string

func (*BlockStmt) StmtNode

func (s *BlockStmt) StmtNode()

func (*BlockStmt) String

func (s *BlockStmt) String() string

func (*BlockStmt) WriteCode

func (s *BlockStmt) WriteCode(ctx *CodeWriteContext)

func (*BlockStmt) WriteCodeInSelfDepth

func (s *BlockStmt) WriteCodeInSelfDepth(ctx *CodeWriteContext, selfDepth bool)

type BoolExpr

type BoolExpr interface {
	Expr
	Bool() bool
}

type BoolLit

type BoolLit struct {
	Value    bool
	ValuePos source.Pos
	Literal  string
}

BoolLit represents a boolean literal.

func Bool

func Bool(value bool, pos source.Pos) *BoolLit

func (*BoolLit) Bool

func (e *BoolLit) Bool() bool

func (*BoolLit) End

func (e *BoolLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*BoolLit) ExprNode

func (e *BoolLit) ExprNode()

func (*BoolLit) Pos

func (e *BoolLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BoolLit) String

func (e *BoolLit) String() string

func (*BoolLit) WriteCode

func (e *BoolLit) WriteCode(ctx *CodeWriteContext)

type BranchStmt

type BranchStmt struct {
	Token    token.Token
	TokenPos source.Pos
	Label    *IdentExpr
}

BranchStmt represents a branch statement.

func SBreak

func SBreak(pos source.Pos) *BranchStmt

func SContinue

func SContinue(pos source.Pos) *BranchStmt

func (*BranchStmt) End

func (s *BranchStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*BranchStmt) Pos

func (s *BranchStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*BranchStmt) StmtNode

func (s *BranchStmt) StmtNode()

func (*BranchStmt) String

func (s *BranchStmt) String() string

func (*BranchStmt) WriteCode

func (s *BranchStmt) WriteCode(ctx *CodeWriteContext)

type CallArgs

type CallArgs struct {
	LParen    source.Pos
	Args      CallExprArgs
	NamedArgs CallExprNamedArgs
	RParen    source.Pos
}

func (*CallArgs) End

func (c *CallArgs) End() source.Pos

End returns the position of first character immediately after the node.

func (*CallArgs) Pos

func (c *CallArgs) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*CallArgs) String

func (c *CallArgs) String() string

func (*CallArgs) StringArg

func (c *CallArgs) StringArg(w io.Writer, lbrace, rbrace string)

func (*CallArgs) StringW

func (c *CallArgs) StringW(w io.Writer)

func (*CallArgs) ToFuncParams

func (c *CallArgs) ToFuncParams() (fp *FuncParams, err error)

func (*CallArgs) WriteCode

func (c *CallArgs) WriteCode(ctx *CodeWriteContext)

func (*CallArgs) WriteCodeBrace

func (c *CallArgs) WriteCodeBrace(ctx *CodeWriteContext, lbrace, rbrace string)

type CallExpr

type CallExpr struct {
	Func Expr
	CallArgs
}

CallExpr represents a function call expression.

func ECall

func ECall(
	f Expr,
	lparen, rparen source.Pos,
	args ...any,
) (ce *CallExpr)

func ECallProxy

func ECallProxy(efunc Expr) *CallExpr

func (*CallExpr) CallPos

func (e *CallExpr) CallPos() source.Pos

CallPos returns the position of the fist valid call pos

func (*CallExpr) End

func (e *CallExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*CallExpr) ExprNode

func (e *CallExpr) ExprNode()

func (*CallExpr) Pos

func (e *CallExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*CallExpr) String

func (e *CallExpr) String() string

func (*CallExpr) WriteCode

func (e *CallExpr) WriteCode(ctx *CodeWriteContext)

type CallExprArgs

type CallExprArgs struct {
	Values []Expr
	Var    *ArgVarLit
}

CallExprArgs represents a call expression arguments.

func NewCallExprArgs

func NewCallExprArgs(
	argVar *ArgVarLit,
	args ...Expr,
) (ce CallExprArgs)

func (*CallExprArgs) String

func (a *CallExprArgs) String() string

func (*CallExprArgs) Valid

func (a *CallExprArgs) Valid() bool

func (*CallExprArgs) WriteCode

func (a *CallExprArgs) WriteCode(ctx *CodeWriteContext)

type CallExprNamedArgs

type CallExprNamedArgs struct {
	Names  []NamedArgExpr
	Values []Expr
	Var    *NamedArgVarLit
}

CallExprNamedArgs represents a call expression keyword arguments.

func NewCallExprNamedArgs

func NewCallExprNamedArgs(
	argVar *NamedArgVarLit,
	names []NamedArgExpr, values []Expr,
) (ce CallExprNamedArgs)

func (*CallExprNamedArgs) Append

func (a *CallExprNamedArgs) Append(name NamedArgExpr, value Expr) *CallExprNamedArgs

func (*CallExprNamedArgs) AppendS

func (a *CallExprNamedArgs) AppendS(name string, value Expr) *CallExprNamedArgs

func (*CallExprNamedArgs) Get

func (a *CallExprNamedArgs) Get(name NamedArgExpr) (index int, value Expr)

func (*CallExprNamedArgs) NamesExpr

func (a *CallExprNamedArgs) NamesExpr() (r []Expr)

func (*CallExprNamedArgs) Prepend

func (a *CallExprNamedArgs) Prepend(name NamedArgExpr, value Expr) *CallExprNamedArgs

func (*CallExprNamedArgs) String

func (a *CallExprNamedArgs) String() string

func (*CallExprNamedArgs) Valid

func (a *CallExprNamedArgs) Valid() bool

func (*CallExprNamedArgs) WriteCode

func (a *CallExprNamedArgs) WriteCode(ctx *CodeWriteContext)

type CalleeKeywordExpr

type CalleeKeywordExpr struct {
	TokenPos source.Pos
	Literal  string
}

func CaleeKW

func CaleeKW(pos source.Pos) *CalleeKeywordExpr

func (*CalleeKeywordExpr) End

func (c *CalleeKeywordExpr) End() source.Pos

func (*CalleeKeywordExpr) ExprNode

func (c *CalleeKeywordExpr) ExprNode()

func (*CalleeKeywordExpr) Pos

func (c *CalleeKeywordExpr) Pos() source.Pos

func (*CalleeKeywordExpr) String

func (c *CalleeKeywordExpr) String() string

func (*CalleeKeywordExpr) WriteCode

func (c *CalleeKeywordExpr) WriteCode(ctx *CodeWriteContext)

type CatchStmt

type CatchStmt struct {
	CatchPos source.Pos
	Ident    *IdentExpr // can be nil if ident is missing
	Body     *BlockStmt
}

CatchStmt represents an catch statement.

func SCatch

func SCatch(
	catchPos source.Pos,
	ident *IdentExpr,
	body *BlockStmt,
) *CatchStmt

func (*CatchStmt) End

func (s *CatchStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*CatchStmt) Pos

func (s *CatchStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*CatchStmt) StmtNode

func (s *CatchStmt) StmtNode()

func (*CatchStmt) String

func (s *CatchStmt) String() string

func (*CatchStmt) WriteCode

func (s *CatchStmt) WriteCode(ctx *CodeWriteContext)

type CharLit

type CharLit struct {
	Value    rune
	ValuePos source.Pos
	Literal  string
}

CharLit represents a character literal.

func Char

func Char(value rune, pos source.Pos) *CharLit

func (*CharLit) End

func (e *CharLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*CharLit) ExprNode

func (e *CharLit) ExprNode()

func (*CharLit) Pos

func (e *CharLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*CharLit) String

func (e *CharLit) String() string

func (*CharLit) WriteCode

func (e *CharLit) WriteCode(ctx *CodeWriteContext)

type ClosureExpr

type ClosureExpr struct {
	ast.NodeData
	Params      FuncParams
	LambdaToken token.Token
	LambdaPos   source.Pos
	Body        Expr
}

ClosureExpr represents a function closure literal.

func EClosure

func EClosure(funcType *FuncType, body Expr) *ClosureExpr

func (*ClosureExpr) End

func (e *ClosureExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*ClosureExpr) ExprNode

func (e *ClosureExpr) ExprNode()

func (*ClosureExpr) Pos

func (e *ClosureExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ClosureExpr) String

func (e *ClosureExpr) String() string

func (*ClosureExpr) WriteCode

func (e *ClosureExpr) WriteCode(ctx *CodeWriteContext)

type CodeBeginStmt

type CodeBeginStmt struct {
	Lit         ast.Literal
	RemoveSpace bool
}

func SCodeBegin

func SCodeBegin(lit ast.Literal, removeSpace bool) *CodeBeginStmt

func (CodeBeginStmt) End

func (s CodeBeginStmt) End() source.Pos

func (CodeBeginStmt) Pos

func (s CodeBeginStmt) Pos() source.Pos

func (CodeBeginStmt) StmtNode

func (s CodeBeginStmt) StmtNode()

func (CodeBeginStmt) String

func (s CodeBeginStmt) String() string

func (*CodeBeginStmt) WriteCode

func (s *CodeBeginStmt) WriteCode(ctx *CodeWriteContext)

type CodeEndStmt

type CodeEndStmt struct {
	Lit         ast.Literal
	RemoveSpace bool
}

func SCodeEnd

func SCodeEnd(lit ast.Literal, removeSpace bool) *CodeEndStmt

func (CodeEndStmt) End

func (s CodeEndStmt) End() source.Pos

func (CodeEndStmt) Pos

func (s CodeEndStmt) Pos() source.Pos

func (CodeEndStmt) StmtNode

func (s CodeEndStmt) StmtNode()

func (CodeEndStmt) String

func (s CodeEndStmt) String() string

func (*CodeEndStmt) WriteCode

func (s *CodeEndStmt) WriteCode(ctx *CodeWriteContext)

type CodeOption

type CodeOption func(ctx *CodeWriteContext)

func CodeTranspile

func CodeTranspile(v *TranspileOptions) CodeOption

func CodeWithPrefix

func CodeWithPrefix(prefix string) CodeOption

type CodeWriteContext

type CodeWriteContext struct {
	Stack     []ast.Node
	Depth     int
	Prefix    string
	Transpile *TranspileOptions
	CodeWriter
}

func NewCodeWriteContext

func NewCodeWriteContext(codeWriter CodeWriter, opt ...CodeOption) *CodeWriteContext

func (CodeWriteContext) Buffer

func (c CodeWriteContext) Buffer(do func(ctx *CodeWriteContext)) string

func (*CodeWriteContext) CurrentPrefix

func (c *CodeWriteContext) CurrentPrefix() string

func (*CodeWriteContext) Pop

func (c *CodeWriteContext) Pop()

func (*CodeWriteContext) PrevPrefix

func (c *CodeWriteContext) PrevPrefix() string

func (*CodeWriteContext) Printf

func (c *CodeWriteContext) Printf(format string, args ...interface{})

func (*CodeWriteContext) Push

func (c *CodeWriteContext) Push(n ast.Node)

func (*CodeWriteContext) Top

func (c *CodeWriteContext) Top() ast.Node

func (*CodeWriteContext) With

func (c *CodeWriteContext) With(n ast.Node, cb func() error) (err error)

func (CodeWriteContext) WithoutPrefix

func (c CodeWriteContext) WithoutPrefix() *CodeWriteContext

func (*CodeWriteContext) WriteExprs

func (c *CodeWriteContext) WriteExprs(sep string, expr ...Expr)

func (*CodeWriteContext) WriteLine

func (c *CodeWriteContext) WriteLine(s string)

func (*CodeWriteContext) WritePrefix

func (c *CodeWriteContext) WritePrefix()

func (*CodeWriteContext) WritePrefixedLine

func (c *CodeWriteContext) WritePrefixedLine()

func (*CodeWriteContext) WritePrevPrefix

func (c *CodeWriteContext) WritePrevPrefix()

func (*CodeWriteContext) WriteSecondLine

func (c *CodeWriteContext) WriteSecondLine()

func (*CodeWriteContext) WriteSemi

func (c *CodeWriteContext) WriteSemi()

func (*CodeWriteContext) WriteSemiOrDoubleLine

func (c *CodeWriteContext) WriteSemiOrDoubleLine()

func (*CodeWriteContext) WriteStmts

func (c *CodeWriteContext) WriteStmts(smt ...Stmt)

type CodeWriter

type CodeWriter interface {
	io.Writer
	WriteString(s ...string)
	WriteSingleByte(b byte)
	WriteRune(b rune)
	WriteLine(s ...string)
	WriteLines(l ...string)
}

func NewCodeWriter

func NewCodeWriter(w io.Writer) CodeWriter

type Coder

type Coder interface {
	WriteCode(ctx *CodeWriteContext)
}

type CondExpr

type CondExpr struct {
	Cond        Expr
	True        Expr
	False       Expr
	QuestionPos source.Pos
	ColonPos    source.Pos
}

CondExpr represents a ternary conditional expression.

func ECond

func ECond(
	cond, trueExpr, falseExpr Expr,
	questionPos, colonPos source.Pos,
) *CondExpr

func (*CondExpr) End

func (e *CondExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*CondExpr) ExprNode

func (e *CondExpr) ExprNode()

func (*CondExpr) Pos

func (e *CondExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*CondExpr) String

func (e *CondExpr) String() string

func (*CondExpr) WriteCode

func (e *CondExpr) WriteCode(ctx *CodeWriteContext)

type ConfigOptions

type ConfigOptions struct {
	Mixed      bool
	NoMixed    bool
	MixedStart string
	MixedEnd   string
}

type ConfigStmt

type ConfigStmt struct {
	ConfigPos source.Pos
	Elements  []*KeyValuePairLit
	Options   ConfigOptions
}

func SConfig

func SConfig(start source.Pos, opts ...*KeyValuePairLit) *ConfigStmt

func (*ConfigStmt) End

func (c *ConfigStmt) End() source.Pos

func (*ConfigStmt) ParseElements

func (c *ConfigStmt) ParseElements()

func (*ConfigStmt) Pos

func (c *ConfigStmt) Pos() source.Pos

func (*ConfigStmt) StmtNode

func (c *ConfigStmt) StmtNode()

func (*ConfigStmt) String

func (c *ConfigStmt) String() string

func (*ConfigStmt) WriteCode

func (c *ConfigStmt) WriteCode(ctx *CodeWriteContext)

type DecimalLit

type DecimalLit struct {
	Value    decimal.Decimal
	ValuePos source.Pos
	Literal  string
}

DecimalLit represents a floating point literal.

func Decimal

func Decimal(value string, pos source.Pos) *DecimalLit

func (*DecimalLit) End

func (e *DecimalLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*DecimalLit) ExprNode

func (e *DecimalLit) ExprNode()

func (*DecimalLit) Pos

func (e *DecimalLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DecimalLit) String

func (e *DecimalLit) String() string

func (*DecimalLit) WriteCode

func (e *DecimalLit) WriteCode(ctx *CodeWriteContext)

type Decl

type Decl interface {
	ast.Node

	Coder
	// contains filtered or unexported methods
}

Decl wraps methods for all declaration nodes.

func NewGenDecl

func NewGenDecl(
	tok token.Token,
	tokPos, lparen, rparen source.Pos,
	specs ...Spec,
) Decl

type DeclStmt

type DeclStmt struct {
	Decl // *GenDecl with VAR token
}

A DeclStmt node represents a declaration in a statement list.

func SDecl

func SDecl(decl Decl) *DeclStmt

func (*DeclStmt) StmtNode

func (*DeclStmt) StmtNode()

type DictElementFuncExpr

type DictElementFuncExpr struct {
	Expr
}

func EDictElementClosure

func EDictElementClosure(c *ClosureExpr) *DictElementFuncExpr

func EDictElementFunc

func EDictElementFunc(f *FuncExpr) *DictElementFuncExpr

func (*DictElementFuncExpr) Closure

func (e *DictElementFuncExpr) Closure() (c *ClosureExpr)

func (*DictElementFuncExpr) Func

func (e *DictElementFuncExpr) Func() (f *FuncExpr)

type DictElementLit

type DictElementLit struct {
	Key      string
	KeyPos   source.Pos
	ColonPos source.Pos
	Value    Expr
}

DictElementLit represents a map element.

func MapElement

func MapElement(
	key string,
	keyPos source.Pos,
	colonPos source.Pos,
	value Expr,
) *DictElementLit

func (*DictElementLit) End

func (e *DictElementLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*DictElementLit) ExprNode

func (e *DictElementLit) ExprNode()

func (*DictElementLit) Func

func (e *DictElementLit) Func() (f *DictElementFuncExpr)

func (*DictElementLit) IsFunc

func (e *DictElementLit) IsFunc() (ok bool)

func (*DictElementLit) Pos

func (e *DictElementLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DictElementLit) String

func (e *DictElementLit) String() string

func (*DictElementLit) WriteCode

func (e *DictElementLit) WriteCode(ctx *CodeWriteContext)

type DictExpr

type DictExpr struct {
	LBrace   source.Pos
	Elements []*DictElementLit
	RBrace   source.Pos
}

DictExpr represents a map literal.

func EDict

func EDict(lbrace, rbrace source.Pos, list ...*DictElementLit) *DictExpr

func (*DictExpr) End

func (e *DictExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*DictExpr) ExprNode

func (e *DictExpr) ExprNode()

func (*DictExpr) Pos

func (e *DictExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DictExpr) String

func (e *DictExpr) String() string

func (*DictExpr) WriteCode

func (e *DictExpr) WriteCode(ctx *CodeWriteContext)

type DotFileLit

type DotFileLit struct {
	TokenPos source.Pos
}

DotFileLit represents an __name__ literal.

func (*DotFileLit) End

func (e *DotFileLit) End() source.Pos

End DotFileLit the position of first character immediately after the node.

func (*DotFileLit) ExprNode

func (e *DotFileLit) ExprNode()

func (*DotFileLit) Pos

func (e *DotFileLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DotFileLit) String

func (e *DotFileLit) String() string

func (*DotFileLit) WriteCode

func (e *DotFileLit) WriteCode(ctx *CodeWriteContext)

type DotFileNameLit

type DotFileNameLit struct {
	TokenPos source.Pos
}

DotFileNameLit represents an __name__ literal.

func (*DotFileNameLit) End

func (e *DotFileNameLit) End() source.Pos

End DotFileNameLit the position of first character immediately after the node.

func (*DotFileNameLit) ExprNode

func (e *DotFileNameLit) ExprNode()

func (*DotFileNameLit) Pos

func (e *DotFileNameLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*DotFileNameLit) String

func (e *DotFileNameLit) String() string

func (*DotFileNameLit) WriteCode

func (e *DotFileNameLit) WriteCode(ctx *CodeWriteContext)

type EmbedExpr

type EmbedExpr struct {
	Path     string
	Token    token.Token
	TokenPos source.Pos
}

EmbedExpr represents an embed expression

func EEmbed

func EEmbed(path string, pos source.Pos) *EmbedExpr

func (*EmbedExpr) End

func (e *EmbedExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*EmbedExpr) ExprNode

func (e *EmbedExpr) ExprNode()

func (*EmbedExpr) Pos

func (e *EmbedExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*EmbedExpr) String

func (e *EmbedExpr) String() string

func (*EmbedExpr) WriteCode

func (e *EmbedExpr) WriteCode(ctx *CodeWriteContext)

type EmptyStmt

type EmptyStmt struct {
	Semicolon source.Pos
	Implicit  bool
}

EmptyStmt represents an empty statement.

func (*EmptyStmt) End

func (s *EmptyStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*EmptyStmt) Pos

func (s *EmptyStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*EmptyStmt) StmtNode

func (s *EmptyStmt) StmtNode()

func (*EmptyStmt) String

func (s *EmptyStmt) String() string

func (*EmptyStmt) WriteCode

func (s *EmptyStmt) WriteCode(*CodeWriteContext)

type Expr

type Expr interface {
	Node
	ExprNode()
}

Expr represents an expression node in the AST.

type ExprSelector

type ExprSelector interface {
	Expr
	SelectorExpr() Expr
}

type ExprStmt

type ExprStmt struct {
	Expr Expr
}

ExprStmt represents an expression statement.

func SExpr

func SExpr(x Expr) *ExprStmt

func (*ExprStmt) End

func (s *ExprStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*ExprStmt) Pos

func (s *ExprStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ExprStmt) StmtNode

func (s *ExprStmt) StmtNode()

func (*ExprStmt) String

func (s *ExprStmt) String() string

func (*ExprStmt) WriteCode

func (s *ExprStmt) WriteCode(ctx *CodeWriteContext)

type Exprs

type Exprs []Expr

type FinallyStmt

type FinallyStmt struct {
	FinallyPos source.Pos
	Body       *BlockStmt
}

FinallyStmt represents an finally statement.

func SFinally

func SFinally(
	finallyPos source.Pos,
	body *BlockStmt,
) *FinallyStmt

func (*FinallyStmt) End

func (s *FinallyStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*FinallyStmt) Pos

func (s *FinallyStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FinallyStmt) StmtNode

func (s *FinallyStmt) StmtNode()

func (*FinallyStmt) String

func (s *FinallyStmt) String() string

func (*FinallyStmt) WriteCode

func (s *FinallyStmt) WriteCode(ctx *CodeWriteContext)

type FlagLit

type FlagLit struct {
	ValuePos source.Pos
	Literal  string
	Value    bool
}

FlagLit represents a yes literal.

func Flag

func Flag(value bool, pos source.Pos) *FlagLit

func (*FlagLit) Bool

func (e *FlagLit) Bool() bool

func (*FlagLit) End

func (e *FlagLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*FlagLit) ExprNode

func (e *FlagLit) ExprNode()

func (*FlagLit) Pos

func (e *FlagLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FlagLit) String

func (e *FlagLit) String() string

func (*FlagLit) WriteCode

func (e *FlagLit) WriteCode(ctx *CodeWriteContext)

type FloatLit

type FloatLit struct {
	Value    float64
	ValuePos source.Pos
	Literal  string
}

FloatLit represents a floating point literal.

func Float

func Float(value float64, pos source.Pos) *FloatLit

func (*FloatLit) End

func (e *FloatLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*FloatLit) ExprNode

func (e *FloatLit) ExprNode()

func (*FloatLit) Pos

func (e *FloatLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FloatLit) String

func (e *FloatLit) String() string

func (*FloatLit) WriteCode

func (e *FloatLit) WriteCode(ctx *CodeWriteContext)

type ForInStmt

type ForInStmt struct {
	ForPos   source.Pos
	Key      *IdentExpr
	Value    *IdentExpr
	Iterable Expr
	Body     *BlockStmt
	Else     *BlockStmt
}

ForInStmt represents a for-in statement.

func SForIn

func SForIn(
	key, value *IdentExpr,
	seq Expr,
	body *BlockStmt,
	pos source.Pos,
	elseb ...*BlockStmt,
) *ForInStmt

func (*ForInStmt) End

func (s *ForInStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*ForInStmt) Pos

func (s *ForInStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ForInStmt) StmtNode

func (s *ForInStmt) StmtNode()

func (*ForInStmt) String

func (s *ForInStmt) String() string

func (*ForInStmt) WriteCode

func (s *ForInStmt) WriteCode(ctx *CodeWriteContext)

type ForStmt

type ForStmt struct {
	ForPos source.Pos
	Init   Stmt
	Cond   Expr
	Post   Stmt
	Body   *BlockStmt
}

ForStmt represents a for statement.

func SFor

func SFor(
	init Stmt,
	cond Expr,
	post Stmt,
	body *BlockStmt,
	pos source.Pos,
) *ForStmt

func (*ForStmt) End

func (s *ForStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*ForStmt) Pos

func (s *ForStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ForStmt) StmtNode

func (s *ForStmt) StmtNode()

func (*ForStmt) String

func (s *ForStmt) String() string

func (*ForStmt) WriteCode

func (s *ForStmt) WriteCode(ctx *CodeWriteContext)

type FuncExpr

type FuncExpr struct {
	ast.NodeData
	Type      *FuncType
	Body      *BlockStmt
	LambdaPos source.Pos
	BodyExpr  Expr
}

FuncExpr represents a function literal.

func EFunc

func EFunc(funcType *FuncType, body *BlockStmt) *FuncExpr

func EFuncBodyE

func EFuncBodyE(funcType *FuncType, body Expr) *FuncExpr

func (*FuncExpr) End

func (e *FuncExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*FuncExpr) ExprNode

func (e *FuncExpr) ExprNode()

func (*FuncExpr) Pos

func (e *FuncExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FuncExpr) String

func (e *FuncExpr) String() string

func (*FuncExpr) WriteCode

func (e *FuncExpr) WriteCode(ctx *CodeWriteContext)

type FuncParams

type FuncParams struct {
	LParen    source.Pos
	Args      ArgsList
	NamedArgs NamedArgsList
	RParen    source.Pos
}

FuncParams represents a function paramsw.

func (*FuncParams) Caller

func (n *FuncParams) Caller() (c *CallArgs)

func (*FuncParams) End

func (n *FuncParams) End() (pos source.Pos)

End returns the position of first character immediately after the node.

func (*FuncParams) Pos

func (n *FuncParams) Pos() (pos source.Pos)

Pos returns the position of first character belonging to the node.

func (*FuncParams) String

func (n *FuncParams) String() string

func (FuncParams) WithNamedValuesNil

func (n FuncParams) WithNamedValuesNil() (c *FuncParams)

type FuncType

type FuncType struct {
	FuncPos      source.Pos
	Ident        *IdentExpr
	Params       FuncParams
	AllowMethods bool
}

FuncType represents a function type definition.

func NewFuncType

func NewFuncType(pos, lparen, rparen source.Pos, v ...any) *FuncType

func ProxyFuncType

func ProxyFuncType() *FuncType

func (*FuncType) End

func (e *FuncType) End() source.Pos

End returns the position of first character immediately after the node.

func (*FuncType) ExprNode

func (e *FuncType) ExprNode()

func (*FuncType) Pos

func (e *FuncType) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*FuncType) String

func (e *FuncType) String() string

type GenDecl

type GenDecl struct {
	TokPos source.Pos  // position of Tok
	Tok    token.Token // Var
	Lparen source.Pos  // position of '(', if any
	Specs  []Spec
	Rparen source.Pos // position of ')', if any
}

A GenDecl node (generic declaration node) represents a variable declaration. A valid Lparen position (Lparen.Line > 0) indicates a parenthesized declaration.

Relationship between Tok value and Specs element type:

token.Var     *ValueSpec

func (*GenDecl) End

func (d *GenDecl) End() source.Pos

End returns the position of first character immediately after the node.

func (*GenDecl) Pos

func (d *GenDecl) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*GenDecl) String

func (d *GenDecl) String() string

func (*GenDecl) WriteCode

func (d *GenDecl) WriteCode(ctx *CodeWriteContext)

type IdentExpr

type IdentExpr struct {
	Name    string
	NamePos source.Pos
	Empty   bool
}

IdentExpr represents an identifier.

func EEmptyIdent

func EEmptyIdent(pos source.Pos) *IdentExpr

func EIdent

func EIdent(name string, pos source.Pos) *IdentExpr

func (*IdentExpr) End

func (e *IdentExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*IdentExpr) ExprNode

func (e *IdentExpr) ExprNode()

func (*IdentExpr) Pos

func (e *IdentExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IdentExpr) String

func (e *IdentExpr) String() string

func (*IdentExpr) WriteCode

func (e *IdentExpr) WriteCode(ctx *CodeWriteContext)

type IdentList

type IdentList struct {
	LParen  source.Pos
	VarArgs bool
	List    []*IdentExpr
	RParen  source.Pos
}

IdentList represents a list of identifiers.

func (*IdentList) End

func (n *IdentList) End() source.Pos

End returns the position of first character immediately after the node.

func (*IdentList) NumFields

func (n *IdentList) NumFields() int

NumFields returns the number of fields.

func (*IdentList) Pos

func (n *IdentList) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IdentList) String

func (n *IdentList) String() string

type IfStmt

type IfStmt struct {
	IfPos source.Pos
	Init  Stmt
	Cond  Expr
	Body  *BlockStmt
	Else  Stmt // else branch; or nil
}

IfStmt represents an if statement.

func SIf

func SIf(
	init Stmt,
	cond Expr,
	body *BlockStmt,
	elseStmt Stmt,
	pos source.Pos,
) *IfStmt

func (*IfStmt) End

func (s *IfStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*IfStmt) Pos

func (s *IfStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IfStmt) StmtNode

func (s *IfStmt) StmtNode()

func (*IfStmt) String

func (s *IfStmt) String() string

func (*IfStmt) WriteCode

func (s *IfStmt) WriteCode(ctx *CodeWriteContext)

type ImportExpr

type ImportExpr struct {
	ModuleName string
	Token      token.Token
	TokenPos   source.Pos
}

ImportExpr represents an import expression

func EImport

func EImport(moduleName string, pos source.Pos) *ImportExpr

func (*ImportExpr) End

func (e *ImportExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*ImportExpr) ExprNode

func (e *ImportExpr) ExprNode()

func (*ImportExpr) Pos

func (e *ImportExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ImportExpr) String

func (e *ImportExpr) String() string

func (*ImportExpr) WriteCode

func (e *ImportExpr) WriteCode(ctx *CodeWriteContext)

type IncDecStmt

type IncDecStmt struct {
	Expr     Expr
	Token    token.Token
	TokenPos source.Pos
}

IncDecStmt represents increment or decrement statement.

func SIncDec

func SIncDec(
	expr Expr,
	tok token.Token,
	pos source.Pos,
) *IncDecStmt

func (*IncDecStmt) End

func (s *IncDecStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*IncDecStmt) Pos

func (s *IncDecStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IncDecStmt) StmtNode

func (s *IncDecStmt) StmtNode()

func (*IncDecStmt) String

func (s *IncDecStmt) String() string

func (*IncDecStmt) WriteCode

func (s *IncDecStmt) WriteCode(ctx *CodeWriteContext)

type IndexExpr

type IndexExpr struct {
	Expr   Expr
	LBrack source.Pos
	Index  Expr
	RBrack source.Pos
}

IndexExpr represents an index expression.

func EIndex

func EIndex(
	x, index Expr,
	lbrack, rbrack source.Pos,
) *IndexExpr

func (*IndexExpr) End

func (e *IndexExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*IndexExpr) ExprNode

func (e *IndexExpr) ExprNode()

func (*IndexExpr) Pos

func (e *IndexExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IndexExpr) String

func (e *IndexExpr) String() string

func (*IndexExpr) WriteCode

func (e *IndexExpr) WriteCode(ctx *CodeWriteContext)

type IntLit

type IntLit struct {
	Value    int64
	ValuePos source.Pos
	Literal  string
}

IntLit represents an integer literal.

func Int

func Int(value int64, pos source.Pos) *IntLit

func (*IntLit) End

func (e *IntLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*IntLit) ExprNode

func (e *IntLit) ExprNode()

func (*IntLit) Pos

func (e *IntLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IntLit) String

func (e *IntLit) String() string

func (*IntLit) WriteCode

func (e *IntLit) WriteCode(ctx *CodeWriteContext)

type IsModuleLit

type IsModuleLit struct {
	TokenPos source.Pos
}

IsModuleLit represents an __is_module__ literal.

func (*IsModuleLit) End

func (e *IsModuleLit) End() source.Pos

End IsModuleLit the position of first character immediately after the node.

func (*IsModuleLit) ExprNode

func (e *IsModuleLit) ExprNode()

func (*IsModuleLit) Pos

func (e *IsModuleLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*IsModuleLit) String

func (e *IsModuleLit) String() string

func (*IsModuleLit) WriteCode

func (e *IsModuleLit) WriteCode(ctx *CodeWriteContext)

type KeyValueArrayLit

type KeyValueArrayLit struct {
	LParen   source.Pos
	Elements Exprs
	RParen   source.Pos
}

KeyValueArrayLit represents a key value array literal.

func (*KeyValueArrayLit) End

func (e *KeyValueArrayLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*KeyValueArrayLit) ExprNode

func (e *KeyValueArrayLit) ExprNode()

func (*KeyValueArrayLit) Pos

func (e *KeyValueArrayLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*KeyValueArrayLit) String

func (e *KeyValueArrayLit) String() string

func (*KeyValueArrayLit) ToMultiParenExpr

func (e *KeyValueArrayLit) ToMultiParenExpr() *MultiParenExpr

func (*KeyValueArrayLit) WriteCode

func (e *KeyValueArrayLit) WriteCode(ctx *CodeWriteContext)

type KeyValueLit

type KeyValueLit struct {
	Key   Expr
	Value Expr
}

KeyValueLit represents a key value element.

func KV

func KV(key Expr, value ...Expr) *KeyValueLit

func (*KeyValueLit) ElementString

func (e *KeyValueLit) ElementString() string

func (*KeyValueLit) End

func (e *KeyValueLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*KeyValueLit) ExprNode

func (e *KeyValueLit) ExprNode()

func (*KeyValueLit) Pos

func (e *KeyValueLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*KeyValueLit) String

func (e *KeyValueLit) String() string

func (*KeyValueLit) WriteCode

func (e *KeyValueLit) WriteCode(ctx *CodeWriteContext)

type KeyValuePairLit

type KeyValuePairLit struct {
	Key   Expr
	Value Expr
}

KeyValuePairLit represents a key value pair element.

func KVp

func KVp(key Expr, value ...Expr) *KeyValuePairLit

func (*KeyValuePairLit) End

func (e *KeyValuePairLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*KeyValuePairLit) ExprNode

func (e *KeyValuePairLit) ExprNode()

func (*KeyValuePairLit) Pos

func (e *KeyValuePairLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*KeyValuePairLit) String

func (e *KeyValuePairLit) String() string

func (*KeyValuePairLit) WriteCode

func (e *KeyValuePairLit) WriteCode(ctx *CodeWriteContext)

type KeyValueSepLit

type KeyValueSepLit struct {
	TokenPos source.Pos
}

KeyValueSepLit represents a key value separator in paren context

func (*KeyValueSepLit) End

func (e *KeyValueSepLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*KeyValueSepLit) ExprNode

func (e *KeyValueSepLit) ExprNode()

func (*KeyValueSepLit) Pos

func (e *KeyValueSepLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*KeyValueSepLit) String

func (e *KeyValueSepLit) String() string

func (*KeyValueSepLit) WriteCode

func (e *KeyValueSepLit) WriteCode(ctx *CodeWriteContext)

type MixedTextExpr

type MixedTextExpr struct {
	StartLit ast.Literal
	EndLit   ast.Literal
	Stmt     MixedTextStmt
}

func (*MixedTextExpr) End

func (e *MixedTextExpr) End() source.Pos

func (*MixedTextExpr) ExprNode

func (e *MixedTextExpr) ExprNode()

func (*MixedTextExpr) Pos

func (e *MixedTextExpr) Pos() source.Pos

func (*MixedTextExpr) String

func (e *MixedTextExpr) String() string

func (*MixedTextExpr) WriteCode

func (e *MixedTextExpr) WriteCode(ctx *CodeWriteContext)

type MixedTextStmt

type MixedTextStmt struct {
	Lit    ast.Literal
	Flags  MixedTextStmtFlag
	LParen source.Pos
	RParen source.Pos
}

MixedTextStmt represents an MixedTextStmt.

func SMixedText

func SMixedText(pos source.Pos, vlit string, flags ...MixedTextStmtFlag) *MixedTextStmt

func (*MixedTextStmt) End

func (s *MixedTextStmt) End() source.Pos

func (*MixedTextStmt) ExprNode

func (s *MixedTextStmt) ExprNode()

func (*MixedTextStmt) Pos

func (s *MixedTextStmt) Pos() source.Pos

func (*MixedTextStmt) StmtNode

func (s *MixedTextStmt) StmtNode()

func (*MixedTextStmt) String

func (s *MixedTextStmt) String() string

func (*MixedTextStmt) TrimLinePrefix

func (s *MixedTextStmt) TrimLinePrefix(prefix string)

func (*MixedTextStmt) ValidLit

func (s *MixedTextStmt) ValidLit() ast.Literal

func (*MixedTextStmt) Value

func (s *MixedTextStmt) Value() string

func (*MixedTextStmt) WriteCode

func (s *MixedTextStmt) WriteCode(ctx *CodeWriteContext)

type MixedTextStmtFlag

type MixedTextStmtFlag uint
const (
	RemoveLeftSpaces MixedTextStmtFlag = 1 << iota
	RemoveRightSpaces
)

func (MixedTextStmtFlag) Has

func (MixedTextStmtFlag) String

func (s MixedTextStmtFlag) String() string

type MixedValueStmt

type MixedValueStmt struct {
	Expr             Expr
	StartLit         ast.Literal
	EndLit           ast.Literal
	RemoveLeftSpace  bool
	RemoveRightSpace bool
	Eq               bool
}

MixedValueStmt represents to text wrapped expression.

func SMixedValue

func SMixedValue(start, end ast.Literal, expr Expr) *MixedValueStmt

func (*MixedValueStmt) End

func (s *MixedValueStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*MixedValueStmt) ExprNode

func (s *MixedValueStmt) ExprNode()

func (*MixedValueStmt) Pos

func (s *MixedValueStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*MixedValueStmt) StmtNode

func (s *MixedValueStmt) StmtNode()

func (*MixedValueStmt) String

func (s *MixedValueStmt) String() string

func (*MixedValueStmt) WriteCode

func (s *MixedValueStmt) WriteCode(ctx *CodeWriteContext)

type MultiParenExpr

type MultiParenExpr struct {
	Exprs  []Expr
	LParen source.Pos
	RParen source.Pos
}

MultiParenExpr represents a parenthesis wrapped expressions.

func (*MultiParenExpr) End

func (e *MultiParenExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*MultiParenExpr) ExprNode

func (e *MultiParenExpr) ExprNode()

func (*MultiParenExpr) Pos

func (e *MultiParenExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*MultiParenExpr) Split

func (e *MultiParenExpr) Split() (left []Expr, right []Expr)

func (*MultiParenExpr) String

func (e *MultiParenExpr) String() string

func (*MultiParenExpr) ToCallArgs

func (e *MultiParenExpr) ToCallArgs(strict bool) (args *CallArgs, err *NodeError)

func (*MultiParenExpr) ToFuncParams

func (e *MultiParenExpr) ToFuncParams() (params FuncParams, err *NodeError)

func (*MultiParenExpr) ToMultiParenExpr

func (e *MultiParenExpr) ToMultiParenExpr() *MultiParenExpr

func (*MultiParenExpr) WriteCode

func (e *MultiParenExpr) WriteCode(ctx *CodeWriteContext)

type NamedArgExpr

type NamedArgExpr struct {
	Lit   *StringLit
	Ident *IdentExpr
	Exp   Expr
}

func (*NamedArgExpr) Expr

func (e *NamedArgExpr) Expr() Expr

func (*NamedArgExpr) Name

func (e *NamedArgExpr) Name() string

func (*NamedArgExpr) String

func (e *NamedArgExpr) String() string

func (*NamedArgExpr) WriteCode

func (e *NamedArgExpr) WriteCode(ctx *CodeWriteContext)

type NamedArgVarLit

type NamedArgVarLit struct {
	TokenPos source.Pos
	Value    Expr
}

NamedArgVarLit represents an variadic of named argument.

func NamedArgVar

func NamedArgVar(pos source.Pos, value Expr) *NamedArgVarLit

func (*NamedArgVarLit) End

func (e *NamedArgVarLit) End() source.Pos

func (*NamedArgVarLit) ExprNode

func (e *NamedArgVarLit) ExprNode()

func (*NamedArgVarLit) Pos

func (e *NamedArgVarLit) Pos() source.Pos

func (*NamedArgVarLit) String

func (e *NamedArgVarLit) String() string

func (*NamedArgVarLit) WriteCode

func (e *NamedArgVarLit) WriteCode(ctx *CodeWriteContext)

type NamedArgsKeywordExpr

type NamedArgsKeywordExpr struct {
	TokenPos source.Pos
	Literal  string
}

func NamedArgsKW

func NamedArgsKW(pos source.Pos) *NamedArgsKeywordExpr

func (*NamedArgsKeywordExpr) End

func (c *NamedArgsKeywordExpr) End() source.Pos

func (*NamedArgsKeywordExpr) ExprNode

func (c *NamedArgsKeywordExpr) ExprNode()

func (*NamedArgsKeywordExpr) Pos

func (c *NamedArgsKeywordExpr) Pos() source.Pos

func (*NamedArgsKeywordExpr) String

func (c *NamedArgsKeywordExpr) String() string

func (*NamedArgsKeywordExpr) WriteCode

func (c *NamedArgsKeywordExpr) WriteCode(ctx *CodeWriteContext)

type NamedArgsList

type NamedArgsList struct {
	Var    *TypedIdentExpr
	Names  []*TypedIdentExpr
	Values []Expr
}

NamedArgsList represents a list of identifier with value pairs.

func NamedArgs

func NamedArgs(vari *TypedIdentExpr, names []*TypedIdentExpr, values []Expr) NamedArgsList

func (*NamedArgsList) Add

func (n *NamedArgsList) Add(name *TypedIdentExpr, value Expr) *NamedArgsList

func (*NamedArgsList) End

func (n *NamedArgsList) End() source.Pos

End returns the position of first character immediately after the node.

func (*NamedArgsList) NumFields

func (n *NamedArgsList) NumFields() int

NumFields returns the number of fields.

func (*NamedArgsList) Pos

func (n *NamedArgsList) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*NamedArgsList) String

func (n *NamedArgsList) String() string

type NamedParamSpec

type NamedParamSpec struct {
	Ident *TypedIdentExpr
	Value Expr
}

A NamedParamSpec node represents a named parameter declaration

func (*NamedParamSpec) End

func (s *NamedParamSpec) End() source.Pos

End returns the position of first character immediately after the spec.

func (*NamedParamSpec) Pos

func (s *NamedParamSpec) Pos() source.Pos

Pos returns the position of first character belonging to the spec.

func (*NamedParamSpec) String

func (s *NamedParamSpec) String() string

func (*NamedParamSpec) WriteCode

func (s *NamedParamSpec) WriteCode(ctx *CodeWriteContext)

type NilLit

type NilLit struct {
	TokenPos source.Pos
}

NilLit represents an nil literal.

func (*NilLit) End

func (e *NilLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*NilLit) ExprNode

func (e *NilLit) ExprNode()

func (*NilLit) Pos

func (e *NilLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*NilLit) String

func (e *NilLit) String() string

func (*NilLit) WriteCode

func (e *NilLit) WriteCode(ctx *CodeWriteContext)

type Node

type Node interface {
	ast.Node
	Coder
}

type NodeError

type NodeError struct {
	Node Node
	Err  string
}

func NewExpectedError

func NewExpectedError(got Node, expected ...Node) *NodeError

func NewUnExpectedError

func NewUnExpectedError(got Node) *NodeError

func (*NodeError) Error

func (e *NodeError) Error() string

func (*NodeError) Pos

func (e *NodeError) Pos() source.Pos

type NullishSelectorExpr

type NullishSelectorExpr struct {
	Expr Expr
	Sel  Expr
}

NullishSelectorExpr represents a selector expression.

func ENullish

func ENullish(
	sel,
	expr Expr,
) *NullishSelectorExpr

func (*NullishSelectorExpr) End

func (e *NullishSelectorExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*NullishSelectorExpr) ExprNode

func (e *NullishSelectorExpr) ExprNode()

func (*NullishSelectorExpr) Pos

func (e *NullishSelectorExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*NullishSelectorExpr) SelectorExpr

func (e *NullishSelectorExpr) SelectorExpr() Expr

func (*NullishSelectorExpr) String

func (e *NullishSelectorExpr) String() string

func (*NullishSelectorExpr) WriteCode

func (e *NullishSelectorExpr) WriteCode(ctx *CodeWriteContext)

type ParamSpec

type ParamSpec struct {
	Ident    *TypedIdentExpr
	Variadic bool
}

A ParamSpec node represents a parameter declaration

func (*ParamSpec) End

func (s *ParamSpec) End() source.Pos

End returns the position of first character immediately after the spec.

func (*ParamSpec) Pos

func (s *ParamSpec) Pos() source.Pos

Pos returns the position of first character belonging to the spec.

func (*ParamSpec) String

func (s *ParamSpec) String() string

func (*ParamSpec) WriteCode

func (s *ParamSpec) WriteCode(ctx *CodeWriteContext)

type ParenExpr

type ParenExpr struct {
	Expr   Expr
	LParen source.Pos
	RParen source.Pos
}

ParenExpr represents a parenthesis wrapped expression.

func EParen

func EParen(x Expr, lparen, rparen source.Pos) *ParenExpr

func (*ParenExpr) End

func (e *ParenExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*ParenExpr) ExprNode

func (e *ParenExpr) ExprNode()

func (*ParenExpr) Items

func (e *ParenExpr) Items() Exprs

func (*ParenExpr) Pos

func (e *ParenExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ParenExpr) String

func (e *ParenExpr) String() string

func (*ParenExpr) ToMultiParenExpr

func (e *ParenExpr) ToMultiParenExpr() *MultiParenExpr

func (*ParenExpr) WriteCode

func (e *ParenExpr) WriteCode(ctx *CodeWriteContext)

type RawHeredocLit

type RawHeredocLit struct {
	Literal    string
	LiteralPos source.Pos
}

func RawHeredoc

func RawHeredoc(value string, pos source.Pos) *RawHeredocLit

func (*RawHeredocLit) End

func (e *RawHeredocLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*RawHeredocLit) ExprNode

func (e *RawHeredocLit) ExprNode()

func (*RawHeredocLit) Pos

func (e *RawHeredocLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*RawHeredocLit) String

func (e *RawHeredocLit) String() string

func (*RawHeredocLit) Value

func (e *RawHeredocLit) Value() string

func (*RawHeredocLit) WriteCode

func (e *RawHeredocLit) WriteCode(ctx *CodeWriteContext)

type RawStringLit

type RawStringLit struct {
	Literal    string
	LiteralPos source.Pos
	Quoted     bool
}

func RawString

func RawString(value string, pos source.Pos) *RawStringLit

func (*RawStringLit) End

func (e *RawStringLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*RawStringLit) ExprNode

func (e *RawStringLit) ExprNode()

func (*RawStringLit) Pos

func (e *RawStringLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*RawStringLit) QuotedValue

func (e *RawStringLit) QuotedValue() string

func (*RawStringLit) String

func (e *RawStringLit) String() string

func (*RawStringLit) UnquotedValue

func (e *RawStringLit) UnquotedValue() string

func (*RawStringLit) WriteCode

func (e *RawStringLit) WriteCode(ctx *CodeWriteContext)

type Return

type Return struct {
	ReturnPos source.Pos
	Result    Expr
}

Return represents an return expression.

func (*Return) End

func (s *Return) End() source.Pos

End returns the position of first character immediately after the node.

func (*Return) Pos

func (s *Return) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*Return) String

func (s *Return) String() string

func (*Return) WriteCode

func (s *Return) WriteCode(ctx *CodeWriteContext)

type ReturnExpr

type ReturnExpr struct {
	Return
}

ReturnExpr represents an return expression.

func EReturnExpr

func EReturnExpr(pos source.Pos, result Expr) *ReturnExpr

func (*ReturnExpr) ExprNode

func (s *ReturnExpr) ExprNode()

type ReturnStmt

type ReturnStmt struct {
	Return
}

ReturnStmt represents a return statement.

func SReturn

func SReturn(pos source.Pos, result Expr) *ReturnStmt

func (*ReturnStmt) StmtNode

func (s *ReturnStmt) StmtNode()

func (*ReturnStmt) WriteCode

func (s *ReturnStmt) WriteCode(ctx *CodeWriteContext)

type SelectorExpr

type SelectorExpr struct {
	Expr Expr
	Sel  Expr
}

SelectorExpr represents a selector expression.

func ESelector

func ESelector(x, sel Expr) *SelectorExpr

func (*SelectorExpr) End

func (e *SelectorExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*SelectorExpr) ExprNode

func (e *SelectorExpr) ExprNode()

func (*SelectorExpr) Pos

func (e *SelectorExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*SelectorExpr) SelectorExpr

func (e *SelectorExpr) SelectorExpr() Expr

func (*SelectorExpr) String

func (e *SelectorExpr) String() string

func (*SelectorExpr) WriteCode

func (e *SelectorExpr) WriteCode(ctx *CodeWriteContext)

type SliceExpr

type SliceExpr struct {
	Expr   Expr
	LBrack source.Pos
	Low    Expr
	High   Expr
	RBrack source.Pos
}

SliceExpr represents a slice expression.

func ESlice

func ESlice(
	x, low, high Expr,
	lbrack, rbrack source.Pos,
) *SliceExpr

func (*SliceExpr) End

func (e *SliceExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*SliceExpr) ExprNode

func (e *SliceExpr) ExprNode()

func (*SliceExpr) Pos

func (e *SliceExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*SliceExpr) String

func (e *SliceExpr) String() string

func (*SliceExpr) WriteCode

func (e *SliceExpr) WriteCode(ctx *CodeWriteContext)

type Spec

type Spec interface {
	ast.Node
	Coder
	// contains filtered or unexported methods
}

Spec node represents a single (non-parenthesized) variable declaration. The Spec type stands for any of *ParamSpec or *ValueSpec.

func NewNamedParamSpec

func NewNamedParamSpec(ident *TypedIdentExpr, value Expr) Spec

func NewParamSpec

func NewParamSpec(variadic bool, ident *TypedIdentExpr) Spec

func NewValueSpec

func NewValueSpec(idents []*IdentExpr, values []Expr) Spec

type StdErrLit

type StdErrLit struct {
	TokenPos source.Pos
}

StdErrLit represents an STDERR literal.

func (*StdErrLit) End

func (e *StdErrLit) End() source.Pos

End StdErrLit the position of first character immediately after the node.

func (*StdErrLit) ExprNode

func (e *StdErrLit) ExprNode()

func (*StdErrLit) Pos

func (e *StdErrLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*StdErrLit) String

func (e *StdErrLit) String() string

func (*StdErrLit) WriteCode

func (e *StdErrLit) WriteCode(ctx *CodeWriteContext)

type StdInLit

type StdInLit struct {
	TokenPos source.Pos
}

StdInLit represents an STDIN literal.

func (*StdInLit) End

func (e *StdInLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*StdInLit) ExprNode

func (e *StdInLit) ExprNode()

func (*StdInLit) Pos

func (e *StdInLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*StdInLit) String

func (e *StdInLit) String() string

func (*StdInLit) WriteCode

func (e *StdInLit) WriteCode(ctx *CodeWriteContext)

type StdOutLit

type StdOutLit struct {
	TokenPos source.Pos
}

StdOutLit represents an STDOUT literal.

func (*StdOutLit) End

func (e *StdOutLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*StdOutLit) ExprNode

func (e *StdOutLit) ExprNode()

func (*StdOutLit) Pos

func (e *StdOutLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*StdOutLit) String

func (e *StdOutLit) String() string

func (*StdOutLit) WriteCode

func (e *StdOutLit) WriteCode(ctx *CodeWriteContext)

type Stmt

type Stmt interface {
	Node
	StmtNode()
}

Stmt represents a statement in the AST.

type Stmts

type Stmts []Stmt

func (*Stmts) Append

func (s *Stmts) Append(n ...Stmt)

func (Stmts) Each

func (s Stmts) Each(f func(i int, sep bool, s Stmt))

func (Stmts) Filter

func (s Stmts) Filter(f func(i int, s Stmt) bool) (l Stmts)

func (Stmts) Map

func (s Stmts) Map(f func(i int, s Stmt) Stmt) (l Stmts)

func (*Stmts) Prepend

func (s *Stmts) Prepend(n ...Stmt)

func (Stmts) String

func (s Stmts) String() string

func (Stmts) WriteCode

func (s Stmts) WriteCode(ctx *CodeWriteContext)

type StmtsExpr

type StmtsExpr struct {
	Stmts Stmts
}

func (*StmtsExpr) End

func (s *StmtsExpr) End() source.Pos

func (*StmtsExpr) ExprNode

func (s *StmtsExpr) ExprNode()

func (*StmtsExpr) Pos

func (s *StmtsExpr) Pos() source.Pos

func (*StmtsExpr) String

func (s *StmtsExpr) String() string

func (*StmtsExpr) WriteCode

func (s *StmtsExpr) WriteCode(ctx *CodeWriteContext)

type StringLit

type StringLit struct {
	ValuePos source.Pos
	Literal  string
}

StringLit represents a string literal.

func String

func String(value string, pos source.Pos) *StringLit

func (*StringLit) CanIdent

func (e *StringLit) CanIdent() bool

func (*StringLit) End

func (e *StringLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*StringLit) ExprNode

func (e *StringLit) ExprNode()

func (*StringLit) Pos

func (e *StringLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*StringLit) String

func (e *StringLit) String() string

func (*StringLit) Value

func (e *StringLit) Value() string

func (*StringLit) WriteCode

func (e *StringLit) WriteCode(ctx *CodeWriteContext)

type TemplateLit

type TemplateLit struct {
	TokenPos source.Pos
	Value    Expr
}

TemplateLit represents an variadic of argument.

func (*TemplateLit) End

func (e *TemplateLit) End() source.Pos

func (*TemplateLit) ExprNode

func (e *TemplateLit) ExprNode()

func (*TemplateLit) Pos

func (e *TemplateLit) Pos() source.Pos

func (*TemplateLit) String

func (e *TemplateLit) String() string

func (*TemplateLit) WriteCode

func (e *TemplateLit) WriteCode(ctx *CodeWriteContext)

type ThrowExpr

type ThrowExpr struct {
	ThrowPos source.Pos
	Expr     Expr
}

ThrowExpr represents an throw expression.

func (*ThrowExpr) End

func (s *ThrowExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*ThrowExpr) ExprNode

func (s *ThrowExpr) ExprNode()

func (*ThrowExpr) Pos

func (s *ThrowExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ThrowExpr) String

func (s *ThrowExpr) String() string

func (*ThrowExpr) WriteCode

func (s *ThrowExpr) WriteCode(ctx *CodeWriteContext)

type ThrowStmt

type ThrowStmt struct {
	ThrowPos source.Pos
	Expr     Expr
}

ThrowStmt represents an throw statement.

func SThrow

func SThrow(
	throwPos source.Pos,
	expr Expr,
) *ThrowStmt

func (*ThrowStmt) End

func (s *ThrowStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*ThrowStmt) Pos

func (s *ThrowStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*ThrowStmt) StmtNode

func (s *ThrowStmt) StmtNode()

func (*ThrowStmt) String

func (s *ThrowStmt) String() string

func (*ThrowStmt) WriteCode

func (s *ThrowStmt) WriteCode(ctx *CodeWriteContext)

type ToMultiParenConverter

type ToMultiParenConverter interface {
	Expr
	ToMultiParenExpr() *MultiParenExpr
}

type TranspileOptions

type TranspileOptions struct {
	RawStrFuncStart string
	RawStrFuncEnd   string
	WriteFunc       string
}

type TryStmt

type TryStmt struct {
	TryPos  source.Pos
	Body    *BlockStmt
	Catch   *CatchStmt   // catch branch; or nil
	Finally *FinallyStmt // finally branch; or nil
}

TryStmt represents an try statement.

func STry

func STry(
	tryPos source.Pos,
	body *BlockStmt,
	catch *CatchStmt,
	finally *FinallyStmt,
) *TryStmt

func (*TryStmt) End

func (s *TryStmt) End() source.Pos

End returns the position of first character immediately after the node.

func (*TryStmt) Pos

func (s *TryStmt) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*TryStmt) StmtNode

func (s *TryStmt) StmtNode()

func (*TryStmt) String

func (s *TryStmt) String() string

func (*TryStmt) WriteCode

func (s *TryStmt) WriteCode(ctx *CodeWriteContext)

type TypedIdentExpr

type TypedIdentExpr struct {
	Ident *IdentExpr
	Type  []*IdentExpr
}

func ETypedIdent

func ETypedIdent(ident *IdentExpr, typ ...*IdentExpr) *TypedIdentExpr

func (*TypedIdentExpr) End

func (e *TypedIdentExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*TypedIdentExpr) ExprNode

func (e *TypedIdentExpr) ExprNode()

func (*TypedIdentExpr) Pos

func (e *TypedIdentExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*TypedIdentExpr) String

func (e *TypedIdentExpr) String() string

func (*TypedIdentExpr) WriteCode

func (e *TypedIdentExpr) WriteCode(ctx *CodeWriteContext)

type UintLit

type UintLit struct {
	Value    uint64
	ValuePos source.Pos
	Literal  string
}

UintLit represents an unsigned integer literal.

func (*UintLit) End

func (e *UintLit) End() source.Pos

End returns the position of first character immediately after the node.

func (*UintLit) ExprNode

func (e *UintLit) ExprNode()

func (*UintLit) Pos

func (e *UintLit) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*UintLit) String

func (e *UintLit) String() string

func (*UintLit) WriteCode

func (e *UintLit) WriteCode(ctx *CodeWriteContext)

type UnaryExpr

type UnaryExpr struct {
	Expr     Expr
	Token    token.Token
	TokenPos source.Pos
}

UnaryExpr represents an unary operator expression.

func EUnary

func EUnary(x Expr, op token.Token, pos source.Pos) *UnaryExpr

func (*UnaryExpr) End

func (e *UnaryExpr) End() source.Pos

End returns the position of first character immediately after the node.

func (*UnaryExpr) ExprNode

func (e *UnaryExpr) ExprNode()

func (*UnaryExpr) Pos

func (e *UnaryExpr) Pos() source.Pos

Pos returns the position of first character belonging to the node.

func (*UnaryExpr) String

func (e *UnaryExpr) String() string

func (*UnaryExpr) WriteCode

func (e *UnaryExpr) WriteCode(ctx *CodeWriteContext)

type ValueSpec

type ValueSpec struct {
	Idents []*IdentExpr // TODO: slice is reserved for tuple assignment
	Values []Expr       // initial values; or nil
	Data   any          // iota
}

A ValueSpec node represents a variable declaration

func (*ValueSpec) End

func (s *ValueSpec) End() source.Pos

End returns the position of first character immediately after the spec.

func (*ValueSpec) Pos

func (s *ValueSpec) Pos() source.Pos

Pos returns the position of first character belonging to the spec.

func (*ValueSpec) String

func (s *ValueSpec) String() string

func (*ValueSpec) WriteCode

func (s *ValueSpec) WriteCode(ctx *CodeWriteContext)

Jump to

Keyboard shortcuts

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