[stringtemplate-interest] Attributes in derived templates.
Terence Parr
parrt at cs.usfca.edu
Mon Apr 23 13:55:15 PDT 2007
On Apr 23, 2007, at 1:14 AM, Andrew Melnichuk wrote:
> Hmm....
>
> I have thought that code below assigns attribute value to template:
>
> StringTemplate stContent = stg.GetInstanceOf("someContent");
> stContent.SetAttribute("attr", "Derrived Content");
>
> Maybe ST does not allow set attributes in this way?
it does, but you are using $someContent()$ below, which does not set
$attr$.
Ter
>
> On 4/23/07, Terence Parr <parrt at cs.usfca.edu> wrote: Hi. it seems
> to me to you are not passing anything to template
> someContent, therefore "$attr$" will have no value and be empty.
>
> sorry for the delay and my absence on the string template list. I
> will be picking up string template development during the summer. I
> am almost done with version 3 release of ANTLR. The book will be
> printed in early May, which includes examples using ANTLR and ST for
> source is code generation!
> Ter
> On Apr 20, 2007, at 1:56 AM, Andrew Melnichuk wrote:
>
> > Hi all.
> >
> > I have a simple base group defined:
> > -------------
> > group basepage;
> >
> > page() ::= <<
> > <html>
> > $someContent()$
> > </html>
> > >>
> >
> > someContent() ::= "Base Content"
> > -----------
> >
> > I also have derived group defined, which overrides content template:
> >
> > -----------
> > group concretepage : basepage;
> >
> > someContent(attr) ::= "$attr$"
> > -----------
> >
> > I want to render a page, and i want it uses a derived content
> > template, with passed attribute's value, so in code i'm doing next:
> >
> > StringTemplateGroup.RegisterDefaultLexer (typeof
> > (DefaultTemplateLexer));
> > StringTemplateGroup.RegisterGroupLoader(loader);
> >
> > StringTemplateGroup stg = StringTemplateGroup.LoadGroup
> > ("concretepage");
> >
> > StringTemplate stPage = stg.GetInstanceOf ("page");
> > StringTemplate stContent = stg.GetInstanceOf
> > ("someContent");
> > stContent.SetAttribute ("attr", "Derrived Content");
> >
> > Console.WriteLine (stPage.ToString());
> >
> > I'm expecting that derived template will get attributes its value,
> > but it does not. So, result i'm having is "<html></html>", but
> > expected "<html>Derrived Content</html>".
> >
> > Am i doing something wrong?
> > --
> > Best regards,
> > Andrew Melnichuk
> > _______________________________________________
> > stringtemplate-interest mailing list
> > stringtemplate-interest at antlr.org
> > http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
>
>
> --
> Best regards,
> Andrew Melnichuk
> _______________________________________________
> 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