antlr4 - Getting token start character position relative to the beginning of file -
is there reliable way antlr4 api token start character position relative beginning of file, not line? after doing research way found use custom implementation of intstream, not treat '\n' line terminators, perhaps i'm missing easier way? i'm using visitor api if matters.
the application i'm working on parses source files , provides insertion coordinates application uses provided coordinates insert additional code. more convenient if application got symbol position in file, rather line:positioninline pair.
you can use of following, depending on whether have token
or terminalnode
.
token.getstartindex()
edit: return token index, not character position.terminalnode.getsourceinterval()
.a
terminalnode.getsymbol()
.getstartindex()
Comments
Post a Comment