user2592325
user2592325

Reputation: 63

Getting token start character position relative to the beginning of file

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.

Upvotes: 6

Views: 1878

Answers (1)

Sam Harwell
Sam Harwell

Reputation: 99949

You can use any of the following, depending on whether you have a Token or a TerminalNode.

Upvotes: 6

Related Questions