Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var InitPos = Pos{Column: 1, Line: 1}
InitPos is an initiaial position value. This should be used as the starting position (presets the column and line to 1).
Functions ¶
Types ¶
type Arithmetic ¶
type Arithmetic struct { Op ArithmeticOp Exprs []Node Posx Pos }
Arithmetic represents a node where the result is arithmetic of two or more operands in the order given.
func (*Arithmetic) Accept ¶
func (n *Arithmetic) Accept(v Visitor) Node
func (*Arithmetic) GoString ¶
func (n *Arithmetic) GoString() string
func (*Arithmetic) Pos ¶
func (n *Arithmetic) Pos() Pos
func (*Arithmetic) String ¶
func (n *Arithmetic) String() string
type ArithmeticOp ¶
type ArithmeticOp int
ArithmeticOp is the operation to use for the math.
const ( ArithmeticOpInvalid ArithmeticOp = 0 ArithmeticOpAdd ArithmeticOp = iota ArithmeticOpSub ArithmeticOpMul ArithmeticOpDiv ArithmeticOpMod ArithmeticOpLogicalAnd ArithmeticOpLogicalOr ArithmeticOpEqual ArithmeticOpNotEqual ArithmeticOpLessThan ArithmeticOpLessThanOrEqual ArithmeticOpGreaterThan ArithmeticOpGreaterThanOrEqual )
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 Conditional ¶
func (*Conditional) Accept ¶
func (n *Conditional) Accept(v Visitor) Node
Accept passes the given visitor to the child nodes in this order: CondExpr, TrueExpr, FalseExpr. It then finally passes itself to the visitor.
func (*Conditional) GoString ¶
func (n *Conditional) GoString() string
func (*Conditional) Pos ¶
func (n *Conditional) Pos() Pos
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 MustNewLiteralNode ¶
func MustNewLiteralNode(value interface{}, pos Pos) *LiteralNode
MustNewLiteralNode wraps NewLiteralNode and panics if an error is returned, thus allowing valid literal nodes to be easily assigned to global variables.
func NewLiteralNode ¶
func NewLiteralNode(value interface{}, pos Pos) (*LiteralNode, error)
NewLiteralNode returns a new literal node representing the given literal Go value, which must correspond to one of the primitive types supported by HIL. Lists and maps cannot currently be constructed via this function.
If an inappropriately-typed value is provided, this function will return an error. The main intended use of this function is to produce "synthetic" literals from constants in code, where the value type is well known at compile time. To easily store these in global variables, see also MustNewLiteralNode.
func (*LiteralNode) Accept ¶
func (n *LiteralNode) Accept(v Visitor) Node
func (*LiteralNode) GoString ¶
func (n *LiteralNode) GoString() string
func (*LiteralNode) IsUnknown ¶
func (n *LiteralNode) IsUnknown() bool
IsUnknown returns true either if the node's value is itself unknown of if it is a collection containing any unknown elements, deeply.
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 Output ¶
Output represents the root node of all interpolation evaluations. If the output only has one expression which is either a TypeList or TypeMap, the Output can be type-asserted to []interface{} or map[string]interface{} respectively. Otherwise the Output evaluates as a string, and concatenates the evaluation of each expression.
type Pos ¶
type Pos struct {
Column, Line int // Column/Line number, starting at 1
Filename string // Optional source filename, if known
}
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 Type ¶
type Type uint32
Type is the type of any value.
const ( TypeInvalid Type = 0 TypeAny Type = 1 << iota TypeBool TypeString TypeInt TypeFloat TypeList TypeMap // This is a special type used by Terraform to mark "unknown" values. // It is impossible for this type to be introduced into your HIL programs // unless you explicitly set a variable to this value. In that case, // any operation including the variable will return "TypeUnknown" as the // type. TypeUnknown )
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.
func NewVariable ¶
NewVariable creates a new Variable for the given value. This will attempt to infer the correct type. If it can't, an error will be returned.
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.