I just ran across this rather messy declaration in an ANTLR 4 grammar:
func_arg
: arg_class param_name? func_type
| param_name arg_class? func_type
| func_type
;
If you look at that and think about it for a second, the idea it's really trying to get across is (pseudocode):
func_arg
: MULTIPLE_IN_ANY_ORDER(arg_class?, param_name?) func_type
;
If there are more than two options, declaring it in this style could lead to a combinatorial explosion of sub-rules. Is there any simpler way to declare the concept of "multiple options in any order"?
No, there is not.
Of course, you can make it a bit more readable by doing something like this:
But there is no ANTLR syntax for "optionally match either A or B only once, in no particular order".