diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hil/parser/error.go')
-rw-r--r-- | vendor/github.com/hashicorp/hil/parser/error.go | 38 |
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 @@ | |||
1 | package parser | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | |||
6 | "github.com/hashicorp/hil/ast" | ||
7 | "github.com/hashicorp/hil/scanner" | ||
8 | ) | ||
9 | |||
10 | type ParseError struct { | ||
11 | Message string | ||
12 | Pos ast.Pos | ||
13 | } | ||
14 | |||
15 | func 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. | ||
24 | func TokenErrorf(token *scanner.Token, format string, args ...interface{}) error { | ||
25 | return Errorf(token.Pos, format, args...) | ||
26 | } | ||
27 | |||
28 | func ExpectationError(wanted string, got *scanner.Token) error { | ||
29 | return TokenErrorf(got, "expected %s but found %s", wanted, got) | ||
30 | } | ||
31 | |||
32 | func (e *ParseError) Error() string { | ||
33 | return fmt.Sprintf("parse error at %s: %s", e.Pos, e.Message) | ||
34 | } | ||
35 | |||
36 | func (e *ParseError) String() string { | ||
37 | return e.Error() | ||
38 | } | ||