Output listener and visitor methods in grammar order

This commit is contained in:
Sam Harwell 2014-09-28 16:02:21 -05:00
parent 08ed19078d
commit 2777bc4d26
3 changed files with 10 additions and 9 deletions

View File

@ -36,8 +36,8 @@ import org.antlr.v4.tool.Rule;
import org.antlr.v4.tool.ast.ActionAST; import org.antlr.v4.tool.ast.ActionAST;
import org.antlr.v4.tool.ast.AltAST; import org.antlr.v4.tool.ast.AltAST;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.HashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -52,13 +52,13 @@ public class ListenerFile extends OutputFile {
/** /**
* The names of all listener contexts. * The names of all listener contexts.
*/ */
public Set<String> listenerNames = new HashSet<String>(); public Set<String> listenerNames = new LinkedHashSet<String>();
/** /**
* For listener contexts created for a labeled outer alternative, maps from * For listener contexts created for a labeled outer alternative, maps from
* a listener context name to the name of the rule which defines the * a listener context name to the name of the rule which defines the
* context. * context.
*/ */
public Map<String, String> listenerLabelRuleNames = new HashMap<String, String>(); public Map<String, String> listenerLabelRuleNames = new LinkedHashMap<String, String>();
@ModelElement public Action header; @ModelElement public Action header;

View File

@ -36,8 +36,8 @@ import org.antlr.v4.tool.Rule;
import org.antlr.v4.tool.ast.ActionAST; import org.antlr.v4.tool.ast.ActionAST;
import org.antlr.v4.tool.ast.AltAST; import org.antlr.v4.tool.ast.AltAST;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.HashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -49,13 +49,13 @@ public class VisitorFile extends OutputFile {
/** /**
* The names of all rule contexts which may need to be visited. * The names of all rule contexts which may need to be visited.
*/ */
public Set<String> visitorNames = new HashSet<String>(); public Set<String> visitorNames = new LinkedHashSet<String>();
/** /**
* For rule contexts created for a labeled outer alternative, maps from * For rule contexts created for a labeled outer alternative, maps from
* a listener context name to the name of the rule which defines the * a listener context name to the name of the rule which defines the
* context. * context.
*/ */
public Map<String, String> visitorLabelRuleNames = new HashMap<String, String>(); public Map<String, String> visitorLabelRuleNames = new LinkedHashMap<String, String>();
@ModelElement public Action header; @ModelElement public Action header;

View File

@ -41,6 +41,7 @@ import org.stringtemplate.v4.misc.MultiMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -212,7 +213,7 @@ public class Rule implements AttributeResolver {
* this label. Unlabeled alternatives are not included in the result. * this label. Unlabeled alternatives are not included in the result.
*/ */
public Map<String, List<Pair<Integer, AltAST>>> getAltLabels() { public Map<String, List<Pair<Integer, AltAST>>> getAltLabels() {
Map<String, List<Pair<Integer, AltAST>>> labels = new HashMap<String, List<Pair<Integer, AltAST>>>(); Map<String, List<Pair<Integer, AltAST>>> labels = new LinkedHashMap<String, List<Pair<Integer, AltAST>>>();
for (int i=1; i<=numberOfAlts; i++) { for (int i=1; i<=numberOfAlts; i++) {
GrammarAST altLabel = alt[i].ast.altLabel; GrammarAST altLabel = alt[i].ast.altLabel;
if ( altLabel!=null ) { if ( altLabel!=null ) {