[stringtemplate-interest] nesting templates and getting theloop count of the outer loop
Roel Vanhout
rvanhout at riks.nl
Tue Oct 28 07:01:52 PDT 2008
To illustrate, I have made a minimal example program. The program and
template file below produce the output:
Group 0
Page 0.0
Page 1.1
Group 1
Page 0.0
Page 1.1
Page 2.2
Whereas I would have expected it to be:
Group 0
Page 0.0
Page 0.1
Group 1
Page 1.0
Page 1.1
Page 1.2
File "Program.cs":
using System;
using System.Text;
using Antlr.StringTemplate;
using System.Collections;
namespace st_test
{
class Page { }
class PageGroup { public ArrayList Pages; }
class Program
{
static void Main(string[] args)
{
StringTemplateGroup group = new StringTemplateGroup(new
System.IO.StreamReader("test.st"));
StringTemplate template = group.GetInstanceOf("main");
ArrayList all_pagegroups = new ArrayList();
PageGroup group1 = new PageGroup();
group1.Pages = new ArrayList();
group1.Pages.Add(new Page());
group1.Pages.Add(new Page());
all_pagegroups.Add(group1);
PageGroup group2 = new PageGroup();
group2.Pages = new ArrayList();
group2.Pages.Add(new Page());
group2.Pages.Add(new Page());
group2.Pages.Add(new Page());
all_pagegroups.Add(group2);
template.SetAttribute("all_pagegroups", all_pagegroups);
Console.WriteLine(template);
}
}
}
File "test.st":
group test;
inner(group_nr) ::= <<
Page <group_nr>.<i0>
>>
outer() ::= <<
Group <i0>
<it.Pages:inner(group_nr=i0);separator="\n">
>>
main(all_pagegroups) ::= <<
<all_pagegroups:outer();separator="\n">
>>
Thanks.
roel
-----Original Message-----
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Roel
Vanhout
Sent: Tuesday, October 28, 2008 11:30
To: Terence Parr
Cc: stringtemplate-interest at antlr.org
Subject: Re: [stringtemplate-interest] nesting templates and getting
theloop count of the outer loop
Hello Terence,
My reasoning was like this: in initialize_dlgs (the 'outer' template),
the group_nr is set to i0 in the 'outer' context. That value is then
passed to the 'inner' template where 'i0' is the counter of the 'inner'
context.
So with data like this:
page_group 0
- page 0
- page 1
page_group 1
- page 0
- page 1
the results would be
0,0
0,1
1,0
1,1
because in the outer loop i0 is the number of the page_group, which is
passed as an argument to the inner loop (the 'initialize_dlg' template)
which then iterates over the pages, where the counter is the number of
the page in that page group.
I hope this is a bit understandable :)
It's very well possible that I'm misunderstanding what the loop counter
represents, although it does exectly what I expect for the 'inner' loop.
What I'm after is a way to find the number of the 'outer' loop inside
the 'inner' template.
Thanks for your time.
cheers,
roel
-----Original Message-----
From: Terence Parr [mailto:parrt at cs.usfca.edu]
Sent: Monday, October 27, 2008 19:27
To: Roel Vanhout
Cc: stringtemplate-interest at antlr.org
Subject: Re: [stringtemplate-interest] nesting templates and getting the
loop count of the outer loop
Hi Roel,
you are saying that group_nr = i0 in the template application; how
could the values be different?
Ter
On Oct 27, 2008, at 9:49 AM, Roel Vanhout wrote:
> Hi,
>
>
> I have situation similar to what was asked here:
> http://markmail.org/message/izumze7jxytlwsds#query
> :stringtemplate%20i0+page:1+mid:izumze7jxytlwsds+state:results but the
> results that the poster there gets are not the same for me. A
> regression maybe, or differences in the Java/C# version? Or more
> probable, me missing something.
>
> My problem is as follows: I have templates like this:
>
> initialize_dlg(group_nr) ::= <<
> m_DialogIndexes["<group_nr>,<i0>"] = newdlg<it.ViewName>; }
> >>
>
> initialize_dlgs() ::= <<
> <it.Pages:initialize_dlg(group_nr=i0);separator="\n">
> >>
>
> The expexted output is for <group_nr> (in initialize_dlg) to be 0 a
> couple of times, then 1 a couple of times etc. However, <group_nr> and
> <i0> are always the same in initialize_dlg, which leads me to believe
> that <group_nr> is somehow passed not as the value of i0 in
> initialize_dlgs() but as a string literal 'i0' which is then re-
> evaluated in initialize_dlg.
>
> I'm using StringTemplate 3.0.1 for C#. Thanks.
>
>
> cheers,
>
> roel
> _______________________________________________
> 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
More information about the stringtemplate-interest
mailing list