ParseTraversalAbs parses the given buffer as a standalone absolute traversal. Parsing as a traversal is more limited than parsing as an expession since it allows only attribute and indexing operations on variables. Traverals are useful as a syntax for referring to objects without necessarily evalua
(src []byte, filename string, start hcl.Pos)
| 97 | // are useful as a syntax for referring to objects without necessarily |
| 98 | // evaluating them. |
| 99 | func ParseTraversalAbs(src []byte, filename string, start hcl.Pos) (hcl.Traversal, hcl.Diagnostics) { |
| 100 | tokens, diags := LexExpression(src, filename, start) |
| 101 | peeker := newPeeker(tokens, false) |
| 102 | parser := &parser{peeker: peeker} |
| 103 | |
| 104 | // Bare traverals are always parsed in "ignore newlines" mode, as if |
| 105 | // they were wrapped in parentheses. |
| 106 | parser.PushIncludeNewlines(false) |
| 107 | |
| 108 | expr, parseDiags := parser.ParseTraversalAbs() |
| 109 | diags = append(diags, parseDiags...) |
| 110 | |
| 111 | parser.PopIncludeNewlines() |
| 112 | |
| 113 | // Panic if the parser uses incorrect stack discipline with the peeker's |
| 114 | // newlines stack, since otherwise it will produce confusing downstream |
| 115 | // errors. |
| 116 | peeker.AssertEmptyIncludeNewlinesStack() |
| 117 | |
| 118 | return expr, diags |
| 119 | } |
| 120 | |
| 121 | // ParseTraversalPartial matches the behavior of ParseTraversalAbs except |
| 122 | // that it allows splat expressions ([*]) to appear in the traversal. |