github.com/hashicorp/hcl/v2@v2.20.0/eval_context.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package hcl
     5  
     6  import (
     7  	"github.com/zclconf/go-cty/cty"
     8  	"github.com/zclconf/go-cty/cty/function"
     9  )
    10  
    11  // An EvalContext provides the variables and functions that should be used
    12  // to evaluate an expression.
    13  type EvalContext struct {
    14  	Variables map[string]cty.Value
    15  	Functions map[string]function.Function
    16  	parent    *EvalContext
    17  }
    18  
    19  // NewChild returns a new EvalContext that is a child of the receiver.
    20  func (ctx *EvalContext) NewChild() *EvalContext {
    21  	return &EvalContext{parent: ctx}
    22  }
    23  
    24  // Parent returns the parent of the receiver, or nil if the receiver has
    25  // no parent.
    26  func (ctx *EvalContext) Parent() *EvalContext {
    27  	return ctx.parent
    28  }