Hi
I am having precedence issues where I would like to control precisely how the precedence works.
Example
RULE_A
//More specific than RULE_B (Larger)
;
RULE_B
//Some rule also matched by RULE_A
;
RULE_C
: RULE_B
| RULE_A
;
I would like RULE_B to be matched instead of RULE_A and there is no way to differentiate RULE_B from RULE_A
So I tried to use gate predicates as follows
@members { boolean notB = true }
RULE_C
: RULE_B {notB = false}
| {notB}? RULE_A
;
However to my surprise, this didn't work as the action does not get executed.
This would mean the lexing is being done as a side process - only returning the matched rule, and thereafter executing the matched rule's action code. In other words it will run through RULE_B, then run through RULE_A, and return as RULE_A as that rule is more specific.
Is there a way to change the variable 'notB' (execute the action) during the lexing ?