forked from jasder/antlr
Cleaner initialization of predefined sets and maps
This commit is contained in:
parent
ac55cf3990
commit
227214765d
|
@ -79,29 +79,35 @@ import java.util.Map;
|
|||
|
||||
/** */
|
||||
public class ActionTranslator implements ActionSplitterListener {
|
||||
public static final Map<String, Class<? extends RulePropertyRef>> thisRulePropToModelMap = new HashMap<String, Class<? extends RulePropertyRef>>() {{
|
||||
put("start", ThisRulePropertyRef_start.class);
|
||||
put("stop", ThisRulePropertyRef_stop.class);
|
||||
put("text", ThisRulePropertyRef_text.class);
|
||||
put("ctx", ThisRulePropertyRef_ctx.class);
|
||||
}};
|
||||
public static final Map<String, Class<? extends RulePropertyRef>> thisRulePropToModelMap =
|
||||
new HashMap<String, Class<? extends RulePropertyRef>>();
|
||||
static {
|
||||
thisRulePropToModelMap.put("start", ThisRulePropertyRef_start.class);
|
||||
thisRulePropToModelMap.put("stop", ThisRulePropertyRef_stop.class);
|
||||
thisRulePropToModelMap.put("text", ThisRulePropertyRef_text.class);
|
||||
thisRulePropToModelMap.put("ctx", ThisRulePropertyRef_ctx.class);
|
||||
}
|
||||
|
||||
public static final Map<String, Class<? extends RulePropertyRef>> rulePropToModelMap = new HashMap<String, Class<? extends RulePropertyRef>>() {{
|
||||
put("start", RulePropertyRef_start.class);
|
||||
put("stop", RulePropertyRef_stop.class);
|
||||
put("text", RulePropertyRef_text.class);
|
||||
put("ctx", RulePropertyRef_ctx.class);
|
||||
}};
|
||||
public static final Map<String, Class<? extends RulePropertyRef>> rulePropToModelMap =
|
||||
new HashMap<String, Class<? extends RulePropertyRef>>();
|
||||
static {
|
||||
rulePropToModelMap.put("start", RulePropertyRef_start.class);
|
||||
rulePropToModelMap.put("stop", RulePropertyRef_stop.class);
|
||||
rulePropToModelMap.put("text", RulePropertyRef_text.class);
|
||||
rulePropToModelMap.put("ctx", RulePropertyRef_ctx.class);
|
||||
}
|
||||
|
||||
public static final Map<String, Class<? extends TokenPropertyRef>> tokenPropToModelMap = new HashMap<String, Class<? extends TokenPropertyRef>>() {{
|
||||
put("text", TokenPropertyRef_text.class);
|
||||
put("type", TokenPropertyRef_type.class);
|
||||
put("line", TokenPropertyRef_line.class);
|
||||
put("index", TokenPropertyRef_index.class);
|
||||
put("pos", TokenPropertyRef_pos.class);
|
||||
put("channel", TokenPropertyRef_channel.class);
|
||||
put("int", TokenPropertyRef_int.class);
|
||||
}};
|
||||
public static final Map<String, Class<? extends TokenPropertyRef>> tokenPropToModelMap =
|
||||
new HashMap<String, Class<? extends TokenPropertyRef>>();
|
||||
static {
|
||||
tokenPropToModelMap.put("text", TokenPropertyRef_text.class);
|
||||
tokenPropToModelMap.put("type", TokenPropertyRef_type.class);
|
||||
tokenPropToModelMap.put("line", TokenPropertyRef_line.class);
|
||||
tokenPropToModelMap.put("index", TokenPropertyRef_index.class);
|
||||
tokenPropToModelMap.put("pos", TokenPropertyRef_pos.class);
|
||||
tokenPropToModelMap.put("channel", TokenPropertyRef_channel.class);
|
||||
tokenPropToModelMap.put("int", TokenPropertyRef_int.class);
|
||||
}
|
||||
|
||||
CodeGenerator gen;
|
||||
ActionAST node;
|
||||
|
|
|
@ -52,15 +52,16 @@ public class AttributeDict {
|
|||
* of predefined attributes. I keep this out of the runtime.Token
|
||||
* object to avoid a runtime type leakage.
|
||||
*/
|
||||
public static AttributeDict predefinedTokenDict = new AttributeDict(DictType.TOKEN) {{
|
||||
add(new Attribute("text"));
|
||||
add(new Attribute("type"));
|
||||
add(new Attribute("line"));
|
||||
add(new Attribute("index"));
|
||||
add(new Attribute("pos"));
|
||||
add(new Attribute("channel"));
|
||||
add(new Attribute("int"));
|
||||
}};
|
||||
public static final AttributeDict predefinedTokenDict = new AttributeDict(DictType.TOKEN);
|
||||
static {
|
||||
predefinedTokenDict.add(new Attribute("text"));
|
||||
predefinedTokenDict.add(new Attribute("type"));
|
||||
predefinedTokenDict.add(new Attribute("line"));
|
||||
predefinedTokenDict.add(new Attribute("index"));
|
||||
predefinedTokenDict.add(new Attribute("pos"));
|
||||
predefinedTokenDict.add(new Attribute("channel"));
|
||||
predefinedTokenDict.add(new Attribute("int"));
|
||||
}
|
||||
|
||||
public static enum DictType {
|
||||
ARG, RET, LOCAL, TOKEN,
|
||||
|
|
|
@ -72,50 +72,50 @@ import java.util.Set;
|
|||
public class Grammar implements AttributeResolver {
|
||||
public static final String GRAMMAR_FROM_STRING_NAME = "<string>";
|
||||
|
||||
public static final Set<String> parserOptions = new HashSet<String>() {{
|
||||
add("superClass");
|
||||
add("TokenLabelType");
|
||||
add("tokenVocab");
|
||||
add("language");
|
||||
}};
|
||||
public static final Set<String> parserOptions = new HashSet<String>();
|
||||
static {
|
||||
parserOptions.add("superClass");
|
||||
parserOptions.add("TokenLabelType");
|
||||
parserOptions.add("tokenVocab");
|
||||
parserOptions.add("language");
|
||||
}
|
||||
|
||||
public static final Set<String> lexerOptions = parserOptions;
|
||||
|
||||
public static final Set<String> ruleOptions = new HashSet<String>() {{
|
||||
}};
|
||||
public static final Set<String> ruleOptions = new HashSet<String>();
|
||||
|
||||
public static final Set<String> ParserBlockOptions = new HashSet<String>() {{
|
||||
}};
|
||||
public static final Set<String> ParserBlockOptions = new HashSet<String>();
|
||||
|
||||
public static final Set<String> LexerBlockOptions = new HashSet<String>() {{
|
||||
}};
|
||||
public static final Set<String> LexerBlockOptions = new HashSet<String>();
|
||||
|
||||
/** Legal options for terminal refs like ID<assoc=right> */
|
||||
public static final Set<String> tokenOptions = new HashSet<String>() {{
|
||||
add("assoc");
|
||||
}};
|
||||
public static final Set<String> tokenOptions = new HashSet<String>();
|
||||
static {
|
||||
tokenOptions.add("assoc");
|
||||
}
|
||||
|
||||
public static final Set<String> actionOptions = new HashSet<String>() {{
|
||||
}};
|
||||
public static final Set<String> actionOptions = new HashSet<String>();
|
||||
|
||||
public static final Set<String> semPredOptions = new HashSet<String>() {{
|
||||
add("fail");
|
||||
}};
|
||||
public static final Set<String> semPredOptions = new HashSet<String>();
|
||||
static {
|
||||
semPredOptions.add("fail");
|
||||
}
|
||||
|
||||
public static final Set doNotCopyOptionsToLexer =
|
||||
new HashSet() {{
|
||||
add("superClass");
|
||||
add("TokenLabelType");
|
||||
add("tokenVocab");
|
||||
}};
|
||||
public static final Set<String> doNotCopyOptionsToLexer = new HashSet<String>();
|
||||
static {
|
||||
doNotCopyOptionsToLexer.add("superClass");
|
||||
doNotCopyOptionsToLexer.add("TokenLabelType");
|
||||
doNotCopyOptionsToLexer.add("tokenVocab");
|
||||
}
|
||||
|
||||
public static Map<String, AttributeDict> grammarAndLabelRefTypeToScope =
|
||||
new HashMap<String, AttributeDict>() {{
|
||||
put("parser:RULE_LABEL", Rule.predefinedRulePropertiesDict);
|
||||
put("parser:TOKEN_LABEL", AttributeDict.predefinedTokenDict);
|
||||
put("combined:RULE_LABEL", Rule.predefinedRulePropertiesDict);
|
||||
put("combined:TOKEN_LABEL", AttributeDict.predefinedTokenDict);
|
||||
}};
|
||||
public static final Map<String, AttributeDict> grammarAndLabelRefTypeToScope =
|
||||
new HashMap<String, AttributeDict>();
|
||||
static {
|
||||
grammarAndLabelRefTypeToScope.put("parser:RULE_LABEL", Rule.predefinedRulePropertiesDict);
|
||||
grammarAndLabelRefTypeToScope.put("parser:TOKEN_LABEL", AttributeDict.predefinedTokenDict);
|
||||
grammarAndLabelRefTypeToScope.put("combined:RULE_LABEL", Rule.predefinedRulePropertiesDict);
|
||||
grammarAndLabelRefTypeToScope.put("combined:TOKEN_LABEL", AttributeDict.predefinedTokenDict);
|
||||
}
|
||||
|
||||
public String name;
|
||||
public GrammarRootAST ast;
|
||||
|
|
|
@ -51,26 +51,28 @@ public class Rule implements AttributeResolver {
|
|||
*
|
||||
* These must be consistent with ActionTranslator.rulePropToModelMap, ...
|
||||
*/
|
||||
public static AttributeDict predefinedRulePropertiesDict =
|
||||
new AttributeDict(AttributeDict.DictType.PREDEFINED_RULE) {{
|
||||
add(new Attribute("text"));
|
||||
add(new Attribute("start"));
|
||||
add(new Attribute("stop"));
|
||||
add(new Attribute("ctx"));
|
||||
}};
|
||||
public static final AttributeDict predefinedRulePropertiesDict =
|
||||
new AttributeDict(AttributeDict.DictType.PREDEFINED_RULE);
|
||||
static {
|
||||
predefinedRulePropertiesDict.add(new Attribute("text"));
|
||||
predefinedRulePropertiesDict.add(new Attribute("start"));
|
||||
predefinedRulePropertiesDict.add(new Attribute("stop"));
|
||||
predefinedRulePropertiesDict.add(new Attribute("ctx"));
|
||||
}
|
||||
|
||||
public static Set<String> validLexerCommands = new HashSet<String>() {{
|
||||
public static final Set<String> validLexerCommands = new HashSet<String>();
|
||||
static {
|
||||
// CALLS
|
||||
add("mode");
|
||||
add("pushMode");
|
||||
add("type");
|
||||
add("channel");
|
||||
validLexerCommands.add("mode");
|
||||
validLexerCommands.add("pushMode");
|
||||
validLexerCommands.add("type");
|
||||
validLexerCommands.add("channel");
|
||||
|
||||
// ACTIONS
|
||||
add("popMode");
|
||||
add("skip");
|
||||
add("more");
|
||||
}};
|
||||
validLexerCommands.add("popMode");
|
||||
validLexerCommands.add("skip");
|
||||
validLexerCommands.add("more");
|
||||
}
|
||||
|
||||
public String name;
|
||||
public List<GrammarAST> modifiers;
|
||||
|
|
|
@ -38,10 +38,11 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public class GrammarRootAST extends GrammarASTWithOptions {
|
||||
public static final Map<String, String> defaultOptions =
|
||||
new HashMap<String, String>() {{
|
||||
put("language","Java");
|
||||
}};
|
||||
public static final Map<String, String> defaultOptions = new HashMap<String, String>();
|
||||
static {
|
||||
defaultOptions.put("language","Java");
|
||||
}
|
||||
|
||||
public int grammarType; // LEXER, PARSER, GRAMMAR (combined)
|
||||
public boolean hasErrors;
|
||||
/** Track stream used to create this tree */
|
||||
|
|
Loading…
Reference in New Issue