aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hil/parser/error.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/hil/parser/error.go')
-rw-r--r--vendor/github.com/hashicorp/hil/parser/error.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hil/parser/error.go b/vendor/github.com/hashicorp/hil/parser/error.go
new file mode 100644
index 0000000..bacd696
--- /dev/null
+++ b/vendor/github.com/hashicorp/hil/parser/error.go
@@ -0,0 +1,38 @@
1package parser
2
3import (
4 "fmt"
5
6 "github.com/hashicorp/hil/ast"
7 "github.com/hashicorp/hil/scanner"
8)
9
10type ParseError struct {
11 Message string
12 Pos ast.Pos
13}
14
15func Errorf(pos ast.Pos, format string, args ...interface{}) error {
16 return &ParseError{
17 Message: fmt.Sprintf(format, args...),
18 Pos: pos,
19 }
20}
21
22// TokenErrorf is a convenient wrapper around Errorf that uses the
23// position of the given token.
24func TokenErrorf(token *scanner.Token, format string, args ...interface{}) error {
25 return Errorf(token.Pos, format, args...)
26}
27
28func ExpectationError(wanted string, got *scanner.Token) error {
29 return TokenErrorf(got, "expected %s but found %s", wanted, got)
30}
31
32func (e *ParseError) Error() string {
33 return fmt.Sprintf("parse error at %s: %s", e.Pos, e.Message)
34}
35
36func (e *ParseError) String() string {
37 return e.Error()
38}