[antlr-interest] StringTemplate - getting started

Adam Connelly adam.rpconnelly at googlemail.com
Fri Jan 18 07:08:51 PST 2008


I think you have to explicitly pass the template up.  Try:

statement: foo | (help { $statement.st = $help.st} );

help: HELP -> help();

or maybe you can do:

statement: st=foo | st=help
                 { $statement.st=$st; };

help: HELP -> help();

I'm fairly certain I had the same problem in the past.

Cheers,

Adam

On 18/01/2008, Mark Volkmann <r.mark.volkmann at gmail.com> wrote:
>
> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080118/055f1e6f/attachment.html 


More information about the antlr-interest mailing list