[stringtemplate-interest] howto set separator in parallel list iteration
Jens Boeykens
jens.boeykens at gmail.com
Mon Jul 7 01:50:36 PDT 2008
I think I solved the bug. In ANTLRv3.g I changed the rule "altList" as
follows:
altList
@init {
// must create root manually as it's used by invoked rules in real antlr
tool.
// leave here to demonstrate use of {...} in rewrite rule
// it's really BLOCK[firstToken,"BLOCK"]; set line/col to previous ( or
: token.
CommonTree blkRoot =
(CommonTree)adaptor.create(BLOCK,input.LT(-1),"BLOCK");
}
: a1=alternative rewrite ( '|' a2=alternative rewrite )*
-> ^( {blkRoot} (alternative rewrite)+ EOB["EOB"] )
;
I deleted the question mark after rewrite in the tree rewrite rule.
Still need to find something for the separator now...
2008/7/7 Jens Boeykens <jens.boeykens at gmail.com>:
> Looks like the parallel iteration doesn't work correctly either. I
> miscopied my input...
>
> input: INT -> test(a={$int}) | CHAR -> test(b={$CHAR})
> output: INT -> test (a = {$int}) CHAR -> test (a = {$int})
>
> So it is correct for the first list [INT, CHAR], but it doesn't iterate
> over the second list [-> test(a={$int}), -> test(b={$CHAR})]
> The "-> test(b={$CHAR})" doesn't appear in the output. Instead the first
> element is displayed twice
>
> What I want to generate is (same as input):
> Expected output: INT -> test(a={$int}) | CHAR -> test(b={$CHAR})
>
> Greetings
>
>
> 2008/7/7 Jens Boeykens <jens.boeykens at gmail.com>:
>
> Hello!
>>
>> I have a problem with iterating parallel lists. I use antlr together with
>> stringtemplate to generate templates. My antlr code looks like this:
>>
>> altList
>> : ^( (a+=alternative r+=rewrite)+ )
>> ->altList(alternative={$a}, rewrite = {$r})
>> ;
>>
>>
>> my stringtemplate:
>>
>> altList(alternative, rewrite) ::= <<
>> <alternative,rewrite: {alt,rw | <alt> <rw>}>
>> >>
>>
>>
>>
>> This gives
>> input : INT -> test (a = {$int}) | CHAR -> test (a = {$int})
>> output: INT -> test (a = {$int}) CHAR -> test (a = {$int})
>>
>> So parallel iterating works, but the separator '|' is missing in the
>> output (before CHAR).
>>
>> What should I change in my template so I can add a separator.
>> Something like <alternative,rewrite: {alt,rw | <alt> <rw> | }> or
>> <alternative,rewrite: {alt,rw | <alt> <rw>; separator=" | "}>
>> doesn't work...
>>
>> Thanks!
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20080707/6e9e9a19/attachment.html
More information about the stringtemplate-interest
mailing list