I want the information from a syntactic predicate but don't want to select an alternative.
Created May 4, 2012
Monty Zukowski
You can't do it, but you can probably work around it. I wanted to know if a case block had any labels, if so the translation was slightly different, so I just wanted to set a flag.
caseBlock { hasLabel = false; } : (#("begin" (~(LABEL))* LABEL))=> {hasLabel = true;} #("begin" rest of rule here... ;
ANTLR complains because you aren't using the syntactic predicate to choose an alternative. What I did was made a seperate rule that does the work of transforming the case block and then passed in a parameter based on the syntactic predicate.
caseBlock : (#("begin" (~(LABEL))* LABEL))=> caseBlockTransform[true] | caseBlockTransform[false] ;