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
|
|
|
|
var hclResult map[string]interface{}
|
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.
|
|
|
|
func Parse(v string) (map[string]interface{}, error) {
|
|
|
|
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
|
|
|
}
|