6 "github.com/hashicorp/hcl/hcl/ast"
7 hclParser "github.com/hashicorp/hcl/hcl/parser"
8 jsonParser "github.com/hashicorp/hcl/json/parser"
11 // ParseBytes accepts as input byte slice and returns ast tree.
13 // Input can be either JSON or HCL
14 func ParseBytes(in []byte) (*ast.File, error) {
18 // ParseString accepts input as a string and returns ast tree.
19 func ParseString(input string) (*ast.File, error) {
20 return parse([]byte(input))
23 func parse(in []byte) (*ast.File, error) {
26 return hclParser.Parse(in)
28 return jsonParser.Parse(in)
31 return nil, fmt.Errorf("unknown config format")
34 // Parse parses the given input and returns the root object.
36 // The input format can be either HCL or JSON.
37 func Parse(input string) (*ast.File, error) {
38 return parse([]byte(input))