hcl/parse.go

24 lines
492 B
Go
Raw Normal View History

2014-08-02 18:44:14 +00:00
package hcl
import (
"fmt"
2015-11-07 07:12:15 +00:00
"github.com/hashicorp/hcl/hcl/ast"
hclParser "github.com/hashicorp/hcl/hcl/parser"
2014-08-02 18:44:14 +00:00
"github.com/hashicorp/hcl/json"
)
2014-08-11 23:33:28 +00:00
// Parse parses the given input and returns the root object.
2014-08-02 18:44:14 +00:00
//
// The input format can be either HCL or JSON.
2015-11-07 07:12:15 +00:00
func Parse(input string) (*ast.File, error) {
2014-08-02 18:44:14 +00:00
switch lexMode(input) {
case lexModeHcl:
2015-11-07 07:12:15 +00:00
return hclParser.Parse([]byte(input))
2014-08-02 18:44:14 +00:00
case lexModeJson:
return json.Parse(input)
}
return nil, fmt.Errorf("unknown config format")
}