diff --git a/tool/src/org/antlr/v4/codegen/model/ElementFrequenciesVisitor.java b/tool/src/org/antlr/v4/codegen/model/ElementFrequenciesVisitor.java index 94deddbac..f61ce8abb 100644 --- a/tool/src/org/antlr/v4/codegen/model/ElementFrequenciesVisitor.java +++ b/tool/src/org/antlr/v4/codegen/model/ElementFrequenciesVisitor.java @@ -185,6 +185,14 @@ protected void enterBlockSet(GrammarAST tree) { @Override protected void exitBlockSet(GrammarAST tree) { + for (Map.Entry entry : frequencies.peek().entrySet()) { + // This visitor counts a block set as a sequence of elements, not a + // sequence of alternatives of elements. Reset the count back to 1 + // for all items when leaving the set to ensure duplicate entries in + // the set are treated as a maximum of one item. + entry.getValue().v = 1; + } + if (minFrequencies.peek().size() > 1) { // Everything is optional minFrequencies.peek().clear();