2016-01-15 18:53:01 +00:00
|
|
|
package hcl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-03-01 00:51:26 +00:00
|
|
|
"github.com/hashicorp/hcl/hcl/ast"
|
|
|
|
hclParser "github.com/hashicorp/hcl/hcl/parser"
|
|
|
|
jsonParser "github.com/hashicorp/hcl/json/parser"
|
2016-01-15 18:53:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 jsonParser.Parse([]byte(input))
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unknown config format")
|
|
|
|
}
|