[stringtemplate-interest] How to redirect StringTemplate output from within tree grammar

Terence Parr parrt at cs.usfca.edu
Tue Oct 23 21:06:58 PDT 2007


On Oct 24, 2007, at 12:01 PM, Eric Jungkurth wrote:

>
> --- Terence Parr <parrt at cs.usfca.edu> wrote:
>
>> Hi. This is really just a "how do I store a string
>> in a file"
>> question.  ST is an interpreter that executes upon
>> toString().  What
>> you do with the string is up to you.  Send to
>> socket, file, window,
>> etc...
>>
>> :)
>>
>> Ter
>>
>
> Thanks for the reply. I'm still a little confused.
> Here's a little tree grammar snippet, for which I'll
> charge nothing ;)
>
> schema : type+
>              ;
>
> type	:	TYPE ID
> 		{
> 		Type t = types.get($ID.text);
> 		String className = t.getClassName();
> 		ArrayList<String> k = t.getKeys();
> 		ArrayList<String> a = t.getAttributes();
> 		}
> 		->
> template(name={className},attributes={a},keys={k})
> 		<<
> 		public class <name> {
>                    blah blah blah
> 		}
> 		>>
> 	;
>
> If I have n types in my model I'll wind up with n
> concatenated class definitions in the StringTemplate
> output.

Actually, you'll get nothing from schema; it doesn't ref the  
$type.st.  ANTLR doesn't do anythin g with templates by dfault.  I  
suggest

schema : (t+=type)+ -> ... ;

to make a template that wraps the type templates.

But, I'm not sure what you're asking for.

Ter


More information about the stringtemplate-interest mailing list