[stringtemplate-interest] Re : Question on using index variable(<i> and <i0>) in invoked template

Matthieu Wipliez mwipliez at yahoo.fr
Mon Nov 28 11:13:42 PST 2011


Hi Jiwon,

you can use an anonymous template to do that:

<insert("pos", {prefix<i0>})>

(the + operator is not available in ST 4 IIRC)

Cheers
Matthieu




>________________________________
> De : Jiwon Seo <jiwon at stanford.edu>
>À : Terence Parr <parrt at cs.usfca.edu> 
>Cc : stringtemplate-interest at antlr.org 
>Envoyé le : Lundi 28 Novembre 2011 20h03
>Objet : Re: [stringtemplate-interest] Question on using index variable(<i> and <i0>) in invoked template
> 
>Thanks.
>
>Actually I have one more question.
>What I really want to do is to concatenate <i0> with a constant string
>and pass it as an argument
>as following:
>
><sorted:{s|<if(s)><insert("pos", "prefix"+<i0>)><endif>}; separator=";\n">
>
>but it seems like it doesn't work with or without <>
>
>-Jiwon
>
>
>On Mon, Nov 28, 2011 at 9:02 AM, Terence Parr <parrt at cs.usfca.edu> wrote:
>> hi. once inside <…> just use i0.  <insert("pos", i0)> :)
>> Ter
>> On Nov 28, 2011, at 2:08 AM, Jiwon Seo wrote:
>>
>>> Hi,
>>>
>>> I'm trying to invoke a template inside an anonymous template as following:
>>>
>>> <sorted:{s|<if(s)><insert("pos", <i0>)><endif>}; separator=";\n">
>>>
>>> So, for each value (s) in the attribute sorted, I want to add a string
>>> generated by the template insert only when s has the value true.
>>> When invoking the insert template, I need to pass the iteration count
>>> (index of s in the sorted).
>>>
>>> The above template code produces an error message that <i0> is
>>> unexpected (more accurately, the "<" is unexpected).
>>>
>>> How can I pass the iteration count to the invoked template?
>>>
>>> Thanks!
>>> _______________________________________________
>>> stringtemplate-interest mailing list
>>> stringtemplate-interest at antlr.org
>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>
>>
>_______________________________________________
>stringtemplate-interest mailing list
>stringtemplate-interest at antlr.org
>http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20111128/46b8bf99/attachment.html 


More information about the stringtemplate-interest mailing list