[stringtemplate-interest] StringTemplate parameters
Aaron Leiby
aleiby.antlr at gmail.com
Tue Jun 10 11:52:23 PDT 2008
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20080610/94c556a9/attachment.html
More information about the stringtemplate-interest
mailing list