Hi,

I want to rewrite a subtrees of the form

     \
      A
    / | \ 
   /  |  \
  B   C   D
         / \
        E...F

to

      \
       D
     / \ \
    A   \  \
   / \   \   \
  B  C    E...F


The problem is that D may be the subtree of an "arbitrary complex" expression 
that I don't know in advance - and I don't want to know. I am just interested 
in the surrounding construct defined by A, B, and C and want to become them 
the first child subtree of D, which itself takes over the place of its former 
parent A in the resulting tree.

Is there a smart way to to do this with tree rewrite rules of antlr 3.2? Or 
must I manually modify the tree?

I can think of a tree pattern rule similar to this

^(a=A b=B c=C ^(d=. children+=.*)) -> ^({$d.token} ^($a $b $c) $children+)

but this is rejected with the error:

Wildcard invalid as root; wildcard can itself be a tree

I found a discussion from 2008 in the archives ("wildcard in tree grammar") 
about that particular topic. The design decision was to interpret "." in a 
tree grammar always as a whole subtree, forbidding constructs like the one 
above. As far as I understood, the underyling mechanism with interleaved 
UP/DOWN tokens for tree grammars, however, is potentially capable to match 
such wildcard patterns.

I appreciate your hints and comments.


Regards,

Sebastian

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to