[stringtemplate-interest] Help with recursive template application

Terence Parr parrt at cs.usfca.edu
Fri Aug 21 11:21:35 PDT 2009


On Aug 21, 2009, at 6:40 AM, Vincent Dupuis wrote:

> Terence, thanks for your reply.
>
> After I read your comments, I tried many combination to make it work
> and the only way was to explicitly assign parameters to the template  
> like this:
>
> group templates;
>
> mainTemplate(listOfClasses) ::= <<
> <listOfClasses:classDeclaration(iter=it, parent="TopClass");  
> separator="\n">
> >>

> <listOfClasses:classDeclaration(parent="TopClass"); separator="\n">

and

> classDeclaration(parent) ::= <<

will work if youuse <it> in classDeclaration.

>
> classDeclaration(iter, parent) ::= <<
> class <iter.name> : public <parent>
> {
>     <iter.listOfSubClasses:classDeclaration(parent=iter.name,  
> iter=it); separator="\n">
> }
> >>
>
> Notice that the parameters are reversed in the second call to  
> classDeclaration().
> It doesn't work if I don't reverse them!?

nor should you expect it to.  no assumed order of operations even in  
param list. it has to pick one and it does in order.

T

>
> Anyway it works, but I don't know if it's normal.
> Maybe I missed something.
>
> Vincent
>
>
>
> > CC: stringtemplate-interest at antlr.org
> > From: parrt at cs.usfca.edu
> > To: vincedupuis at hotmail.com
> > Subject: Re: [stringtemplate-interest] Help with recursive  
> template application
> > Date: Thu, 20 Aug 2009 11:53:22 -0700
> >
> >
> > On Aug 19, 2009, at 6:28 PM, Vincent Dupuis wrote:
> >
> > > Hi,
> > >
> > > I'm trying to pass a "parent" value in a recursive template
> > > application
> > > but without success. Here are my templates:
> > >
> > > group templates;
> > >
> > > mainTemplate(listOfClasses) ::= <<
> > > <listOfClasses:classDeclaration("TopClass"); separator="\n">
> > > >>
> >
> > you are passing to parameters here: the iterated value and the  
> string.
> > If there is one parameter, the iteration operator sets that sole
> > parameter to the iterated value.
> > T
> >
> > >
> > > classDeclaration(parent) ::= <<
> > > class <it.name> : public <parent>
> > > {
> > > <it.listOfSubClasses:classDeclaration({<it.name>});
> > > separator="\n">
> > > }
> > > >>
> > >
> > > Considering A, B, and C classes are TopClass and that BB class  
> is an
> > > inner class of B.
> > >
> > > and the output is...
> > >
> > > class A : public TopClass
> > > {
> > > }
> > > class B : public TopClass
> > > {
> > > class BB : public BB
> > > {
> > > }
> > > }
> > > class C : public TopClass
> > > {
> > > }
> > >
> > >
> > > Why I don't get the right value for class BB ?
> > > Like:
> > >
> > > class BB : public B
> > > {
> > > }
> > >
> > >
> > > Somebody knows why?
> > >
> > > Thanks,
> > >
> > > Vince
> > >
> > >
> > > Créez un personnage à votre image pour votre WL Messenger Venez  
> voir
> > > _______________________________________________
> > > stringtemplate-interest mailing list
> > > stringtemplate-interest at antlr.org
> > > http://www.antlr.org/mailman/listinfo/stringtemplate-interest
> >
>
> Attention à tous les Humains. Nous sommes vos photos. Libérez-nous  
> de vos disques durs.



More information about the stringtemplate-interest mailing list