String lexerName,
String parserStartRuleName,
String treeParserStartRuleName,
boolean debug)
{
ST outputFileST = new ST(
"import org.antlr.runtime.*;\n" +
"import org.antlr.runtime.tree.*;\n" +
"import org.antlr.runtime.debug.*;\n" +
"\n" +
"class Profiler2 extends Profiler {\n" +
" public void terminate() { ; }\n" +
"}\n"+
"public class Test {\n" +
" public static void main(String[] args) throws Exception {\n" +
" CharStream input = new ANTLRFileStream(args[0]);\n" +
" <lexerName> lex = new <lexerName>(input);\n" +
" TokenRewriteStream tokens = new TokenRewriteStream(lex);\n" +
" <createParser>\n"+
" <parserName>.<parserStartRuleName>_return r = parser.<parserStartRuleName>();\n" +
" <if(!treeParserStartRuleName)>\n" +
" if ( r.tree!=null ) {\n" +
" System.out.println(((Tree)r.tree).toStringTree());\n" +
" ((CommonTree)r.tree).sanityCheckParentAndChildIndexes();\n" +
" }\n" +
" <else>\n" +
" CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree);\n" +
" nodes.setTokenStream(tokens);\n" +
" <treeParserName> walker = new <treeParserName>(nodes);\n" +
" walker.<treeParserStartRuleName>();\n" +
" <endif>\n" +
" }\n" +
"}"
);
ST createParserST =
new ST(
" Profiler2 profiler = new Profiler2();\n"+
" <parserName> parser = new <parserName>(tokens,profiler);\n" +
" profiler.setParser(parser);\n");
if ( !debug ) {
createParserST =
new ST(
" <parserName> parser = new <parserName>(tokens);\n");
}
outputFileST.add("createParser", createParserST);
outputFileST.add("parserName", parserName);
outputFileST.add("treeParserName", treeParserName);