I'm creating an antlr4 grammar for a language that has several possibilities for variable declaration prefixes, e.g. a variable declaration could be any of the following:
IDENTIFIER
PREFIX1 IDENTIFIER
PREFIX2 IDENTIFIER
PREFIX1 PREFIX2 IDENTIFIER
PREFIX2 PREFIX1 IDENTIFIER
and the prefixes are optional and can be in any order, but at most one of each.
If I have a rule:
var_declaration: (PREFIX1 | PREFIX2)? IDENTIFIER;
then that will handle none or a single prefix of either type. How do I handle none, one or both in either order but prevent two prefixes the same?