Skip to content

How to instruct the grammar to NOT generate certain methods in the ANTLR listener?

I have this grammar:

foo : bar EOF;
bar : 'hello';

The listener interface, which ANTLR generates, contains these four methods:

public void enterFoo(final FooParser.LicenseContext ctx);
public void exitFoo(final FooParser.LicenseContext ctx);
public void enterBar(final FooParser.LicenseContext ctx);
public void exitBar(final FooParser.LicenseContext ctx);

Two of them are not needed for me: exitFoo() and enterBar(). Is it possible to tell ANTLR somehow to NOT generate them in the interface? I would actually prefer to find a way to somehow tell the grammar which grammar rules need those enter/exit methods, and all others would be ignored. Is it possible?



You cannot suppress the generation of any of these methods, because the parser expects them to be there when triggering the listener for each parse step.

User contributions licensed under: CC BY-SA
9 People found this is helpful