consider the following lexer rules in ANTLR4:
ID: [a-z]+;
INT: [0-9]+;
ARRAY: ID '[' INT ']';
Is it possible in a tree walking scenario where I have access to ctx.ARRAY()
(where ctx
is a subclass of ParserRuleContext
that was generated out of a parser rule) to get the text representation of the lexer rules ID
and INT
?
I currently fetch the whole text representation with ctx.ARRAY().getText()
and parse the contents of ID
and INT
using regexes and was just wondering if there is a 'cleaner' out of the box solution ANTLR provides.
Note: Because of external dependencies making ARRAY
a parser rule is not an option.
Thanks in advance for meaningful answers.