Documentation
¶
Index ¶
- Constants
- func ConvNumber(s string, integer, float bool) (valid, iok bool, i int64, f float64)
- func Inspect(node Node, f func(Node) bool)
- func Walk(v Visitor, n Node)
- type Assign
- type ConstBool
- type ConstFloat
- type ConstIdent
- type ConstInt
- type ConstNil
- type ConstString
- type ConstVariadic
- type DoBlock
- type Expr
- type ForLoopGeneric
- type ForLoopNumeric
- type FuncCall
- type FuncDecl
- type Goto
- type If
- type Label
- type Node
- type Operator
- type Parens
- type RepeatUntilLoop
- type Return
- type Stmt
- type TableAccessor
- type TableConstructor
- type Visitor
- type WhileLoop
Constants ¶
const ( OpAdd opTyp = iota OpSub OpMul OpMod OpPow OpDiv OpIDiv OpBinAND OpBinOR OpBinXOR OpBinShiftL OpBinShiftR OpUMinus OpBinNot OpNot OpLength OpConcat OpEqual OpNotEqual OpLessThan OpGreaterThan OpLessOrEqual OpGreaterOrEqual OpAnd OpOr )
Operator type for use with the Operator Expr Node.
Variables ¶
This section is empty.
Functions ¶
func ConvNumber ¶
ConvNumber converts a string to a number. This is intended for internal use by various Lua related packages, you should not use this unless you know what you are doing.
func Inspect ¶
Inspect is exactly like Walk, except f is called for each node only if a call to f returns true for that node's parent (f is always called for the root node).
func Walk ¶
Walk traverses the given AST node and it's children in depth-first order. For each node it calls the visitor for that level and then uses the returned visitor for the child nodes (if any). If the visitor for a given node returns nil that node's children will not be visited. Once all of a node's children are visited the visitor for that level is called one final time with nil as its argument.
Types ¶
type Assign ¶
type Assign struct {
// Is this a local variable declaration statement?
LocalDecl bool
// Special case handling for "local function f() end", this should be treated like "local f; f = function() end".
LocalFunc bool
Targets []Expr
Values []Expr // If len == 0 no values were given, if len == 1 then the value may be a multi-return function call.
// contains filtered or unexported fields
}
Assign represents an assignment statement.
type ConstBool ¶
type ConstBool struct {
Value bool
// contains filtered or unexported fields
}
ConstBool represents a boolean constant.
type ConstFloat ¶
type ConstFloat struct {
Value string
// contains filtered or unexported fields
}
ConstFloat stores a floating point constant.
type ConstIdent ¶
type ConstIdent struct {
Value string
// contains filtered or unexported fields
}
ConstIdent stores an identifier constant.
type ConstInt ¶
type ConstInt struct {
Value string
// contains filtered or unexported fields
}
ConstInt stores an integer constant.
type ConstNil ¶
type ConstNil struct {
// contains filtered or unexported fields
}
ConstNil represents the constant "nil".
type ConstString ¶
type ConstString struct {
Value string
// contains filtered or unexported fields
}
ConstString stores a string constant.
type ConstVariadic ¶
type ConstVariadic struct {
// contains filtered or unexported fields
}
ConstVariadic represents the variadic expression element (...).
type DoBlock ¶
type DoBlock struct {
Block []Stmt
// contains filtered or unexported fields
}
DoBlock represents a do block (do ... end).
type Expr ¶
type Expr interface {
Node
// contains filtered or unexported methods
}
Expr represents an expression element Node.
type ForLoopGeneric ¶
type ForLoopGeneric struct {
Locals []string
Init []Expr // This will always be adjusted to three return results, but AFAIK there is no actual limit on expression count.
Block []Stmt
// contains filtered or unexported fields
}
ForLoopGeneric represents a generic for loop.
type ForLoopNumeric ¶
type ForLoopNumeric struct {
Counter string
Init Expr
Limit Expr
Step Expr
Block []Stmt
// contains filtered or unexported fields
}
ForLoopNumeric represents a numeric for loop.
type FuncCall ¶
type FuncCall struct {
Receiver Expr // The call receiver if any (the part before the ':')
Function Expr // The function value itself, if Receiver is provided this is the part *after* the colon, else it is the whole name.
Args []Expr
// contains filtered or unexported fields
}
FuncCall represents a function call. This has the unique property of being both a Stmt and an Expr.
type FuncDecl ¶
type FuncDecl struct {
Params []string
IsVariadic bool
Source string
Block []Stmt
// contains filtered or unexported fields
}
FuncDecl represents a function declaration.
type Goto ¶
type Goto struct {
// True if this Goto is actually a break statement. There is no matching label.
// If Label is not "break" then this is actually a continue statement (a custom
// extension that the default lexer/parser does not use).
IsBreak bool
Label string
// contains filtered or unexported fields
}
type Node ¶
type Node interface {
Line() int
// contains filtered or unexported methods
}
Node represents an item in the AST.
type Operator ¶
type Operator struct {
Op opTyp
Left Expr // Nil if operator is unary
Right Expr
// contains filtered or unexported fields
}
Operator represents an operator and it's operands.
type Parens ¶
type Parens struct {
Inner Expr
// contains filtered or unexported fields
}
Parens represents a pair of parenthesis and the expression inside of them.
type RepeatUntilLoop ¶
RepeatUntilLoop represents a repeat-until loop.
type Stmt ¶
type Stmt interface {
Node
// contains filtered or unexported methods
}
Stmt represents a statement Node.
type TableAccessor ¶
TableAccessor represents a table access expression, one of `a.b` or `a[b]`.
type TableConstructor ¶
type TableConstructor struct {
Keys []Expr // A nil key for a particular position means that no key was given.
Vals []Expr
// contains filtered or unexported fields
}
TableConstructor represents a table constructor.
type Visitor ¶
Visitor is used with Walk.
func NewVisitor ¶
NewVisitor takes a simple function and turns it into a basic Visitor, ready to use with Walk.