-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonErrorListener.py
More file actions
24 lines (20 loc) · 855 Bytes
/
pythonErrorListener.py
File metadata and controls
24 lines (20 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from antlr4.error.ErrorListener import *
class Python3ErrorListener(ErrorListener):
def __init__(self, output):
self.output = output
self._symbol = ''
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
self.output.write(msg)
self._symbol = offendingSymbol.text
stack = recognizer.getRuleInvocationStack()
stack.reverse()
print("rule stack: {}".format(str(stack)))
print("line {} : {} at {} : {}".format(str(line),
str(column),
str(offendingSymbol).replace(" ", u'\u23B5'),
msg.replace(" ", u'\u23B5')))
@property
def symbol(self):
return self._symbol
def output(self):
return self.output