[antlr-interest] Manually raising recognition error

Mike Lischke mike at lischke-online.de
Wed Jul 25 09:20:50 PDT 2012


Hey Jim,

thanks for your detailed answer.

> Next, you should be overriding displayRecognitionError and unlike the built in sample, you are usually better off adding error messages to a collection that is used for the whole run of your tool chain. The lever adds messages if it needs to, then the parser, then your tree walkers and so on. You then report all the errors at the end. 

Sure, this is already the case.

> 
> You create some functions to form these messages from raw information, tokens, tree nodes and anything else you need. 
> 
> Now in your empty alt, you just call one of the methods
> 
> {
>  error(E_MISSING_THINGY, line, col);
> }
> 
> And it will be duly reported. The built in mechanism isn't called but you don't need it here. 


My hope was that there's something I can just call (like { report_missing_token(TOKEN); } and the exception is created like those produced by the parser itself (and the normal error reporting kicks in). I can of course mimic the exception creation code in the parser, but thought there would be a simpler way.

Thanks again for all the help. Much appreciated.

Mike
-- 
www.soft-gems.net




More information about the antlr-interest mailing list