sync for use at home
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9146]
This commit is contained in:
parent
9eb19cf929
commit
688f69541c
|
@ -172,9 +172,10 @@ public abstract class BaseRecognizer extends Recognizer<ParserATNSimulator> {
|
|||
}
|
||||
|
||||
public void enterOuterAlt(ParserRuleContext localctx, int altNum) {
|
||||
// if we have new localctx, make sure we add to parse tree
|
||||
if ( buildParseTrees && _ctx != localctx ) addContextToParseTree();
|
||||
_ctx = localctx;
|
||||
_ctx.altNum = altNum;
|
||||
addContextToParseTree();
|
||||
}
|
||||
|
||||
/** Consume the current symbol and return it. E.g., given the following
|
||||
|
@ -193,15 +194,20 @@ public abstract class BaseRecognizer extends Recognizer<ParserATNSimulator> {
|
|||
getInputStream().consume();
|
||||
if ( buildParseTrees ) {
|
||||
// TODO: tree parsers?
|
||||
if ( _errHandler.inErrorRecoveryMode(this) ) _ctx.addErrorNode((Token) o);
|
||||
if ( _errHandler.inErrorRecoveryMode(this) ) {
|
||||
System.out.println("consume in error recovery mode for "+o);
|
||||
_ctx.addErrorNode((Token) o);
|
||||
}
|
||||
else _ctx.addChild((Token)o);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
protected void addContextToParseTree() {
|
||||
if ( buildParseTrees ) {
|
||||
if ( _ctx.parent!=null ) _ctx.parent.addChild(_ctx);
|
||||
RuleContext parent = _ctx.parent;
|
||||
// add current context to parent if we have a parent
|
||||
if ( parent!=null ) {
|
||||
parent.addChild(_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,10 @@ public class DefaultANTLRErrorStrategy implements ANTLRErrorStrategy {
|
|||
{
|
||||
// if we've already reported an error and have not matched a token
|
||||
// yet successfully, don't report any errors.
|
||||
if (errorRecoveryMode) return; // don't count spurious errors
|
||||
if (errorRecoveryMode) {
|
||||
System.err.print("[SPURIOUS] ");
|
||||
//return; // don't count spurious errors
|
||||
}
|
||||
recognizer.syntaxErrors++;
|
||||
beginErrorCondition(recognizer);
|
||||
if ( e instanceof NoViableAltException ) {
|
||||
|
@ -80,8 +83,7 @@ public class DefaultANTLRErrorStrategy implements ANTLRErrorStrategy {
|
|||
// lastErrorIndex+
|
||||
// ", states="+lastErrorStates);
|
||||
if ( lastErrorIndex==recognizer.getInputStream().index() &&
|
||||
lastErrorStates.contains(recognizer._ctx.s) )
|
||||
{
|
||||
lastErrorStates.contains(recognizer._ctx.s) ) {
|
||||
// uh oh, another error at same token index and previously-visited
|
||||
// state in ATN; must be a case where LT(1) is in the recovery
|
||||
// token set so nothing got consumed. Consume a single token
|
||||
|
@ -424,7 +426,7 @@ public class DefaultANTLRErrorStrategy implements ANTLRErrorStrategy {
|
|||
|
||||
/** Consume tokens until one matches the given token set */
|
||||
public void consumeUntil(BaseRecognizer recognizer, IntervalSet set) {
|
||||
//System.out.println("consumeUntil("+set.toString(getTokenNames())+")");
|
||||
System.out.println("consumeUntil("+set.toString(recognizer.getTokenNames())+")");
|
||||
int ttype = recognizer.getInputStream().LA(1);
|
||||
while (ttype != Token.EOF && !set.contains(ttype) ) {
|
||||
//System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]);
|
||||
|
|
|
@ -63,6 +63,7 @@ public class Parser extends BaseRecognizer {
|
|||
_ctx = localctx;
|
||||
_ctx.start = _input.LT(1);
|
||||
_ctx.ruleIndex = ruleIndex;
|
||||
if ( buildParseTrees ) addContextToParseTree();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue