# HG changeset patch # User Paul Boddie # Date 1483985504 -3600 # Node ID 0982751b90e31b1cc7956f881d42b010853526db # Parent 40e31f6740089744c6bf3a5b5a344843b345e403 Handle syntax errors produced by pyparser. diff -r 40e31f674008 -r 0982751b90e3 lplc --- a/lplc Mon Jan 09 19:11:31 2017 +0100 +++ b/lplc Mon Jan 09 19:11:44 2017 +0100 @@ -3,6 +3,7 @@ from errors import * from os import rename from os.path import abspath, exists, join, split +from pyparser import error from subprocess import Popen, PIPE from time import time import importer, deducer, optimiser, generator, translator @@ -26,6 +27,12 @@ for module_name, name in missing: print >>sys.stderr, "Module %s references an unknown object: %s" % (module_name, name) +def show_syntax_error(exc): + print >>sys.stderr, "Syntax error at column %d on line %d in file %s:" % (exc.offset, exc.lineno, exc.filename) + print >>sys.stderr + print >>sys.stderr, exc.text.rstrip() + print >>sys.stderr, " " * exc.offset + "^" + def stopwatch(activity, now): print >>sys.stderr, "%s took %.2f seconds" % (activity, time() - now) return time() @@ -151,6 +158,12 @@ # Report any errors. + except error.SyntaxError, exc: + show_syntax_error(exc) + if "-tb" in args: + raise + sys.exit(1) + except ProcessingError, exc: print exc if "-tb" in args: