change enterRule to enter in listener interface

This commit is contained in:
Terence Parr 2012-02-13 17:35:29 -08:00
parent b68ce1f5aa
commit 2091f2d001
3 changed files with 8 additions and 13 deletions

View File

@ -10,6 +10,7 @@ e returns [int v]
| '(' x=e ')'
;
INT : '9';
/*
a : u=A A -> x
| B b {Token t=$B;} -> y

View File

@ -28,7 +28,6 @@
*/
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
public class TestA {
@ -41,7 +40,7 @@ public class TestA {
}
@Override
public void enterRule(AParser.eContext ctx) {
public void enter(AParser.eContext ctx) {
System.out.println("enter alt w/o -> label: "+ctx.toInfoString(p));
}
@ -54,15 +53,10 @@ public class TestA {
}
@Override
public void exitRule(AParser.multContext ctx) {
public void exit(AParser.multContext ctx) {
System.out.println("mult "+ctx.a.v+" * "+ctx.b.v);
ctx.v = ctx.a.v * ctx.b.v; // repeat of what parser did--set return value
}
@Override
public void exitRule(AParser.addContext ctx) {
System.out.println("add "+ctx.a.v+" + "+ctx.b.v);
ctx.v = ctx.a.v + ctx.b.v;
}
}
public static void main(String[] args) throws Exception {
ALexer lexer = new ALexer(new ANTLRFileStream(args[0]));

View File

@ -34,8 +34,8 @@ import org.antlr.v4.runtime.Token;
public interface <file.grammarName>Listener extends ParseTreeListener\<<InputSymbolType()>\> {
<file.listenerNames:{lname |
void enterRule(<file.parserName>.<lname>Context ctx);
void exitRule(<file.parserName>.<lname>Context ctx);}; separator="\n">
void enter(<file.parserName>.<lname>Context ctx);
void exit(<file.parserName>.<lname>Context ctx);}; separator="\n">
}
>>
@ -47,8 +47,8 @@ import org.antlr.v4.runtime.Token;
public class Blank<file.grammarName>Listener implements <file.grammarName>Listener {
<file.listenerNames:{lname |
@Override public void enterRule(<file.parserName>.<lname>Context ctx) { \}
@Override public void exitRule(<file.parserName>.<lname>Context ctx) { \}}; separator="\n">
@Override public void enter(<file.parserName>.<lname>Context ctx) { \}
@Override public void exit(<file.parserName>.<lname>Context ctx) { \}}; separator="\n">
@Override public void enterEveryRule(ParserRuleContext\<<InputSymbolType()>\> ctx) { }
@Override public void exitEveryRule(ParserRuleContext\<<InputSymbolType()>\> ctx) { }
@ -540,7 +540,7 @@ public static class <s.name> extends <currentRule.name>Context {
VisitorDispatchMethod(method) ::= <<
@Override
public void <if(method.isEnter)>enter<else>exit<endif>Rule(ParseTreeListener\<<InputSymbolType()>\> listener) {
if ( listener instanceof <parser.grammarName>Listener ) ((<parser.grammarName>Listener)listener).<if(method.isEnter)>enter<else>exit<endif>Rule(this);
if ( listener instanceof <parser.grammarName>Listener ) ((<parser.grammarName>Listener)listener).<if(method.isEnter)>enter<else>exit<endif>(this);
}
>>