Reputation: 306
Is there a way in ANTLR 4 to be able to return the line number of the the last character for the current token ?
I referred Antlr, get last line from token but that would be specific to a rule. I wanted something more generic but couldn't find what would suit me in the ANTLR API.
Upvotes: 2
Views: 1048
Reputation: 99949
There is no direct way to get this information. However, if you don't have any -> skip
commands in your lexer you can derive it from the following token.
Suppose token b
follows token a
. If b.getCharPositionInLine()==0
, the last character of a
is on line b.getLine()-1
. Otherwise, the last character of a
is on line b.getLine()
.
Upvotes: 4