[antlr-interest] StringTemplate output issues

Olivier Dragon dragonoe at mcmaster.ca
Fri Nov 4 07:46:39 PST 2005


Hi,

I'm having problems with StringTemplate and I would appreciate very much
if someone with experience would help me to look through what is
happening and tell me what silly mistake I'm making :)

I am trying to use StringTemplate to generate code from a syntax tree.
I use an ANTLR grammar to parse the input code and generate the AST, and
a tree grammar to parse the AST and feed it to a template
(StringTemplate). I've based my tree grammar and template on the C- to
Java example found on stringtemplate.org.

However the template doesn't work. I'm getting the template text
literally, including the attribute placeholder. I've looked at the
toDebugString() output and everything looks good to me. I've even tried
to debug it through Eclipse and everything looks fine there too. Here's
my result:

<units; separator="\nc\n">

And the debug string:


template-<programUnits([units])@10>:chunks=[<units; separator="\nc\n">]attributes=[units=template-<subroutine([name, parameters])@11>:chunks=[      subroutine <name> (<parameters>),
,
,       end]attributes=[parameters=template-<commaSeparatedList([listItems])@12>:chunks=[<listItems; separator=", ">]attributes=[listItems=[incy, cy, ca, cx, n, incx]],name=caxpy]]


And the exerpt from my main program, where CodePrinter is the name of
the TreeParser class:

        CodePrinter printer = new CodePrinter();
        File tmpl = new File("fortran77/printer/f77-code_template.stg");
        printer.setTemplates(new StringTemplateGroup(new FileReader(tmpl)));
        StringTemplate code = printer.program(tree);
        System.out.println(code.toString());
        System.out.println(code.toDebugString());


I'm attaching my tree grammar and template files in case it could be
useful.

Thank you. I very much appreciate any help.

-Olivier

-- 
          __-/|    ? ?     |\-__
     __--/  /  \   (^^)   /  \  \--__
  _-/   /   /  /\ / ( )  /\  \   \   \-_
 /  /   /  /  /  (   ^^ ~  \  \  \   \  \
 / Oli Dragon    ( dragonoe at mcmaster.ca \
/  B.Eng. Sfwr   (     )    \    \  \    \
/  /  /    /__--_ (   ) __--__\    \  \  \
|  /  /  _/        \_ \_       \_  \  \  |
 \/  / _/            \_ \_       \_ \  \/
  \_/ /                -\_\        \ \_/
    \/                    )         \/
                        *~
        ___--<***************>--___
       [http://dragon.homelinux.org]
        ~~~--<***************>--~~~
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20051104/7ed32481/attachment-0001.bin


More information about the antlr-interest mailing list