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

Function ParseTemplate

hclsyntax/public.go:78–91  ·  view source on GitHub ↗

ParseTemplate parses the given buffer as a standalone HCL template, returning it as an instance of Expression.

(src []byte, filename string, start hcl.Pos)

Source from the content-addressed store, hash-verified

76// ParseTemplate parses the given buffer as a standalone HCL template,
77// returning it as an instance of Expression.
78func ParseTemplate(src []byte, filename string, start hcl.Pos) (Expression, hcl.Diagnostics) {
79 tokens, diags := LexTemplate(src, filename, start)
80 peeker := newPeeker(tokens, false)
81 parser := &parser{peeker: peeker}
82 expr, parseDiags := parser.ParseTemplate()
83 diags = append(diags, parseDiags...)
84
85 // Panic if the parser uses incorrect stack discipline with the peeker's
86 // newlines stack, since otherwise it will produce confusing downstream
87 // errors.
88 peeker.AssertEmptyIncludeNewlinesStack()
89
90 return expr, diags
91}
92
93// ParseTraversalAbs parses the given buffer as a standalone absolute traversal.
94//

Callers 7

FuzzParseTemplateFunction · 0.92
ValueMethod · 0.92
VariablesMethod · 0.92

Calls 4

ParseTemplateMethod · 0.95
LexTemplateFunction · 0.85
newPeekerFunction · 0.70