[stringtemplate-interest] ST v4 with ANTLR 3.3

alejandro.osso at integraware.com.br alejandro.osso at integraware.com.br
Fri Jun 17 06:59:15 PDT 2011


Hi Michael, 

I'm glad you posted this reply, thank you.  It really helped.

Kind regards,

Alejandro Osso.




From:   Michael Bedward <michael.bedward at gmail.com>
To:     alejandro.osso at integraware.com.br
Cc:     stringtemplate-interest at antlr.org
Date:   14/06/2011 00:39
Subject:        Re: [stringtemplate-interest] ST v4 with ANTLR 3.3



Hi Alejandro,

I was hoping someone else would reply to your question with an easier
suggestion than my own, but since they haven't...

Using ST4 in an ANTLR 3.3. grammar, you don't have the normal string
template syntax available. Instead you have to do everything
"manually".  The way that I've done this is to have a superclass which
is responsible for loading the template group file...

// group is a field in the superclass
group = new STGroupFile( path );

The superclass also provides a helper method to get individual 
templates...

    protected ST getTemplate(String name) {
        ST st = group.getInstanceOf(name);
        if (st == null) {
            throw new RuntimeException("template not found: " + name);
        }
        return st;
    }

Then in my grammar I use that helper method and have each rule return
an ST object, as in this example...

assignmentExpression returns [ST st]
                : ^(op=assignmentOp id=assignableVar e=expression)
                {
                    $st = getTemplate("binaryexpr");
                    $st.add("lhs", $id.st);
                    $st.add("op", $op.st);
                    $st.add("rhs", $e.st);
                }
                ;

Of course, when ANTLR catches up with ST4 this will be unnecessary.

Hope this helps.

Michael



On 8 June 2011 01:58,  <alejandro.osso at integraware.com.br> wrote:
> Good morning to all!
>
> I would like to use ST v4 along with an ANTLR 3.3 tree grammar.  Can I 
do
> this?   ANTLR complains about the setTemplateLib(group) for STv4 groups.
>
>
> Kind regards,
>
> Alejandro Osso.
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110617/bfdbf438/attachment.html 


More information about the stringtemplate-interest mailing list