Assume there is a rule about 'type'. It is either a predefined type (referred by IDENTIFIER) or a typeDescriptor.
type
: IDENTIFIER
| typeDescriptor
;
In my program, I have got an instance of typeContext 'ctx'. How do I know if the path IDENTIFIER is chosen, or typeDescriptor is chosen.
I recognise one way which is to test ctx.IDENTIFIER() == null
and ctx.typeDescriptor() == null
. But it seems not working very well when there are a lot more alternatives. Is there a way to return an index to indicate which rule is chosen? Thanks.