use of org.stringtemplate.v4.gui.STViz in project antlr4 by antlr.
the class TestCodeGeneration method getEvalInfoForString.
public List<String> getEvalInfoForString(String grammarString, String pattern) throws RecognitionException {
ErrorQueue equeue = new ErrorQueue();
Grammar g = new Grammar(grammarString);
List<String> evals = new ArrayList<String>();
if (g.ast != null && !g.ast.hasErrors) {
SemanticPipeline sem = new SemanticPipeline(g);
sem.process();
ATNFactory factory = new ParserATNFactory(g);
if (g.isLexer())
factory = new LexerATNFactory((LexerGrammar) g);
g.atn = factory.createATN();
CodeGenerator gen = new CodeGenerator(g);
ST outputFileST = gen.generateParser();
// STViz viz = outputFileST.inspect();
// try {
// viz.waitForClose();
// }
// catch (Exception e) {
// e.printStackTrace();
// }
boolean debug = false;
DebugInterpreter interp = new DebugInterpreter(outputFileST.groupThatCreatedThisInstance, outputFileST.impl.nativeGroup.errMgr, debug);
InstanceScope scope = new InstanceScope(null, outputFileST);
StringWriter sw = new StringWriter();
AutoIndentWriter out = new AutoIndentWriter(sw);
interp.exec(out, scope);
for (String e : interp.evals) {
if (e.contains(pattern)) {
evals.add(e);
}
}
}
if (equeue.size() > 0) {
System.err.println(equeue.toString());
}
return evals;
}
use of org.stringtemplate.v4.gui.STViz in project antlr4 by tunnelvisionlabs.
the class TestGenerator method generateTestFile.
protected void generateTestFile(STGroup index, STGroup targetGroup, String testdir, Collection<String> testTemplates) {
ErrorBuffer errors = new ErrorBuffer();
targetGroup.setListener(errors);
File targetFolder = getOutputDir(testdir);
String testName = testdir.substring(testdir.lastIndexOf('/') + 1);
File targetFile = new File(targetFolder, "Test" + testName + ".java");
// System.out.println("Generating file "+targetFile.getAbsolutePath());
List<ST> templates = new ArrayList<ST>();
for (String template : testTemplates) {
STGroup testGroup = new STGroupFile(testdir + "/" + template + STGroup.GROUP_FILE_EXTENSION);
importLanguageTemplates(testGroup, targetGroup);
ST testType = testGroup.getInstanceOf("TestType");
if (testType == null) {
warn(String.format("Unable to generate tests for %s: no TestType specified.", template));
continue;
}
ST testMethodTemplate = targetGroup.getInstanceOf(testType.render() + "TestMethod");
if (testMethodTemplate == null) {
warn(String.format("Unable to generate tests for %s: TestType '%s' is not supported by the current runtime.", template, testType.render()));
continue;
}
testMethodTemplate.add(testMethodTemplate.impl.formalArguments.keySet().iterator().next(), testGroup);
templates.add(testMethodTemplate);
}
ST testFileTemplate = targetGroup.getInstanceOf("TestFile");
testFileTemplate.addAggr("file.{Options,name,tests}", index.rawGetDictionary("Options"), testName, templates);
if (visualize) {
STViz viz = testFileTemplate.inspect();
try {
viz.waitForClose();
} catch (InterruptedException ex) {
}
}
try {
String output = testFileTemplate.render();
if (errors.errors.size() > 0) {
System.err.println("errors in " + targetGroup.getName() + ": " + errors);
}
writeFile(targetFile, output);
} catch (IOException ex) {
error(String.format("Failed to write output file: %s", targetFile), ex);
}
}
use of org.stringtemplate.v4.gui.STViz in project antlr4 by tunnelvisionlabs.
the class TestCodeGeneration method getEvalInfoForString.
public List<String> getEvalInfoForString(String grammarString, String pattern) throws RecognitionException {
ErrorQueue equeue = new ErrorQueue();
Grammar g = new Grammar(grammarString);
List<String> evals = new ArrayList<String>();
if (g.ast != null && !g.ast.hasErrors) {
SemanticPipeline sem = new SemanticPipeline(g);
sem.process();
ATNFactory factory = new ParserATNFactory(g);
if (g.isLexer())
factory = new LexerATNFactory((LexerGrammar) g);
g.atn = factory.createATN();
CodeGenerator gen = new CodeGenerator(g);
ST outputFileST = gen.generateParser();
// STViz viz = outputFileST.inspect();
// try {
// viz.waitForClose();
// }
// catch (Exception e) {
// e.printStackTrace();
// }
boolean debug = false;
DebugInterpreter interp = new DebugInterpreter(outputFileST.groupThatCreatedThisInstance, outputFileST.impl.nativeGroup.errMgr, debug);
InstanceScope scope = new InstanceScope(null, outputFileST);
StringWriter sw = new StringWriter();
AutoIndentWriter out = new AutoIndentWriter(sw);
interp.exec(out, scope);
for (String e : interp.evals) {
if (e.contains(pattern)) {
evals.add(e);
}
}
}
if (equeue.size() > 0) {
System.err.println(equeue.toString());
}
return evals;
}
Aggregations