parse
This commit is contained in:
parent
d5f339015f
commit
3a02b49a51
23
parse.go
Normal file
23
parse.go
Normal file
@ -0,0 +1,23 @@
|
||||
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")
|
||||
}
|
Loading…
Reference in New Issue
Block a user