forked from nyaruka/goflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
46 lines (36 loc) · 1.01 KB
/
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
40
41
42
43
44
45
46
package excellent
import (
"bytes"
"fmt"
"strconv"
"github.com/antlr/antlr4/runtime/Go/antlr"
)
// TemplateErrors represents the list of errors we may have received during execution
type TemplateErrors []error
// Error returns a single string describing all the errors encountered
func (e TemplateErrors) Error() string {
if len(e) == 1 {
return e[0].Error()
}
msg := "multiple errors:"
for _, err := range e {
msg += "\n" + err.Error()
}
return msg
}
type errorListener struct {
errors bytes.Buffer
*antlr.DefaultErrorListener
}
func NewErrorListener() *errorListener {
return &errorListener{}
}
func (l *errorListener) HasErrors() bool {
return l.errors.Len() > 0
}
func (l *errorListener) Errors() string {
return l.errors.String()
}
func (l *errorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) {
l.errors.WriteString(fmt.Sprintln("line " + strconv.Itoa(line) + ":" + strconv.Itoa(column) + " " + msg))
}