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)
| 53 | // Any expression accepted by AbsTraversalForExpr is also accepted by |
| 54 | // RelTraversalForExpr. |
| 55 | func 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. |