Search in sources :

Example 1 with FailedPredicateException

use of org.antlr.v4.runtime.FailedPredicateException in project beetl2.0 by javamonkey.

the class BeetlAntlrErrorStrategy method reportError.

@Override
public void reportError(Parser recognizer, RecognitionException e) {
    // yet successfully, don't report any errors.
    if (inErrorRecoveryMode(recognizer)) {
        // don't report spurious errors
        return;
    }
    beginErrorCondition(recognizer);
    if (e instanceof NoViableAltException) {
        reportNoViableAlternative(recognizer, (NoViableAltException) e);
    } else if (e instanceof InputMismatchException) {
        reportInputMismatch(recognizer, (InputMismatchException) e);
    } else if (e instanceof FailedPredicateException) {
        reportFailedPredicate(recognizer, (FailedPredicateException) e);
    } else {
        // System.err.println("unknown recognition error type: " + e.getClass().getName());
        BeetlException exception = new BeetlException(BeetlException.PARSER_UNKNOW_ERROR, e.getClass().getName(), e);
        // exception.token = this.getGrammarToken(e.getOffendingToken());
        exception.pushToken(this.getGrammarToken(e.getOffendingToken()));
        throw exception;
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) NoViableAltException(org.antlr.v4.runtime.NoViableAltException) FailedPredicateException(org.antlr.v4.runtime.FailedPredicateException) InputMismatchException(org.antlr.v4.runtime.InputMismatchException)

Example 2 with FailedPredicateException

use of org.antlr.v4.runtime.FailedPredicateException in project beakerx by twosigma.

the class JavaParser method expression.

private ExpressionContext expression(int _p) throws RecognitionException {
    ParserRuleContext _parentctx = _ctx;
    int _parentState = getState();
    ExpressionContext _localctx = new ExpressionContext(_ctx, _parentState);
    ExpressionContext _prevctx = _localctx;
    int _startState = 174;
    enterRecursionRule(_localctx, 174, RULE_expression, _p);
    int _la;
    try {
        int _alt;
        enterOuterAlt(_localctx, 1);
        {
            setState(1060);
            switch(getInterpreter().adaptivePredict(_input, 123, _ctx)) {
                case 1:
                    {
                        setState(1048);
                        match(LPAREN);
                        setState(1049);
                        type();
                        setState(1050);
                        match(RPAREN);
                        setState(1051);
                        expression(17);
                    }
                    break;
                case 2:
                    {
                        setState(1053);
                        _la = _input.LA(1);
                        if (!(((((_la - 79)) & ~0x3f) == 0 && ((1L << (_la - 79)) & ((1L << (INC - 79)) | (1L << (DEC - 79)) | (1L << (ADD - 79)) | (1L << (SUB - 79)))) != 0))) {
                            _errHandler.recoverInline(this);
                        } else {
                            consume();
                        }
                        setState(1054);
                        expression(15);
                    }
                    break;
                case 3:
                    {
                        setState(1055);
                        _la = _input.LA(1);
                        if (!(_la == BANG || _la == TILDE)) {
                            _errHandler.recoverInline(this);
                        } else {
                            consume();
                        }
                        setState(1056);
                        expression(14);
                    }
                    break;
                case 4:
                    {
                        setState(1057);
                        primary();
                    }
                    break;
                case 5:
                    {
                        setState(1058);
                        match(NEW);
                        setState(1059);
                        creator();
                    }
                    break;
            }
            _ctx.stop = _input.LT(-1);
            setState(1147);
            _errHandler.sync(this);
            _alt = getInterpreter().adaptivePredict(_input, 128, _ctx);
            while (_alt != 2 && _alt != ATN.INVALID_ALT_NUMBER) {
                if (_alt == 1) {
                    if (_parseListeners != null)
                        triggerExitRuleEvent();
                    _prevctx = _localctx;
                    {
                        setState(1145);
                        switch(getInterpreter().adaptivePredict(_input, 127, _ctx)) {
                            case 1:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1062);
                                    if (!(precpred(_ctx, 13)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 13)");
                                    setState(1063);
                                    _la = _input.LA(1);
                                    if (!(((((_la - 83)) & ~0x3f) == 0 && ((1L << (_la - 83)) & ((1L << (MUL - 83)) | (1L << (DIV - 83)) | (1L << (MOD - 83)))) != 0))) {
                                        _errHandler.recoverInline(this);
                                    } else {
                                        consume();
                                    }
                                    setState(1064);
                                    expression(14);
                                }
                                break;
                            case 2:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1065);
                                    if (!(precpred(_ctx, 12)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 12)");
                                    setState(1066);
                                    _la = _input.LA(1);
                                    if (!(_la == ADD || _la == SUB)) {
                                        _errHandler.recoverInline(this);
                                    } else {
                                        consume();
                                    }
                                    setState(1067);
                                    expression(13);
                                }
                                break;
                            case 3:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1068);
                                    if (!(precpred(_ctx, 11)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 11)");
                                    setState(1076);
                                    switch(getInterpreter().adaptivePredict(_input, 124, _ctx)) {
                                        case 1:
                                            {
                                                setState(1069);
                                                match(LT);
                                                setState(1070);
                                                match(LT);
                                            }
                                            break;
                                        case 2:
                                            {
                                                setState(1071);
                                                match(GT);
                                                setState(1072);
                                                match(GT);
                                                setState(1073);
                                                match(GT);
                                            }
                                            break;
                                        case 3:
                                            {
                                                setState(1074);
                                                match(GT);
                                                setState(1075);
                                                match(GT);
                                            }
                                            break;
                                    }
                                    setState(1078);
                                    expression(12);
                                }
                                break;
                            case 4:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1079);
                                    if (!(precpred(_ctx, 10)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 10)");
                                    setState(1080);
                                    _la = _input.LA(1);
                                    if (!(((((_la - 67)) & ~0x3f) == 0 && ((1L << (_la - 67)) & ((1L << (GT - 67)) | (1L << (LT - 67)) | (1L << (LE - 67)) | (1L << (GE - 67)))) != 0))) {
                                        _errHandler.recoverInline(this);
                                    } else {
                                        consume();
                                    }
                                    setState(1081);
                                    expression(11);
                                }
                                break;
                            case 5:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1082);
                                    if (!(precpred(_ctx, 8)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 8)");
                                    setState(1083);
                                    _la = _input.LA(1);
                                    if (!(_la == EQUAL || _la == NOTEQUAL)) {
                                        _errHandler.recoverInline(this);
                                    } else {
                                        consume();
                                    }
                                    setState(1084);
                                    expression(9);
                                }
                                break;
                            case 6:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1085);
                                    if (!(precpred(_ctx, 7)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 7)");
                                    setState(1086);
                                    match(BITAND);
                                    setState(1087);
                                    expression(8);
                                }
                                break;
                            case 7:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1088);
                                    if (!(precpred(_ctx, 6)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 6)");
                                    setState(1089);
                                    match(CARET);
                                    setState(1090);
                                    expression(7);
                                }
                                break;
                            case 8:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1091);
                                    if (!(precpred(_ctx, 5)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 5)");
                                    setState(1092);
                                    match(BITOR);
                                    setState(1093);
                                    expression(6);
                                }
                                break;
                            case 9:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1094);
                                    if (!(precpred(_ctx, 4)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 4)");
                                    setState(1095);
                                    match(AND);
                                    setState(1096);
                                    expression(5);
                                }
                                break;
                            case 10:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1097);
                                    if (!(precpred(_ctx, 3)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 3)");
                                    setState(1098);
                                    match(OR);
                                    setState(1099);
                                    expression(4);
                                }
                                break;
                            case 11:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1100);
                                    if (!(precpred(_ctx, 2)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 2)");
                                    setState(1101);
                                    match(QUESTION);
                                    setState(1102);
                                    expression(0);
                                    setState(1103);
                                    match(COLON);
                                    setState(1104);
                                    expression(3);
                                }
                                break;
                            case 12:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1106);
                                    if (!(precpred(_ctx, 1)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 1)");
                                    setState(1107);
                                    _la = _input.LA(1);
                                    if (!(((((_la - 66)) & ~0x3f) == 0 && ((1L << (_la - 66)) & ((1L << (ASSIGN - 66)) | (1L << (ADD_ASSIGN - 66)) | (1L << (SUB_ASSIGN - 66)) | (1L << (MUL_ASSIGN - 66)) | (1L << (DIV_ASSIGN - 66)) | (1L << (AND_ASSIGN - 66)) | (1L << (OR_ASSIGN - 66)) | (1L << (XOR_ASSIGN - 66)) | (1L << (MOD_ASSIGN - 66)) | (1L << (LSHIFT_ASSIGN - 66)) | (1L << (RSHIFT_ASSIGN - 66)) | (1L << (URSHIFT_ASSIGN - 66)))) != 0))) {
                                        _errHandler.recoverInline(this);
                                    } else {
                                        consume();
                                    }
                                    setState(1108);
                                    expression(1);
                                }
                                break;
                            case 13:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1109);
                                    if (!(precpred(_ctx, 25)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 25)");
                                    setState(1110);
                                    match(DOT);
                                    setState(1111);
                                    match(Identifier);
                                }
                                break;
                            case 14:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1112);
                                    if (!(precpred(_ctx, 24)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 24)");
                                    setState(1113);
                                    match(DOT);
                                    setState(1114);
                                    match(THIS);
                                }
                                break;
                            case 15:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1115);
                                    if (!(precpred(_ctx, 23)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 23)");
                                    setState(1116);
                                    match(DOT);
                                    setState(1117);
                                    match(NEW);
                                    setState(1119);
                                    _la = _input.LA(1);
                                    if (_la == LT) {
                                        {
                                            setState(1118);
                                            nonWildcardTypeArguments();
                                        }
                                    }
                                    setState(1121);
                                    innerCreator();
                                }
                                break;
                            case 16:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1122);
                                    if (!(precpred(_ctx, 22)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 22)");
                                    setState(1123);
                                    match(DOT);
                                    setState(1124);
                                    match(SUPER);
                                    setState(1125);
                                    superSuffix();
                                }
                                break;
                            case 17:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1126);
                                    if (!(precpred(_ctx, 21)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 21)");
                                    setState(1127);
                                    match(DOT);
                                    setState(1128);
                                    explicitGenericInvocation();
                                }
                                break;
                            case 18:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1129);
                                    if (!(precpred(_ctx, 20)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 20)");
                                    setState(1130);
                                    match(LBRACK);
                                    setState(1131);
                                    expression(0);
                                    setState(1132);
                                    match(RBRACK);
                                }
                                break;
                            case 19:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1134);
                                    if (!(precpred(_ctx, 19)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 19)");
                                    setState(1135);
                                    match(LPAREN);
                                    setState(1137);
                                    _la = _input.LA(1);
                                    if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << BOOLEAN) | (1L << BYTE) | (1L << CHAR) | (1L << DOUBLE) | (1L << FLOAT) | (1L << INT) | (1L << LONG) | (1L << NEW) | (1L << SHORT) | (1L << SUPER) | (1L << THIS) | (1L << VOID) | (1L << IntegerLiteral) | (1L << FloatingPointLiteral) | (1L << BooleanLiteral) | (1L << CharacterLiteral) | (1L << StringLiteral) | (1L << NullLiteral) | (1L << LPAREN))) != 0) || ((((_la - 68)) & ~0x3f) == 0 && ((1L << (_la - 68)) & ((1L << (LT - 68)) | (1L << (BANG - 68)) | (1L << (TILDE - 68)) | (1L << (INC - 68)) | (1L << (DEC - 68)) | (1L << (ADD - 68)) | (1L << (SUB - 68)) | (1L << (Identifier - 68)))) != 0)) {
                                        {
                                            setState(1136);
                                            expressionList();
                                        }
                                    }
                                    setState(1139);
                                    match(RPAREN);
                                }
                                break;
                            case 20:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1140);
                                    if (!(precpred(_ctx, 16)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 16)");
                                    setState(1141);
                                    _la = _input.LA(1);
                                    if (!(_la == INC || _la == DEC)) {
                                        _errHandler.recoverInline(this);
                                    } else {
                                        consume();
                                    }
                                }
                                break;
                            case 21:
                                {
                                    _localctx = new ExpressionContext(_parentctx, _parentState);
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(1142);
                                    if (!(precpred(_ctx, 9)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 9)");
                                    setState(1143);
                                    match(INSTANCEOF);
                                    setState(1144);
                                    type();
                                }
                                break;
                        }
                    }
                }
                setState(1149);
                _errHandler.sync(this);
                _alt = getInterpreter().adaptivePredict(_input, 128, _ctx);
            }
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        unrollRecursionContexts(_parentctx);
    }
    return _localctx;
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) FailedPredicateException(org.antlr.v4.runtime.FailedPredicateException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 3 with FailedPredicateException

use of org.antlr.v4.runtime.FailedPredicateException in project antlr4 by tunnelvisionlabs.

the class ParserInterpreter method visitState.

protected void visitState(ATNState p) {
    int predictedAlt = 1;
    if (p.getNumberOfTransitions() > 1) {
        predictedAlt = visitDecisionState((DecisionState) p);
    }
    Transition transition = p.transition(predictedAlt - 1);
    switch(transition.getSerializationType()) {
        case Transition.EPSILON:
            if (pushRecursionContextStates.get(p.stateNumber) && !(transition.target instanceof LoopEndState)) {
                // We are at the start of a left recursive rule's (...)* loop
                // and we're not taking the exit branch of loop.
                InterpreterRuleContext localctx = createInterpreterRuleContext(_parentContextStack.peek().getItem1(), _parentContextStack.peek().getItem2(), _ctx.getRuleIndex());
                pushNewRecursionContext(localctx, atn.ruleToStartState[p.ruleIndex].stateNumber, _ctx.getRuleIndex());
            }
            break;
        case Transition.ATOM:
            match(((AtomTransition) transition).label);
            break;
        case Transition.RANGE:
        case Transition.SET:
        case Transition.NOT_SET:
            if (!transition.matches(_input.LA(1), Token.MIN_USER_TOKEN_TYPE, 65535)) {
                recoverInline();
            }
            matchWildcard();
            break;
        case Transition.WILDCARD:
            matchWildcard();
            break;
        case Transition.RULE:
            RuleStartState ruleStartState = (RuleStartState) transition.target;
            int ruleIndex = ruleStartState.ruleIndex;
            InterpreterRuleContext newctx = createInterpreterRuleContext(_ctx, p.stateNumber, ruleIndex);
            if (ruleStartState.isPrecedenceRule) {
                enterRecursionRule(newctx, ruleStartState.stateNumber, ruleIndex, ((RuleTransition) transition).precedence);
            } else {
                enterRule(newctx, transition.target.stateNumber, ruleIndex);
            }
            break;
        case Transition.PREDICATE:
            PredicateTransition predicateTransition = (PredicateTransition) transition;
            if (!sempred(_ctx, predicateTransition.ruleIndex, predicateTransition.predIndex)) {
                throw new FailedPredicateException(this);
            }
            break;
        case Transition.ACTION:
            ActionTransition actionTransition = (ActionTransition) transition;
            action(_ctx, actionTransition.ruleIndex, actionTransition.actionIndex);
            break;
        case Transition.PRECEDENCE:
            if (!precpred(_ctx, ((PrecedencePredicateTransition) transition).precedence)) {
                throw new FailedPredicateException(this, String.format("precpred(_ctx, %d)", ((PrecedencePredicateTransition) transition).precedence));
            }
            break;
        default:
            throw new UnsupportedOperationException("Unrecognized ATN transition type.");
    }
    setState(transition.target.stateNumber);
}
Also used : LoopEndState(org.antlr.v4.runtime.atn.LoopEndState) ActionTransition(org.antlr.v4.runtime.atn.ActionTransition) RuleStartState(org.antlr.v4.runtime.atn.RuleStartState) AtomTransition(org.antlr.v4.runtime.atn.AtomTransition) RuleTransition(org.antlr.v4.runtime.atn.RuleTransition) ActionTransition(org.antlr.v4.runtime.atn.ActionTransition) PredicateTransition(org.antlr.v4.runtime.atn.PredicateTransition) PrecedencePredicateTransition(org.antlr.v4.runtime.atn.PrecedencePredicateTransition) Transition(org.antlr.v4.runtime.atn.Transition) PredicateTransition(org.antlr.v4.runtime.atn.PredicateTransition) PrecedencePredicateTransition(org.antlr.v4.runtime.atn.PrecedencePredicateTransition) PrecedencePredicateTransition(org.antlr.v4.runtime.atn.PrecedencePredicateTransition) DecisionState(org.antlr.v4.runtime.atn.DecisionState)

Example 4 with FailedPredicateException

use of org.antlr.v4.runtime.FailedPredicateException in project antlr4 by antlr.

the class ParserInterpreter method visitState.

protected void visitState(ATNState p) {
    // System.out.println("visitState "+p.stateNumber);
    int predictedAlt = 1;
    if (p instanceof DecisionState) {
        predictedAlt = visitDecisionState((DecisionState) p);
    }
    Transition transition = p.transition(predictedAlt - 1);
    switch(transition.getSerializationType()) {
        case Transition.EPSILON:
            if (p.getStateType() == ATNState.STAR_LOOP_ENTRY && ((StarLoopEntryState) p).isPrecedenceDecision && !(transition.target instanceof LoopEndState)) {
                // We are at the start of a left recursive rule's (...)* loop
                // and we're not taking the exit branch of loop.
                InterpreterRuleContext localctx = createInterpreterRuleContext(_parentContextStack.peek().a, _parentContextStack.peek().b, _ctx.getRuleIndex());
                pushNewRecursionContext(localctx, atn.ruleToStartState[p.ruleIndex].stateNumber, _ctx.getRuleIndex());
            }
            break;
        case Transition.ATOM:
            match(((AtomTransition) transition).label);
            break;
        case Transition.RANGE:
        case Transition.SET:
        case Transition.NOT_SET:
            if (!transition.matches(_input.LA(1), Token.MIN_USER_TOKEN_TYPE, 65535)) {
                recoverInline();
            }
            matchWildcard();
            break;
        case Transition.WILDCARD:
            matchWildcard();
            break;
        case Transition.RULE:
            RuleStartState ruleStartState = (RuleStartState) transition.target;
            int ruleIndex = ruleStartState.ruleIndex;
            InterpreterRuleContext newctx = createInterpreterRuleContext(_ctx, p.stateNumber, ruleIndex);
            if (ruleStartState.isLeftRecursiveRule) {
                enterRecursionRule(newctx, ruleStartState.stateNumber, ruleIndex, ((RuleTransition) transition).precedence);
            } else {
                enterRule(newctx, transition.target.stateNumber, ruleIndex);
            }
            break;
        case Transition.PREDICATE:
            PredicateTransition predicateTransition = (PredicateTransition) transition;
            if (!sempred(_ctx, predicateTransition.ruleIndex, predicateTransition.predIndex)) {
                throw new FailedPredicateException(this);
            }
            break;
        case Transition.ACTION:
            ActionTransition actionTransition = (ActionTransition) transition;
            action(_ctx, actionTransition.ruleIndex, actionTransition.actionIndex);
            break;
        case Transition.PRECEDENCE:
            if (!precpred(_ctx, ((PrecedencePredicateTransition) transition).precedence)) {
                throw new FailedPredicateException(this, String.format("precpred(_ctx, %d)", ((PrecedencePredicateTransition) transition).precedence));
            }
            break;
        default:
            throw new UnsupportedOperationException("Unrecognized ATN transition type.");
    }
    setState(transition.target.stateNumber);
}
Also used : LoopEndState(org.antlr.v4.runtime.atn.LoopEndState) ActionTransition(org.antlr.v4.runtime.atn.ActionTransition) StarLoopEntryState(org.antlr.v4.runtime.atn.StarLoopEntryState) RuleStartState(org.antlr.v4.runtime.atn.RuleStartState) AtomTransition(org.antlr.v4.runtime.atn.AtomTransition) RuleTransition(org.antlr.v4.runtime.atn.RuleTransition) ActionTransition(org.antlr.v4.runtime.atn.ActionTransition) PredicateTransition(org.antlr.v4.runtime.atn.PredicateTransition) PrecedencePredicateTransition(org.antlr.v4.runtime.atn.PrecedencePredicateTransition) Transition(org.antlr.v4.runtime.atn.Transition) PredicateTransition(org.antlr.v4.runtime.atn.PredicateTransition) PrecedencePredicateTransition(org.antlr.v4.runtime.atn.PrecedencePredicateTransition) PrecedencePredicateTransition(org.antlr.v4.runtime.atn.PrecedencePredicateTransition) DecisionState(org.antlr.v4.runtime.atn.DecisionState)

Example 5 with FailedPredicateException

use of org.antlr.v4.runtime.FailedPredicateException in project oxTrust by GluuFederation.

the class ScimFilterParser method expression.

private ExpressionContext expression(int _p) throws RecognitionException {
    ParserRuleContext _parentctx = _ctx;
    int _parentState = getState();
    ExpressionContext _localctx = new ExpressionContext(_ctx, _parentState);
    ExpressionContext _prevctx = _localctx;
    int _startState = 2;
    enterRecursionRule(_localctx, 2, RULE_expression, _p);
    int _la;
    try {
        int _alt;
        enterOuterAlt(_localctx, 1);
        {
            setState(92);
            _errHandler.sync(this);
            switch(getInterpreter().adaptivePredict(_input, 11, _ctx)) {
                case 1:
                    {
                        _localctx = new NOT_EXPRContext(_localctx);
                        _ctx = _localctx;
                        _prevctx = _localctx;
                        setState(17);
                        match(NOT);
                        setState(19);
                        _errHandler.sync(this);
                        _alt = 1 + 1;
                        do {
                            switch(_alt) {
                                case 1 + 1:
                                    {
                                        {
                                            setState(18);
                                            match(WS);
                                        }
                                    }
                                    break;
                                default:
                                    throw new NoViableAltException(this);
                            }
                            setState(21);
                            _errHandler.sync(this);
                            _alt = getInterpreter().adaptivePredict(_input, 1, _ctx);
                        } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                        setState(23);
                        expression(9);
                    }
                    break;
                case 2:
                    {
                        _localctx = new ATTR_OPER_EXPRContext(_localctx);
                        _ctx = _localctx;
                        _prevctx = _localctx;
                        setState(24);
                        match(ATTRNAME);
                        setState(26);
                        _errHandler.sync(this);
                        _alt = 1 + 1;
                        do {
                            switch(_alt) {
                                case 1 + 1:
                                    {
                                        {
                                            setState(25);
                                            match(WS);
                                        }
                                    }
                                    break;
                                default:
                                    throw new NoViableAltException(this);
                            }
                            setState(28);
                            _errHandler.sync(this);
                            _alt = getInterpreter().adaptivePredict(_input, 2, _ctx);
                        } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                        setState(30);
                        operator();
                        setState(32);
                        _errHandler.sync(this);
                        _alt = 1 + 1;
                        do {
                            switch(_alt) {
                                case 1 + 1:
                                    {
                                        {
                                            setState(31);
                                            match(WS);
                                        }
                                    }
                                    break;
                                default:
                                    throw new NoViableAltException(this);
                            }
                            setState(34);
                            _errHandler.sync(this);
                            _alt = getInterpreter().adaptivePredict(_input, 3, _ctx);
                        } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                        setState(36);
                        expression(4);
                    }
                    break;
                case 3:
                    {
                        _localctx = new ATTR_PRContext(_localctx);
                        _ctx = _localctx;
                        _prevctx = _localctx;
                        setState(38);
                        match(ATTRNAME);
                        setState(40);
                        _errHandler.sync(this);
                        _alt = 1 + 1;
                        do {
                            switch(_alt) {
                                case 1 + 1:
                                    {
                                        {
                                            setState(39);
                                            match(WS);
                                        }
                                    }
                                    break;
                                default:
                                    throw new NoViableAltException(this);
                            }
                            setState(42);
                            _errHandler.sync(this);
                            _alt = getInterpreter().adaptivePredict(_input, 4, _ctx);
                        } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                        setState(44);
                        match(PR);
                    }
                    break;
                case 4:
                    {
                        _localctx = new ATTR_OPER_CRITERIAContext(_localctx);
                        _ctx = _localctx;
                        _prevctx = _localctx;
                        setState(45);
                        match(ATTRNAME);
                        setState(47);
                        _errHandler.sync(this);
                        _alt = 1 + 1;
                        do {
                            switch(_alt) {
                                case 1 + 1:
                                    {
                                        {
                                            setState(46);
                                            match(WS);
                                        }
                                    }
                                    break;
                                default:
                                    throw new NoViableAltException(this);
                            }
                            setState(49);
                            _errHandler.sync(this);
                            _alt = getInterpreter().adaptivePredict(_input, 5, _ctx);
                        } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                        setState(51);
                        operator();
                        setState(53);
                        _errHandler.sync(this);
                        _alt = 1 + 1;
                        do {
                            switch(_alt) {
                                case 1 + 1:
                                    {
                                        {
                                            setState(52);
                                            match(WS);
                                        }
                                    }
                                    break;
                                default:
                                    throw new NoViableAltException(this);
                            }
                            setState(55);
                            _errHandler.sync(this);
                            _alt = getInterpreter().adaptivePredict(_input, 6, _ctx);
                        } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                        setState(57);
                        criteria();
                    }
                    break;
                case 5:
                    {
                        _localctx = new LPAREN_EXPR_RPARENContext(_localctx);
                        _ctx = _localctx;
                        _prevctx = _localctx;
                        setState(59);
                        match(LPAREN);
                        setState(63);
                        _errHandler.sync(this);
                        _alt = getInterpreter().adaptivePredict(_input, 7, _ctx);
                        while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER) {
                            if (_alt == 1 + 1) {
                                {
                                    {
                                        setState(60);
                                        match(WS);
                                    }
                                }
                            }
                            setState(65);
                            _errHandler.sync(this);
                            _alt = getInterpreter().adaptivePredict(_input, 7, _ctx);
                        }
                        setState(66);
                        expression(0);
                        setState(70);
                        _errHandler.sync(this);
                        _alt = getInterpreter().adaptivePredict(_input, 8, _ctx);
                        while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER) {
                            if (_alt == 1 + 1) {
                                {
                                    {
                                        setState(67);
                                        match(WS);
                                    }
                                }
                            }
                            setState(72);
                            _errHandler.sync(this);
                            _alt = getInterpreter().adaptivePredict(_input, 8, _ctx);
                        }
                        setState(73);
                        match(RPAREN);
                    }
                    break;
                case 6:
                    {
                        _localctx = new LBRAC_EXPR_RBRACContext(_localctx);
                        _ctx = _localctx;
                        _prevctx = _localctx;
                        setState(75);
                        match(ATTRNAME);
                        setState(76);
                        match(LBRAC);
                        setState(80);
                        _errHandler.sync(this);
                        _alt = getInterpreter().adaptivePredict(_input, 9, _ctx);
                        while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER) {
                            if (_alt == 1 + 1) {
                                {
                                    {
                                        setState(77);
                                        match(WS);
                                    }
                                }
                            }
                            setState(82);
                            _errHandler.sync(this);
                            _alt = getInterpreter().adaptivePredict(_input, 9, _ctx);
                        }
                        setState(83);
                        expression(0);
                        setState(87);
                        _errHandler.sync(this);
                        _alt = getInterpreter().adaptivePredict(_input, 10, _ctx);
                        while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER) {
                            if (_alt == 1 + 1) {
                                {
                                    {
                                        setState(84);
                                        match(WS);
                                    }
                                }
                            }
                            setState(89);
                            _errHandler.sync(this);
                            _alt = getInterpreter().adaptivePredict(_input, 10, _ctx);
                        }
                        setState(90);
                        match(RBRAC);
                    }
                    break;
            }
            _ctx.stop = _input.LT(-1);
            setState(136);
            _errHandler.sync(this);
            _alt = getInterpreter().adaptivePredict(_input, 19, _ctx);
            while (_alt != 2 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER) {
                if (_alt == 1) {
                    if (_parseListeners != null)
                        triggerExitRuleEvent();
                    _prevctx = _localctx;
                    {
                        setState(134);
                        _errHandler.sync(this);
                        switch(getInterpreter().adaptivePredict(_input, 18, _ctx)) {
                            case 1:
                                {
                                    _localctx = new EXPR_AND_EXPRContext(new ExpressionContext(_parentctx, _parentState));
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(94);
                                    if (!(precpred(_ctx, 8)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 8)");
                                    setState(96);
                                    _errHandler.sync(this);
                                    _alt = 1 + 1;
                                    do {
                                        switch(_alt) {
                                            case 1 + 1:
                                                {
                                                    {
                                                        setState(95);
                                                        match(WS);
                                                    }
                                                }
                                                break;
                                            default:
                                                throw new NoViableAltException(this);
                                        }
                                        setState(98);
                                        _errHandler.sync(this);
                                        _alt = getInterpreter().adaptivePredict(_input, 12, _ctx);
                                    } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                                    setState(100);
                                    match(AND);
                                    setState(102);
                                    _errHandler.sync(this);
                                    _alt = 1 + 1;
                                    do {
                                        switch(_alt) {
                                            case 1 + 1:
                                                {
                                                    {
                                                        setState(101);
                                                        match(WS);
                                                    }
                                                }
                                                break;
                                            default:
                                                throw new NoViableAltException(this);
                                        }
                                        setState(104);
                                        _errHandler.sync(this);
                                        _alt = getInterpreter().adaptivePredict(_input, 13, _ctx);
                                    } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                                    setState(106);
                                    expression(9);
                                }
                                break;
                            case 2:
                                {
                                    _localctx = new EXPR_OR_EXPRContext(new ExpressionContext(_parentctx, _parentState));
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(107);
                                    if (!(precpred(_ctx, 7)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 7)");
                                    setState(109);
                                    _errHandler.sync(this);
                                    _alt = 1 + 1;
                                    do {
                                        switch(_alt) {
                                            case 1 + 1:
                                                {
                                                    {
                                                        setState(108);
                                                        match(WS);
                                                    }
                                                }
                                                break;
                                            default:
                                                throw new NoViableAltException(this);
                                        }
                                        setState(111);
                                        _errHandler.sync(this);
                                        _alt = getInterpreter().adaptivePredict(_input, 14, _ctx);
                                    } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                                    setState(113);
                                    match(OR);
                                    setState(115);
                                    _errHandler.sync(this);
                                    _la = _input.LA(1);
                                    do {
                                        {
                                            {
                                                setState(114);
                                                match(WS);
                                            }
                                        }
                                        setState(117);
                                        _errHandler.sync(this);
                                        _la = _input.LA(1);
                                    } while (_la == WS);
                                    setState(119);
                                    expression(8);
                                }
                                break;
                            case 3:
                                {
                                    _localctx = new EXPR_OPER_EXPRContext(new ExpressionContext(_parentctx, _parentState));
                                    pushNewRecursionContext(_localctx, _startState, RULE_expression);
                                    setState(120);
                                    if (!(precpred(_ctx, 6)))
                                        throw new FailedPredicateException(this, "precpred(_ctx, 6)");
                                    setState(122);
                                    _errHandler.sync(this);
                                    _alt = 1 + 1;
                                    do {
                                        switch(_alt) {
                                            case 1 + 1:
                                                {
                                                    {
                                                        setState(121);
                                                        match(WS);
                                                    }
                                                }
                                                break;
                                            default:
                                                throw new NoViableAltException(this);
                                        }
                                        setState(124);
                                        _errHandler.sync(this);
                                        _alt = getInterpreter().adaptivePredict(_input, 16, _ctx);
                                    } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                                    setState(126);
                                    operator();
                                    setState(128);
                                    _errHandler.sync(this);
                                    _alt = 1 + 1;
                                    do {
                                        switch(_alt) {
                                            case 1 + 1:
                                                {
                                                    {
                                                        setState(127);
                                                        match(WS);
                                                    }
                                                }
                                                break;
                                            default:
                                                throw new NoViableAltException(this);
                                        }
                                        setState(130);
                                        _errHandler.sync(this);
                                        _alt = getInterpreter().adaptivePredict(_input, 17, _ctx);
                                    } while (_alt != 1 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER);
                                    setState(132);
                                    expression(7);
                                }
                                break;
                        }
                    }
                }
                setState(138);
                _errHandler.sync(this);
                _alt = getInterpreter().adaptivePredict(_input, 19, _ctx);
            }
        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        unrollRecursionContexts(_parentctx);
    }
    return _localctx;
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) NoViableAltException(org.antlr.v4.runtime.NoViableAltException) FailedPredicateException(org.antlr.v4.runtime.FailedPredicateException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Aggregations

FailedPredicateException (org.antlr.v4.runtime.FailedPredicateException)5 NoViableAltException (org.antlr.v4.runtime.NoViableAltException)4 RecognitionException (org.antlr.v4.runtime.RecognitionException)3 InputMismatchException (org.antlr.v4.runtime.InputMismatchException)2 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)2 ActionTransition (org.antlr.v4.runtime.atn.ActionTransition)2 AtomTransition (org.antlr.v4.runtime.atn.AtomTransition)2 DecisionState (org.antlr.v4.runtime.atn.DecisionState)2 LoopEndState (org.antlr.v4.runtime.atn.LoopEndState)2 PrecedencePredicateTransition (org.antlr.v4.runtime.atn.PrecedencePredicateTransition)2 PredicateTransition (org.antlr.v4.runtime.atn.PredicateTransition)2 RuleStartState (org.antlr.v4.runtime.atn.RuleStartState)2 RuleTransition (org.antlr.v4.runtime.atn.RuleTransition)2 Transition (org.antlr.v4.runtime.atn.Transition)2 DetailNode (com.puppycrawl.tools.checkstyle.api.DetailNode)1 JavadocParser (com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocParser)1 CommonToken (org.antlr.v4.runtime.CommonToken)1 Token (org.antlr.v4.runtime.Token)1 StarLoopEntryState (org.antlr.v4.runtime.atn.StarLoopEntryState)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1