opentofu/config/expr_parse.go

41 lines
782 B
Go
Raw Normal View History

2014-07-22 17:59:53 -05:00
package config
import (
"sync"
"github.com/hashicorp/terraform/helper/multierror"
)
// exprErrors are the errors built up from parsing. These should not
// be accessed directly.
var exprErrors []error
var exprLock sync.Mutex
var exprResult Interpolation
// ExprParse parses the given expression and returns an executable
// Interpolation.
func ExprParse(v string) (Interpolation, error) {
exprLock.Lock()
defer exprLock.Unlock()
exprErrors = nil
exprResult = nil
// Parse
2014-09-09 16:33:50 -05:00
lex := &exprLex{Input: v}
exprParse(lex)
2014-07-22 17:59:53 -05:00
// Build up the errors
var err error
if lex.Err != nil {
err = multierror.ErrorAppend(err, lex.Err)
}
2014-07-22 17:59:53 -05:00
if len(exprErrors) > 0 {
err = multierror.ErrorAppend(err, exprErrors...)
}
if err != nil {
2014-07-22 17:59:53 -05:00
exprResult = nil
}
return exprResult, err
}