Return the line number of the last character for current token

╄→гoц情女王★ 提交于 2019-12-11 03:34:15

问题


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.


回答1:


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().



来源:https://stackoverflow.com/questions/17487718/return-the-line-number-of-the-last-character-for-current-token

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!