[antlr-interest] how to tweak the handling of include files

siemsen at ucar.edu siemsen at ucar.edu
Mon Jan 7 08:48:27 PST 2008


Thomas Brandon provided a working answer to this.   Moving the call  
to "emit" after the call to "reset" allows the emitted token to be  
seen by the parser.  Thanks Thomas!

-- Pete

On Jan 6, 2008, at 7:37 PM, siemsen at ucar.edu wrote:

> I'm parsing some "include" statements using the code suggested by  
> the ANTLR Wiki page entitled "How do I implement include files?" at  
> http://www.antlr.org/wiki/pages/viewpage.action?pageId=557057.  It  
> works but for one thing.  The code executes in the lexer, and  
> quietly replaces the include statement with tokens representing the  
> contents of the include file.  This is expocted, but no tokens  
> representing the include statement itself get into the token  
> stream.  The include statement itself is "lost".
>
> Is there any way for the parser to see the name of the include  
> file?  I want it for a problem specific to the files I'm parsing,  
> but I can imagine a more general case where the the parser might  
> want to report the name of the include file in error messages or  
> something.
>
> I tried inserting an "emit" call into the code to explicitly emit a  
> token containing the file name, but the following calls to  
> setCharStream and reset eat the resulting token, so the parser  
> never sees it.
>
> -- Pete
>



More information about the antlr-interest mailing list