b2e6e2d0d0
If we can't find a function in the given EvalContext, we must traverse the context chain until either we run out of contexts or we find a matching function. At present there is no reason for a non-root context to have any functions, so this will always traverse to the root. This may change in future if we introduce constructs that define local functions.
26 lines
644 B
Go
26 lines
644 B
Go
package zcl
|
|
|
|
import (
|
|
"github.com/zclconf/go-cty/cty"
|
|
"github.com/zclconf/go-cty/cty/function"
|
|
)
|
|
|
|
// An EvalContext provides the variables and functions that should be used
|
|
// to evaluate an expression.
|
|
type EvalContext struct {
|
|
Variables map[string]cty.Value
|
|
Functions map[string]function.Function
|
|
parent *EvalContext
|
|
}
|
|
|
|
// NewChild returns a new EvalContext that is a child of the receiver.
|
|
func (ctx *EvalContext) NewChild() *EvalContext {
|
|
return &EvalContext{parent: ctx}
|
|
}
|
|
|
|
// Parent returns the parent of the receiver, or nil if the receiver has
|
|
// no parent.
|
|
func (ctx *EvalContext) Parent() *EvalContext {
|
|
return ctx.parent
|
|
}
|