Java Code Examples for org.antlr.stringtemplate.StringTemplate
The following examples show how to use
org.antlr.stringtemplate.StringTemplate. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jFuzzyLogic Source File: CTarget.java License: GNU Lesser General Public License v3.0 | 6 votes |
protected void genRecognizerHeaderFile(Tool tool, CodeGenerator generator, Grammar grammar, StringTemplate headerFileST, String extName) throws IOException { // Pick up the file name we are generating. This method will return a // a file suffixed with .c, so we must substring and add the extName // to it as we cannot assign into strings in Java. /// String fileName = generator.getRecognizerFileName(grammar.name, grammar.type); fileName = fileName.substring(0, fileName.length()-2) + extName; System.out.println("Generating " + fileName); generator.write(headerFileST, fileName); }
Example 2
Source Project: swift-k Source File: IForeach.java License: Apache License 2.0 | 6 votes |
@Override protected void setTemplateAttributes(OutputContext oc, StringTemplate st) { Collection<String> cleanups = getScope().getCleanups(); if (cleanups != null) { cleanups.remove(varName); if (indexVarName != null) { cleanups.remove(indexVarName); } } super.setTemplateAttributes(oc, st); st.setAttribute("var", varName); st.setAttribute("in", in.getTemplate(oc)); if (indexVarName != null) { st.setAttribute("indexVar", indexVarName); st.setAttribute("indexVarField", indexVarFieldName); } if (selfClose) { st.setAttribute("selfClose", "true"); } setPartials(st, wrefs, "wrefs"); mergeRefs(rrefs, wrefs); setPartials(st, rrefs, "rrefs"); }
Example 3
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 6 votes |
public void testFullyQualifiedRefToCurrentRuleRetVal() throws Exception { String action = "$a.i;"; String expecting = "retval.i;"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "grammar t;\n"+ "a returns [int i, int j]: {"+action+"}\n" + " ;\n"); Tool antlr = newTool(); CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // forces load of templates ActionTranslator translator = new ActionTranslator(generator,"a", new antlr.CommonToken(ANTLRParser.ACTION,action),1); String rawTranslation = translator.translate(); StringTemplateGroup templates = new StringTemplateGroup(".", AngleBracketTemplateLexer.class); StringTemplate actionST = new StringTemplate(templates, rawTranslation); String found = actionST.toString(); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }
Example 4
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 6 votes |
public void testFullyQualifiedRefToCurrentRuleParameter() throws Exception { String action = "$a.i;"; String expecting = "i;"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "grammar t;\n"+ "a[int i]: {"+action+"}\n" + " ;\n"); Tool antlr = newTool(); CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // forces load of templates ActionTranslator translator = new ActionTranslator(generator,"a", new antlr.CommonToken(ANTLRParser.ACTION,action),1); String rawTranslation = translator.translate(); StringTemplateGroup templates = new StringTemplateGroup(".", AngleBracketTemplateLexer.class); StringTemplate actionST = new StringTemplate(templates, rawTranslation); String found = actionST.toString(); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }
Example 5
Source Project: jFuzzyLogic Source File: GrammarSyntaxMessage.java License: GNU Lesser General Public License v3.0 | 6 votes |
public String toString() { line = 0; column = 0; if ( offendingToken!=null ) { line = offendingToken.getLine(); column = offendingToken.getColumn(); } // TODO: actually set the right Grammar instance to get the filename // TODO: have to update all v2 grammar files for this. or use errormanager and tool to get the current grammar if (g != null) { file = g.getFileName(); } StringTemplate st = getMessageTemplate(); if ( arg!=null ) { st.setAttribute("arg", arg); } return super.toString(st); }
Example 6
Source Project: protostuff Source File: ProtoToJavaBeanCompiler.java License: Apache License 2.0 | 6 votes |
protected void writeMessages(ProtoModule module, Proto proto, String javaPackageName, StringTemplateGroup group) throws IOException { for (Message m : proto.getMessages()) { Writer writer = CompilerUtil.newWriter(module, javaPackageName, m.getName() + ".java"); AutoIndentWriter out = new AutoIndentWriter(writer); StringTemplate messageBlock = group.getInstanceOf("message_block"); messageBlock.setAttribute("message", m); messageBlock.setAttribute("module", module); messageBlock.setAttribute("options", module.getOptions()); messageBlock.write(out); writer.close(); } }
Example 7
Source Project: swift-k Source File: IConditionBranch.java License: Apache License 2.0 | 6 votes |
private void addPre(OutputContext oc, StringTemplate st, Map<String, Integer> counts, String templateName) { if (counts != null) { boolean any = false; StringTemplate pre = oc.template(templateName); for (Map.Entry<String, Integer> e : counts.entrySet()) { if (e.getValue() > 0) { pre.setAttribute("items", e.getKey()); pre.setAttribute("items", e.getValue()); any = true; } } if (any) { st.setAttribute("statements", pre); } } }
Example 8
Source Project: protostuff Source File: ProtoToJavaBeanCompiler.java License: Apache License 2.0 | 6 votes |
protected void writeEnums(ProtoModule module, Proto proto, String javaPackageName, StringTemplateGroup group) throws IOException { for (EnumGroup eg : proto.getEnumGroups()) { Writer writer = CompilerUtil.newWriter(module, javaPackageName, eg.getName() + ".java"); AutoIndentWriter out = new AutoIndentWriter(writer); StringTemplate enumBlock = group.getInstanceOf("enum_block"); enumBlock.setAttribute("eg", eg); enumBlock.setAttribute("module", module); enumBlock.setAttribute("options", module.getOptions()); enumBlock.write(out); writer.close(); } }
Example 9
Source Project: protostuff Source File: ProtoToJavaV2ProtocSchemaCompiler.java License: Apache License 2.0 | 6 votes |
@Override protected void compile(ProtoModule module, Proto proto) throws IOException { String javaPackageName = proto.getJavaPackageName(); StringTemplateGroup group = getSTG(getOutputId()); String fileName = resolveFileName(proto); Writer writer = CompilerUtil.newWriter(module, javaPackageName, "Schema" + fileName + ".java"); AutoIndentWriter out = new AutoIndentWriter(writer); StringTemplate protoOuterBlock = group.getInstanceOf("proto_block"); protoOuterBlock.setAttribute("proto", proto); protoOuterBlock.setAttribute("module", module); protoOuterBlock.setAttribute("options", module.getOptions()); protoOuterBlock.write(out); writer.close(); }
Example 10
Source Project: jFuzzyLogic Source File: NonRegularDecisionMessage.java License: GNU Lesser General Public License v3.0 | 6 votes |
public String toString() { GrammarAST decisionASTNode = probe.dfa.getDecisionASTNode(); line = decisionASTNode.getLine(); column = decisionASTNode.getColumn(); String fileName = probe.dfa.nfa.grammar.getFileName(); if ( fileName!=null ) { file = fileName; } StringTemplate st = getMessageTemplate(); String ruleName = probe.dfa.getNFADecisionStartState().enclosingRule.name; st.setAttribute("ruleName", ruleName); List sortedAlts = new ArrayList(); sortedAlts.addAll(altsWithRecursion); Collections.sort(sortedAlts); // make sure it's 1, 2, ... st.setAttribute("alts", sortedAlts); return super.toString(st); }
Example 11
Source Project: pitest Source File: MutationHtmlReportListener.java License: Apache License 2.0 | 6 votes |
private void createPackageIndexPage(final PackageSummaryData psData) { final StringTemplateGroup group = new StringTemplateGroup("mutation_test"); final StringTemplate st = group .getInstanceOf("templates/mutation/package_index"); final Writer writer = this.outputStrategy.createWriterForFile(psData .getPackageDirectory() + File.separator + "index.html"); st.setAttribute("packageData", psData); try { writer.write(st.toString()); writer.close(); } catch (final IOException e) { e.printStackTrace(); } }
Example 12
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 6 votes |
public void testForwardRefRuleLabels() throws Exception { String action = "$r.x; $r.start; $r.stop; $r.tree; $a.x; $a.tree;"; String expecting = "(r!=null?r.x:0); (r!=null?((Token)r.start):null); (r!=null?((Token)r.stop):null); (r!=null?((Object)r.tree):null); (r!=null?r.x:0); (r!=null?((Object)r.tree):null);"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "parser grammar t;\n"+ "b : r=a {###"+action+"!!!}\n" + " ;\n" + "a returns [int x]\n" + " : ;\n"); Tool antlr = newTool(); antlr.setOutputDirectory(null); // write to /dev/null CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // codegen phase sets some vars we need StringTemplate codeST = generator.getRecognizerST(); String code = codeST.toString(); String found = code.substring(code.indexOf("###")+3,code.indexOf("!!!")); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }
Example 13
Source Project: jFuzzyLogic Source File: DOTGenerator.java License: GNU Lesser General Public License v3.0 | 6 votes |
/** Return a String containing a DOT description that, when displayed, * will show the incoming state machine visually. All nodes reachable * from startState will be included. */ public String getDOT(State startState) { if ( startState==null ) { return null; } // The output DOT graph for visualization StringTemplate dot = null; markedStates = new HashSet(); if ( startState instanceof DFAState ) { dot = stlib.getInstanceOf("org/antlr/tool/templates/dot/dfa"); dot.setAttribute("startState", Utils.integer(startState.stateNumber)); dot.setAttribute("useBox", Boolean.valueOf(Tool.internalOption_ShowNFAConfigsInDFA)); walkCreatingDFADOT(dot, (DFAState)startState); } else { dot = stlib.getInstanceOf("org/antlr/tool/templates/dot/nfa"); dot.setAttribute("startState", Utils.integer(startState.stateNumber)); walkRuleNFACreatingDOT(dot, startState); } dot.setAttribute("rankdir", rankdir); return dot.toString(); }
Example 14
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 6 votes |
public void testRefToStartAttributeForCurrentRule() throws Exception { String action = "$start;"; String expecting = "((Token)retval.start);"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "parser grammar t;\n" + "a : {###"+action+"!!!}\n" + " ;\n"); Tool antlr = newTool(); CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // forces load of templates ActionTranslator translator = new ActionTranslator(generator,"a", new antlr.CommonToken(ANTLRParser.ACTION,action),1); StringTemplate codeST = generator.getRecognizerST(); String code = codeST.toString(); String found = code.substring(code.indexOf("###")+3,code.indexOf("!!!")); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }
Example 15
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 6 votes |
public void testRuleRefWhenRuleHasScope() throws Exception { String action = "$b.start;"; String expecting = "(b1!=null?((Token)b1.start):null);"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "grammar t;\n" + "a : b {###"+action+"!!!} ;\n" + "b\n" + "scope {\n" + " int n;\n" + "} : 'b' \n" + " ;\n"); Tool antlr = newTool(); CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // forces load of templates StringTemplate codeST = generator.getRecognizerST(); String code = codeST.toString(); String found = code.substring(code.indexOf("###")+3,code.indexOf("!!!")); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }
Example 16
Source Project: yatspec Source File: WikiResultRenderer.java License: Apache License 2.0 | 5 votes |
public String render(Result result) throws Exception { final EnhancedStringTemplateGroup group = new EnhancedStringTemplateGroup(getClass()); sequence(customRenderers).fold(group, registerRenderer()); group.registerRenderer(instanceOf(JavaSource.class), callable(new JavaSourceRenderer())); group.registerRenderer(instanceOf(Notes.class), callable(new NotesRenderer())); final StringTemplate template = group.getInstanceOf("wiki"); template.setAttribute("testResult", result); StringWriter writer = new StringWriter(); template.write(new NoIndentWriter(writer)); return writer.toString(); }
Example 17
Source Project: yatspec Source File: HtmlIndexRenderer.java License: Apache License 2.0 | 5 votes |
private String render(File yatspecOutputDir, Index index) throws Exception { EnhancedStringTemplateGroup group = new EnhancedStringTemplateGroup(getClass()); StringTemplate template = group.getInstanceOf("index", model(). add("script", loadContent("index.js")). add("stylesheet", HtmlResultRenderer.loadContent("yatspec.css")). add("cssClass", getCssMap()). add("result", new IndexModel(index, yatspecOutputDir).asModel()).toMap()); return template.toString(); }
Example 18
Source Project: jFuzzyLogic Source File: CSharp2Target.java License: GNU Lesser General Public License v3.0 | 5 votes |
protected StringTemplate chooseWhereCyclicDFAsGo(Tool tool, CodeGenerator generator, Grammar grammar, StringTemplate recognizerST, StringTemplate cyclicDFAST) { return recognizerST; }
Example 19
Source Project: swellrt Source File: Pst.java License: Apache License 2.0 | 5 votes |
/** * Runs the code generation for all templates. */ public void run() throws PstException { List<PstException.TemplateException> exceptions = Lists.newArrayList(); for (File template : templates) { try { MessageProperties properties = createProperties(template); String groupName = stripSuffix(".st", template.getName()); String templateName = properties.hasTemplateName() ? properties.getTemplateName() : ""; StringTemplateGroup group = new StringTemplateGroup(groupName + "Group", dir(template)); StringTemplate st = group.getInstanceOf(groupName); for (Descriptor messageDescriptor : fd.getMessageTypes()) { Message message = new Message(messageDescriptor, templateName, properties); st.reset(); st.setAttribute("m", message); write(st, new File( outputDir.getPath() + File.separator + message.getFullJavaType().replace('.', File.separatorChar) + "." + (properties.hasFileExtension() ? properties.getFileExtension() : "java"))); } } catch (Exception e) { exceptions.add(new PstException.TemplateException(template.getPath(), e)); } } if (!exceptions.isEmpty()) { throw new PstException(exceptions); } }
Example 20
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 5 votes |
public void testSimplePlusEqualLabel() throws Exception { String action = "$ids.size();"; // must be qualified String expecting = "list_ids.size();"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "parser grammar t;\n"+ "a : ids+=ID ( COMMA ids+=ID {"+action+"})* ;\n"); Tool antlr = newTool(); CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // forces load of templates ActionTranslator translator = new ActionTranslator(generator, "a", new antlr.CommonToken(ANTLRParser.ACTION,action),1); String rawTranslation = translator.translate(); StringTemplateGroup templates = new StringTemplateGroup(".", AngleBracketTemplateLexer.class); StringTemplate actionST = new StringTemplate(templates, rawTranslation); String found = actionST.toString(); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }
Example 21
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 5 votes |
public void testPlusEqualSetLabel() throws Exception { String action = "$ids.size();"; // must be qualified String expecting = "list_ids.size();"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "grammar t;\n"+ "a : ids+=('a'|'b') ( ',' ids+=ID {"+action+"})* ;" + "ID : 'a';\n"); Tool antlr = newTool(); CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // forces load of templates ActionTranslator translator = new ActionTranslator(generator, "a", new antlr.CommonToken(ANTLRParser.ACTION,action),1); String rawTranslation = translator.translate(); StringTemplateGroup templates = new StringTemplateGroup(".", AngleBracketTemplateLexer.class); StringTemplate actionST = new StringTemplate(templates, rawTranslation); String found = actionST.toString(); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }
Example 22
Source Project: quetzal Source File: Expression.java License: Eclipse Public License 2.0 | 5 votes |
protected List<String> getNumericTypeCheckSQL(FilterContext context, Store store) { List<String> types = new LinkedList<String>(); for (Variable v : this.gatherVariables()) { StringTemplate t = store.getInstanceOf(BETWEEN_TYPE_TEST); t.setAttribute("typeCol", context.getVarMap().get(v.getName()).snd); t.setAttribute("start", TypeMap.DATATYPE_NUMERICS_IDS_START); t.setAttribute("end", TypeMap.DATATYPE_NUMERICS_IDS_END); types.add(t.toString()); } return types; }
Example 23
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 5 votes |
public void testReturnValues() throws Exception { String action = "$i; $i.x; $u; $u.x"; String expecting = "retval.i; retval.i.x; retval.u; retval.u.x"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "parser grammar t;\n"+ "a returns [User u, int i]\n" + " : {"+action+"}\n" + " ;"); Tool antlr = newTool(); CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // forces load of templates ActionTranslator translator = new ActionTranslator(generator,"a", new antlr.CommonToken(ANTLRParser.ACTION,action),1); String rawTranslation = translator.translate(); StringTemplateGroup templates = new StringTemplateGroup(".", AngleBracketTemplateLexer.class); StringTemplate actionST = new StringTemplate(templates, rawTranslation); String found = actionST.toString(); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }
Example 24
Source Project: protostuff Source File: PluginProtoCompiler.java License: Apache License 2.0 | 5 votes |
public static void compileMessageBlock(ProtoModule module, Message message, String packageName, String fileName, StringTemplate messageBlockTemplate) throws IOException { Writer writer = CompilerUtil.newWriter(module, packageName, fileName); compileMessageBlockTo(writer, module, message, messageBlockTemplate); writer.close(); }
Example 25
Source Project: swift-k Source File: IRangeExpression.java License: Apache License 2.0 | 5 votes |
@Override protected void setTemplateAttributes(OutputContext oc, StringTemplate st) { super.setTemplateAttributes(oc, st); st.setAttribute("from", from.getTemplate(oc)); st.setAttribute("to", to.getTemplate(oc)); if (step != null) { st.setAttribute("step", step.getTemplate(oc)); } }
Example 26
Source Project: swift-k Source File: IField.java License: Apache License 2.0 | 5 votes |
@Override protected void setTemplateAttributes(OutputContext oc, StringTemplate st) { super.setTemplateAttributes(oc, st); if (key instanceof INode) { st.setAttribute("key", ((INode) key).getTemplate(oc)); } else { st.setAttribute("key", "\"" + key + "\""); } st.setAttribute("value", value.getTemplate(oc)); }
Example 27
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 5 votes |
public void testTypeOfGuardedAttributeRefIsCorrect() throws Exception { String action = "int x = $b::n;"; String expecting = "int x = ((b_scope)b_stack.peek()).n;"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "grammar t;\n" + "s : b ;\n"+ "b\n" + "scope {\n" + " int n;\n" + "} : '(' b ')' {"+action+"}\n" + // refers to current invocation's n " ;\n"); Tool antlr = newTool(); CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // forces load of templates ActionTranslator translator = new ActionTranslator(generator, "b", new antlr.CommonToken(ANTLRParser.ACTION,action),1); String rawTranslation = translator.translate(); StringTemplateGroup templates = new StringTemplateGroup(".", AngleBracketTemplateLexer.class); StringTemplate actionST = new StringTemplate(templates, rawTranslation); String found = actionST.toString(); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }
Example 28
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 5 votes |
public void testRuleScopeFromAnotherRule() throws Exception { String action = "$a::n;"; // must be qualified String expecting = "((a_scope)a_stack.peek()).n;"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "grammar t;\n"+ "a\n" + "scope {\n" + " boolean n;\n" + "} : b\n" + " ;\n" + "b : {"+action+"}\n" + " ;\n"); Tool antlr = newTool(); CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // forces load of templates ActionTranslator translator = new ActionTranslator(generator, "b", new antlr.CommonToken(ANTLRParser.ACTION,action),1); String rawTranslation = translator.translate(); StringTemplateGroup templates = new StringTemplateGroup(".", AngleBracketTemplateLexer.class); StringTemplate actionST = new StringTemplate(templates, rawTranslation); String found = actionST.toString(); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }
Example 29
Source Project: swift-k Source File: IApplication.java License: Apache License 2.0 | 5 votes |
@Override protected void setTemplateAttributes(OutputContext oc, StringTemplate st) { super.setTemplateAttributes(oc, st); setAll(oc, st, commands, "commands"); if (profile != null) { st.setAttribute("attributes", profile.getTemplate(oc)); } }
Example 30
Source Project: jFuzzyLogic Source File: TestAttributes.java License: GNU Lesser General Public License v3.0 | 5 votes |
public void testRuleLabelsWithSpecialToken() throws Exception { String action = "$r.x; $r.start; $r.stop; $r.tree; $a.x; $a.stop;"; String expecting = "(r!=null?r.x:0); (r!=null?((MYTOKEN)r.start):null); (r!=null?((MYTOKEN)r.stop):null); (r!=null?((Object)r.tree):null); (r!=null?r.x:0); (r!=null?((MYTOKEN)r.stop):null);"; ErrorQueue equeue = new ErrorQueue(); ErrorManager.setErrorListener(equeue); Grammar g = new Grammar( "parser grammar t;\n"+ "options {TokenLabelType=MYTOKEN;}\n"+ "a returns [int x]\n" + " :\n" + " ;\n"+ "b : r=a {###"+action+"!!!}\n" + " ;"); Tool antlr = newTool(); antlr.setOutputDirectory(null); // write to /dev/null CodeGenerator generator = new CodeGenerator(antlr, g, "Java"); g.setCodeGenerator(generator); generator.genRecognizer(); // codegen phase sets some vars we need StringTemplate codeST = generator.getRecognizerST(); String code = codeST.toString(); String found = code.substring(code.indexOf("###")+3,code.indexOf("!!!")); assertEquals(expecting, found); assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size()); }