don't pass new term node

This commit is contained in:
Terence Parr 2012-09-08 10:21:42 -07:00
parent bbfc441438
commit 7586afff27
1 changed files with 6 additions and 4 deletions

View File

@ -40,7 +40,6 @@ import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.antlr.v4.runtime.tree.TerminalNodeImpl;
import java.util.ArrayList;
import java.util.List;
@ -365,15 +364,18 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator<Token>
public Token consume() {
Token o = getCurrentToken();
getInputStream().consume();
TerminalNode tnode = null;
if (_buildParseTrees) {
if ( _errHandler.inErrorRecoveryMode(this) ) {
_ctx.addErrorNode(o);
tnode = _ctx.addErrorNode(o);
}
else {
tnode = _ctx.addChild(o);
}
else _ctx.addChild(o);
}
if ( _parseListeners != null) {
for (ParseTreeListener<Token> l : _parseListeners) {
l.visitTerminal(new TerminalNodeImpl<Token>(o));
l.visitTerminal(tnode);
}
}
return o;