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;
}
/** 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 */
public List<String> getDFAStrings() {
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
* that overrides this to point to their String[] tokenNames.
*/
public String[] getTokenNames() {
return null;
}
public abstract String[] getTokenNames();
public String[] getRuleNames() {
return null;
}
public abstract String[] getRuleNames();
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; }

View File

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

View File

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