Extract abstract method in Recognizer for Parser.getGrammarFileName() and generated lexer's getGrammarFileName(). Make Recognizer.getTokenNames(), getRuleNames(), and getATN() abstract - implementations are always generated.

This commit is contained in:
Sam Harwell 2012-02-20 17:18:57 -06:00
parent d166e6d5d1
commit a81b1a17eb
4 changed files with 19 additions and 14 deletions

View File

@ -476,13 +476,6 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator<Token>
return stack; return stack;
} }
/** For debugging and other purposes, might want the grammar name.
* Have ANTLR generate an implementation for this method.
*/
public String getGrammarFileName() {
return null;
}
/** For debugging and other purposes */ /** For debugging and other purposes */
public List<String> getDFAStrings() { public List<String> getDFAStrings() {
List<String> s = new ArrayList<String>(); List<String> s = new ArrayList<String>();

View File

@ -53,15 +53,16 @@ public abstract class Recognizer<Symbol, ATNInterpreter extends ATNSimulator> {
* error reporting. The generated parsers implement a method * error reporting. The generated parsers implement a method
* that overrides this to point to their String[] tokenNames. * that overrides this to point to their String[] tokenNames.
*/ */
public String[] getTokenNames() { public abstract String[] getTokenNames();
return null;
}
public String[] getRuleNames() { public abstract String[] getRuleNames();
return null;
}
public ATN getATN() { return null; } /** For debugging and other purposes, might want the grammar name.
* Have ANTLR generate an implementation for this method.
*/
public abstract String getGrammarFileName();
public abstract ATN getATN();
public ATNInterpreter getInterpreter() { return _interp; } public ATNInterpreter getInterpreter() { return _interp; }

View File

@ -723,6 +723,7 @@ public class <lexer.name> extends Lexer {
_interp = new LexerATNSimulator(this,_ATN); _interp = new LexerATNSimulator(this,_ATN);
} }
@Override
public String getGrammarFileName() { return "<lexer.grammarFileName>"; } public String getGrammarFileName() { return "<lexer.grammarFileName>"; }
@Override @Override

View File

@ -45,6 +45,11 @@ public class ParserInterpreter {
this.g = g; this.g = g;
} }
@Override
public String getGrammarFileName() {
return null;
}
@Override @Override
public String[] getRuleNames() { public String[] getRuleNames() {
return g.rules.keySet().toArray(new String[g.rules.size()]); return g.rules.keySet().toArray(new String[g.rules.size()]);
@ -54,6 +59,11 @@ public class ParserInterpreter {
public String[] getTokenNames() { public String[] getTokenNames() {
return g.getTokenNames(); return g.getTokenNames();
} }
@Override
public ATN getATN() {
return null;
}
} }
protected Grammar g; protected Grammar g;