From b63c493844261e533edfcb30ca76d2f3412ae0cb Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 2 Jun 2013 14:25:35 +0300 Subject: Better error reporting for parsing errors. --- mparser.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'mparser.py') diff --git a/mparser.py b/mparser.py index 27bec58a4..d13a1f0db 100644 --- a/mparser.py +++ b/mparser.py @@ -17,6 +17,12 @@ import ply.lex as lex import ply.yacc as yacc import nodes +from coredata import MesonException + +class ParserException(MesonException): + def __init__(self, text, lineno): + MesonException.__init__(self, text) + self.lineno = lineno reserved = {'true' : 'TRUE', 'false' : 'FALSE', @@ -90,8 +96,7 @@ def t_EOL_CONTINUE(t): t.lexer.lineno += 1 def t_error(t): - print("Illegal character '%s'" % t.value[0]) - t.lexer.skip(1) + raise ParserException("Illegal character '%s'." % t.value[0], t.lineno) # Yacc part @@ -228,7 +233,7 @@ def p_error(t): txt = 'NONE' else: txt = t.value - print('Parser errored out at: ' + txt) + raise ParserException('Parser errored out at: %s.' % txt, t.lineno) def test_lexer(): s = """hello = (something) # this = (that) -- cgit v1.2.3