Reputation: 918
Given a set S of n rules, I need an antlr4 rule to match any of S subset, in any order :
Example :
Given S = {a,b}, (n = 2) the rule must match
while "a b b", for instance must not match.
It is possible to parse such expression with an antlr4 grammar ? My real set has n = 6, so listing all combinations in the grammar seems not to be a possible choice !
Upvotes: 1
Views: 125
Reputation: 170308
No, you can't define combinations and/or permutations of rules in ANTLR (or any other parser generator that I know).
You could use predicates to accomplish your goal, but that means adding target specific code to your grammar: I'd just parse any a
or b
and validate the structure after parsing (in a custom visitor/listener).
Upvotes: 2