Thanks for the help. I didn't know the behavior I was employing was undefined. With some re-factoring I have my grammars working again. The refactor was more complex when the sub rule could return different root types (I ended up adding sub-rules with predicates) and when the contents of the new root-node depend on a value matched in the sub-rule (where I now use a return value). It works great though, I'm glad to know now that I was mistaken before.
-JC On Tue, Jan 4, 2011 at 6:54 PM, Jim Idle <[email protected]> wrote: > Your grammar is erroneous and just 'happened' to work in 3.2. The root of > a node can only be the result of a sib rule if the subrule contains a > single node, otherwise the results are undefined. > > You would need: > > callTarget > : call > -> ^(FUNCTION call PACK) > ; > > call > : ID ID ID > ; > > Which is easily constructed in all situations, even if you add an extra > root node: > > > callTarget > : call > -> ^(CALL call PACK) > ; > > call > : one=ID two=ID three=ID > -> ^(FUNCTION $one $two $three) > ; > > > > -----Original Message----- > > From: [email protected] [mailto:antlr-interest- > > [email protected]] On Behalf Of Joseph Cottam > > Sent: Tuesday, January 04, 2011 3:48 PM > > To: [email protected] > > Subject: [antlr-interest] AST loosing leaves in 3.3 vs. 3.2 > > > > Upgrading from v3.2 to v3.3, I started loosing the leaves in some of my > > rules. All affected rule-pairs have the same structure: The results of > > called rule becomes the root of the AST returned by the rule doing the > > calling AND the calling rule adds more nodes to the AST (not just > > returning the results of the called rule). In the example below, the > > result of matching the "call" rule is truncated to just its root when > > it is referred to in the construction of the AST for "callTarget." I > > feel like I am missing something simple, but I can't figure out what > > part of the v3.3 release notes covers this circumstance. > > > > 3.2 output: (FUNCTION first second third PACK) > > 3.3 output: (FUNCTION PACK) > > > > -Joseph A. Cottam > > > > > > input------------------------ > > first second third > > > > grammar------------------- > > grammar Error; > > > > options { > > language = Java; > > output=AST; > > } > > > > tokens {FUNCTION; PACK;} > > > > callTarget > > : call > > -> ^(call PACK) > > ; > > > > call > > : one=ID two=ID three=ID > > -> ^(FUNCTION $one $two $three) > > ; > > > > ID : ('a'..'z' | 'A'..'Z' | '_') ('.'? ('a'..'z' | 'A'..'Z' | '_' | > > '0'..'9'))*; > > WS : (' '|'\r'|'\t'|'\u000C'|'\n')+ {skip();}; > > > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your- > > email-address > 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.
