/
error_listener.go
59 lines (53 loc) · 1.44 KB
/
error_listener.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package parse
import (
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/sirupsen/logrus"
)
// SyslParserErrorListener ...
type SyslParserErrorListener struct {
*antlr.DefaultErrorListener
hasErrors bool
}
// SyntaxError ...
func (d *SyslParserErrorListener) SyntaxError(
recognizer antlr.Recognizer,
offendingSymbol interface{},
line, column int,
msg string,
e antlr.RecognitionException,
) {
d.hasErrors = true
tokenType := offendingSymbol.(*antlr.CommonToken).GetTokenType()
logrus.Printf("SyntaxError: Token: %s\n", recognizer.GetSymbolicNames()[tokenType])
}
// ReportAttemptingFullContext ...
func (d *SyslParserErrorListener) ReportAttemptingFullContext(
recognizer antlr.Parser,
dfa *antlr.DFA,
startIndex, stopIndex int,
conflictingAlts *antlr.BitSet,
configs antlr.ATNConfigSet,
) {
logrus.Printf("ReportAttemptingFullContext: %d %d\n", startIndex, stopIndex)
}
// ReportAmbiguity ...
func (d *SyslParserErrorListener) ReportAmbiguity(
recognizer antlr.Parser,
dfa *antlr.DFA,
startIndex, stopIndex int,
exact bool,
ambigAlts *antlr.BitSet,
configs antlr.ATNConfigSet,
) {
logrus.Printf("ReportAmbiguity: %d %d\n", startIndex, stopIndex)
}
// ReportContextSensitivity ...
func (d *SyslParserErrorListener) ReportContextSensitivity(
recognizer antlr.Parser,
dfa *antlr.DFA,
startIndex, stopIndex int,
prediction int,
configs antlr.ATNConfigSet,
) {
logrus.Printf("ReportContextSensitivity: %d %d\n", startIndex, stopIndex)
}