-
Notifications
You must be signed in to change notification settings - Fork 601
/
static_expr.go
43 lines (35 loc) · 1 KB
/
static_expr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package hcl
import (
"github.com/zclconf/go-cty/cty"
)
type staticExpr struct {
val cty.Value
rng Range
}
// StaticExpr returns an Expression that always evaluates to the given value.
//
// This is useful to substitute default values for expressions that are
// not explicitly given in configuration and thus would otherwise have no
// Expression to return.
//
// Since expressions are expected to have a source range, the caller must
// provide one. Ideally this should be a real source range, but it can
// be a synthetic one (with an empty-string filename) if no suitable range
// is available.
func StaticExpr(val cty.Value, rng Range) Expression {
return staticExpr{val, rng}
}
func (e staticExpr) Value(ctx *EvalContext) (cty.Value, Diagnostics) {
return e.val, nil
}
func (e staticExpr) Variables() []Traversal {
return nil
}
func (e staticExpr) Range() Range {
return e.rng
}
func (e staticExpr) StartRange() Range {
return e.rng
}