[antlr-interest] retrieving the length of a production match
Adrian Herscu
bmf1972 at fastmail.fm
Wed Aug 22 01:59:40 PDT 2007
Hmmm... It means that I must touch all the parsing rules. Am I right?
(hoped that there is some trick... just a one liner...)
Regarding the "$rulelabel.start and $rulelabel.stop"... I haven't
specified in my question that I am still using ANTLR 2.7.6. I am looking
at the 3.0 API and now I am discovering these... Anything similar in 2.7.6?
Adrian.
Jim Idle wrote:
> Just refer to $start and $stop in a rule or more likely for you
> $rulelabel.start and $rulelabel.stop.
>
> These are the actual tokens, which will give you the offset of their
> text start in your input stream, which will give you the length in terms
> of the input text as well as the start point.
>
> Also, if you determine that there is a semantic error (say an incorrect
> cast or something), then you presumably know the tokens involved and can
> use their text offsets to determine the length of the text that
> indicates the error?
>
> Jim
>
More information about the antlr-interest
mailing list