[antlr-interest] I want to throw an exception and stop parse, please!
Kevin Chen
bestgembler at hotmail.com
Sat May 30 23:21:19 PDT 2009
thanks for your reply!
But, there's no throws in original recover method:
public void recover(IntStream input, RecognitionException re)
Thus, I can't throw an exception in overriding recover method. :-)
Thanks a lot!
THE
POWER
OF
JAVA
>Ah, forgot. Things changed after the book was written. I
guess you have to override the following two methods from
>BaseRecognizer
>
>void recover (IntStream input, RecognitionException
re)
>Object recoverFromMismatchedSet (IntStream input,
RecognitionException e, BitSet follow) throws
RecognitionException
>Cheers, Indhu
/*******************************************************/
/*******************************************************/
>>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
_________________________________________________________________
Show them the way! Add maps and directions to your party invites.
http://www.microsoft.com/windows/windowslive/products/events.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090531/88d32203/attachment.html
More information about the antlr-interest
mailing list