[antlr-interest] Getting the offset/Overloading Constructors

Warren Wong wawong at bea.com
Mon Oct 17 14:26:04 PDT 2005


Hi,

 

I'm trying to get the offset of the current token in the token stream
provided by ANTLR. However, since we can only get the line and column #
of the current token and the next token, I can't actually figure out
where I am in the input buffer since parts of the parser changes the
length of the text. For example, 

{{ 

x 

}} may get parsed as { x } (three tokens). The offsets are 0,3,5.
However, the ANTLR tokens only keep track of lines & columns, so I'll
get back line 1, col 1, line 2, col 1, line 3, col 1, which can't be
easily translated to offsets since I don't know what col line 1 ends up.

 

I've tried to solve this problem by overloading CharScanner (the token
stream I'm using). However, since I'm muxing multiple lexers, I can't
keep track of the offset in this subclass. Therefore, I tried to
overload the LexerSharedInputState as well to keep track of the offset.
However, the subclass of this subclass (generated by the .g file) does
not allow me to create my own constructors (which ANTLR generates
automatically). This leaves me with the very ugly option of having to
create a separate constructor for my overloaded LexerSharedInputState
type but still having the automatically generated constructor for ANTLR
sending in a LexerSharedInputState, which the subclass of CharScanner
still has to support (but has to report an error). 

 

What's the proper way of resolving these issues?

 

Thanks,

Warren

________________________________________________________________________________
BEAWorld 2005: coming to a city near you.  Everything you need for SOA and enterprise infrastructure success.

 
Register now at http://www.bea.com/4beaworld

 
London 11-12 Oct| Paris13-14 Oct| Prague18-19 Oct |Tokyo 25-26 Oct| Beijing 7-8 Dec
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20051017/94d30d57/attachment.html


More information about the antlr-interest mailing list