I'm rewriting a tree in a way that I think follows the rules.  Here's
a sample input fragment:

"one" == "two" && "three" == "four" && "five" == "six"

The following rewrite works correctly, but then I have to iterate over
the list and match rhs-lhs pairs,a mere minor annoyance I suppose:

matchExpression
  : (object EQUALS object) (AND object EQUALS object)*
    -> ^(AST_MATCH object+)
  ;

This version gives the following tree:

(AST_MATCH "one" "two" "three" "four" "five" "six")

I'd prefer to have a list of the right-hand side and one of the
left-hand side, so I tried the following:

matchExpression
  : (rhs=object EQUALS lhs=object) (AND rhs=object EQUALS lhs=object)*
    -> ^(AST_MATCH ^(AST_MATCH_ARG $rhs+) ^(AST_MATCH_ARG $lhs+))
  ;

The above yields the following tree:

(AST_MATCH (AST_MATCH_ARG "five") (AST_MATCH_ARG "six"))

But I expected the following:

(AST_MATCH (AST_MATCH_ARG "one" "three" "five") (AST_MATCH_ARG "two"
"four" "six"))

As 'rhs' and 'lhs' are indeed present more than once, and being
matched more than once, shouldn't the rewritten tree contain all the
nodes or am I misunderstanding something?

Thanks.

--
Kaleb Pederson

Blog - http://kalebpederson.com
Twitter - http://twitter.com/kalebpederson

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