For some reason, I misread your suggestion as that I needed to override
recoverFromMismatchedSet.
After looking at the source for BaseRecognizer, and re-reading your suggestion,
I realized my error.
I added this to my grammar:
protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet
follow) throws RecognitionException{
throw new MissingTokenException(ttype, input, null);
}
I guess the Definitive Guide was written before MissingTokenException, because
it only covers overriding recoverFromMismatchedSet...
I'm not sure if passing null into MissingTokenException could cause any
problems, but this seems to work fine. I basically just want to make sure I
throw some type of RecognitionException. Now AntlrWorks also terminates the
parsing when I debug, as expect, rather than placing MissingTokenException into
the parse tree. Thanks for your help.
-geoff
"When I do good, I feel good. When I do bad, I feel bad. That's my religion."
-A. Lincoln
________________________________
From: Terence Parr <[EMAIL PROTECTED]>
To: Geoff hendrey <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
Sent: Thursday, October 30, 2008 10:55:51 AM
Subject: Re: [antlr-interest] (POST THIRD TIME) how to bail on
MissingTokenException
Missing comes from the automatic in-line error recovery. You need to override
protected Object recoverFromMismatchedToken(IntStream input, int ttype,
BitSet follow)
just throw an exception. make sure you don't catch anything later... this
should be in the book under how to make the parser bail on first exception.
Ter
On Oct 29, 2008, at 9:25 PM, Geoff hendrey wrote:
> Hi,
>
> thanks for the response, I really appreciate it. Do you mean "mismatch" or
> "missing"? Just to be sure we are on the same page, I am getting a
> MissingTokenException, not MismatchedTokenException. My grammar file already
> deals with MismatchedTokenException, nd I have no problem with that. I need
> to find out how to abort parsing on MISSINGTokenException.
>
> Thanks, and sorry for using caps and bold. Just wanted to make sure we are on
> the same page.
>
> -geoff
>
>
>
> From: Terence Parr <[EMAIL PROTECTED]>
> To: Geoff hendrey <[EMAIL PROTECTED]>
> Cc: [EMAIL PROTECTED]
> Sent: Wednesday, October 29, 2008 12:58:28 PM
> Subject: Re: [antlr-interest] (POST THIRD TIME) how to bail on
> MissingTokenException
>
> Hi Geoff, isn't there something in the source code that says " override me if
> you want to turn off automatic in-line error recovery for mismatch token"?
> Ter
>
> List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address