I have an antlr4.7
grammar like this, where all sub rules are labeled.
date_expr
: attr op=( '+' | '-' ) dt_interval=ISO8601_INTERVAL
#dateexpr_Op
| DATETIME_NAME
#dateexpr_Named
| d=( DATETIME_LITERAL | DATE_LITERAL | TIME_LITERAL )
#dateexpr_Literal
| attr
#dateexpr_Attr
| '(' date_expr ')'
#dateexpr_Paren
;
I would like to annotate the tree when a date_expr
rule completes. However, looking at the generated listener class, I see no exitDate_expr
. How can I add this? Or, do I have to use a visitor interface for it. I am not much familiar with grammar tools.
Thanks.
To achieve
beforeAllLabledAlts
andafterAllLabledAlts
visit points, wrap the labeled alt rule in a singleton rule:The ANTLR tool will then generate the listener interface (and/or visitor interface) with
AnyDateContext
onEntry
andonExit
methods.