[antlr-interest] tracking token position when original file is pre-processed

Bob Frankel bios.bob.frankel at gmail.com
Wed Jan 6 17:24:20 PST 2010


my language has a simple pre-processor that expands text of the form 
${<env-var-name>} as a first phase of translation; the expanded stream 
is then input to my ANTLRInputStream, where it proceeds onward to the 
lexer/parser in the usual fashion.  said another way, neither the lexer 
nor the parser is aware of the ${...} construct.

needless to say, character-position information (eg., token start/stop) 
are relative to the expanded stream and not the original file; this 
creates an problem, of course, when error indicators are not correctly 
positioned in the original source file (as i'm doing through some editor 
integration inside eclipse).

is there some pattern and/or (simple!) example that illustrates a 
technique for managing this situation; is there some way (say) i might 
embedded the equivalent of #line directives in the expanded stream which 
are then stripped further downstream while adjusting token offsets???




More information about the antlr-interest mailing list