[stringtemplate-interest] Attaching model to stringtemplate group
John Snyders
jjsnyders at rcn.com
Mon Sep 24 19:22:00 PDT 2007
If your template is going to be called recursively then the data structure should be recursive. Before setting the Elements attribute on the template you need to create all the elements and then for each of them create the children elements and their children and so on. The complete tree structure of elements must be created before calling StringTemplate. You need only explicitly set the Name, StartRule, and Elements attributes.
Does this answer your question or did I miss the point?
-John
---- Original message ----
>Date: Sun, 23 Sep 2007 20:09:29 +0200
>From: Johannes Luber <jaluber at gmx.de>
>Subject: Re: [stringtemplate-interest] Attaching model to stringtemplate group
>Cc: StringTemplate <stringtemplate-interest at antlr.org>
>
>Terence Parr wrote:
>> On Sep 17, 2007, at 8:23 AM, Johannes Luber wrote:
>>
>> Hi Johannes,
>>
>> I am not sure what you're asking here. There is no attaching a model
>> to the templates. You must send in data via setAttribute() to every
>> template and for all of the attributes that you intend to use in the
>> template.
>>
>> ST by itself requires you to manually set attributes and so on with
>> code, I'm afraid. Perhaps that is what you are asking. ANTLR
>> actions allow you to say %foo() to load template foo and then %x.y =
>> "hi" to set attribute y of template x to "hi".
>>
>> Ter
>
>The following is my entire STG-file (only two rules):
>
>group ANTLR3ToRelaxNG;
>
>/* Can AnyElement match only a single element or as many as wished?
>*/
>
>/** The start template. Call only this template from a program. */
>Grammar(Name, StartRule, Elements) ::= <<
># Grammar <Name>
>grammar{
>start = element <StartRule> { <StartRule>Content }
>
><Elements:{e|<CreateContent(element=e)>}; separator="\n">
>
>EpsilonToken = empty
>
>}
>>>
>
>/** This rule generates the content elements. */
>CreateContent(element) ::= <<
><if(element.IsRootElement)>
><element.Name>Content =
> <element.Children:{c|<CreateContent(element=c)>}>
><endif>
><if(element.IsAndElement)>(<element.Children:{c|<CreateContent(element=c)>};
>separator=",\n">)<endif>
><if(element.IsOrElement)>(<element.Children:{c|<CreateContent(element=c)>};
>separator="|\n">)<endif><endif>
><if(element.IsOptionalElement)><element.Children:{c|<CreateContent(element=c)>}>?<endif>
><if(element.IsZeroOrMoreElement)><element.Children:{c|<CreateContent(element=c)>}>*<endif>
><if(element.IsOneOrMoreElement)><element.Children:{c|<CreateContent(element=c)>}>+<endif>
><if(element.IsEmptyElement)><element.Name>Content = empty<endif>
><if(element.IsTextElement)><element.Name>Content = text<endif>
><if(element.IsAnyElement)><element.Name>Content = *<endif>
><if(element.IsLeafElement)>element <element.Name> {
><element.Name>Content }<endif>
>>>
>
>As you can see the second rule is to be used recursively. How do I setup
>the string template objects with the tree objects? How am I supposed to
>set the values correctly? The elements have properties with the same
>name as the tested attribute. Do you need any other information?
>
>On another note: Having read your problem with extended typing sessions:
>Did you consider already to switch the keyboard layout? I recommend
>Colemak on <http://www.colemak.com>. Better than Dvorák and once you get
>up to speed, even faster than Dvorák. I'm using it to reduce the strain
>on my fingers, too, and have been very satisfied. The only problem is
>the speed hit you take. The first week is especially gruesome and it
>took a few months to return to the old marks, so the undertaking is not
>for the faint of hard. :( But it is better than having constantly pain,
>isn't it?
>
>Johannes
>_______________________________________________
>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