[antlr-interest] antlr and stringtemplate

tilman walter tilman.walter at gmx.de
Fri Jul 4 06:50:26 PDT 2008


hi list,

are there any major restriction for using stringtemplate with a tree 
grammar.
I am trying to emit a simple text and set my options to this:
    output=template;
    rewrite=true;
    ASTLabelType = CommonTree;

Then i created  a  GroupFile  test.stg  with  a single entry:
test(id,value) ::= <<
just a trial text
 >>

In my tree grammar exists a rule:
assign:
    IDENT '=' VALUE
        -> assign(id={$IDENT},value={$VALUE})
    ;


The main class that invokes my parser,etc contains the code to
    ...
            String templateFile = "test.stg";
            Reader reader = new FileReader(templateFile);
            StringTemplateGroup templates = new StringTemplateGroup(reader);
            treeParser.setTemplateLib(templates);
            reader.close();
            MyTreeParser.start_return result = treeparser.start();
            System.out.println(result.getTemplate());
    ...

Unfortunately result alway is null, even though the template is loaded 
as far as my debugger is concerned.
Does every rule needs a template rewrite?

Maybe anybody can help.
Thanks Tilman


More information about the antlr-interest mailing list