diff --git a/runtime/Java/src/org/antlr/v4/runtime/Parser.java b/runtime/Java/src/org/antlr/v4/runtime/Parser.java index 2bc1eb49d..a2947eda6 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/Parser.java +++ b/runtime/Java/src/org/antlr/v4/runtime/Parser.java @@ -626,7 +626,6 @@ public abstract class Parser extends Recognizer { _ctx = localctx; _ctx.start = _input.LT(1); if (_buildParseTrees) addContextToParseTree(); - if ( _parseListeners != null) triggerEnterRuleEvent(); } public void exitRule() { diff --git a/tool/playground/Main.java b/tool/playground/Main.java new file mode 100644 index 000000000..5a441efcb --- /dev/null +++ b/tool/playground/Main.java @@ -0,0 +1,48 @@ +import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.ParserRuleContext; + +public class Main +{ + public static void main(String[] args) + { + TParser parser = new TParser(new CommonTokenStream(new TLexer(new ANTLRInputStream("b")))); + parser.addParseListener(new MyTBaseListener()); + + parser.a(); + + System.out.println("######################"); + parser = new TParser(new CommonTokenStream(new TLexer(new ANTLRInputStream("x")))); + parser.addParseListener(new MyTBaseListener()); + parser.b(); + } + + private static class MyTBaseListener extends TBaseListener { + @Override + public void enterAlt1(TParser.Alt1Context ctx) + { + System.out.println("entering alt1"); + } + + @Override + public void exitAlt1(TParser.Alt1Context ctx) + { + System.out.println("exiting alt1"); + } + + @Override + public void enterB(TParser.BContext ctx) { + System.out.println("enter b"); + } + + @Override + public void exitB(TParser.BContext ctx) { + System.out.println("exiting b"); + } + + @Override + public void enterEveryRule(ParserRuleContext ctx) { + System.out.println("enterEveryRule"); + } + } +} diff --git a/tool/playground/T.g4 b/tool/playground/T.g4 new file mode 100644 index 000000000..33b79b8f9 --- /dev/null +++ b/tool/playground/T.g4 @@ -0,0 +1,8 @@ +grammar T; + +a + : 'b' #alt1 + | 'c' #alt2 + ; + +b : 'x' | 'y' {} ; diff --git a/tool/tool.iml b/tool/tool.iml index 44b1c5917..252bf4581 100644 --- a/tool/tool.iml +++ b/tool/tool.iml @@ -16,6 +16,7 @@ +