[antlr-interest] exceptions in the lexer

Don Caton dcaton at shorelinesoftware.com
Mon Dec 6 17:58:44 PST 2004


> -----Original Message-----
> From: Terence Parr [mailto:parrt at cs.usfca.edu] 
> Sent: Monday, December 06, 2004 8:03 PM
> To: antlr-interest at yahoogroups.com
> Subject: Re: [antlr-interest] exceptions in the lexer
> 
> 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.
In fact, it removes functionality by preventing access to the original
RecognitionException because it is stored in a private member of
TokenStreamRecognitionException.

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?

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.

Just my 2 cents.

Don




 
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