diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hil/parse.go')
-rw-r--r-- | vendor/github.com/hashicorp/hil/parse.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hil/parse.go b/vendor/github.com/hashicorp/hil/parse.go new file mode 100644 index 0000000..ecbe1fd --- /dev/null +++ b/vendor/github.com/hashicorp/hil/parse.go | |||
@@ -0,0 +1,29 @@ | |||
1 | package hil | ||
2 | |||
3 | import ( | ||
4 | "github.com/hashicorp/hil/ast" | ||
5 | "github.com/hashicorp/hil/parser" | ||
6 | "github.com/hashicorp/hil/scanner" | ||
7 | ) | ||
8 | |||
9 | // Parse parses the given program and returns an executable AST tree. | ||
10 | // | ||
11 | // Syntax errors are returned with error having the dynamic type | ||
12 | // *parser.ParseError, which gives the caller access to the source position | ||
13 | // where the error was found, which allows (for example) combining it with | ||
14 | // a known source filename to add context to the error message. | ||
15 | func Parse(v string) (ast.Node, error) { | ||
16 | return ParseWithPosition(v, ast.Pos{Line: 1, Column: 1}) | ||
17 | } | ||
18 | |||
19 | // ParseWithPosition is like Parse except that it overrides the source | ||
20 | // row and column position of the first character in the string, which should | ||
21 | // be 1-based. | ||
22 | // | ||
23 | // This can be used when HIL is embedded in another language and the outer | ||
24 | // parser knows the row and column where the HIL expression started within | ||
25 | // the overall source file. | ||
26 | func ParseWithPosition(v string, pos ast.Pos) (ast.Node, error) { | ||
27 | ch := scanner.Scan(v, pos) | ||
28 | return parser.Parse(ch) | ||
29 | } | ||