[antlr-interest] wildcard in tree grammar

Oliver Zeigermann oliver.zeigermann at gmail.com
Thu Nov 27 08:23:19 PST 2008


Right. Exactly that is my problem :(

2008/11/27 Sam Harwell <sharwell at pixelminegames.com>:
> That should be correct, but under the current implementation, I believe
> it will match any tree with the . wildcard, then find 0 instances of
> tree. The problem doesn't occur in the rule you have here, but this rule
> will only print 1 line, regardless of the input tree:
>
> tree : ^(. {System.out.println("tree node");} tree*)
>
> Sam
>
> -----Original Message-----
> From: Oliver Zeigermann [mailto:oliver.zeigermann at gmail.com]
> Sent: Thursday, November 27, 2008 2:24 AM
> To: Gavin Lambert
> Cc: Terence Parr; Sam Harwell; antlr-interest Interest
> Subject: Re: [antlr-interest] wildcard in tree grammar
>
> 2008/11/27 Gavin Lambert <antlr at mirality.co.nz>:
>> In other words (in vaguely ANTLR-like syntax):
>>
>>   wildtree : ANYNODE | ^(ANYNODE wildtree*) ;
>>
>>   .          => wild
>>   ^(.)       => ANYNODE
>>   ^(. FOO)   => ^(ANYNODE FOO)
>>   ^(FOO .)   => ^(FOO wildtree)
>>   ^(FOO . .) => ^(FOO wildtree wildtree)
>>   ^(FOO .+)  => ^(FOO wildtree+)
>>   ^(FOO .*)  => ^(FOO wildtree*)
>
> Using these semantics my original rule
>
> tree : ^(. tree* ) ;
>
> would match any tree even if subtrees are single nodes only, right?
>
> Oliver
>


More information about the antlr-interest mailing list