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 ')' | '(' x=e ')'
; ;
INT : '9';
/* /*
a : u=A A -> x a : u=A A -> x
| B b {Token t=$B;} -> y | B b {Token t=$B;} -> y

View File

@ -28,7 +28,6 @@
*/ */
import org.antlr.v4.runtime.*; import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker; import org.antlr.v4.runtime.tree.ParseTreeWalker;
public class TestA { public class TestA {
@ -41,7 +40,7 @@ public class TestA {
} }
@Override @Override
public void enterRule(AParser.eContext ctx) { public void enter(AParser.eContext ctx) {
System.out.println("enter alt w/o -> label: "+ctx.toInfoString(p)); System.out.println("enter alt w/o -> label: "+ctx.toInfoString(p));
} }
@ -54,15 +53,10 @@ public class TestA {
} }
@Override @Override
public void exitRule(AParser.multContext ctx) { public void exit(AParser.multContext ctx) {
System.out.println("mult "+ctx.a.v+" * "+ctx.b.v); 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 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 { public static void main(String[] args) throws Exception {
ALexer lexer = new ALexer(new ANTLRFileStream(args[0])); 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()>\> { public interface <file.grammarName>Listener extends ParseTreeListener\<<InputSymbolType()>\> {
<file.listenerNames:{lname | <file.listenerNames:{lname |
void enterRule(<file.parserName>.<lname>Context ctx); void enter(<file.parserName>.<lname>Context ctx);
void exitRule(<file.parserName>.<lname>Context ctx);}; separator="\n"> 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 { public class Blank<file.grammarName>Listener implements <file.grammarName>Listener {
<file.listenerNames:{lname | <file.listenerNames:{lname |
@Override public void enterRule(<file.parserName>.<lname>Context ctx) { \} @Override public void enter(<file.parserName>.<lname>Context ctx) { \}
@Override public void exitRule(<file.parserName>.<lname>Context ctx) { \}}; separator="\n"> @Override public void exit(<file.parserName>.<lname>Context ctx) { \}}; separator="\n">
@Override public void enterEveryRule(ParserRuleContext\<<InputSymbolType()>\> ctx) { } @Override public void enterEveryRule(ParserRuleContext\<<InputSymbolType()>\> ctx) { }
@Override public void exitEveryRule(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) ::= << VisitorDispatchMethod(method) ::= <<
@Override @Override
public void <if(method.isEnter)>enter<else>exit<endif>Rule(ParseTreeListener\<<InputSymbolType()>\> listener) { 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);
} }
>> >>