From 25c836048e9be166fcd85dc1217854bb50321dea Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 12 Oct 2015 22:42:32 -0700 Subject: [PATCH] Adding better error messages for Tokenization and Parsing - More msg, less stack trace --- kll.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kll.py b/kll.py index c4386e0..cae70f8 100755 --- a/kll.py +++ b/kll.py @@ -683,13 +683,17 @@ def parse( tokenSequence ): def processKLLFile( filename ): with open( filename ) as file: data = file.read() - tokenSequence = tokenize( data ) + try: + tokenSequence = tokenize( data ) + except LexerError as e: + print ( "{0} Tokenization error in '{1}' - {2}".format( ERROR, filename, e ) ) + sys.exit( 1 ) #print ( pformat( tokenSequence ) ) # Display tokenization try: tree = parse( tokenSequence ) except NoParseError as e: - print("Error parsing %s. %s" % (filename, e.msg), file=sys.stderr) - sys.exit(1) + print ( "{0} Parsing error in '{1}' - {2}".format( ERROR, filename, e ) ) + sys.exit( 1 ) ### Misc Utility Functions ###