I encountered a situation where my JavaCC parser does not simply throw
a ParseException on unwanted/undeclared input, but it throws a
TokenMgrError (which, simply put, was not good for the rest of the
application). This happens when the input ends in \ , i.e. a
backslash.
Solution is easy: transform the exceptional condition "parser does not
like token" into an exceptional condition "parser does not like input",
i.e. catch Error and rethrow ParseException. However, I think this
should not be necessary. When JavaCC's parser encounters an undeclared
Token (I had no TOKEN rule involving \ ), it should simply throw a
ParseException, because what's the difference between having a Token
that does not match any possible grammar production, and having a
Character that does not match any possible TOKEN rule? To me both
kinds of error look similar, i.e. they should be in the same 'class'
(like ParseException).


|