[antlr-interest] potentially stupid question

Jim Crafton jim.crafton at gmail.com
Wed Oct 19 16:57:27 PDT 2005


Martin,

> > How does one get the exact character position at a given moment in a
> > parser? Is this even possible?
>
> Well, there is no such thing - your code in the parser is in a given
> rule, but line numbers/cols are related to single tokens, so you have to
> specify of what you want to get the line number. You can get the exact
> character position of a given AST/Token you have, e.g.:
>
> rule: t:TOKEN { t.getLine(); }

Well I do get that. As you mentioned, I have subclassed the AST to my
own custom class.
What I also need is the offset, from the beginning of the input
stream/buffer. I noticed a mark() method in the Parser base class, but
I'm not sure if this is what I want to use.

Cheers,

Jim


More information about the antlr-interest mailing list