add cmd-line interface, add map in Index.stg to targets-specific templates.

This commit is contained in:
Terence Parr 2015-06-01 18:18:44 -07:00
parent b15e66985e
commit e3325ab606
6 changed files with 37 additions and 12 deletions

View File

@ -78,7 +78,7 @@ def compile():
cp = uniformpath("out") + os.pathsep + \
os.path.join(JARCACHE, "antlr-3.5.2-complete.jar") + os.pathsep + \
"runtime/Java/lib/org.abego.treelayout.core.jar" + os.pathsep
srcpath = ["gen3", "gen4", "runtime/Java/src", "tool/src"]
srcpath = ["gen3", "gen4", "runtime/Java/src", "runtime-testsuite/src", "tool/src"]
args = ["-Xlint", "-Xlint:-serial", "-g", "-sourcepath", string.join(srcpath, os.pathsep)]
for sp in srcpath:
javac(sp, "out", version="1.6", cp=cp, args=args)
@ -90,6 +90,7 @@ def compile():
def mkjar_complete():
require(compile)
copytree(src="tool/resources", trg="out") # messages, Java code gen, etc...
copytree(src="runtime-testsuite/resources", trg="out") # templates for generating unit tests
manifest = \
"Main-Class: org.antlr.v4.Tool\n" +\
"Implementation-Title: ANTLR 4 Tool\n" +\

View File

@ -14,5 +14,15 @@ TestFolders ::= [
"Sets": []
]
//TestTemplates ::= [
//]
/** Base templates specific to targets needed by tests in TestFolders */
Targets ::= [
"Java" : "./tool/test/org/antlr/v4/test/runtime/java/Java.test.stg",
"CSharp" : "../antlr4-csharp/tool/test/org/antlr/v4/test/rt/csharp/CSharp.test.stg",
"Python2" : "../antlr4-python2/tool/test/org/antlr/v4/test/rt/py2/Python2.test.stg",
"Python3" : "../antlr4-python3/tool/test/org/antlr/v4/test/rt/py3/Python3.test.stg",
"NodeJS" : "../antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/node/NodeJS.test.stg",
"Safari" : "../antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/safari/Safari.test.stg",
"Firefox" : "../antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/firefox/Firefox.test.stg",
"Chrome" : "../antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/chrome/Chrome.test.stg",
"Explorer" : "../antlr4-javascript/tool/test/org/antlr/v4/test/rt/js/explorer/Explorer.test.stg"
]

View File

@ -7,7 +7,7 @@ TestTemplates ::= [
"SingleTokenDeletionConsumption": [],
"SingleTokenDeletionExpectingSet": [],
"SingleTokenInsertion": [],
"SingleTokenInsertionConsumption": [],
"SingleSetInsertionConsumption": [],
"ConjuringUpToken": [],
"SingleSetInsertion": [],
"ConjuringUpTokenFromSet": [],

View File

@ -44,6 +44,7 @@ import java.util.List;
import java.util.Map;
public class TestGenerator {
public static final String antlrRoot = "."; // assume antlr4 root dir is current working dir
// This project uses UTF-8, but the plugin might be used in another project
// which is not. Always load templates with UTF-8, but write using the
@ -56,12 +57,19 @@ public class TestGenerator {
private final boolean visualize;
/**
* $ java TestGenerator -o targetrootdir -templates target.test.stg -viz
public static final String mainTestIndex = "org/antlr4/runtime/test/templates/Index.stg";
/** Execute from antlr4 root dir
* $ java TestGenerator -o output-root-dir -target (Java|Python2|Python3|Javascript|CSharp) -viz
*
* Example:
*
* $ java TestGenerator -o /Users/parrt/antlr/code/antlr4/tool/test -target Java
*/
public static void main(String[] args) {
String outDir = ".";
String targetSpecificTemplateFile = "";
String targetSpecificTemplateFile;
String target = "Java";
boolean viz = false;
int i = 0;
@ -71,9 +79,9 @@ public class TestGenerator {
i++;
outDir = args[i];
}
else if (arg.startsWith("-templates")) {
else if (arg.startsWith("-target")) {
i++;
targetSpecificTemplateFile = args[i];
target = args[i];
}
else if (arg.startsWith("-viz")) {
viz = true;
@ -81,6 +89,11 @@ public class TestGenerator {
i++;
}
STGroup index = new STGroupFile(antlrRoot+"/runtime-testsuite/resources/"+mainTestIndex);
index.load();
Map<String, Object> folders = index.rawGetDictionary("Targets"); // get map target to .stg file
targetSpecificTemplateFile = (String)folders.get(target);
TestGenerator gen = new TestGenerator("UTF-8",
new File(targetSpecificTemplateFile),
new File(outDir),
@ -102,8 +115,8 @@ public class TestGenerator {
targetGroup.defineDictionary("lines", new LinesStringMap());
targetGroup.defineDictionary("strlen", new StrlenStringMap());
String rootFolder = "org/antlr4/runtime/test/templates";
STGroup index = new STGroupFile(rootFolder + "/Index.stg");
String rootFolder = "runtime-testsuite/resources/org/antlr4/runtime/test/templates";
STGroup index = new STGroupFile(rootFolder+"/Index.stg");
generateCodeForFolder(targetGroup, rootFolder, index);
}

View File

@ -10,7 +10,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="ST-4.0.7" level="application" />
<orderEntry type="module-library">
<library>
<CLASSES>

View File

@ -18,6 +18,7 @@
<sourceFolder url="file://$MODULE_DIR$/../antlr4-maven-plugin/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/playground" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../runtime-testsuite/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../runtime-testsuite/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/../.idea" />
<excludeFolder url="file://$MODULE_DIR$/../antlr4-maven-plugin" />
<excludeFolder url="file://$MODULE_DIR$/../build" />
@ -26,6 +27,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="runtime" />
<orderEntry type="library" scope="TEST" name="ST-4.0.8" level="application" />
<orderEntry type="library" name="antlr-3.5.2-complete-no-st3" level="application" />
<orderEntry type="library" name="junit-4.11" level="application" />
<orderEntry type="library" name="hamcrest-core-1.3" level="application" />