]> git.donarmstrong.com Git - kiibohd-kll.git/commitdiff
Adding better error messages for Tokenization and Parsing
authorJacob Alexander <haata@kiibohd.com>
Tue, 13 Oct 2015 05:42:32 +0000 (22:42 -0700)
committerJacob Alexander <haata@kiibohd.com>
Tue, 13 Oct 2015 05:42:32 +0000 (22:42 -0700)
 - More msg, less stack trace

kll.py

diff --git a/kll.py b/kll.py
index c4386e0bf7cb34bbadfb38da0e7d52dea37602e0..cae70f8694ec139d94dc62cc11833a1e9fe104de 100755 (executable)
--- 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 ###