[stringtemplate-interest] Iteration over multi-valued attribute using implied counter $i$ and first() rest()
Michael Albanese (malbanes)
malbanes at cisco.com
Thu Jan 8 16:44:39 PST 2009
> -----Original Message-----
> From: Terence Parr [mailto:parrt at cs.usfca.edu]
> Sent: Thursday, January 08, 2009 4:33 PM
> To: Michael Albanese (malbanes)
> Cc: stringtemplate-interest at antlr.org
> Subject: Re: [stringtemplate-interest] Iteration over
> multi-valued attribute using implied counter $i$ and first() rest()
>
> Hi. I believe all you need is:
>
> make_keys_comparison(keys) ::= <<
> $keys:{record[$i$] == $it$)}; separator=" and "$ >>
>
> Ter
Thank you, yes this did it.
I had started down a similar path but struggled with the
correct syntax concerning of the semi colon.
As with all good answers it looks obvious now :{
Thanks again,
Michael
> On Jan 8, 2009, at 2:16 PM, Michael Albanese (malbanes) wrote:
>
> > I have a need to traverse a multi-valued attribute utilizing the
> > built-in iteration counter $i$ in addition to special casing for
> > elements first() then rest().
> >
> > The following worker template that is passed a vector of strings
> > almost works for my needs.
> >
> > make_keys_comparison(keys) ::= <<
> > $first(keys):{(record[$i$] == $it$)}$ $rest(keys):{ and
> (record[$i$]
> > == $it$)}$
> >>>
> >
> > I am using the implied $i$ iteration counter for part of the source
> > generation as it conveniently could serve as the field
> offset for my
> > generated lua source code.
> >
> > ...my desired output is an 'if' condition in lua source
> code. So in a
> > good world I want the following output where keys = { agent slot
> > module }.
> >
> > if (record[1] == agent) and (record[2] == slot) and (record[3] ==
> > module) then
> > return record
> > end
> >
> > ...where the make_keys_comparison() template produces the
> conditionals
> > inside the 'if' and the generated array offsets graduate
> sequentially
> > from 1 to 'n'.
> >
> >
> > What I get however is slightly off, and I believe has to do
> with the
> > scoping of the implied $i$ counter. Apparently a new
> instance of the
> > $i$ counter is scoped for both the first() and rest() attribute
> > operators, and for my needs this hurts as evidenced by the actual
> > output.
> >
> > if (record[1] == agent) and (record[1] == slot) and (record[2] ==
> > module) then
> > return record
> > end
> >
> > Here one can see that the record[] offsets are not
> accurate. They are
> > affected apparently by the scoping of $i$ between first()
> and rest().
> >
> > I'd like to know if using the $i$ is the wrong tact here
> (or perhaps
> > there is a bug and this should work ?).
> >
> > If not is there a way to count and display that count value
> along with
> > each element(s) in the multi-valued 'keys' attribute while also
> > retaining the special casing needed for first/rest ?
> >
> > Thanks,
> > Michael
> >
> >
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > stringtemplate-interest mailing list
> > stringtemplate-interest at antlr.org
> > http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
>
More information about the stringtemplate-interest
mailing list