File: parse.go

package info (click to toggle)
golang-github-hashicorp-hil 0.0~git20160711.1e86c6b-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 352 kB
  • sloc: yacc: 161; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 633 bytes parent folder | download | duplicates (2)
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
package hil

import (
	"sync"

	"github.com/hashicorp/hil/ast"
)

var parserLock sync.Mutex
var parserResult ast.Node

// Parse parses the given program and returns an executable AST tree.
func Parse(v string) (ast.Node, error) {
	// Unfortunately due to the way that goyacc generated parsers are
	// formatted, we can only do a single parse at a time without a lot
	// of extra work. In the future we can remove this limitation.
	parserLock.Lock()
	defer parserLock.Unlock()

	// Reset our globals
	parserResult = nil

	// Create the lexer
	lex := &parserLex{Input: v}

	// Parse!
	parserParse(lex)

	return parserResult, lex.Err
}