<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">might be bug where i ignore arg if only one formal arg and you iterate.<div>Ter<br><div><div>On Aug 22, 2009, at 5:02 AM, Vincent Dupuis wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; ">If you have time to try it, here is the code:<br><br>Main.java :<br><br>package javaapplication2;<br><br>import java.io.FileNotFoundException;<br>import java.io.FileReader;<br>import java.io.IOException;<br>import java.util.ArrayList;<br>import java.util.List;<br>import org.antlr.stringtemplate.StringTemplate;<br>import org.antlr.stringtemplate.StringTemplateGroup;<br><br>public class Main<br>{<br> public static void main(String[] args)<br> {<br> StringTemplateGroup stg;<br> stg = openTemplateFile("templates.stg");<br><br> StringTemplate aClass;<br> StringTemplate aClass2;<br> List list = new ArrayList();<br> List list2 = new ArrayList();<br><br> aClass = new StringTemplate();<br> aClass.setAttribute("name", "A");<br> list.add(aClass);<br><br> aClass2 = new StringTemplate();<br> aClass2.setAttribute("name", "InnerB");<br> list2.add(aClass2);<br><br> aClass = new StringTemplate();<br> aClass.setAttribute("name", "B");<br> aClass.setAttribute("listOfSubClasses", list2);<br> list.add(aClass);<br><br> aClass = new StringTemplate();<br> aClass.setAttribute("name", "C");<br> list.add(aClass);<br><br> StringTemplate st = stg.getInstanceOf("mainTemplate");<br> st.setAttribute("listOfClasses", list);<br><br> System.out.println(st.toString());<br> }<br><br> private static StringTemplateGroup openTemplateFile(String fileName)<br> {<br> try<br> {<br> FileReader fileReader;<br> fileReader = new FileReader(fileName);<br><br> StringTemplateGroup templates;<br> templates = new StringTemplateGroup(fileReader);<br><br> fileReader.close();<br><br> return templates;<br> }<br> catch (FileNotFoundException e)<br> {<br> System.err.println(e.toString());<br> System.exit(1);<br> return null;<br> }<br> catch (IOException e)<br> {<br> System.err.println(e.toString());<br> System.exit(1);<br> return null;<br> }<br> }<br>}<br><br><br>templates.stg :<br><br>group templates;<br><br>mainTemplate(listOfClasses) ::= <<<br><listOfClasses:classDeclaration(parent="TopClass"); separator="\n"><br>>><br><br>classDeclaration(parent) ::= <<<br>class <it.name> : public <parent><br>{<br> <it.listOfSubClasses:classDeclaration(parent=it.name); separator="\n"><br>}<br>>><br><br><br>Expected output for class B :<br><br>class B : public TopClass<br>{<br> class InnerB : public B<br> {<br> }<br>}<br><br><br>V<br><br><hr id="stopSpelling">From:<span class="Apple-converted-space"> </span><a href="mailto:parrt@cs.usfca.edu">parrt@cs.usfca.edu</a><br>To:<span class="Apple-converted-space"> </span><a href="mailto:vincedupuis@hotmail.com">vincedupuis@hotmail.com</a><br>Subject: Re: [stringtemplate-interest] Help with recursive template application<br>Date: Fri, 21 Aug 2009 17:09:12 -0700<br><br>verrrry strange. not sure what's up.<div>Ter<br><div><div>On Aug 21, 2009, at 4:24 PM, Vincent Dupuis wrote:</div><br class="EC_Apple-interchange-newline"><blockquote><span class="EC_Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; "><div class="EC_hmmessage" style="font-size: 10pt; font-family: Verdana; ">I retried just to be sure, but it doesn't work.<br><br>I removed the iter parameter and use <it> in classDeclaration<span class="EC_Apple-converted-space"> </span><br>and I still don't get the good output. (see blow).<br><br>V<br><br><br>> CC:<span class="EC_Apple-converted-space"> </span><a href="mailto:stringtemplate-interest@antlr.org">stringtemplate-interest@antlr.org</a><br>> From:<span class="EC_Apple-converted-space"> </span><a href="mailto:parrt@cs.usfca.edu">parrt@cs.usfca.edu</a><br>> To:<span class="EC_Apple-converted-space"> </span><a href="mailto:vincedupuis@hotmail.com">vincedupuis@hotmail.com</a><br>> Subject: Re: [stringtemplate-interest] Help with recursive template application<br>> Date: Fri, 21 Aug 2009 11:21:35 -0700<br>><span class="EC_Apple-converted-space"> </span><br>><span class="EC_Apple-converted-space"> </span><br>> On Aug 21, 2009, at 6:40 AM, Vincent Dupuis wrote:<br>><span class="EC_Apple-converted-space"> </span><br>> > Terence, thanks for your reply.<br>> ><br>> > After I read your comments, I tried many combination to make it work<br>> > and the only way was to explicitly assign parameters to the template<span class="EC_Apple-converted-space"> </span><br>> > like this:<br>> ><br>> > group templates;<br>> ><br>> > mainTemplate(listOfClasses) ::= <<<br>> > <listOfClasses:classDeclaration(iter=it, parent="TopClass");<span class="EC_Apple-converted-space"> </span><br>> > separator="\n"><br>> > >><br>><span class="EC_Apple-converted-space"> </span><br>> > <listOfClasses:classDeclaration(parent="TopClass"); separator="\n"><br>><span class="EC_Apple-converted-space"> </span><br>> and<br>><span class="EC_Apple-converted-space"> </span><br>> > classDeclaration(parent) ::= <<<br>><span class="EC_Apple-converted-space"> </span><br>> will work if youuse <it> in classDeclaration.<br>><span class="EC_Apple-converted-space"> </span><br>> ><br>> > classDeclaration(iter, parent) ::= <<<br>> > class <iter.name> : public <parent><br>> > {<br>> > <iter.listOfSubClasses:classDeclaration(parent=iter.name,<span class="EC_Apple-converted-space"> </span><br>> > iter=it); separator="\n"><br>> > }<br>> > >><br>> ><br>> > Notice that the parameters are reversed in the second call to<span class="EC_Apple-converted-space"> </span><br>> > classDeclaration().<br>> > It doesn't work if I don't reverse them!?<br>><span class="EC_Apple-converted-space"> </span><br>> nor should you expect it to. no assumed order of operations even in<span class="EC_Apple-converted-space"> </span><br>> param list. it has to pick one and it does in order.<br>><span class="EC_Apple-converted-space"> </span><br>> T<br>><span class="EC_Apple-converted-space"> </span><br>> ><br>> > Anyway it works, but I don't know if it's normal.<br>> > Maybe I missed something.<br>> ><br>> > Vincent<br>> ><br>> ><br>> ><br>> > > CC:<span class="EC_Apple-converted-space"> </span><a href="mailto:stringtemplate-interest@antlr.org">stringtemplate-interest@antlr.org</a><br>> > > From:<span class="EC_Apple-converted-space"> </span><a href="mailto:parrt@cs.usfca.edu">parrt@cs.usfca.edu</a><br>> > > To:<span class="EC_Apple-converted-space"> </span><a href="mailto:vincedupuis@hotmail.com">vincedupuis@hotmail.com</a><br>> > > Subject: Re: [stringtemplate-interest] Help with recursive<span class="EC_Apple-converted-space"> </span><br>> > template application<br>> > > Date: Thu, 20 Aug 2009 11:53:22 -0700<br>> > ><br>> > ><br>> > > On Aug 19, 2009, at 6:28 PM, Vincent Dupuis wrote:<br>> > ><br>> > > > Hi,<br>> > > ><br>> > > > I'm trying to pass a "parent" value in a recursive template<br>> > > > application<br>> > > > but without success. Here are my templates:<br>> > > ><br>> > > > group templates;<br>> > > ><br>> > > > mainTemplate(listOfClasses) ::= <<<br>> > > > <listOfClasses:classDeclaration("TopClass"); separator="\n"><br>> > > > >><br>> > ><br>> > > you are passing to parameters here: the iterated value and the<span class="EC_Apple-converted-space"> </span><br>> > string.<br>> > > If there is one parameter, the iteration operator sets that sole<br>> > > parameter to the iterated value.<br>> > > T<br>> > ><br>> > > ><br>> > > > classDeclaration(parent) ::= <<<br>> > > > class <it.name> : public <parent><br>> > > > {<br>> > > > <it.listOfSubClasses:classDeclaration({<it.name>});<br>> > > > separator="\n"><br>> > > > }<br>> > > > >><br>> > > ><br>> > > > Considering A, B, and C classes are TopClass and that BB class<span class="EC_Apple-converted-space"> </span><br>> > is an<br>> > > > inner class of B.<br>> > > ><br>> > > > and the output is...<br>> > > ><br>> > > > class A : public TopClass<br>> > > > {<br>> > > > }<br>> > > > class B : public TopClass<br>> > > > {<br>> > > > class BB : public BB<br>> > > > {<br>> > > > }<br>> > > > }<br>> > > > class C : public TopClass<br>> > > > {<br>> > > > }<br>> > > ><br>> > > ><br>> > > > Why I don't get the right value for class BB ?<br>> > > > Like:<br>> > > ><br>> > > > class BB : public B<br>> > > > {<br>> > > > }<br>> > > ><br>> > > ><br>> > > > Somebody knows why?<br>> > > ><br>> > > > Thanks,<br>> > > ><br>> > > > Vince<br>> > > ><br>> > > ><br>> > > > Créez un personnage à votre image pour votre WL Messenger Venez<span class="EC_Apple-converted-space"> </span><br>> > voir<br>> > > > _______________________________________________<br>> > > > stringtemplate-interest mailing list<br>> > > ><span class="EC_Apple-converted-space"> </span><a href="mailto:stringtemplate-interest@antlr.org">stringtemplate-interest@antlr.org</a><br>> > > ><span class="EC_Apple-converted-space"> </span><a href="http://www.antlr.org/mailman/listinfo/stringtemplate-interest">http://www.antlr.org/mailman/listinfo/stringtemplate-interest</a><br>> > ><br>> ><br>> > Attention à tous les Humains. Nous sommes vos photos. Libérez-nous<span class="EC_Apple-converted-space"> </span><br>> > de vos disques durs.<br>><span class="EC_Apple-converted-space"> </span><br><br><hr>Nous sommes vos photos. Partagez-nous dès maintenant avec<span class="EC_Apple-converted-space"> </span><a href="http://go.microsoft.com/?linkid=9666049">Windows Live Photos.</a></div></span></blockquote></div><br></div><br><hr>Nous sommes vos photos. Partagez-nous dès maintenant avec<span class="Apple-converted-space"> </span><a href="http://go.microsoft.com/?linkid=9666049" target="_new">Windows Live Photos.</a></div></span></blockquote></div><br></div></body></html>