Search in sources :

Example 6 with BindingDescr

use of org.drools.compiler.lang.descr.BindingDescr in project drools by kiegroup.

the class MVELDumperTest method testDumpBindingsComplexOp2.

@Test
public void testDumpBindingsComplexOp2() throws Exception {
    String input = "$x : age not in (10, 20, $someVal)";
    String expected = "age != 10 && age != 20 && age != $someVal";
    ConstraintConnectiveDescr descr = parse(input);
    MVELDumperContext ctx = new MVELDumperContext();
    String result = dumper.dump(descr, ctx);
    assertEquals(expected, result);
    assertEquals(1, ctx.getBindings().size());
    BindingDescr bind = ctx.getBindings().get(0);
    assertEquals("$x", bind.getVariable());
    assertEquals("age", bind.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) MVELDumperContext(org.drools.compiler.lang.MVELDumper.MVELDumperContext) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 7 with BindingDescr

use of org.drools.compiler.lang.descr.BindingDescr in project drools by kiegroup.

the class MVELDumperTest method testDumpBindingsWithRestriction.

@Test
public void testDumpBindingsWithRestriction() throws Exception {
    String input = "$x : age > 10 && < 20 || > 30";
    String expected = "( age > 10 && age < 20 || age > 30 )";
    ConstraintConnectiveDescr descr = parse(input);
    MVELDumperContext ctx = new MVELDumperContext();
    String result = dumper.dump(descr, ctx);
    assertEquals(expected, result);
    assertEquals(1, ctx.getBindings().size());
    BindingDescr bind = ctx.getBindings().get(0);
    assertEquals("$x", bind.getVariable());
    assertEquals("age", bind.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) MVELDumperContext(org.drools.compiler.lang.MVELDumper.MVELDumperContext) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 8 with BindingDescr

use of org.drools.compiler.lang.descr.BindingDescr in project drools by kiegroup.

the class DRL6Expressions method inExpression.

// $ANTLR end "instanceOfExpression"
// $ANTLR start "inExpression"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:325:1: inExpression returns [BaseDescr result] : left= relationalExpression ( ( not_key in_key )=> not_key in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN |in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN )? ;
public final BaseDescr inExpression() throws RecognitionException {
    BaseDescr result = null;
    BaseDescr left = null;
    ParserRuleReturnScope e1 = null;
    ParserRuleReturnScope e2 = null;
    ConstraintConnectiveDescr descr = null;
    BaseDescr leftDescr = null;
    BindingDescr binding = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:328:3: (left= relationalExpression ( ( not_key in_key )=> not_key in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN |in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN )? )
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:328:5: left= relationalExpression ( ( not_key in_key )=> not_key in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN |in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN )?
        {
            pushFollow(FOLLOW_relationalExpression_in_inExpression1615);
            left = relationalExpression();
            state._fsp--;
            if (state.failed)
                return result;
            if (state.backtracking == 0) {
                if (buildDescr) {
                    result = left;
                }
                if (left instanceof BindingDescr) {
                    binding = (BindingDescr) left;
                    leftDescr = new AtomicExprDescr(binding.getExpression());
                } else {
                    leftDescr = left;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:337:5: ( ( not_key in_key )=> not_key in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN |in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN )?
            int alt36 = 3;
            int LA36_0 = input.LA(1);
            if ((LA36_0 == ID)) {
                int LA36_1 = input.LA(2);
                if ((LA36_1 == ID)) {
                    int LA36_3 = input.LA(3);
                    if ((LA36_3 == LEFT_PAREN) && ((((helper.validateIdentifierKey(DroolsSoftKeywords.NOT))) && synpred8_DRL6Expressions()))) {
                        alt36 = 1;
                    }
                } else if ((LA36_1 == LEFT_PAREN) && (((helper.validateIdentifierKey(DroolsSoftKeywords.IN))))) {
                    alt36 = 2;
                }
            }
            switch(alt36) {
                case 1:
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:337:6: ( not_key in_key )=> not_key in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN
                    {
                        pushFollow(FOLLOW_not_key_in_inExpression1635);
                        not_key();
                        state._fsp--;
                        if (state.failed)
                            return result;
                        pushFollow(FOLLOW_in_key_in_inExpression1639);
                        in_key();
                        state._fsp--;
                        if (state.failed)
                            return result;
                        match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_inExpression1641);
                        if (state.failed)
                            return result;
                        if (state.backtracking == 0) {
                            helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
                        }
                        pushFollow(FOLLOW_expression_in_inExpression1663);
                        e1 = expression();
                        state._fsp--;
                        if (state.failed)
                            return result;
                        if (state.backtracking == 0) {
                            descr = ConstraintConnectiveDescr.newAnd();
                            RelationalExprDescr rel = new RelationalExprDescr("!=", false, null, leftDescr, (e1 != null ? ((DRL6Expressions.expression_return) e1).result : null));
                            descr.addOrMerge(rel);
                            result = descr;
                        }
                        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:345:7: ( COMMA e2= expression )*
                        loop34: while (true) {
                            int alt34 = 2;
                            int LA34_0 = input.LA(1);
                            if ((LA34_0 == COMMA)) {
                                alt34 = 1;
                            }
                            switch(alt34) {
                                case 1:
                                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:345:8: COMMA e2= expression
                                    {
                                        match(input, COMMA, FOLLOW_COMMA_in_inExpression1682);
                                        if (state.failed)
                                            return result;
                                        pushFollow(FOLLOW_expression_in_inExpression1686);
                                        e2 = expression();
                                        state._fsp--;
                                        if (state.failed)
                                            return result;
                                        if (state.backtracking == 0) {
                                            RelationalExprDescr rel = new RelationalExprDescr("!=", false, null, leftDescr, (e2 != null ? ((DRL6Expressions.expression_return) e2).result : null));
                                            descr.addOrMerge(rel);
                                        }
                                    }
                                    break;
                                default:
                                    break loop34;
                            }
                        }
                        match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_inExpression1707);
                        if (state.failed)
                            return result;
                        if (state.backtracking == 0) {
                            helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_END);
                        }
                    }
                    break;
                case 2:
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:351:7: in= in_key LEFT_PAREN e1= expression ( COMMA e2= expression )* RIGHT_PAREN
                    {
                        pushFollow(FOLLOW_in_key_in_inExpression1723);
                        in_key();
                        state._fsp--;
                        if (state.failed)
                            return result;
                        match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_inExpression1725);
                        if (state.failed)
                            return result;
                        if (state.backtracking == 0) {
                            helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
                        }
                        pushFollow(FOLLOW_expression_in_inExpression1747);
                        e1 = expression();
                        state._fsp--;
                        if (state.failed)
                            return result;
                        if (state.backtracking == 0) {
                            descr = ConstraintConnectiveDescr.newOr();
                            RelationalExprDescr rel = new RelationalExprDescr("==", false, null, leftDescr, (e1 != null ? ((DRL6Expressions.expression_return) e1).result : null));
                            descr.addOrMerge(rel);
                            result = descr;
                        }
                        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:359:7: ( COMMA e2= expression )*
                        loop35: while (true) {
                            int alt35 = 2;
                            int LA35_0 = input.LA(1);
                            if ((LA35_0 == COMMA)) {
                                alt35 = 1;
                            }
                            switch(alt35) {
                                case 1:
                                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:359:8: COMMA e2= expression
                                    {
                                        match(input, COMMA, FOLLOW_COMMA_in_inExpression1766);
                                        if (state.failed)
                                            return result;
                                        pushFollow(FOLLOW_expression_in_inExpression1770);
                                        e2 = expression();
                                        state._fsp--;
                                        if (state.failed)
                                            return result;
                                        if (state.backtracking == 0) {
                                            RelationalExprDescr rel = new RelationalExprDescr("==", false, null, leftDescr, (e2 != null ? ((DRL6Expressions.expression_return) e2).result : null));
                                            descr.addOrMerge(rel);
                                        }
                                    }
                                    break;
                                default:
                                    break loop35;
                            }
                        }
                        match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_inExpression1791);
                        if (state.failed)
                            return result;
                        if (state.backtracking == 0) {
                            helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_END);
                        }
                    }
                    break;
            }
        }
        if (state.backtracking == 0) {
            if (binding != null && descr != null)
                descr.addOrMerge(binding);
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) AnnotatedBaseDescr(org.drools.compiler.lang.descr.AnnotatedBaseDescr) AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr)

