Subrules vist listener

34 views
Skip to first unread message

paul.l...@gmail.com

unread,
Apr 9, 2013, 4:43:59 AM4/9/13
to antlr-di...@googlegroups.com
Hi everybody!

I have some problem with traversing the AST, produced by ANTLR. I Have some grammar like

{{{

definition : classType Identifier ('=' expression)?
| classType classMethod;

get : (KW_GET definition (from)? (where)?)
| (KW_GET aggregation '(' definition ')' (from)? (where)?)
| (aggregation '(' KW_GET definition (from)? (where)?')');

}}}

The point is that visitor finds the second level definitions, but doesn't visit sub definitions in the get rule.

{{{
public class DefinitionVisitor extends SMLGrammarBaseListener {

@Override
public void exitDefinition(DefinitionContext ctx) {
String id = ctx.Identifier().getText();
String type = ctx.classType().getText();
}
}}}

Tree from TestRig is fine.

Thanks for your help!

paul.l...@gmail.com

unread,
Apr 9, 2013, 4:59:09 AM4/9/13
to antlr-di...@googlegroups.com, paul.l...@gmail.com
Is it possible to get different trees using TestRig and API of ANTLR?


вторник, 9 апреля 2013 г., 12:43:59 UTC+4 пользователь paul.l...@gmail.com написал:

Sam Harwell

unread,
Apr 9, 2013, 3:48:05 PM4/9/13
to antlr-di...@googlegroups.com
Hi Paul,

You should really call your class DefinitionListener, since ANTLR 4 produces both listener and visitor interfaces and you are using the listener interface.

The following will result in DefinitionListener.exitDefinition() being called for every DefinitionContext in the parse tree.

DefinitionContext definition = parser.definition();
DefinitionListener listener = new DefinitionListener();
ParseTreeWalker.DEFAULT.walk(listener, tree)

--
Sam Harwell
Owner, Lead Developer
http://tunnelvisionlabs.com
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


paul.l...@gmail.com

unread,
Apr 9, 2013, 4:17:47 PM4/9/13
to antlr-di...@googlegroups.com
Thank you for your help! Could you tell me, is it possible to get different trees using TestRig and API of ANTLR?

Sam Harwell

unread,
Apr 9, 2013, 4:36:47 PM4/9/13
to antlr-di...@googlegroups.com
Can you give an example of what you're looking for?

Thank you,
Reply all
Reply to author
Forward
0 new messages