report line and column number on parsing error
This commit is contained in:
parent
58d3cfd804
commit
94677bc79e
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import sys
|
||||||
import ply.yacc as yacc
|
import ply.yacc as yacc
|
||||||
from Lexer import Lexer
|
from Lexer import Lexer
|
||||||
from nodes import *
|
from nodes import *
|
||||||
@ -48,6 +49,9 @@ class Parser(object):
|
|||||||
|
|
||||||
def p_error(self, p):
|
def p_error(self, p):
|
||||||
self.saw_error = True
|
self.saw_error = True
|
||||||
|
col = p.lexpos - max(0, self.input.rfind('\n', 0, p.lexpos))
|
||||||
|
sys.stdout.write('Error: Unexpected %s at line %d, col %d\n' % (
|
||||||
|
p.type, p.lineno, col))
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
return self.parser.parse(self.input, lexer = self.lexer)
|
return self.parser.parse(self.input, lexer = self.lexer)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user