made "a4 -message-format antlr T.g" work; deactivated the options that don't work yet.
This commit is contained in:
parent
60a17f3157
commit
26bf5acf19
|
@ -1,7 +1,3 @@
|
|||
grammar T;
|
||||
|
||||
options {
|
||||
superClass=Z;
|
||||
}
|
||||
|
||||
s : A ;
|
||||
|
|
|
@ -125,24 +125,24 @@ public class Tool {
|
|||
public boolean verbose_dfa = false;
|
||||
public boolean gen_listener = true;
|
||||
public boolean gen_visitor = false;
|
||||
public boolean abstract_recognizer = false;
|
||||
public Map<String, String> grammarOptions = null;
|
||||
|
||||
public static Option[] optionDefs = {
|
||||
new Option("outputDirectory", "-o", OptionArgType.STRING, "specify output directory where all output is generated"),
|
||||
new Option("libDirectory", "-lib", OptionArgType.STRING, "specify location of grammars, tokens files"),
|
||||
/*
|
||||
new Option("report", "-report", "print out a report about the grammar(s) processed"),
|
||||
new Option("printGrammar", "-print", "print out the grammar without actions"),
|
||||
new Option("debug", "-debug", "generate a parser that emits debugging events"),
|
||||
new Option("profile", "-profile", "generate a parser that computes profiling information"),
|
||||
*/
|
||||
new Option("generate_ATN_dot", "-atn", "generate rule augmented transition network diagrams"),
|
||||
new Option("grammarEncoding", "-encoding", OptionArgType.STRING, "specify grammar file encoding; e.g., euc-jp"),
|
||||
new Option("msgFormat", "-message-format", OptionArgType.STRING, "specify output style for messages"),
|
||||
new Option("msgFormat", "-message-format", OptionArgType.STRING, "specify output style for messages in antlr, gnu, vs2005"),
|
||||
new Option("gen_listener", "-listener", "generate parse tree listener (default)"),
|
||||
new Option("gen_listener", "-no-listener", "don't generate parse tree listener"),
|
||||
new Option("gen_visitor", "-visitor", "generate parse tree visitor"),
|
||||
new Option("gen_visitor", "-no-visitor", "don't generate parse tree visitor (default)"),
|
||||
new Option("abstract_recognizer", "-abstract", "generate abstract recognizer classes"),
|
||||
new Option("", "-D<option>=value", "set a grammar-level option"),
|
||||
|
||||
|
||||
|
@ -166,7 +166,7 @@ public class Tool {
|
|||
|
||||
protected List<String> grammarFiles = new ArrayList<String>();
|
||||
|
||||
public ErrorManager errMgr = new ErrorManager(this);
|
||||
public ErrorManager errMgr;
|
||||
public LogManager logMgr = new LogManager();
|
||||
|
||||
List<ANTLRToolListener> listeners = new CopyOnWriteArrayList<ANTLRToolListener>();
|
||||
|
@ -207,6 +207,8 @@ public class Tool {
|
|||
public Tool(String[] args) {
|
||||
this.args = args;
|
||||
handleArgs();
|
||||
errMgr = new ErrorManager(this);
|
||||
errMgr.setFormat(msgFormat);
|
||||
}
|
||||
|
||||
protected void handleArgs() {
|
||||
|
|
|
@ -82,11 +82,6 @@ public class ErrorManager {
|
|||
|
||||
public ErrorManager(Tool tool) {
|
||||
this.tool = tool;
|
||||
// try to load the message format group
|
||||
// the user might have specified one on the command line
|
||||
// if not, or if the user has given an illegal value, we will fall back to "antlr"
|
||||
setFormat("antlr");
|
||||
//org.stringtemplate.v4.misc.ErrorManager.setErrorListener(theDefaultSTListener);
|
||||
}
|
||||
|
||||
public void resetErrorState() {
|
||||
|
|
|
@ -402,8 +402,7 @@ public class Grammar implements AttributeResolver {
|
|||
}
|
||||
|
||||
public boolean isAbstract() {
|
||||
return Boolean.parseBoolean(getOptionString("abstract"))
|
||||
|| (tool != null && tool.abstract_recognizer);
|
||||
return Boolean.parseBoolean(getOptionString("abstract"));
|
||||
}
|
||||
|
||||
/** Get the name of the generated recognizer; may or may not be same
|
||||
|
@ -729,25 +728,6 @@ public class Grammar implements AttributeResolver {
|
|||
|
||||
public String getOptionString(String key) { return ast.getOptionString(key); }
|
||||
|
||||
/** Manually get language option from tree */
|
||||
// TODO: move to general tree visitor/parser class?
|
||||
// TODO: don't need anymore as i set optins in parser?
|
||||
public static String getLanguageOption(GrammarRootAST ast) {
|
||||
GrammarAST options = (GrammarAST)ast.getFirstChildWithType(ANTLRParser.OPTIONS);
|
||||
String language = "Java";
|
||||
if ( options!=null ) {
|
||||
for (Object o : options.getChildren()) {
|
||||
GrammarAST c = (GrammarAST)o;
|
||||
if ( c.getType() == ANTLRParser.ASSIGN &&
|
||||
c.getChild(0).getText().equals("language") )
|
||||
{
|
||||
language = c.getChild(1).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return language;
|
||||
}
|
||||
|
||||
/** Given ^(TOKEN_REF ^(OPTIONS ^(ELEMENT_OPTIONS (= assoc right))))
|
||||
* set option assoc=right in TOKEN_REF.
|
||||
*/
|
||||
|
|
|
@ -40,6 +40,7 @@ public class GrammarRootAST extends GrammarASTWithOptions {
|
|||
public static final Map<String, String> defaultOptions =
|
||||
new HashMap<String, String>() {{
|
||||
put("language","Java");
|
||||
put("abstract","false");
|
||||
}};
|
||||
public int grammarType; // LEXER, PARSER, GRAMMAR (combined)
|
||||
public boolean hasErrors;
|
||||
|
|
Loading…
Reference in New Issue