问题
I'm a little confused about how to do this. For example, I have this rule:
stat : '(' expression ')' #ExpressionStatement;
expression1
: expression2 ('==' expression2)* #ValidateExpression1
;
expression2
: literal ('!=' literal)* #ValidateExpression2
;
literal
: ( 'true' | 'false') #literal
;
In this case, if I pass "(true)"
to the parser, how can I just visit VisitListeral()
and return true
instead visiting the entire tree until the match? In the visitor: VisitExpressionStatement()
if I do
Visit(context.expression())
all visitors will be called, until they reach their correspondent, the
VisitLiteral()
In this case, and I would be required to implement all previous visitors with all their infinite validations.
来源:https://stackoverflow.com/questions/62283232/call-correct-antlr-visitors-without-call-all-before-visitors-ultil-match