Archived
1
0

Adding better error messages for Tokenization and Parsing

- More msg, less stack trace
This commit is contained in:
Jacob Alexander 2015-10-12 22:42:32 -07:00
parent c3ec73860d
commit 25c836048e

8
kll.py
View File

@ -683,13 +683,17 @@ def parse( tokenSequence ):
def processKLLFile( filename ): def processKLLFile( filename ):
with open( filename ) as file: with open( filename ) as file:
data = file.read() data = file.read()
try:
tokenSequence = tokenize( data ) 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 #print ( pformat( tokenSequence ) ) # Display tokenization
try: try:
tree = parse( tokenSequence ) tree = parse( tokenSequence )
except NoParseError as e: except NoParseError as e:
print("Error parsing %s. %s" % (filename, e.msg), file=sys.stderr) print ( "{0} Parsing error in '{1}' - {2}".format( ERROR, filename, e ) )
sys.exit(1) sys.exit( 1 )
### Misc Utility Functions ### ### Misc Utility Functions ###