[antlr-interest] wildcard in tree grammar

Terence Parr parrt at cs.usfca.edu
Mon Dec 1 11:26:06 PST 2008


On Dec 1, 2008, at 10:16 AM, Oliver Zeigermann wrote:

> 2008/12/1 Terence Parr <parrt at cs.usfca.edu>:
>>
>> On Nov 30, 2008, at 11:15 PM, Gavin Lambert wrote:
>>>
>>> And then of course there's Oliver's example, where he just wanted to
>>> traverse the (sub)tree regardless of structure (presumably to  
>>> pretty-print
>>> it or something).
>>
>> If you don't care about structure, one could argue why you're using a
>> grammar to do that ;)
>
> Maybe you care about structure, but only in certain sections of the
> tree and still want to touch every single node of the tree (which
> makes this different from the new cool partial tree matching in 3.2)
>
> treee
>       : ^(ID treee*)  { do something very different with $ID here and
> maybe also something with the children}
>       | ^(a=. treee* ) { do something meaningful with $a here }
>       ;
>
> Does that make sense?

It seems to me like you're saying "do x on ID or y on any other  
node".  remember that once you match a node, you can ask for child  
list or even parent.

Ter


More information about the antlr-interest mailing list