Documentation
¶
Overview ¶
Package vm provides a River expression evaluator.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator evaluates River AST nodes into Go values. Each Evaluator is bound to a single AST node. To evaluate the node, call Evaluate.
func New ¶
func New(node ast.Node) *Evaluator
New creates a new Evaluator for the given AST node. The given node must be either an *ast.File, *ast.BlockStmt, ast.Body, or assignable to an ast.Expr.
func (*Evaluator) Evaluate ¶
func (vm *Evaluator) Evaluate(scope *Scope, v interface{}) (err error)
Evaluate evaluates the Evaluator's node into a River value and decodes that value into the Go value v.
Each call to Evaluate may provide a different scope with new values for available variables. If a variable used by the Evaluator's node isn't defined in scope or any of the parent scopes, Evaluate will return an error.
type Scope ¶
type Scope struct {
// Parent optionally points to a parent Scope containing more variable.
// Variables defined in children scopes take precedence over variables of the
// same name found in parent scopes.
Parent *Scope
// Variables holds the list of available variable names that can be used when
// evaluating a node.
//
// Values in the Variables map should considered immutable after passed to
// Evaluate; maps and slices will be copied by reference for performance
// optimizations.
Variables map[string]interface{}
}
A Scope exposes a set of variables available to use during evaluation.