Add the -XdbgSTWait command line option to block the tool execution until the STViz inspection dialog is closed

This commit is contained in:
Sam Harwell 2013-01-01 21:37:01 -06:00
parent b6a824ddd5
commit 26d267ca38
2 changed files with 19 additions and 4 deletions

View File

@ -127,6 +127,7 @@ public class Tool {
public String grammarEncoding = null; // use default locale's encoding
public String msgFormat = "antlr";
public boolean launch_ST_inspector = false;
public boolean ST_inspector_wait_for_close = false;
public boolean force_atn = false;
public boolean log = false;
public boolean gen_listener = true;
@ -153,6 +154,7 @@ public class Tool {
new Option("", "-D<option>=value", "set/override a grammar-level option"),
new Option("warnings_are_errors", "-Werror", "treat warnings as errors"),
new Option("launch_ST_inspector", "-XdbgST", "launch StringTemplate visualizer on generated code"),
new Option("ST_inspector_wait_for_close", "-XdbgSTWait", "wait for STViz to close before continuing"),
new Option("force_atn", "-Xforce-atn", "use the ATN simulator for all predictions"),
new Option("log", "-Xlog", "dump lots of logging info to antlr-timestamp.log"),
};

View File

@ -36,6 +36,7 @@ import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.ast.GrammarAST;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.gui.STViz;
import java.util.List;
@ -66,13 +67,11 @@ public class CodeGenPipeline {
if ( g.isLexer() ) {
ST lexer = gen.generateLexer();
if ( g.tool.launch_ST_inspector ) lexer.inspect();
gen.writeRecognizer(lexer);
writeRecognizer(lexer, gen);
}
else {
ST parser = gen.generateParser();
if ( g.tool.launch_ST_inspector ) parser.inspect();
gen.writeRecognizer(parser);
writeRecognizer(parser, gen);
if ( g.tool.gen_listener ) {
gen.writeListener(gen.generateListener());
gen.writeBaseListener(gen.generateBaseListener());
@ -85,4 +84,18 @@ public class CodeGenPipeline {
}
gen.writeVocabFile();
}
protected void writeRecognizer(ST template, CodeGenerator gen) {
if ( g.tool.launch_ST_inspector ) {
STViz viz = template.inspect();
if (g.tool.ST_inspector_wait_for_close) {
try {
viz.waitForClose();
} catch (InterruptedException ex) {
}
}
}
gen.writeRecognizer(template);
}
}