report line and column number on parsing error

This commit is contained in:
Josh Holtrop 2011-08-30 16:20:38 -04:00
parent 58d3cfd804
commit 94677bc79e

View File

@ -1,4 +1,5 @@
import sys
import ply.yacc as yacc
from Lexer import Lexer
from nodes import *
@ -48,6 +49,9 @@ class Parser(object):
def p_error(self, p):
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):
return self.parser.parse(self.input, lexer = self.lexer)