I use JAVACC to parse some string defined by a bnf grammar with initial non-terminal G. I would like to catch errors thrown by TokenMgrError. In particular, I want to handle the following two cases:
Currently I'm getting TokenMgrError 's in each of this case instead. I started to modify the generated files (i.e, to change Error to Exception and add appropriate try/catch/throws statements), but I found it to be tedious. In addition, automatic generation of the modified files produced by JAVACC does not work. Is there a smarter way to accomplish this?
You can always eliminate all TokenMgrErrors by including
<*> TOKEN : { <UNEXPECTED: ~[] > }
as the final rule. This pushes all you issues to the grammar level where you can generally deal with them more easily.