forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expr_parse.go
40 lines (33 loc) · 782 Bytes
/
expr_parse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
lex := &exprLex{Input: v}
exprParse(lex)
// Build up the errors
var err error
if lex.Err != nil {
err = multierror.ErrorAppend(err, lex.Err)
}
if len(exprErrors) > 0 {
err = multierror.ErrorAppend(err, exprErrors...)
}
if err != nil {
exprResult = nil
}
return exprResult, err
}