If the input to a grako/tatsu generated parser has a syntax error, such as 3 + / 3
to the calc.py examples, one gets a long list of Python calling sequences in addition to the relevant
3 + / 3
^
I could use try
- except
constructions but then I lose the relevant part of the error message as well.
I would like to use grako/tatsu to parse grammar rules for a rule compiler and I appreciate the possibility of separating the syntax and semantics in a clean way. The users would be quite annoyed of the excessive error messages. Is there a way for clean error messages?
This should be the same as in any Python program. If you let the exception escape main()
, then a stack trace will be printed. Instead, you can write:
try:
do_parse()
except Exception as e:
print(str(e))