Is there any reliable way with antlr4 API to get Token start character position relative to the beginning of file, not line? After doing some research the only way I found is to use some custom implementation of IntStream, that does not treat '\n' as line terminators, but perhaps I'm missing some easier way? I'm using Visitor API if it matters.
The application I'm working on parses source files and provides insertion coordinates for another application that uses provided coordinates to insert additional code. It would be much more convenient if that another application got symbol position in file, rather than line:positionInLine pair.
Token.getStartIndex()
, because it is marked as optional in the Token javadoc, and didn't knew about theTerminalNode
way. Guess I'll just give it a try withgetStartIndex()
. – Whip