Reputation: 41
public void enterStatus(Parser.Context ctx)
{
}
Parser.Context ctx doesn't have the method like getLinuNumber().How could I get the parser line number?
Upvotes: 0
Views: 664
Reputation: 4434
You can use ctx.getStart().getLine()
public Token getStart() Get the initial token in this context. Note that the range from start to stop is inclusive, so for rules that do not consume anything (for example, zero length or error productions) this token may exceed stop
From the doc: http://www.antlr.org/api/Java/org/antlr/v4/runtime/ParserRuleContext.html#getStart()
and
int getLine() The line number on which the 1st character of this token was matched, line=1..n
from: http://www.antlr.org/api/Java/org/antlr/v4/runtime/Token.html#getLine()
Upvotes: 1