[antlr-interest] Filtering peer nodes in a tree

Terence Parr parrt at cs.usfca.edu
Sat Jul 18 17:08:23 PDT 2009


On Jul 18, 2009, at 5:06 PM, J. Stephen Riley Silber wrote:

> Hi gang,
>
> I'm having a bit of trouble with a tree filter.  I'm trying to take  
> ASSIGN trees like this:
>
> ^( ASSIGN ID expr )
>
> and merge them together whenever they are adjacent to each other in  
> a tree under a BLOCK node.  So, bigger example:
>
> ^( BLOCK
>     ^( foo ... )
>     ^( ASSIGN ID expr )
>     ^( ASSIGN ID expr )
>     ^( bar ... )
>  )
>
> would become
>
> ^( BLOCK
>     ^( foo ... )
>     ^( ASSIGN ID expr ID expr )
>     ^( bar ... )
>  )
>
> I tried using a rule like ^( BLOCK .* ASSIGN ASSIGN .* ), but that  
> didn't seem to work.

I've recently discovered that .* on the end doesn't seem to work too  
well. I think I tried .+ or was it .* followed by UP...no, i think it  
was ~UP*. I need to fix this.
Ter


More information about the antlr-interest mailing list