On Sep 12, 2009, at 12:06 AM, Gerald Rosenberg wrote:

> Given an existing AST with the two paths:
>
> ^( a b? ^(m n) c? d )
>
> and
>
> ^( a b? ^(x y? ^(m n)) c? d )
>
> (that is, both paths have the same root node 'a')
>
> Given that 'm' is the interesting node, is there a way to write tree  
> pattern matching rules that distinguish the 'm' based on the  
> separate paths?
>
>
> topdown : ^(m .*)  ; // works nicely, but matches on both paths
>
> topdown : ^(a .* ^(m *.) .*) ; // should this work?  I would expect  
> it to still match both paths

Hiya. i think structure is a bit off. you need ^(m .*) down a level.

> // should this work?
> topdown : ^(a .* ( ^(x .* ^(m .*) )    { call_1($m); } // on match  
> second path
>                  | ^(m .*)             { call_2($m); } // on match  
> first path
>                  )
>                  .*) ;

something like that *should* work but might not due to bug.

> As a concrete example, the ANTLR grammar defines identical  
> ^(OPTIONS .*) blocks, one that is a subtree of GRAMMAR and another  
> that is a subtree of RULE, which in turn is a subtree of GRAMMAR.   
> Would be best to directly distinguish them in the pattern match,  
> rather than poking around in the AST to examine parents.
>

i'd recommend doing ^(m .*) match and a pred in front that says  
hasAncestor(a) or something
Ter

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