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

Function ParseConfig

hclsyntax/public.go:20–40  ·  view source on GitHub ↗

ParseConfig parses the given buffer as a whole HCL config file, returning a *hcl.File representing its contents. If HasErrors called on the returned diagnostics returns true, the returned body is likely to be incomplete and should therefore be used with care. The body in the returned file has dynam

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

Source from the content-addressed store, hash-verified

18// should be served using the hcl.Body interface to ensure compatibility with
19// other configurationg syntaxes, such as JSON.
20func ParseConfig(src []byte, filename string, start hcl.Pos) (*hcl.File, hcl.Diagnostics) {
21 tokens, diags := LexConfig(src, filename, start)
22 peeker := newPeeker(tokens, false)
23 parser := &parser{peeker: peeker}
24 body, parseDiags := parser.ParseBody(TokenEOF)
25 diags = append(diags, parseDiags...)
26
27 // Panic if the parser uses incorrect stack discipline with the peeker's
28 // newlines stack, since otherwise it will produce confusing downstream
29 // errors.
30 peeker.AssertEmptyIncludeNewlinesStack()
31
32 return &hcl.File{
33 Body: body,
34 Bytes: src,
35
36 Nav: navigation{
37 root: body,
38 },
39 }, diags
40}
41
42// ParseExpression parses the given buffer as a standalone HCL expression,
43// returning it as an instance of Expression.

Callers 15

DecodeFunction · 0.92
FuzzParseConfigFunction · 0.92
TestRoundTripFormatFunction · 0.92
parseFunction · 0.92
ParseHCLMethod · 0.92
TestDecodeUserFunctionsFunction · 0.92
TestVariablesFunction · 0.92
TestHCLDecDecodeToExprFunction · 0.92
TestTerraformLikeFunction · 0.92
TestDefaultSpecFunction · 0.92
TestValidateFuncSpecFunction · 0.92
TestRefineValueSpecFunction · 0.92

Calls 4

ParseBodyMethod · 0.95
LexConfigFunction · 0.85
newPeekerFunction · 0.70

Tested by 15

FuzzParseConfigFunction · 0.74
TestRoundTripFormatFunction · 0.74
TestDecodeUserFunctionsFunction · 0.74
TestVariablesFunction · 0.74
TestHCLDecDecodeToExprFunction · 0.74
TestTerraformLikeFunction · 0.74
TestDefaultSpecFunction · 0.74
TestValidateFuncSpecFunction · 0.74
TestRefineValueSpecFunction · 0.74
TestVariablesFunction · 0.74
TestDecodeFunction · 0.74
TestSourceRangeFunction · 0.74