--- antlr3-3.5.3/tool/src/main/antlr3/org/antlr/grammar/v3/CodeGenTreeWalker.g 2024-09-21 12:35:02.440474037 +0200 +++ antlr3-3.5.3/tool/src/main/antlr3/org/antlr/grammar/v3/CodeGenTreeWalker.g 2024-09-21 12:52:37.133715512 +0200 @@ -53,9 +53,10 @@ import org.antlr.tool.*; import org.antlr.codegen.*; -import java.util.HashSet; +import java.util.TreeSet; import java.util.Set; import java.util.Collection; +import java.util.Collections; import org.antlr.runtime.BitSet; import org.antlr.runtime.DFA; import org.stringtemplate.v4.ST; @@ -73,7 +74,7 @@ protected ST currentBlockST = null; protected boolean currentAltHasASTRewrite = false; protected int rewriteTreeNestingLevel = 0; -protected HashSet rewriteRuleRefs = null; +protected TreeSet rewriteRuleRefs = null; public String getCurrentRuleName() { return currentRuleName; @@ -284,6 +285,7 @@ } labels.add( label ); } + Collections.sort(labels); // ensure reproducible order return labels; } @@ -1202,18 +1204,18 @@ $code.add("rewriteBlockLevel", OUTER_REWRITE_NESTING_LEVEL); $code.add("referencedElementsDeep", getTokenTypesAsTargetLabels($start.rewriteRefsDeep)); - Set tokenLabels = - grammar.getLabels($start.rewriteRefsDeep, Grammar.TOKEN_LABEL); - Set tokenListLabels = - grammar.getLabels($start.rewriteRefsDeep, Grammar.TOKEN_LIST_LABEL); - Set ruleLabels = - grammar.getLabels($start.rewriteRefsDeep, Grammar.RULE_LABEL); - Set ruleListLabels = - grammar.getLabels($start.rewriteRefsDeep, Grammar.RULE_LIST_LABEL); - Set wildcardLabels = - grammar.getLabels($start.rewriteRefsDeep, Grammar.WILDCARD_TREE_LABEL); - Set wildcardListLabels = - grammar.getLabels($start.rewriteRefsDeep, Grammar.WILDCARD_TREE_LIST_LABEL); + TreeSet tokenLabels = + new TreeSet(grammar.getLabels($start.rewriteRefsDeep, Grammar.TOKEN_LABEL)); + TreeSet tokenListLabels = + new TreeSet(grammar.getLabels($start.rewriteRefsDeep, Grammar.TOKEN_LIST_LABEL)); + TreeSet ruleLabels = + new TreeSet(grammar.getLabels($start.rewriteRefsDeep, Grammar.RULE_LABEL)); + TreeSet ruleListLabels = + new TreeSet(grammar.getLabels($start.rewriteRefsDeep, Grammar.RULE_LIST_LABEL)); + TreeSet wildcardLabels = + new TreeSet(grammar.getLabels($start.rewriteRefsDeep, Grammar.WILDCARD_TREE_LABEL)); + TreeSet wildcardListLabels = + new TreeSet(grammar.getLabels($start.rewriteRefsDeep, Grammar.WILDCARD_TREE_LIST_LABEL)); // just in case they ref $r for "previous value", make a stream // from retval.tree ST retvalST = templates.getInstanceOf("prevRuleRootRef"); @@ -1236,7 +1238,7 @@ } : ^( REWRITES ( - {rewriteRuleRefs = new HashSet();} + {rewriteRuleRefs = new TreeSet();} ^( r=REWRITE (pred=SEMPRED)? alt=rewrite_alternative) { rewriteBlockNestingLevel = OUTER_REWRITE_NESTING_LEVEL;