github.com/adamar/terraform@v0.2.2-0.20141016210445-2e703afdad0e/config/expr_parse.go (about) 1 package config 2 3 import ( 4 "sync" 5 6 "github.com/hashicorp/terraform/helper/multierror" 7 ) 8 9 // exprErrors are the errors built up from parsing. These should not 10 // be accessed directly. 11 var exprErrors []error 12 var exprLock sync.Mutex 13 var exprResult Interpolation 14 15 // ExprParse parses the given expression and returns an executable 16 // Interpolation. 17 func ExprParse(v string) (Interpolation, error) { 18 exprLock.Lock() 19 defer exprLock.Unlock() 20 exprErrors = nil 21 exprResult = nil 22 23 // Parse 24 lex := &exprLex{Input: v} 25 exprParse(lex) 26 27 // Build up the errors 28 var err error 29 if lex.Err != nil { 30 err = multierror.ErrorAppend(err, lex.Err) 31 } 32 if len(exprErrors) > 0 { 33 err = multierror.ErrorAppend(err, exprErrors...) 34 } 35 if err != nil { 36 exprResult = nil 37 } 38 39 return exprResult, err 40 }