...
1 package hcl
2
3 import (
4 "fmt"
5
6 "github.com/hashicorp/hcl/hcl/ast"
7 hclParser "github.com/hashicorp/hcl/hcl/parser"
8 jsonParser "github.com/hashicorp/hcl/json/parser"
9 )
10
11
12
13
14 func ParseBytes(in []byte) (*ast.File, error) {
15 return parse(in)
16 }
17
18
19 func ParseString(input string) (*ast.File, error) {
20 return parse([]byte(input))
21 }
22
23 func parse(in []byte) (*ast.File, error) {
24 switch lexMode(in) {
25 case lexModeHcl:
26 return hclParser.Parse(in)
27 case lexModeJson:
28 return jsonParser.Parse(in)
29 }
30
31 return nil, fmt.Errorf("unknown config format")
32 }
33
34
35
36
37 func Parse(input string) (*ast.File, error) {
38 return parse([]byte(input))
39 }
40
View as plain text