hcl/parse.go

24 lines
467 B
Go
Raw Normal View History

2014-08-02 18:44:14 +00:00
package hcl
import (
"fmt"
"github.com/hashicorp/hcl/ast"
"github.com/hashicorp/hcl/hcl"
"github.com/hashicorp/hcl/json"
)
// Parse parses the given input and returns the root of the AST.
//
// The input format can be either HCL or JSON.
func Parse(input string) (*ast.ObjectNode, error) {
switch lexMode(input) {
case lexModeHcl:
return hcl.Parse(input)
case lexModeJson:
return json.Parse(input)
}
return nil, fmt.Errorf("unknown config format")
}