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

Function ParseTraversalAbs

hclsyntax/public.go:99–119  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

97// are useful as a syntax for referring to objects without necessarily
98// evaluating them.
99func 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.

Callers 5

FuzzParseTraversalAbsFunction · 0.92
AsTraversalMethod · 0.92
MockExprTraversalSrcFunction · 0.92
TestParseTraversalAbsFunction · 0.85

Calls 6

ParseTraversalAbsMethod · 0.95
LexExpressionFunction · 0.85
PushIncludeNewlinesMethod · 0.80
PopIncludeNewlinesMethod · 0.80
newPeekerFunction · 0.70

Tested by 3

FuzzParseTraversalAbsFunction · 0.74
TestParseTraversalAbsFunction · 0.68