[stringtemplate-interest] Region Usage
Udo Borkowski
ub at abego-software.de
Wed Feb 2 14:01:46 PST 2011
I can only talk about StringTemplate 4.0, but I assume it is same with ST 3:
> 1) can i define region inside the same templategroup file?
Yes. Rendering this group's main() template:
-----
/* RegionTest.stg */
method(name,code) ::= <<
public void <name>() {
<@preamble()>
<code>
}
>>
@method.preamble() ::= <<System.out.println("enter");>>
main() ::= <<
<method(name="sample",code="beep();")>
>>
--------
will output:
--------
public void sample() {
System.out.println("enter");
beep();
}
--------
> 2) how can i turn on/off region template (starting from 1° wiki region example, how could i generate code with <@preamble()> and without it?)
If you don't define the region referenced by <@preamble()> nothing will be generated. E.g. back to the above example: without the @method.preamble()… stuff, i.e. with this group:
-------------
/* RegionTest2.stg */
method(name,code) ::= <<
public void <name>() {
<@preamble()>
<code>
}
>>
main() ::= <<
<method(name="sample",code="beep();")>
>>
-------------
the output will be
-------------
public void sample() {
beep();
}
-------------
You may now create a new group and import the above group:
------------
import "RegionTest2.stg"
main() ::= <<
<method(name="makeNoise",code="beep();")>
>>
------------
to use the method template from the "RegionTest" group. Here we get the following result:
------------
public void makeNoise() {
beep();
}
-------------
And in this new group you may define the region, too.
------------
import "RegionTest2.stg"
@method.preamble() ::= <<log("enter");>>
main() ::= <<
<method(name="makeNoise",code="beep();")>
>>
------------
resulting in this output:
------------
public void makeNoise() {
log("enter");
beep();
}
-------------
Hope this helps,
Udo
On 02.02.2011, at 19:59, Massimiliano Donini wrote:
> Hi, i have read following on link http://www.antlr.org/wiki/display/ST/Template+regions region usage but i'm unable to find code usage.
> I have 2 simple questions:
> 1) can i define region inside the same templategroup file?
> 2) how can i turn on/off region template (starting from 1° wiki region example, how could i generate code with <@preamble()> and without it?)
>
> Best Regards
> Max
> _______________________________________________
> 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/20110202/2311fe73/attachment.html
More information about the stringtemplate-interest
mailing list