[antlr-interest] I want to throw an exception and stop parse, please!

Kevin Chen bestgembler at hotmail.com
Sun May 24 23:18:47 PDT 2009


Thanks for your reply!

I cannot find "mismatch" method in "org.antlr.runtime.Parser" and "org.antlr.runtime.BaseRecognizer" both, just found "recoverFromMismatchedSet" method in "org.antlr.runtime.BaseRecognizer".      :-)

My antlr runtime version is 3.1.3.

Thanks a lot!     :-)









>Two methods of parser (mismatch and 
recoverFromMismatchedSet) are responsible for auto-recovery and showing >error 
messages.> 
>If you want to throw an exception and exit right on the 
first error you need to override these methods and >just throw the exception 
instead of handling it.> 
>Something like this:> 
>@members {
>protected void mismatch(IntStream input, int ttype, BitSet 
follow)
>throws RecognitionException
>{
>throw new 
MismatchedTokenException(ttype, input);
>}
>>public void recoverFromMismatchedSet(IntStream input, 
RecognitionException e, BitSet follow)>>throws 
RecognitionException>>{>>throw e;>>}>
>}
> 
>Cheers, Indhu











_________________________________________________________________
Windows Live™: Keep your life in sync. Check it out!
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090525/369fb340/attachment.html 


More information about the antlr-interest mailing list