[antlr-interest] exceptions in the lexer

Terence Parr parrt at cs.usfca.edu
Tue Dec 7 11:12:39 PST 2004



On Dec 6, 2004, at 5:58 PM, Don Caton wrote:
>> Ok, generated nextToken looks like it catches and rethrows:
>>
>>              catch (RecognitionException e) {
>>                  throw new TokenStreamRecognitionException(e);
>>              }
>>
>
> Ter:
>
> What's the point of this?  TokenStreamRecognitionException simply 
> wraps a
> RecognitionException and does not appear to add any useful 
> functionality.

I believe I wanted TokenStream.nextToken() to be independent of the 
normal recognition errors etc... found in antlr's lexers; might be 
using another tool.

public interface TokenStream {
     public Token nextToken() throws TokenStreamException;
}

> In fact, it removes functionality by preventing access to the original
> RecognitionException because it is stored in a private member of
> TokenStreamRecognitionException.

Ack!  Heh, wait, looks public:

public class TokenStreamRecognitionException extends 
TokenStreamException {
     public RecognitionException recog;
....
}

> This makes it impossible to retrieve the line and column information 
> from
> the RecognitionException.  Which in turn makes it impossible to display
> anything other than the hard coded error message using the toString() 
> method
> provided by TokenStreamRecognitionException.
>
> TokenStreamRecognitionException itself is a do-nothing subclass of
> TokenStreamException, which in turn is a do-nothing subclass of
> AntlrException.  Why the complexity?  Are there some 
> backwards-compatibility
> reasons for this?

Do nothing, but mean something ;)

> At the risk of breaking existing code, I'd like to see a simplified 
> error
> reporting mechanism in 2.7.5 where a single exception type is thrown,
> perhaps with a "reason" code or enumeration.  Then we only need to 
> handle a
> single exception type.  Or at least, have every exception inherit from 
> a
> base class, don't wrap one exception up in another.

Good thoughts, Don.  I'm afraid of breaking stuff for 2.7.5 though.  
This will be my next topic (error recovery) for 3.0 as I've got 3.0 
good enough to handle Java parsing/lexing now.

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list