Mercurial > louis > kiibohd-kll
changeset 67:27a8e6a81fa7
Adding better error messages for Tokenization and Parsing
- More msg, less stack trace
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Mon, 12 Oct 2015 22:42:32 -0700 |
parents | 0962ed6bdc5f |
children | e436d20057a3 |
files | kll.py |
diffstat | 1 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/kll.py Mon Oct 12 18:56:21 2015 -0700 +++ b/kll.py Mon Oct 12 22:42:32 2015 -0700 @@ -683,13 +683,17 @@ 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 ###