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

siemsen at ucar.edu siemsen at ucar.edu
Sun Jan 6 18:37:18 PST 2008


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