[antlr-interest] StringTemplate - getting started

Mark Volkmann r.mark.volkmann at gmail.com
Fri Jan 18 06:39:44 PST 2008


I'm giving StringTemplate a go. However, I just get "null" for the
output. I wonder if the problem is that my start rule doesn't
explicitly specify any output. For example, I have something like
this.

statement: foo | help;

help: HELP -> help();

---

"help" is a template that I load from a .stg as shown in section 9.4
of the book.
It doesn't take an parameters.
I know it is finding this template because if I rename it in the .stg,
I get an error saying it can't find the template.
Here's the template. Note that my tree parser grammar name is "MathTree".

group MathTree;
help() :== "This is help!"

My Java code creates a StringTemplateGroup, passes it to
treeParser.setTemplateLib.
The code that attempts to output the template looks like this.

MathTree.statement_return r = treeParser.statement();
System.out.println("r = " + r); // This outputs "null".
System.out.println(r.getTemplate().toString()); // and of course I get
a NullPointerException here.

Any idea why I get back null from treeParser.statement()?

-- 
R. Mark Volkmann
Object Computing, Inc.


More information about the antlr-interest mailing list