aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hcl2/hcl/expr_call.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/expr_call.go')
-rw-r--r--vendor/github.com/hashicorp/hcl2/hcl/expr_call.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/expr_call.go b/vendor/github.com/hashicorp/hcl2/hcl/expr_call.go
new file mode 100644
index 0000000..6963fba
--- /dev/null
+++ b/vendor/github.com/hashicorp/hcl2/hcl/expr_call.go
@@ -0,0 +1,46 @@
1package hcl
2
3// ExprCall tests if the given expression is a function call and,
4// if so, extracts the function name and the expressions that represent
5// the arguments. If the given expression is not statically a function call,
6// error diagnostics are returned.
7//
8// A particular Expression implementation can support this function by
9// offering a method called ExprCall that takes no arguments and returns
10// *StaticCall. This method should return nil if a static call cannot
11// be extracted. Alternatively, an implementation can support
12// UnwrapExpression to delegate handling of this function to a wrapped
13// Expression object.
14func ExprCall(expr Expression) (*StaticCall, Diagnostics) {
15 type exprCall interface {
16 ExprCall() *StaticCall
17 }
18
19 physExpr := UnwrapExpressionUntil(expr, func(expr Expression) bool {
20 _, supported := expr.(exprCall)
21 return supported
22 })
23
24 if exC, supported := physExpr.(exprCall); supported {
25 if call := exC.ExprCall(); call != nil {
26 return call, nil
27 }
28 }
29 return nil, Diagnostics{
30 &Diagnostic{
31 Severity: DiagError,
32 Summary: "Invalid expression",
33 Detail: "A static function call is required.",
34 Subject: expr.StartRange().Ptr(),
35 },
36 }
37}
38
39// StaticCall represents a function call that was extracted statically from
40// an expression using ExprCall.
41type StaticCall struct {
42 Name string
43 NameRange Range
44 Arguments []Expression
45 ArgsRange Range
46}