[antlr-interest] case sensitivity for ANTLR v3 lexers

Terence Parr parrt at cs.usfca.edu
Tue May 16 23:24:00 PDT 2006


On May 16, 2006, at 7:30 PM, Don Caton wrote:
> Doesn't look any different than v2.  The problem is not here, the  
> problem is
> in the exception classes.

They have no strings except place holder toStrings for debugging.   
All the meat is here in BaseRecognizer:

     public static void displayRecognitionError(String name,
                                                Object[] tokenNames,
                                                RecognitionException e)
     {
           System.err.print(getRuleInvocationStack(e, name)+
                          ": line "+e.line+":"+e.charPositionInLine+"  
");
	...

override that i guess...ooops.

>> If you override reportError you are golden...no strings...
>
> No, I think you're missing the point (or maybe the Java  
> implementation is
> completely different than C++).
>
> The default reportError() does nothing more than call re.toString()  
> and send
> it to cerr.  It makes sense to override it if you want to direct  
> the error
> message to a destination other than cerr.

uh, that's not what the code says that I sent.  it clearly calls the  
display function, right?

> It doesn't make any sense to override reportError() to change the  
> behavior
> of RecognitionException.  Why should reportError() have any  
> knowledge of the
> implementation details of any of the exception classes?

it doesn't...per the code I sent.

> All I'm saying is that the exception subclasses should not have  
> hard-coded
> strings,

they are no longer this way. :)

> they should call some sort of helper or utility method to obtain
> the string.

per the code I sent.  yes.

>   A simple example is in NoViableAltForCharException's
> toString(), which is:
>
>    return string("unexpected char: ")+charName(foundChar);
>
> This is bad.  It ought to be something like:
>
>    sprintf( buffer, getString( ANTLR_UNEXPECTED_CHAR ), charName 
> ( foundChar
> ) );
>    return string( buffer );

I think it's easy enough to override the display function to do just  
what you need. :) Presumably this would load a message from a  
template file for a specific app just like you're asking for. :)

Ter


More information about the antlr-interest mailing list