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

Indhu Bharathi indhu.b at s7software.com
Sun May 24 22:02:21 PDT 2009


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

  ----- Original Message ----- 
  From: Kevin Chen 
  To: antlr-interest at antlr.org 
  Sent: Monday, May 25, 2009 7:26 AM
  Subject: [antlr-interest] I want to throw an exception and stop parse,please!


  I want to throw an exception and stop parse when get errors during parsing,
  I don't want to display the errors, I need to throw an exception to client.

  Is there anyone can help me, please?

  Thanks a lot!        :-)

  THE
       POWER
               OF
                  JAVA




------------------------------------------------------------------------------
  check out the rest of the Windows Live™. More than mail–Windows Live™ goes way beyond your inbox. More than messages 


------------------------------------------------------------------------------



  List: http://www.antlr.org/mailman/listinfo/antlr-interest
  Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090525/209f1a92/attachment.html 


More information about the antlr-interest mailing list