Better error reporting for parsing errors.

This commit is contained in:
Jussi Pakkanen 2013-06-02 14:25:35 +03:00
parent c3972d512a
commit b63c493844
2 changed files with 18 additions and 5 deletions

View File

@ -598,7 +598,11 @@ class Interpreter():
if len(code.strip()) == 0:
raise InvalidCode('Builder file is empty.')
assert(isinstance(code, str))
self.ast = mparser.build_ast(code)
try:
self.ast = mparser.build_ast(code)
except coredata.MesonException as me:
me.file = environment.build_filename
raise me
self.sanity_check_ast()
self.variables = {}
self.builtin = {}
@ -859,7 +863,11 @@ class Interpreter():
self.build_def_files.append(buildfilename)
code = open(os.path.join(self.environment.get_source_dir(), buildfilename)).read()
assert(isinstance(code, str))
codeblock = mparser.build_ast(code)
try:
codeblock = mparser.build_ast(code)
except coredata.MesonException as me:
me.file = buildfilename
raise me
print('Going to subdirectory "%s".' % self.subdir)
self.evaluate_codeblock(codeblock)
self.subdir = prev_subdir

View File

@ -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)