github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/config/lang/parse.go (about)

     1  package lang
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/hashicorp/terraform/config/lang/ast"
     7  )
     8  
     9  var parserErrors []error
    10  var parserLock sync.Mutex
    11  var parserResult ast.Node
    12  
    13  // Parse parses the given program and returns an executable AST tree.
    14  func Parse(v string) (ast.Node, error) {
    15  	// Unfortunately due to the way that goyacc generated parsers are
    16  	// formatted, we can only do a single parse at a time without a lot
    17  	// of extra work. In the future we can remove this limitation.
    18  	parserLock.Lock()
    19  	defer parserLock.Unlock()
    20  
    21  	// Reset our globals
    22  	parserErrors = nil
    23  	parserResult = nil
    24  
    25  	// Create the lexer
    26  	lex := &parserLex{Input: v}
    27  
    28  	// Parse!
    29  	parserParse(lex)
    30  
    31  	return parserResult, lex.Err
    32  }