MCPcopy
hub / github.com/hashicorp/hcl / RelTraversalForExpr

Function RelTraversalForExpr

traversal_for_expr.go:55–68  ·  view source on GitHub ↗

RelTraversalForExpr is similar to AbsTraversalForExpr but it returns a relative traversal instead. Due to the nature of HCL expressions, the first element of the returned traversal is always a TraverseAttr, and then it will be followed by zero or more other expressions. Any expression accepted by A

(expr Expression)

Source from the content-addressed store, hash-verified

53// Any expression accepted by AbsTraversalForExpr is also accepted by
54// RelTraversalForExpr.
55func RelTraversalForExpr(expr Expression) (Traversal, Diagnostics) {
56 traversal, diags := AbsTraversalForExpr(expr)
57 if len(traversal) > 0 {
58 ret := make(Traversal, len(traversal))
59 copy(ret, traversal)
60 root := traversal[0].(TraverseRoot)
61 ret[0] = TraverseAttr{
62 Name: root.Name,
63 SrcRange: root.SrcRange,
64 }
65 return ret, diags
66 }
67 return traversal, diags
68}
69
70// ExprAsKeyword attempts to interpret the given expression as a static keyword,
71// returning the keyword string if possible, and the empty string if not.

Callers 1

TestRelTraversalForExprFunction · 0.85

Calls 1

AbsTraversalForExprFunction · 0.85

Tested by 1

TestRelTraversalForExprFunction · 0.68