[stringtemplate-interest] StringTemplate parameters

Terence Parr parrt at cs.usfca.edu
Wed Jun 11 01:23:29 PDT 2008


Hi Aaron,

This is the perfect example of dynamic scoping.  If a method is  
embedded within a class tempalte, it can see all of class's  
attributes.  So, use

class(className, methods) ::= ...

and then use <className> in the method (w/o declaring as parameter)  
and you're golden!
Ter
On Jun 10, 2008, at 8:52 PM, Aaron Leiby wrote:

> I wasn't sure if I should post StringTemplate specific questions  
> here, or on the ANTLR list (since I'm using StringTemplate within  
> ANTLR as opposed to embedding in HTML).
>
> Anyway, I'm trying to figure out if it's possible to pass  
> additional parameters to templates within a group file.
>
> As an example, suppose you are generating a pair of C++ files  
> (header + implementation).
>
> The header might look like this:
>
> class(name, methods) ::= <<
> class <name>
> {
>     <methods>
> };
> >>
>
> method(name, rtype, args) ::= <<
> <rtype> <name>(<args; separator=", ");
>
> >>
>
> args(name, type) ::= "<type> <name>"
>
> Then when you go to do the implementation, you realize you need the  
> class name in the method template in order to scope it:
>
> class(name, methods) ::= <<
> #include "<name>.h"
>
> <methods>
>
> >>
>
> method(name, rtype, args) ::= <<
> <rtype> <scope>::<name>(<args; separator=", ")
> {
>     ...
> }
>
> >>
>
> args(name, type) ::= "<type> <name>"
>
> Is there any way to pass that in from the class template*, or do  
> you have to go back to your grammar and pass it in from there (even  
> though it's not needed in other templates)?
>
> * for example:
>
> class(name, methods) ::= <<
> #include "<name>.h"
>
> <methods[scope=<name>]>
>
> >>
>
> method(scope, name, rtype, args) ::= <<
> ...
>
>
> Thanks!  Also, please let me know if there's a better source of  
> info for this type of stuff beyond what's found here:
> http://www.antlr.org/wiki/display/ST/StringTemplate+3.1+Documentation
>
> Aaron
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list