[antlr-interest] Re: Request enhancement ANTLR

Silvain Piree s.piree at enneya.com
Mon Jun 24 23:42:24 PDT 2002


Ter,

> > Why not implement setFilename/getFilename in class Token 
> > exactly like setText/getText are currently?
> 
> Makes sense to me...adding to list.

That would indeed be the best solution .... with one problem: 
it's not compatible with current implementations.

The problem again is the error message (NoViableAlt) raised
by the parser. The generated parser uses the getFilename()
method of the Parser class to determine the current filename.

When registering the filename with the token, the parser
class would have to get the filename from the token (e.g.
LT(1).getFilename() ). 

But that will only work when getFilename() is implemented
for Token. Otherwise it will fail ....

That's why I suggested to define another getFilename()
method in the Parser class where you pass the current 
token as parameter. Then the implementer can decide
where to get the current filename.

An alternative would be something like:
    
    throw new NoViableAltException(..., 
        LT(1).getFilename() != null? 
            LT(1).getFilename() : getFilename() );

Silvain




 

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



More information about the antlr-interest mailing list