如何指示语法不在 ANTLR 侦听器中生成某些方法?
How to instruct the grammar to NOT generate certain methods in the ANTLR listener?
我有这个语法:
foo : bar EOF;
bar : 'hello';
ANTLR 生成的侦听器接口包含以下四个方法:
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);
我不需要其中两个:exitFoo()
和 enterBar()
。是否可以以某种方式告诉 ANTLR 不要在界面中生成它们?实际上,我更愿意找到一种方法以某种方式告诉语法哪些语法规则需要那些 enter/exit 方法,而所有其他的都将被忽略。可能吗?
您不能抑制任何这些方法的生成,因为解析器希望它们在每个解析步骤触发侦听器时都存在。
我有这个语法:
foo : bar EOF;
bar : 'hello';
ANTLR 生成的侦听器接口包含以下四个方法:
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);
我不需要其中两个:exitFoo()
和 enterBar()
。是否可以以某种方式告诉 ANTLR 不要在界面中生成它们?实际上,我更愿意找到一种方法以某种方式告诉语法哪些语法规则需要那些 enter/exit 方法,而所有其他的都将被忽略。可能吗?
您不能抑制任何这些方法的生成,因为解析器希望它们在每个解析步骤触发侦听器时都存在。