[antlr-interest] How to feedback to users the string expected on MismatchedTokenException

Benjamin Niemann pink at odahoda.de
Tue Jun 12 13:27:15 PDT 2007


John B. Brodie wrote:

>>In the java runtime, when the antlr 3.0 encounter a mismatched token
>>parser error it issue a message like:
>>
>>"line 1:7 mismatched input 'update' expecting SELECT"
>>
>>What this basically means is that parser got an 'update' string while
>>expecting the SELECT token.
>>
>>The problem is that SELECT token is defined as:
>>...snipped...
>>And that I should prefer to respond to such erroneous input with the
>>string that is expected ('select') and not with the token type (SELECT).
>>...snipped...
> 
> Does the tokenNames array published by the generated parser help you
> to build your own error reporting method to solve this?

That's where the default error handler is getting the 'SELECT' from ;)

I'd say the OP should override the getErrorMessage() method and use an own
mapping from token types to descriptive names instead of tokenNames.

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/



More information about the antlr-interest mailing list