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)
| 18 | // should be served using the hcl.Body interface to ensure compatibility with |
| 19 | // other configurationg syntaxes, such as JSON. |
| 20 | func 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. |