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

Eric Jungkurth ejungkurth at yahoo.com
Tue Oct 23 21:01:29 PDT 2007


--- 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. 

I suppose I could instantiate a template in the
grammar action and do away with the -> clause.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the stringtemplate-interest mailing list