[antlr-interest] found more bugs in ANTLRv3.g + howto add separator when parallel iterating 2 lists in stringtemplate
Jens Boeykens
jens.boeykens at gmail.com
Mon Jul 7 14:23:43 PDT 2008
Response at the bottem;)
Terence Parr schreef:
>
> On Jul 7, 2008, at 2:44 AM, Jens Boeykens wrote:
>
>> I think I found 2 more bugs in ANTLRv3.g
>> http://www.antlr.org/grammar/ANTLR
>>
>> Rule altlist:
>>
>> 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 removed the question mark after rewrite in the tree rewrite
>> subrule. This caused problems with parallel iteration of lists. (Only
>> the first rewrite appeared in the tree).
>
> Ah! Correct. Thanks. Updated in the depot.
>
>> Also see my post on the stringtemplate mailing list.
>>
>> Rule block:
>>
>> block
>> : lp='('
>> ( (opts=optionsSpec)? ':' )?
>> a1=alternative rewrite ( '|' a2=alternative rewrite )*
>> rp=')'
>> -> ^( BLOCK[$lp,"BLOCK"] optionsSpec? (alternative rewrite)+
>> EOB[$rp,"EOB"] )
>> ;
>
> Fixed.
>
>> I added "rewrite" to the tree rewrite subrule. Otherwise rewrite was
>> missing in the tree. Also changed block in ANTLRv3Tree.g
>>
>> block
>> : ^( BLOCK optOptionsSpec (a+=alternative r+=rewrite)+ EOB )
>> -> block(blok={$BLOCK}, optionsSpec={$optOptionsSpec.st},
>> alternative={$a}, rewrite={$r},
>> eob={$EOB})
>> ;
>
> Fixed.
>
>> I now have a problem iterating parallel through 2 lists (alternative
>> and rewrite) in my stringtemplate:
>>
>> block(blok, optionsSpec, alternative, rewrite, eob) ::= <<
>> <alternative,rewrite: {alt,rw | <alt> <rw> }>
>> >>
>>
>> This should regenerate a rule like r: a -> int | b -> char;
>> My output however is: r: a -> int b -> char;
>> Thus no separator.
>>
>> If I use template (added a '|'):
>>
>> block(blok, optionsSpec, alternative, rewrite, eob) ::= <<
>> <alternative,rewrite: {alt,rw | <alt> <rw> | }>
>> >>
>>
>> I have one '|' too many in my output:
>> r: a -> int | b -> char |;
>
> Use <...; separator="|">
Sorry I can't find the exact syntax to use here. Remember I need 2 lists
here.
<alternative,rewrite; separator=" | "> and <alternative rewrite;
separator=" | "> give errors...
>
> Ter
>
More information about the antlr-interest
mailing list