Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BasicScope ¶
BasicScope is a simple scope that looks up variables and functions using a map.
func (*BasicScope) LookupFunc ¶
func (s *BasicScope) LookupFunc(n string) (Function, bool)
type Concat ¶
Concat represents a node where the result of two or more expressions are concatenated. The result of all expressions must be a string.
type Function ¶
type Function struct { // ArgTypes is the list of types in argument order. These are the // required arguments. // // ReturnType is the type of the returned value. The Callback MUST // return this type. ArgTypes []Type ReturnType Type // Variadic, if true, says that this function is variadic, meaning // it takes a variable number of arguments. In this case, the // VariadicType must be set. Variadic bool VariadicType Type // Callback is the function called for a function. The argument // types are guaranteed to match the spec above by the type checker. // The length of the args is strictly == len(ArgTypes) unless Varidiac // is true, in which case its >= len(ArgTypes). Callback func([]interface{}) (interface{}, error) }
Function defines a function that can be executed by the engine. The type checker will validate that the proper types will be called to the callback.
type LiteralNode ¶
LiteralNode represents a single literal value, such as "foo" or 42 or 3.14159. Based on the Type, the Value can be safely cast.
func (*LiteralNode) Accept ¶
func (n *LiteralNode) Accept(v Visitor) Node
func (*LiteralNode) GoString ¶
func (n *LiteralNode) GoString() string
func (*LiteralNode) Pos ¶
func (n *LiteralNode) Pos() Pos
func (*LiteralNode) String ¶
func (n *LiteralNode) String() string
type Node ¶
type Node interface { // Accept is called to dispatch to the visitors. It must return the // resulting Node (which might be different in an AST transform). Accept(Visitor) Node // Pos returns the position of this node in some source. Pos() Pos // Type returns the type of this node for the given context. Type(Scope) (Type, error) }
Node is the interface that all AST nodes must implement.
type Pos ¶
type Pos struct {
Column, Line int // Column/Line number, starting at 1
}
Pos is the starting position of an AST node
type Scope ¶
Scope is the interface used to look up variables and functions while evaluating. How these functions/variables are defined are up to the caller.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack is a stack of Node.
type Variable ¶
type Variable struct { Value interface{} Type Type }
Variable is a variable value for execution given as input to the engine. It records the value of a variables along with their type.
type VariableAccess ¶
VariableAccess represents a variable access.
func (*VariableAccess) Accept ¶
func (n *VariableAccess) Accept(v Visitor) Node
func (*VariableAccess) GoString ¶
func (n *VariableAccess) GoString() string
func (*VariableAccess) Pos ¶
func (n *VariableAccess) Pos() Pos
func (*VariableAccess) String ¶
func (n *VariableAccess) String() string
type Visitor ¶
Visitors are just implementations of this function.
The function must return the Node to replace this node with. "nil" is _not_ a valid return value. If there is no replacement, the original node should be returned. We build this replacement directly into the visitor pattern since AST transformations are a common and useful tool and building it into the AST itself makes it required for future Node implementations and very easy to do.
Note that this isn't a true implementation of the visitor pattern, which generally requires proper type dispatch on the function. However, implementing this basic visitor pattern style is still very useful even if you have to type switch.