Documentation ¶
Index ¶
- func IsNumber(e ExpNode) bool
- type AssignStat
- type BFunctionCall
- type BinOp
- type BlockStat
- type Bool
- type BreakStat
- type CondStat
- type EmptyStat
- type Etc
- type ExpNode
- type ExpProcessor
- type Float
- type ForInStat
- type ForStat
- type Function
- type FunctionCall
- type GotoStat
- type HWriter
- type IfStat
- type IndentWriter
- type IndexExp
- type Int
- type LabelStat
- type LocalAttrib
- type LocalFunctionStat
- type LocalStat
- type Location
- type Locator
- type Name
- type NameAttrib
- type Nil
- type NoTableKey
- type Node
- type Operation
- type ParList
- type RepeatStat
- type Stat
- type StatProcessor
- type String
- type TableConstructor
- type TableField
- type TailExpNode
- type TailExpProcessor
- type UnOp
- type Var
- type VarProcessor
- type WhileStat
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AssignStat ¶
AssignStat represents an assignment var1, ..., varN = src1, ..., srcM.
M and N do not have to be the same
func NewAssignStat ¶
func NewAssignStat(dst []Var, src []ExpNode) AssignStat
NewAssignStat makes a new AssignStat.
func NewFunctionStat ¶
func NewFunctionStat(fName Var, method Name, fx Function) AssignStat
NewFunctionStat returns an AssgnStat, ie. "function f() ..." gets transformed to "f = function() ...". This is a shortcut, probably should make a specific node for this.
func (AssignStat) HWrite ¶
func (s AssignStat) HWrite(w HWriter)
HWrite prints the AST in tree form.
func (AssignStat) ProcessStat ¶
func (s AssignStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type BFunctionCall ¶
A BFunctionCall is an expression node that represents a function call surrounded by brackets. This changes the semantics of the call in some situations (e.g. ellipsis, tail calls).
For example:
return f(x) -- this may return multiple values and will be subject to TCO return (f(x)) -- this will only return one single value and will not be subject to TCO
func (BFunctionCall) HWrite ¶
func (f BFunctionCall) HWrite(w HWriter)
HWrite prints a tree representation of the node.
func (BFunctionCall) ProcessExp ¶
func (f BFunctionCall) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
type BinOp ¶
A BinOp is a expression node that represents any binary operator. The right hand side can be a list of operations of the same type (OpType). All operations of the same type have the same precedence and can be merged into a list.
func NewBinOp ¶
NewBinOp creates a new BinOp from the given arguments. If the left node is already a BinOp node with the same operator type, a new node based on that will be created.
func (BinOp) ProcessExp ¶
func (b BinOp) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
type BlockStat ¶
A BlockStat is a statement node that represents a block of statements, optionally ending in a return statement (if Return is not a nil slice - note that a bare return is encoded as a non-nil slice of length 0).
func NewBlockStat ¶
NewBlockStat returns a BlockStat instance conatining the given stats and return statement.
func (BlockStat) ProcessStat ¶
func (s BlockStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type Bool ¶
Bool is an expression node representing a boolean literal.
func (Bool) ProcessExp ¶
func (b Bool) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
type BreakStat ¶
type BreakStat struct {
Location
}
BreakStat is a statement node representing the "break" statement.
func NewBreakStat ¶
NewBreakStat returns a BreakStat instance (the token is needed to record the location of the statement).
func (BreakStat) ProcessStat ¶
func (s BreakStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type CondStat ¶
CondStat is a conditional statement, used in e.g. if statements and while / repeat until loops.
type EmptyStat ¶
type EmptyStat struct {
Location
}
EmptyStat is a statement expression containing an empty statement.
func NewEmptyStat ¶
NewEmptyStat returns an EmptyStat instance (located from the given token).
func (EmptyStat) ProcessStat ¶
func (s EmptyStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type Etc ¶
type Etc struct {
Location
}
Etc is the "..." expression node (ellipsis).
func (Etc) ProcessExp ¶
func (e Etc) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
func (Etc) ProcessTailExp ¶
func (e Etc) ProcessTailExp(p TailExpProcessor)
ProcessTailExp uses the given TailExpProcessor to process the reveiver.
type ExpProcessor ¶
type ExpProcessor interface { ProcessBFunctionCallExp(BFunctionCall) ProcessBinOpExp(BinOp) ProcesBoolExp(Bool) ProcessEtcExp(Etc) ProcessFunctionExp(Function) ProcessFunctionCallExp(FunctionCall) ProcessIndexExp(IndexExp) ProcessNameExp(Name) ProcessNilExp(Nil) ProcessIntExp(Int) ProcessFloatExp(Float) ProcessStringExp(String) ProcessTableConstructorExp(TableConstructor) ProcessUnOpExp(UnOp) }
An ExpProcessor can process all implementations of ExpNode (i.e. expressions)
type Float ¶
Float is an expression node representing a floating point numeric literal.
func (Float) ProcessExp ¶
func (f Float) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
type ForInStat ¶
ForInStat is a statement node representing the "for Vars in Params do Body end" statement.
func NewForInStat ¶
func NewForInStat(startTok, endTok *token.Token, itervars []Name, params []ExpNode, body BlockStat) *ForInStat
NewForInStat returns a ForInStat instance from the given parts.
func (ForInStat) ProcessStat ¶
func (s ForInStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type ForStat ¶
ForStat represents the statement node "for Var = Start, Stop, Step do Body end".
func NewForStat ¶
func NewForStat(startTok, endTok *token.Token, itervar Name, params []ExpNode, body BlockStat) *ForStat
NewForStat returns a ForStat from the given parts.
func (ForStat) ProcessStat ¶
func (s ForStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type Function ¶
A Function is an expression node representing a function definition, i.e. "function Name(ParList) do Body end". The Name is optional.
func NewFunction ¶
NewFunction returns a Function instance built from the given arguments.
func (Function) ProcessExp ¶
func (f Function) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
type FunctionCall ¶
type FunctionCall struct {
*BFunctionCall
}
A FunctionCall is an expression node that represents a function call.
func NewFunctionCall ¶
func NewFunctionCall(target ExpNode, method Name, args []ExpNode) FunctionCall
NewFunctionCall returns a FunctionCall instance representing the call of <target> with <args>. The <method> arg should be non-nil if the call syntax included ":", e.g. stack:pop().
func (FunctionCall) InBrackets ¶
func (f FunctionCall) InBrackets() *BFunctionCall
InBrackets turns the receiver into a BFunctionCall.
func (FunctionCall) ProcessExp ¶
func (f FunctionCall) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
func (FunctionCall) ProcessStat ¶
func (f FunctionCall) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
func (FunctionCall) ProcessTailExp ¶
func (f FunctionCall) ProcessTailExp(p TailExpProcessor)
ProcessTailExp uses the give TailExpProcessor to process the receiver.
type GotoStat ¶
GotoStat is a statement node representing a goto statement.
func NewGotoStat ¶
NewGotoStat returns a GotoStat instance with the given label.
func (GotoStat) ProcessStat ¶
func (s GotoStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type HWriter ¶
type HWriter interface { Writef(string, ...interface{}) Indent() Dedent() Next() }
HWriter is an interface for printing nodes
type IfStat ¶
IfStat is a statement node representing an "if ... [elseif] ... [else] ... end" statement, where the else clause is optional and there can be 0 or more elseif clauses.
func (IfStat) AddElseIf ¶
AddElseIf returns an IfStat based on the receiver but adding an extra elseif clause.
func (IfStat) ProcessStat ¶
func (s IfStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type IndentWriter ¶
type IndentWriter struct {
// contains filtered or unexported fields
}
IndentWriter is an implementation of HWriter that writes AST with indentation to show the tree structure.
func NewIndentWriter ¶
func NewIndentWriter(w io.Writer) *IndentWriter
NewIndentWriter returns a new pointer to IndentWriter that will write using the given io.Writer.
func (*IndentWriter) Dedent ¶
func (w *IndentWriter) Dedent()
Dedent decrements the current indentation by one level.
func (*IndentWriter) Indent ¶
func (w *IndentWriter) Indent()
Indent increments the current indentation by one level.
func (*IndentWriter) Next ¶
func (w *IndentWriter) Next()
Next moves on to the next line and adds the necessary indentation.
func (*IndentWriter) Writef ¶
func (w *IndentWriter) Writef(f string, args ...interface{})
Writef is like Printf.
type IndexExp ¶
An IndexExp is an expression node representing indexing, i.e. "Coll[Index]".
func NewIndexExp ¶
NewIndexExp returns an IndexExp instance for the given collection and index.
func (IndexExp) FunctionName ¶
FunctionName returns the function name associated with this expression (i.e. if it is part of a function definition statement), or an empty string if there is no sensible name.
func (IndexExp) ProcessExp ¶
func (e IndexExp) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
func (IndexExp) ProcessVar ¶
func (e IndexExp) ProcessVar(p VarProcessor)
ProcessVar uses the given VarProcessor to process the receiver.
type Int ¶
Int is an expression node representing a non-negative integer literal.
func (Int) ProcessExp ¶
func (n Int) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
type LabelStat ¶
LabelStat is a statement node that represents a label.
func NewLabelStat ¶
NewLabelStat returns a LabelStat instance for the given label.
func (LabelStat) ProcessStat ¶
func (s LabelStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type LocalAttrib ¶
type LocalAttrib uint8
LocalAttrib is the type of a local name attrib
const ( NoAttrib LocalAttrib = iota ConstAttrib // <const>, introduced in Lua 5.4 CloseAttrib // <close>, introduced in Lua 5.4 )
Valid values for LocalAttrib
type LocalFunctionStat ¶
LocalFunctionStat is a statement node that represents a local function definition, i.e. "local function Name() ...".
func NewLocalFunctionStat ¶
func NewLocalFunctionStat(name Name, fx Function) LocalFunctionStat
NewLocalFunctionStat returns a LocalFunctionStat instance for the given name and function definition.
func (LocalFunctionStat) HWrite ¶
func (s LocalFunctionStat) HWrite(w HWriter)
HWrite prints a tree representation of the node.
func (LocalFunctionStat) ProcessStat ¶
func (s LocalFunctionStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type LocalStat ¶
type LocalStat struct { Location NameAttribs []NameAttrib Values []ExpNode }
LocalStat is a statement node representing the declaration / definition of a list of local variables.
func NewLocalStat ¶
func NewLocalStat(nameAttribs []NameAttrib, values []ExpNode) LocalStat
NewLocalStat returns a LocalStat instance defining the given names with the given values.
func (LocalStat) ProcessStat ¶
func (s LocalStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type Location ¶
type Location struct {
// contains filtered or unexported fields
}
A Location is a span between two token in the source code.
func LocFromToken ¶
LocFromToken returns a location that starts and ends at the token's position.
func LocFromTokens ¶
LocFromTokens returns a location that starts at t1 and ends at t2 (t1 and t2 may be nil).
func MergeLocations ¶
MergeLocations takes two locators and merges them into one Location, starting at the earliest start and ending at the latest end.
type Locator ¶
type Locator interface {
Locate() Location
}
Locator can provide a location in code. All AST nodes are locators.
type Name ¶
Name is an expression token representing a name (identifier).
func (Name) AstString ¶
AstString returns a String with the same value and location as the receiver.
func (Name) FunctionName ¶
FunctionName returns the string associated with the name.
func (Name) ProcessExp ¶
func (n Name) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
func (Name) ProcessVar ¶
func (n Name) ProcessVar(p VarProcessor)
ProcessVar process the receiver using the given VarProcessor.
type NameAttrib ¶
type NameAttrib struct { Location Name Name Attrib LocalAttrib }
A NameAttrib is a name introduce by a local definition, together with an optional attribute (in Lua 5.4 that is 'close' or 'const').
func NewNameAttrib ¶
func NewNameAttrib(name Name, attribName *Name, attrib LocalAttrib) NameAttrib
NewNameAttrib returns a new NameAttribe for the given name and attrib.
type Nil ¶
type Nil struct {
Location
}
Nil is an expression node representing "nil".
func (Nil) ProcessExp ¶
func (n Nil) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
type NoTableKey ¶
type NoTableKey struct {
Location
}
NoTableKey is a special expression node that can only be used as the Key of a TableField, meaning a field with no key.
func (NoTableKey) HWrite ¶
func (k NoTableKey) HWrite(w HWriter)
HWrite prints a tree representation of the node.
func (NoTableKey) ProcessExp ¶
func (k NoTableKey) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver. It panics as this type is a placeholder that should not be processed as an expression.
type Operation ¶
An Operation is a pair (operator, operand) which can be applied to an expression node (e.g. "+ 2" or "/ 5").
type ParList ¶
A ParList represents a function parameter list (it is not a node).
func NewParList ¶
NewParList returns ParList instance for the given parameters.
type RepeatStat ¶
RepeatStat ia a statement expression that represents a repeat / until statement.
func NewRepeatStat ¶
func NewRepeatStat(repTok *token.Token, body BlockStat, cond ExpNode) RepeatStat
NewRepeatStat returns a RepeatStat instance representing the statement "repeat <body> until <cond>".
func (RepeatStat) HWrite ¶
func (s RepeatStat) HWrite(w HWriter)
HWrite prints a tree representation of the node.
func (RepeatStat) ProcessStat ¶
func (s RepeatStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
type StatProcessor ¶
type StatProcessor interface { ProcessAssignStat(AssignStat) ProcessBlockStat(BlockStat) ProcessBreakStat(BreakStat) ProcessEmptyStat(EmptyStat) ProcessForInStat(ForInStat) ProcessForStat(ForStat) ProcessFunctionCallStat(FunctionCall) ProcessGotoStat(GotoStat) ProcessIfStat(IfStat) ProcessLabelStat(LabelStat) ProcessLocalFunctionStat(LocalFunctionStat) ProcessLocalStat(LocalStat) ProcessRepeatStat(RepeatStat) ProcessWhileStat(WhileStat) }
A StatProcessor can process all implementations of Stat (i.e. statements).
type String ¶
String is a string literal.
func NewLongString ¶
NewLongString returns a String computed from a token containing a Lua long string.
func NewString ¶
NewString returns a String from a token containing a Lua short string literal, or an error if it couln't (although perhaps it should panic instead? Parsing should ensure well-formed string token).
func (String) ProcessExp ¶
func (s String) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
type TableConstructor ¶
type TableConstructor struct { Location Fields []TableField }
A TableConstructor is an expression node representing a table literal, e.g.
{ "hello", 4.5, x = 2, [z] = true }
func NewTableConstructor ¶
func NewTableConstructor(opTok, clTok *token.Token, fields []TableField) TableConstructor
NewTableConstructor returns a TableConstructor instance with the given fields.
func (TableConstructor) HWrite ¶
func (c TableConstructor) HWrite(w HWriter)
HWrite prints a tree representation of the node.
func (TableConstructor) ProcessExp ¶
func (c TableConstructor) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
type TableField ¶
A TableField is a (key, value ) pair of expression nodes representing a field in a table literal. There is a special key type called "NoTableKey" for fields that do not have a key.
func NewTableField ¶
func NewTableField(key ExpNode, value ExpNode) TableField
type TailExpNode ¶
type TailExpNode interface { Node ProcessTailExp(TailExpProcessor) }
TailExpNode is an expression which can be the tail of an exp list
type TailExpProcessor ¶
type TailExpProcessor interface { ProcessEtcTailExp(Etc) ProcessFunctionCallTailExp(FunctionCall) }
A TailExpProcessor can process all implementations fo TailExpNode.
type UnOp ¶
An UnOp is an expression node representing the application of a unary operation on an expression.
func (UnOp) ProcessExp ¶
func (u UnOp) ProcessExp(p ExpProcessor)
ProcessExp uses the given ExpProcessor to process the receiver.
type Var ¶
type Var interface { ExpNode FunctionName() string ProcessVar(VarProcessor) }
Var is an l-value, i.e. it can be assigned to.
type VarProcessor ¶
A VarProcessor can process all types of l-values.
type WhileStat ¶
WhileStat represents a while / end statement
func NewWhileStat ¶
NewWhileStat returns a WhileStat instance representing the statement "while <cond> do <body> done".
func (WhileStat) ProcessStat ¶
func (s WhileStat) ProcessStat(p StatProcessor)
ProcessStat uses the given StatProcessor to process the receiver.
Source Files ¶
- assignstat.go
- binopexp.go
- blockstat.go
- bool.go
- breakstat.go
- condstat.go
- emptystat.go
- etc.go
- forinstat.go
- forstat.go
- function.go
- functioncall.go
- functionstat.go
- gotostat.go
- ifstat.go
- indentwriter.go
- indexexp.go
- interfaces.go
- labelstat.go
- localfunctionstat.go
- localstat.go
- location.go
- name.go
- nil.go
- number.go
- repeatstat.go
- string.go
- tableconstructor.go
- unopexp.go
- whilestat.go