diff --git a/tool/playground/A.g4 b/tool/playground/A.g4 index 4faa35bde..fe231e8c7 100644 --- a/tool/playground/A.g4 +++ b/tool/playground/A.g4 @@ -10,6 +10,7 @@ e returns [int v] | '(' x=e ')' ; +INT : '9'; /* a : u=A A -> x | B b {Token t=$B;} -> y diff --git a/tool/playground/TestA.java b/tool/playground/TestA.java index 5b5fc3cc1..dbd968e29 100644 --- a/tool/playground/TestA.java +++ b/tool/playground/TestA.java @@ -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])); diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg index 6b80e4e0a..2c8dd748d 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg @@ -34,8 +34,8 @@ import org.antlr.v4.runtime.Token; public interface Listener extends ParseTreeListener\<\> { .Context ctx); -void exitRule(.Context ctx);}; separator="\n"> +void enter(.Context ctx); +void exit(.Context ctx);}; separator="\n"> } >> @@ -47,8 +47,8 @@ import org.antlr.v4.runtime.Token; public class BlankListener implements Listener { .Context ctx) { \} -@Override public void exitRule(.Context ctx) { \}}; separator="\n"> +@Override public void enter(.Context ctx) { \} +@Override public void exit(.Context ctx) { \}}; separator="\n"> @Override public void enterEveryRule(ParserRuleContext\<\> ctx) { } @Override public void exitEveryRule(ParserRuleContext\<\> ctx) { } @@ -540,7 +540,7 @@ public static class extends Context { VisitorDispatchMethod(method) ::= << @Override public void enterexitRule(ParseTreeListener\<\> listener) { - if ( listener instanceof Listener ) ((Listener)listener).enterexitRule(this); + if ( listener instanceof Listener ) ((Listener)listener).enterexit(this); } >>