forked from jasder/antlr
Merge pull request #880 from parrt/fix-parse-listeners
Fix parse listeners
This commit is contained in:
commit
c2ea6aa491
|
@ -626,7 +626,6 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
|
||||||
_ctx = localctx;
|
_ctx = localctx;
|
||||||
_ctx.start = _input.LT(1);
|
_ctx.start = _input.LT(1);
|
||||||
if (_buildParseTrees) addContextToParseTree();
|
if (_buildParseTrees) addContextToParseTree();
|
||||||
if ( _parseListeners != null) triggerEnterRuleEvent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exitRule() {
|
public void exitRule() {
|
||||||
|
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
grammar T;
|
||||||
|
|
||||||
|
a
|
||||||
|
: 'b' #alt1
|
||||||
|
| 'c' #alt2
|
||||||
|
;
|
||||||
|
|
||||||
|
b : 'x' | 'y' {} ;
|
|
@ -16,6 +16,7 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/../gen3" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/../gen3" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/../antlr4-maven-plugin/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/../antlr4-maven-plugin/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/playground" isTestSource="false" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/../.idea" />
|
<excludeFolder url="file://$MODULE_DIR$/../.idea" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/../antlr4-maven-plugin" />
|
<excludeFolder url="file://$MODULE_DIR$/../antlr4-maven-plugin" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/../build" />
|
<excludeFolder url="file://$MODULE_DIR$/../build" />
|
||||||
|
|
Loading…
Reference in New Issue