6 "github.com/hashicorp/hcl2/hcl"
9 // NewFile creates a new file object that is empty and ready to have constructs
11 func NewFile() *File {
19 file.body = file.inTree.children.Append(body)
23 // ParseConfig interprets the given source bytes into a *hclwrite.File. The
24 // resulting AST can be used to perform surgical edits on the source code
25 // before turning it back into bytes again.
26 func ParseConfig(src []byte, filename string, start hcl.Pos) (*File, hcl.Diagnostics) {
27 return parse(src, filename, start)
30 // Format takes source code and performs simple whitespace changes to transform
31 // it to a canonical layout style.
33 // Format skips constructing an AST and works directly with tokens, so it
34 // is less expensive than formatting via the AST for situations where no other
35 // changes will be made. It also ignores syntax errors and can thus be applied
36 // to partial source code, although the result in that case may not be
38 func Format(src []byte) []byte {
39 tokens := lexConfig(src)
41 buf := &bytes.Buffer{}