Documentation ¶
Index ¶
- Constants
- type Assign
- type BinaryOp
- type Block
- type Break
- type Case
- type Code
- type Const
- type Continue
- type Dec
- type Default
- type Expression
- type Fallthrough
- type File
- type Float
- type For
- type Foreach
- type Function
- type FunctionCall
- type GlobalContext
- type Goto
- type If
- type Inc
- type Negation
- type Node
- type Number
- type Return
- type Str
- type Switch
- type Typ
- type UnaryMinus
- type VarDef
- type VarRef
- type Variable
Constants ¶
const ( Void = "" Int = "int" String = "string" Float64 = "float64" Bool = "bool" Anything = "interface{}" Writer = "io.Writer" SQL = "std.SQL" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assign ¶
type Assign struct { Right *Expression FirstDefinition bool // contains filtered or unexported fields }
type BinaryOp ¶
type BinaryOp struct { Operation string // contains filtered or unexported fields }
func NewBinaryOp ¶
func NewBinaryOp(op string, left, right Expression) (*BinaryOp, error)
func (BinaryOp) OperatorPrecedence ¶
type Block ¶
type Block interface { Node AddStatement(Node) DefineVariable(*Variable) // HasVariable tries to find a variable definition // at any cost, even searching out of scope. It is // bounded to the DefinesVariable, this function // does the out of scope search, HasVariable changes // the definition so it can be used in Go. HasVariable(string, bool) *Variable // contains filtered or unexported methods }
Block is the second most common type found in the AST. It can contain nodes, and has own symbol table, in my case it is just an array of defined variables.
type Case ¶
type Case struct { Block *Code Condition Expression // contains filtered or unexported fields }
func (Case) AddStatement ¶
func (Case) DefineVariable ¶
type Dec ¶
type Dec struct {
// contains filtered or unexported fields
}
func NewDec ¶
func NewDec(parent Node, v *VarRef, strV func(Expression) (Expression, error)) *Dec
type Default ¶
type Default struct { Block *Code // contains filtered or unexported fields }
func NewDefault ¶
func (Default) AddStatement ¶
func (Default) DefineVariable ¶
type Expression ¶
Expression the the most common type here. It represents everything, which can return value. In the hielarchy it is on the same level as Block, just another Node representation. But this one returns value, thanks to that it can be used in the arithmetic operations and so on.
type Fallthrough ¶
type Fallthrough struct {
// contains filtered or unexported fields
}
func (Fallthrough) Parent ¶
func (c Fallthrough) Parent() Node
func (*Fallthrough) SetParent ¶
func (c *Fallthrough) SetParent(n Node)
func (Fallthrough) String ¶
func (c Fallthrough) String() string
type File ¶
type File struct { Name string Funcs map[string]*Function Main *Function // contains filtered or unexported fields }
func (*File) DefineVariable ¶
type Float ¶
type Float struct { Value string // contains filtered or unexported fields }
Float and Number can be merged, only Type is different. There is no way how can I write down 0.0 as some nice string for := operator.
type For ¶
type For struct { Vars []*Variable Init Node Loop Node Block *Code Labels []Const // contains filtered or unexported fields }
func (*For) AddStatement ¶
func (*For) DefineVariable ¶
func (*For) SetCond ¶
func (f *For) SetCond(e Expression) error
type Foreach ¶
type Foreach struct { Iterated Expression Key *Variable Value Variable Block *Code Labels []Const // contains filtered or unexported fields }
TODO: This does not work as it should, that variable assignment is done just by a simple string, I do not care if these values are used later on. This makes sense if I want to use this structure for other languages, too. Range is fairly specific.
func NewForeach ¶
func (*Foreach) AddStatement ¶
func (*Foreach) DefineVariable ¶
type Function ¶
type Function struct { Args []*Variable VariadicCount bool Body Code NeedsGlobal bool Name string Return Typ // contains filtered or unexported fields }
func (*Function) AddStatement ¶
func (*Function) DefineVariable ¶
type FunctionCall ¶
type FunctionCall struct { Func *Function Name string Args []Expression Return Typ // contains filtered or unexported fields }
func (*FunctionCall) AddArg ¶
func (f *FunctionCall) AddArg(e Expression)
func (FunctionCall) Parent ¶
func (f FunctionCall) Parent() Node
func (*FunctionCall) SetParent ¶
func (f *FunctionCall) SetParent(n Node)
func (*FunctionCall) String ¶
func (f *FunctionCall) String() string
func (FunctionCall) Type ¶
func (f FunctionCall) Type() Typ
type GlobalContext ¶
func NewGlobalContext ¶
func NewGlobalContext() *GlobalContext
func (*GlobalContext) Add ¶
func (gc *GlobalContext) Add(f *File)
func (*GlobalContext) DefineVariable ¶
func (gc *GlobalContext) DefineVariable(v *Variable)
func (*GlobalContext) HasVariable ¶
func (gc *GlobalContext) HasVariable(name string, oos bool) *Variable
func (GlobalContext) String ¶
func (gc GlobalContext) String() string
type If ¶
type If struct { Vars []*Variable Init Node True *Code False Block // contains filtered or unexported fields }
func (*If) AddStatement ¶
func (*If) DefineVariable ¶
func (*If) SetCond ¶
func (i *If) SetCond(e Expression) error
type Inc ¶
type Inc struct {
// contains filtered or unexported fields
}
func NewInc ¶
func NewInc(parent Node, v *VarRef, strV func(Expression) (Expression, error)) *Inc
type Negation ¶
type Negation struct { Right Expression // contains filtered or unexported fields }
type Node ¶
type Node interface { fmt.Stringer // SetParent is needed to have an // option to move up in the tree. SetParent(Node) // Parent returns node's predecessor. Parent() Node }
Node represents the most simple thing which can appear in the AST.
type Return ¶
type Return struct { Expression Expression // contains filtered or unexported fields }
type Switch ¶
type Switch struct { Condition Expression // Default will end up here too, // to keep the order from PHP. Cases []Node Labels []Const // contains filtered or unexported fields }
func (*Switch) AddStatement ¶
func (*Switch) DefineVariable ¶
type Typ ¶
type UnaryMinus ¶
type UnaryMinus struct { Expr Expression // contains filtered or unexported fields }
func (UnaryMinus) Parent ¶
func (m UnaryMinus) Parent() Node
func (*UnaryMinus) SetParent ¶
func (m *UnaryMinus) SetParent(n Node)
func (UnaryMinus) String ¶
func (m UnaryMinus) String() string
func (UnaryMinus) Type ¶
func (m UnaryMinus) Type() Typ
type VarDef ¶
type VarDef struct { V *Variable Right Expression // contains filtered or unexported fields }
type VarRef ¶
type VarRef struct { V *Variable // contains filtered or unexported fields }