How to get line number in ANTLR3 TreeParser

I am trying to get the line number in the grammar of the ANTLR3 tree (the code generated by ANTLR3 belongs to the TreeParser class).
Google just found solutions for ANTLR2 that, unfortunately, do not work in ANTLR3.
for clarification, I'm trying to access the line number in the .g file itself.

I think I need to rewrite the method or extend the class, I just don't know which one.

tnx in advance

Edit: I have to indicate that I am using java api

+3
source share
2 answers

it would seem that I was looking for a way far. to access the line number of the rule in Tree Grammar, and in the .g file just ask token.getLine (); (internally this is CommonTree)

eg,

: ID '=' {int line = $ID.getLine()};//$ID CommonTree

+3
+1

Source: https://habr.com/ru/post/1784184/


All Articles