Add the -XdbgSTWait command line option to block the tool execution until the STViz inspection dialog is closed
This commit is contained in:
parent
b6a824ddd5
commit
26d267ca38
|
@ -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"),
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue