[antlr-interest] How to get the end line / end column of a a token / rule

Jan Finis finis at in.tum.de
Mon Oct 31 10:41:01 PDT 2011


Hello,

I am trying to build a sophisticated AST using ANTLR. The attributes 
.line and .pos allow me to obtain the start line and column position of 
a token. However, is it also possible to get the end line and column? 
(since I want to have that information in the AST as well to allow 
underlining specific rules in the input text)

I think it would be possible by using .text and then counting chars and 
newlines in that string. However, I think text building is costly and 
not the right way to do it.

So what is the "best" way to get the end line and end column of a token 
or rule in ANTLR?

Best regards,
Jan Finis


More information about the antlr-interest mailing list