[antlr-interest] StringTemplate

Terence Parr parrt at cs.usfca.edu
Fri Sep 25 12:33:32 PDT 2009


On Sep 25, 2009, at 4:32 AM, John851 wrote:

> Hello,
>
> I try to use StringTemplate to write a simple codegen.
>
> Can I use nested ST templates in my .stg file?
> Smth. like this:
> //---------------------------------------
> group ANTLRLangCodGen;
>
> dictdef()::="dict([<element; separator=",">])"
>
> element()::="<cell; separator=",">"
>
> cell(axis,value)::="(<axis; separator=",">),<value>"
> //---------------------------------------
>
> Where "element" and "cell" are nested templates.

  when you reference cell, it looks for attribute called cell not a  
template. cell() does that.

> And other question:
> How to load a .stg file and use templates in my tree grammar in  
> ANTLRworks ?

AW 1.3b I think allows you to specify what the test rig looks like;  
otherwise you can't really tell it how to load the template group. do  
remote debugging instead of trying to launch the debugger directly  
from AW.

> And how to pass plain string argument's value to template? Is it  
> possible only via labels like in the following example?
>
> rule1: $var1=WORLD -> SayHello(word={$var1.text});

-> foo(arg={"blah"}
Ter
>
> Thank you
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list