Example 9 with BindingDescr

use of org.drools.compiler.lang.descr.BindingDescr in project drools by kiegroup.

the class DRL6Expressions method unaryExpressionNotPlusMinus.

// $ANTLR start "unaryExpressionNotPlusMinus"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:500:1: unaryExpressionNotPlusMinus returns [BaseDescr result] : ( TILDE unaryExpression | NEGATION unaryExpression | ( castExpression )=> castExpression | ( backReferenceExpression )=> backReferenceExpression | ( ({...}? (var= ID COLON ) ) | ({...}? (var= ID UNIFY ) ) )? ( ( xpathSeparator ID )=>left2= xpathPrimary |left1= primary ) ( ( selector )=> selector )* ( ( INCR | DECR )=> ( INCR | DECR ) )? );
public final DRL6Expressions.unaryExpressionNotPlusMinus_return unaryExpressionNotPlusMinus() throws RecognitionException {
    DRL6Expressions.unaryExpressionNotPlusMinus_return retval = new DRL6Expressions.unaryExpressionNotPlusMinus_return();
    retval.start = input.LT(1);
    Token var = null;
    Token COLON9 = null;
    Token UNIFY10 = null;
    BaseDescr left2 = null;
    BaseDescr left1 = null;
    boolean isLeft = false;
    BindingDescr bind = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:502:5: ( TILDE unaryExpression | NEGATION unaryExpression | ( castExpression )=> castExpression | ( backReferenceExpression )=> backReferenceExpression | ( ({...}? (var= ID COLON ) ) | ({...}? (var= ID UNIFY ) ) )? ( ( xpathSeparator ID )=>left2= xpathPrimary |left1= primary ) ( ( selector )=> selector )* ( ( INCR | DECR )=> ( INCR | DECR ) )? )
        int alt54 = 5;
        int LA54_0 = input.LA(1);
        if ((LA54_0 == TILDE)) {
            alt54 = 1;
        } else if ((LA54_0 == NEGATION)) {
            alt54 = 2;
        } else if ((LA54_0 == LEFT_PAREN)) {
            int LA54_3 = input.LA(2);
            if ((synpred15_DRL6Expressions())) {
                alt54 = 3;
            } else if ((true)) {
                alt54 = 5;
            }
        } else if ((LA54_0 == DOT) && (synpred16_DRL6Expressions())) {
            alt54 = 4;
        } else if ((LA54_0 == BOOL || LA54_0 == DECIMAL || LA54_0 == DIV || LA54_0 == FLOAT || LA54_0 == HEX || LA54_0 == ID || (LA54_0 >= LEFT_SQUARE && LA54_0 <= LESS) || LA54_0 == NULL || LA54_0 == QUESTION_DIV || (LA54_0 >= STAR && LA54_0 <= STRING) || LA54_0 == TIME_INTERVAL)) {
            alt54 = 5;
        } else {
            if (state.backtracking > 0) {
                state.failed = true;
                return retval;
            }
            NoViableAltException nvae = new NoViableAltException("", 54, 0, input);
            throw nvae;
        }
        switch(alt54) {
            case 1:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:502:9: TILDE unaryExpression
                {
                    match(input, TILDE, FOLLOW_TILDE_in_unaryExpressionNotPlusMinus2453);
                    if (state.failed)
                        return retval;
                    pushFollow(FOLLOW_unaryExpression_in_unaryExpressionNotPlusMinus2455);
                    unaryExpression();
                    state._fsp--;
                    if (state.failed)
                        return retval;
                }
                break;
            case 2:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:503:8: NEGATION unaryExpression
                {
                    match(input, NEGATION, FOLLOW_NEGATION_in_unaryExpressionNotPlusMinus2464);
                    if (state.failed)
                        return retval;
                    pushFollow(FOLLOW_unaryExpression_in_unaryExpressionNotPlusMinus2466);
                    unaryExpression();
                    state._fsp--;
                    if (state.failed)
                        return retval;
                }
                break;
            case 3:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:504:9: ( castExpression )=> castExpression
                {
                    pushFollow(FOLLOW_castExpression_in_unaryExpressionNotPlusMinus2480);
                    castExpression();
                    state._fsp--;
                    if (state.failed)
                        return retval;
                }
                break;
            case 4:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:505:9: ( backReferenceExpression )=> backReferenceExpression
                {
                    pushFollow(FOLLOW_backReferenceExpression_in_unaryExpressionNotPlusMinus2494);
                    backReferenceExpression();
                    state._fsp--;
                    if (state.failed)
                        return retval;
                }
                break;
            case 5:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:506:9: ( ({...}? (var= ID COLON ) ) | ({...}? (var= ID UNIFY ) ) )? ( ( xpathSeparator ID )=>left2= xpathPrimary |left1= primary ) ( ( selector )=> selector )* ( ( INCR | DECR )=> ( INCR | DECR ) )?
                {
                    if (state.backtracking == 0) {
                        isLeft = helper.getLeftMostExpr() == null;
                    }
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:507:9: ( ({...}? (var= ID COLON ) ) | ({...}? (var= ID UNIFY ) ) )?
                    int alt50 = 3;
                    int LA50_0 = input.LA(1);
                    if ((LA50_0 == ID)) {
                        int LA50_1 = input.LA(2);
                        if ((LA50_1 == COLON)) {
                            int LA50_3 = input.LA(3);
                            if (((inMap == 0 && ternOp == 0 && input.LA(2) == DRL6Lexer.COLON))) {
                                alt50 = 1;
                            }
                        } else if ((LA50_1 == UNIFY)) {
                            alt50 = 2;
                        }
                    }
                    switch(alt50) {
                        case 1:
                            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:507:11: ({...}? (var= ID COLON ) )
                            {
                                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:507:11: ({...}? (var= ID COLON ) )
                                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:507:12: {...}? (var= ID COLON )
                                {
                                    if (!((inMap == 0 && ternOp == 0 && input.LA(2) == DRL6Lexer.COLON))) {
                                        if (state.backtracking > 0) {
                                            state.failed = true;
                                            return retval;
                                        }
                                        throw new FailedPredicateException(input, "unaryExpressionNotPlusMinus", "inMap == 0 && ternOp == 0 && input.LA(2) == DRL6Lexer.COLON");
                                    }
                                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:507:75: (var= ID COLON )
                                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:507:76: var= ID COLON
                                    {
                                        var = (Token) match(input, ID, FOLLOW_ID_in_unaryExpressionNotPlusMinus2522);
                                        if (state.failed)
                                            return retval;
                                        COLON9 = (Token) match(input, COLON, FOLLOW_COLON_in_unaryExpressionNotPlusMinus2524);
                                        if (state.failed)
                                            return retval;
                                        if (state.backtracking == 0) {
                                            hasBindings = true;
                                            helper.emit(var, DroolsEditorType.IDENTIFIER_VARIABLE);
                                            helper.emit(COLON9, DroolsEditorType.SYMBOL);
                                            if (buildDescr) {
                                                bind = new BindingDescr((var != null ? var.getText() : null), null, false);
                                                helper.setStart(bind, var);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        case 2:
                            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:509:11: ({...}? (var= ID UNIFY ) )
                            {
                                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:509:11: ({...}? (var= ID UNIFY ) )
                                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:509:12: {...}? (var= ID UNIFY )
                                {
                                    if (!((inMap == 0 && ternOp == 0 && input.LA(2) == DRL6Lexer.UNIFY))) {
                                        if (state.backtracking > 0) {
                                            state.failed = true;
                                            return retval;
                                        }
                                        throw new FailedPredicateException(input, "unaryExpressionNotPlusMinus", "inMap == 0 && ternOp == 0 && input.LA(2) == DRL6Lexer.UNIFY");
                                    }
                                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:509:75: (var= ID UNIFY )
                                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:509:76: var= ID UNIFY
                                    {
                                        var = (Token) match(input, ID, FOLLOW_ID_in_unaryExpressionNotPlusMinus2563);
                                        if (state.failed)
                                            return retval;
                                        UNIFY10 = (Token) match(input, UNIFY, FOLLOW_UNIFY_in_unaryExpressionNotPlusMinus2565);
                                        if (state.failed)
                                            return retval;
                                        if (state.backtracking == 0) {
                                            hasBindings = true;
                                            helper.emit(var, DroolsEditorType.IDENTIFIER_VARIABLE);
                                            helper.emit(UNIFY10, DroolsEditorType.SYMBOL);
                                            if (buildDescr) {
                                                bind = new BindingDescr((var != null ? var.getText() : null), null, true);
                                                helper.setStart(bind, var);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                    }
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:513:9: ( ( xpathSeparator ID )=>left2= xpathPrimary |left1= primary )
                    int alt51 = 2;
                    int LA51_0 = input.LA(1);
                    if ((LA51_0 == DIV || LA51_0 == QUESTION_DIV) && (synpred17_DRL6Expressions())) {
                        alt51 = 1;
                    } else if ((LA51_0 == BOOL || LA51_0 == DECIMAL || LA51_0 == FLOAT || LA51_0 == HEX || LA51_0 == ID || (LA51_0 >= LEFT_PAREN && LA51_0 <= LESS) || LA51_0 == NULL || (LA51_0 >= STAR && LA51_0 <= STRING) || LA51_0 == TIME_INTERVAL)) {
                        alt51 = 2;
                    } else {
                        if (state.backtracking > 0) {
                            state.failed = true;
                            return retval;
                        }
                        NoViableAltException nvae = new NoViableAltException("", 51, 0, input);
                        throw nvae;
                    }
                    switch(alt51) {
                        case 1:
                            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:513:11: ( xpathSeparator ID )=>left2= xpathPrimary
                            {
                                pushFollow(FOLLOW_xpathPrimary_in_unaryExpressionNotPlusMinus2619);
                                left2 = xpathPrimary();
                                state._fsp--;
                                if (state.failed)
                                    return retval;
                                if (state.backtracking == 0) {
                                    if (buildDescr) {
                                        retval.result = left2;
                                    }
                                }
                            }
                            break;
                        case 2:
                            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:514:13: left1= primary
                            {
                                pushFollow(FOLLOW_primary_in_unaryExpressionNotPlusMinus2637);
                                left1 = primary();
                                state._fsp--;
                                if (state.failed)
                                    return retval;
                                if (state.backtracking == 0) {
                                    if (buildDescr) {
                                        retval.result = left1;
                                    }
                                }
                            }
                            break;
                    }
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:517:9: ( ( selector )=> selector )*
                    loop52: while (true) {
                        int alt52 = 2;
                        int LA52_0 = input.LA(1);
                        if ((LA52_0 == DOT) && (synpred18_DRL6Expressions())) {
                            alt52 = 1;
                        } else if ((LA52_0 == LEFT_SQUARE) && (synpred18_DRL6Expressions())) {
                            alt52 = 1;
                        }
                        switch(alt52) {
                            case 1:
                                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:517:10: ( selector )=> selector
                                {
                                    pushFollow(FOLLOW_selector_in_unaryExpressionNotPlusMinus2665);
                                    selector();
                                    state._fsp--;
                                    if (state.failed)
                                        return retval;
                                }
                                break;
                            default:
                                break loop52;
                        }
                    }
                    if (state.backtracking == 0) {
                        if (buildDescr) {
                            String expr = input.toString(retval.start, input.LT(-1));
                            if (isLeft) {
                                helper.setLeftMostExpr(expr);
                            }
                            if (bind != null) {
                                if (bind.isUnification()) {
                                    expr = expr.substring(expr.indexOf(":=") + 2).trim();
                                } else {
                                    expr = expr.substring(expr.indexOf(":") + 1).trim();
                                }
                                bind.setExpressionAndBindingField(expr);
                                helper.setEnd(bind);
                                retval.result = bind;
                            }
                        }
                    }
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:536:9: ( ( INCR | DECR )=> ( INCR | DECR ) )?
                    int alt53 = 2;
                    int LA53_0 = input.LA(1);
                    if ((LA53_0 == DECR || LA53_0 == INCR) && (synpred19_DRL6Expressions())) {
                        alt53 = 1;
                    }
                    switch(alt53) {
                        case 1:
                            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:536:10: ( INCR | DECR )=> ( INCR | DECR )
                            {
                                if (input.LA(1) == DECR || input.LA(1) == INCR) {
                                    input.consume();
                                    state.errorRecovery = false;
                                    state.failed = false;
                                } else {
                                    if (state.backtracking > 0) {
                                        state.failed = true;
                                        return retval;
                                    }
                                    MismatchedSetException mse = new MismatchedSetException(null, input);
                                    throw mse;
                                }
                            }
                            break;
                    }
                }
                break;
        }
        retval.stop = input.LT(-1);
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return retval;
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) AnnotatedBaseDescr(org.drools.compiler.lang.descr.AnnotatedBaseDescr)

Example 10 with BindingDescr

use of org.drools.compiler.lang.descr.BindingDescr in project drools by kiegroup.

the class DRL5Expressions method relationalExpression.

// $ANTLR start "relationalExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:354:1: relationalExpression returns [BaseDescr result] : left= shiftExpression ( ( operator | LEFT_PAREN )=>right= orRestriction )* ;
public final BaseDescr relationalExpression() throws RecognitionException {
    relationalExpression_stack.push(new relationalExpression_scope());
    BaseDescr result = null;
    ParserRuleReturnScope left = null;
    BaseDescr right = null;
    relationalExpression_stack.peek().lsd = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:357:3: (left= shiftExpression ( ( operator | LEFT_PAREN )=>right= orRestriction )* )
        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:357:5: left= shiftExpression ( ( operator | LEFT_PAREN )=>right= orRestriction )*
        {
            pushFollow(FOLLOW_shiftExpression_in_relationalExpression1750);
            left = shiftExpression();
            state._fsp--;
            if (state.failed)
                return result;
            if (state.backtracking == 0) {
                if (buildDescr) {
                    if ((left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null) == null) {
                        result = new AtomicExprDescr((left != null ? input.toString(left.start, left.stop) : null));
                    } else if ((left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null) instanceof AtomicExprDescr) {
                        if ((left != null ? input.toString(left.start, left.stop) : null).equals(((AtomicExprDescr) (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null)).getExpression())) {
                            result = (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null);
                        } else {
                            result = new AtomicExprDescr((left != null ? input.toString(left.start, left.stop) : null));
                        }
                    } else if ((left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null) instanceof BindingDescr) {
                        if ((left != null ? input.toString(left.start, left.stop) : null).equals(((BindingDescr) (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null)).getExpression())) {
                            result = (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null);
                        } else {
                            BindingDescr bind = (BindingDescr) (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null);
                            int offset = bind.isUnification() ? 2 : 1;
                            String fullExpression = (left != null ? input.toString(left.start, left.stop) : null).substring((left != null ? input.toString(left.start, left.stop) : null).indexOf(":") + offset).trim();
                            result = new BindingDescr(bind.getVariable(), bind.getExpression(), fullExpression, bind.isUnification());
                        }
                    } else {
                        result = (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null);
                    }
                    relationalExpression_stack.peek().lsd = result;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:382:3: ( ( operator | LEFT_PAREN )=>right= orRestriction )*
            loop37: while (true) {
                int alt37 = 2;
                int LA37_0 = input.LA(1);
                if ((LA37_0 == ID)) {
                    int LA37_2 = input.LA(2);
                    if (((synpred8_DRL5Expressions() && (((helper.validateIdentifierKey(DroolsSoftKeywords.NOT))) || ((helper.isPluggableEvaluator(false))))))) {
                        alt37 = 1;
                    }
                } else if ((LA37_0 == EQUALS)) {
                    int LA37_3 = input.LA(2);
                    if ((synpred8_DRL5Expressions())) {
                        alt37 = 1;
                    }
                } else if ((LA37_0 == NOT_EQUALS)) {
                    int LA37_4 = input.LA(2);
                    if ((synpred8_DRL5Expressions())) {
                        alt37 = 1;
                    }
                } else if ((LA37_0 == LESS)) {
                    int LA37_20 = input.LA(2);
                    if ((synpred8_DRL5Expressions())) {
                        alt37 = 1;
                    }
                } else if ((LA37_0 == GREATER)) {
                    int LA37_21 = input.LA(2);
                    if ((synpred8_DRL5Expressions())) {
                        alt37 = 1;
                    }
                } else if ((LA37_0 == TILDE) && (synpred8_DRL5Expressions())) {
                    alt37 = 1;
                } else if ((LA37_0 == LESS_EQUALS) && (synpred8_DRL5Expressions())) {
                    alt37 = 1;
                } else if ((LA37_0 == GREATER_EQUALS) && (synpred8_DRL5Expressions())) {
                    alt37 = 1;
                } else if ((LA37_0 == LEFT_PAREN) && (synpred8_DRL5Expressions())) {
                    alt37 = 1;
                }
                switch(alt37) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:382:5: ( operator | LEFT_PAREN )=>right= orRestriction
                        {
                            pushFollow(FOLLOW_orRestriction_in_relationalExpression1775);
                            right = orRestriction();
                            state._fsp--;
                            if (state.failed)
                                return result;
                            if (state.backtracking == 0) {
                                if (buildDescr) {
                                    result = right;
                                    relationalExpression_stack.peek().lsd = result;
                                }
                            }
                        }
                        break;
                    default:
                        break loop37;
                }
            }
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
        // do for sure before leaving
        relationalExpression_stack.pop();
    }
    return result;
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) AnnotatedBaseDescr(org.drools.compiler.lang.descr.AnnotatedBaseDescr) AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr)

Aggregations

BindingDescr (org.drools.compiler.lang.descr.BindingDescr)41 ConstraintConnectiveDescr (org.drools.compiler.lang.descr.ConstraintConnectiveDescr)17 Test (org.junit.Test)17 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)12 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)11 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)11 AtomicExprDescr (org.drools.compiler.lang.descr.AtomicExprDescr)10 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)9 Cheese (org.drools.compiler.Cheese)8 AndDescr (org.drools.compiler.lang.descr.AndDescr)8 AnnotatedBaseDescr (org.drools.compiler.lang.descr.AnnotatedBaseDescr)8 RelationalExprDescr (org.drools.compiler.lang.descr.RelationalExprDescr)8 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)7 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)6 MVELDumperContext (org.drools.compiler.lang.MVELDumper.MVELDumperContext)5 ClassObjectType (org.drools.core.base.ClassObjectType)5 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)5 Declaration (org.drools.core.rule.Declaration)5 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)5 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)4