forked from mperham/inspeqtor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
executable file
·39 lines (34 loc) · 871 Bytes
/
errors.go
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
31
32
33
34
35
36
37
38
39
package errors
import(
"bytes"
"fmt"
"github.com/mperham/inspeqtor/conf/global/token"
)
type ErrorSymbol interface {
}
type Error struct {
Err error
ErrorToken *token.Token
ErrorSymbols []ErrorSymbol
ExpectedTokens []string
}
func (E *Error) String() string {
w := new(bytes.Buffer)
fmt.Fprintf(w, "Error")
if E.Err != nil {
fmt.Fprintf(w, " %s\n", E.Err)
} else {
fmt.Fprintf(w, "\n")
}
fmt.Fprintf(w, "Token: type=%d, lit=%s\n", E.ErrorToken.Type, E.ErrorToken.Lit)
fmt.Fprintf(w, "Pos: offset=%d, line=%d, column=%d\n", E.ErrorToken.Pos.Offset, E.ErrorToken.Pos.Line, E.ErrorToken.Pos.Column)
fmt.Fprintf(w, "Expected one of: ")
for _, sym := range E.ExpectedTokens {
fmt.Fprintf(w, "%s ", sym)
}
fmt.Fprintf(w, "ErrorSymbol:\n")
for _, sym := range E.ErrorSymbols {
fmt.Fprintf(w, "%v\n", sym)
}
return w.String()
}