aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hcl2/hcl/static_expr.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/static_expr.go')
-rw-r--r--vendor/github.com/hashicorp/hcl2/hcl/static_expr.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/static_expr.go b/vendor/github.com/hashicorp/hcl2/hcl/static_expr.go
new file mode 100644
index 0000000..98ada87
--- /dev/null
+++ b/vendor/github.com/hashicorp/hcl2/hcl/static_expr.go
@@ -0,0 +1,40 @@
1package hcl
2
3import (
4 "github.com/zclconf/go-cty/cty"
5)
6
7type staticExpr struct {
8 val cty.Value
9 rng Range
10}
11
12// StaticExpr returns an Expression that always evaluates to the given value.
13//
14// This is useful to substitute default values for expressions that are
15// not explicitly given in configuration and thus would otherwise have no
16// Expression to return.
17//
18// Since expressions are expected to have a source range, the caller must
19// provide one. Ideally this should be a real source range, but it can
20// be a synthetic one (with an empty-string filename) if no suitable range
21// is available.
22func StaticExpr(val cty.Value, rng Range) Expression {
23 return staticExpr{val, rng}
24}
25
26func (e staticExpr) Value(ctx *EvalContext) (cty.Value, Diagnostics) {
27 return e.val, nil
28}
29
30func (e staticExpr) Variables() []Traversal {
31 return nil
32}
33
34func (e staticExpr) Range() Range {
35 return e.rng
36}
37
38func (e staticExpr) StartRange() Range {
39 return e.rng
40}