hcl/parse.go
Mitchell Hashimoto 9501fc5ad0 decoder work
2015-11-06 23:12:15 -08:00

24 lines
492 B
Go

package hcl
import (
"fmt"
"github.com/hashicorp/hcl/hcl/ast"
hclParser "github.com/hashicorp/hcl/hcl/parser"
"github.com/hashicorp/hcl/json"
)
// Parse parses the given input and returns the root object.
//
// The input format can be either HCL or JSON.
func Parse(input string) (*ast.File, error) {
switch lexMode(input) {
case lexModeHcl:
return hclParser.Parse([]byte(input))
case lexModeJson:
return json.Parse(input)
}
return nil, fmt.Errorf("unknown config format")
}