hcl/parse.go

34 lines
623 B
Go
Raw Normal View History

2014-07-31 20:56:51 +00:00
package hcl
import (
"sync"
2014-07-31 21:08:31 +00:00
"github.com/hashicorp/terraform/helper/multierror"
2014-07-31 20:56:51 +00:00
)
2014-07-31 21:08:31 +00:00
// hclErrors are the errors built up from parsing. These should not
2014-07-31 20:56:51 +00:00
// be accessed directly.
2014-07-31 21:08:31 +00:00
var hclErrors []error
var hclLock sync.Mutex
2014-08-01 01:44:21 +00:00
var hclResult *ObjectNode
2014-07-31 20:56:51 +00:00
2014-07-31 21:08:31 +00:00
// Parse parses the given string and returns the result.
2014-08-01 01:44:21 +00:00
func Parse(v string) (*ObjectNode, error) {
2014-07-31 21:08:31 +00:00
hclLock.Lock()
defer hclLock.Unlock()
hclErrors = nil
hclResult = nil
2014-07-31 20:56:51 +00:00
// Parse
2014-07-31 21:08:31 +00:00
hclParse(&hclLex{Input: v})
2014-07-31 20:56:51 +00:00
// Build up the errors
var err error
2014-07-31 21:08:31 +00:00
if len(hclErrors) > 0 {
err = &multierror.Error{Errors: hclErrors}
hclResult = nil
2014-07-31 20:56:51 +00:00
}
2014-07-31 21:08:31 +00:00
return hclResult, err
2014-07-31 20:56:51 +00:00
}