Search in sources :

Example 46 with ConstraintConnectiveDescr

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

the class DRL5Expressions method andExpression.

// $ANTLR end "exclusiveOrExpression"
// $ANTLR start "andExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:272:1: andExpression returns [BaseDescr result] : left= equalityExpression ( AMPER right= equalityExpression )* ;
public final BaseDescr andExpression() throws RecognitionException {
    BaseDescr result = null;
    BaseDescr left = null;
    BaseDescr right = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:273:3: (left= equalityExpression ( AMPER right= equalityExpression )* )
        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:273:5: left= equalityExpression ( AMPER right= equalityExpression )*
        {
            pushFollow(FOLLOW_equalityExpression_in_andExpression1348);
            left = equalityExpression();
            state._fsp--;
            if (state.failed)
                return result;
            if (state.backtracking == 0) {
                if (buildDescr) {
                    result = left;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:274:3: ( AMPER right= equalityExpression )*
            loop30: while (true) {
                int alt30 = 2;
                int LA30_0 = input.LA(1);
                if ((LA30_0 == AMPER)) {
                    alt30 = 1;
                }
                switch(alt30) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:274:5: AMPER right= equalityExpression
                        {
                            match(input, AMPER, FOLLOW_AMPER_in_andExpression1356);
                            if (state.failed)
                                return result;
                            pushFollow(FOLLOW_equalityExpression_in_andExpression1360);
                            right = equalityExpression();
                            state._fsp--;
                            if (state.failed)
                                return result;
                            if (state.backtracking == 0) {
                                if (buildDescr) {
                                    ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newIncAnd();
                                    descr.addOrMerge(result);
                                    descr.addOrMerge(right);
                                    result = descr;
                                }
                            }
                        }
                        break;
                    default:
                        break loop30;
                }
            }
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BaseDescr(org.drools.compiler.lang.descr.BaseDescr) AnnotatedBaseDescr(org.drools.compiler.lang.descr.AnnotatedBaseDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr)

Example 47 with ConstraintConnectiveDescr

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

the class DRL5Expressions method orRestriction.

// $ANTLR end "relationalExpression"
// $ANTLR start "orRestriction"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:391:1: orRestriction returns [BaseDescr result] : left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )? ;
public final BaseDescr orRestriction() throws RecognitionException {
    BaseDescr result = null;
    Token lop = null;
    BaseDescr left = null;
    AnnotationDescr args = null;
    BaseDescr right = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:392:3: (left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )? )
        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:392:5: left= andRestriction ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )* ( EOF )?
        {
            pushFollow(FOLLOW_andRestriction_in_orRestriction1810);
            left = andRestriction();
            state._fsp--;
            if (state.failed)
                return result;
            if (state.backtracking == 0) {
                if (buildDescr) {
                    result = left;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:393:5: ( ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction )*
            loop39: while (true) {
                int alt39 = 2;
                int LA39_0 = input.LA(1);
                if ((LA39_0 == DOUBLE_PIPE)) {
                    int LA39_9 = input.LA(2);
                    if ((synpred9_DRL5Expressions())) {
                        alt39 = 1;
                    }
                }
                switch(alt39) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:393:7: ( DOUBLE_PIPE ( fullAnnotation[null] )? andRestriction )=>lop= DOUBLE_PIPE (args= fullAnnotation[null] )? right= andRestriction
                        {
                            lop = (Token) match(input, DOUBLE_PIPE, FOLLOW_DOUBLE_PIPE_in_orRestriction1832);
                            if (state.failed)
                                return result;
                            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:393:79: (args= fullAnnotation[null] )?
                            int alt38 = 2;
                            int LA38_0 = input.LA(1);
                            if ((LA38_0 == AT)) {
                                alt38 = 1;
                            }
                            switch(alt38) {
                                case 1:
                                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:393:79: args= fullAnnotation[null]
                                    {
                                        pushFollow(FOLLOW_fullAnnotation_in_orRestriction1836);
                                        args = fullAnnotation(null);
                                        state._fsp--;
                                        if (state.failed)
                                            return result;
                                    }
                                    break;
                            }
                            pushFollow(FOLLOW_andRestriction_in_orRestriction1842);
                            right = andRestriction();
                            state._fsp--;
                            if (state.failed)
                                return result;
                            if (state.backtracking == 0) {
                                if (buildDescr) {
                                    ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newOr();
                                    descr.addOrMerge(result);
                                    descr.addOrMerge(right);
                                    if (args != null) {
                                        descr.addAnnotation(args);
                                    }
                                    result = descr;
                                }
                            }
                        }
                        break;
                    default:
                        break loop39;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:402:7: ( EOF )?
            int alt40 = 2;
            int LA40_0 = input.LA(1);
            if ((LA40_0 == EOF)) {
                int LA40_1 = input.LA(2);
                if ((LA40_1 == EOF)) {
                    int LA40_3 = input.LA(3);
                    if ((LA40_3 == EOF)) {
                        alt40 = 1;
                    }
                } else if (((LA40_1 >= AMPER && LA40_1 <= AND_ASSIGN) || LA40_1 == AT || (LA40_1 >= COLON && LA40_1 <= COMMA) || LA40_1 == DIV_ASSIGN || (LA40_1 >= DOUBLE_AMPER && LA40_1 <= DOUBLE_PIPE) || (LA40_1 >= EQUALS && LA40_1 <= EQUALS_ASSIGN) || (LA40_1 >= GREATER && LA40_1 <= GREATER_EQUALS) || LA40_1 == ID || LA40_1 == LEFT_PAREN || (LA40_1 >= LESS && LA40_1 <= LESS_EQUALS) || LA40_1 == MINUS_ASSIGN || LA40_1 == MOD_ASSIGN || LA40_1 == MULT_ASSIGN || LA40_1 == NOT_EQUALS || LA40_1 == OR_ASSIGN || LA40_1 == PIPE || (LA40_1 >= PLUS_ASSIGN && LA40_1 <= SEMICOLON) || LA40_1 == TILDE || (LA40_1 >= XOR && LA40_1 <= XOR_ASSIGN))) {
                    alt40 = 1;
                }
            }
            switch(alt40) {
                case 1:
                    // src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:402:7: EOF
                    {
                        match(input, EOF, FOLLOW_EOF_in_orRestriction1861);
                        if (state.failed)
                            return result;
                    }
                    break;
            }
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BaseDescr(org.drools.compiler.lang.descr.BaseDescr) AnnotatedBaseDescr(org.drools.compiler.lang.descr.AnnotatedBaseDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) AnnotationDescr(org.drools.compiler.lang.descr.AnnotationDescr)

Example 48 with ConstraintConnectiveDescr

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

the class DRLExprParserTest method testDeepBinding.

@Test
public void testDeepBinding() throws Exception {
    String source = "($a : a > $b : b[10].prop || 10 != 20) && $x : someMethod(10) == 20";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(2, result.getDescrs().size());
    ConstraintConnectiveDescr or = (ConstraintConnectiveDescr) result.getDescrs().get(0);
    assertEquals(ConnectiveType.OR, or.getConnective());
    assertEquals(2, or.getDescrs().size());
    RelationalExprDescr expr = (RelationalExprDescr) or.getDescrs().get(0);
    assertEquals(">", expr.getOperator());
    BindingDescr leftBind = (BindingDescr) expr.getLeft();
    BindingDescr rightBind = (BindingDescr) expr.getRight();
    assertEquals("$a", leftBind.getVariable());
    assertEquals("a", leftBind.getExpression());
    assertEquals("$b", rightBind.getVariable());
    assertEquals("b[10].prop", rightBind.getExpression());
    expr = (RelationalExprDescr) or.getDescrs().get(1);
    assertEquals("!=", expr.getOperator());
    AtomicExprDescr leftExpr = (AtomicExprDescr) expr.getLeft();
    AtomicExprDescr rightExpr = (AtomicExprDescr) expr.getRight();
    assertEquals("10", leftExpr.getExpression());
    assertEquals("20", rightExpr.getExpression());
    expr = (RelationalExprDescr) result.getDescrs().get(1);
    assertEquals("==", expr.getOperator());
    leftBind = (BindingDescr) expr.getLeft();
    rightExpr = (AtomicExprDescr) expr.getRight();
    assertEquals("$x", leftBind.getVariable());
    assertEquals("someMethod(10)", leftBind.getExpression());
    assertEquals("20", rightExpr.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) Test(org.junit.Test)

Example 49 with ConstraintConnectiveDescr

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

the class DRLExprParserTest method testConnective2.

@Test
public void testConnective2() throws Exception {
    String source = "(a > b || 10 != 20) && someMethod(10) == 20";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(2, result.getDescrs().size());
    ConstraintConnectiveDescr or = (ConstraintConnectiveDescr) result.getDescrs().get(0);
    assertEquals(ConnectiveType.OR, or.getConnective());
    assertEquals(2, or.getDescrs().size());
    RelationalExprDescr expr = (RelationalExprDescr) or.getDescrs().get(0);
    assertEquals(">", expr.getOperator());
    AtomicExprDescr left = (AtomicExprDescr) expr.getLeft();
    AtomicExprDescr right = (AtomicExprDescr) expr.getRight();
    assertEquals("a", left.getExpression());
    assertEquals("b", right.getExpression());
    expr = (RelationalExprDescr) or.getDescrs().get(1);
    assertEquals("!=", expr.getOperator());
    left = (AtomicExprDescr) expr.getLeft();
    right = (AtomicExprDescr) expr.getRight();
    assertEquals("10", left.getExpression());
    assertEquals("20", right.getExpression());
    expr = (RelationalExprDescr) result.getDescrs().get(1);
    assertEquals("==", expr.getOperator());
    left = (AtomicExprDescr) expr.getLeft();
    right = (AtomicExprDescr) expr.getRight();
    assertEquals("someMethod(10)", left.getExpression());
    assertEquals("20", right.getExpression());
}
Also used : AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) Test(org.junit.Test)

Example 50 with ConstraintConnectiveDescr

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

the class DRLExprParserTest method testSimpleExpression.

@Test
public void testSimpleExpression() throws Exception {
    String source = "a > b";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(1, result.getDescrs().size());
    RelationalExprDescr expr = (RelationalExprDescr) result.getDescrs().get(0);
    assertEquals(">", expr.getOperator());
    AtomicExprDescr left = (AtomicExprDescr) expr.getLeft();
    AtomicExprDescr right = (AtomicExprDescr) expr.getRight();
    assertEquals("a", left.getExpression());
    assertEquals("b", right.getExpression());
}
Also used : AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) Test(org.junit.Test)

Aggregations

ConstraintConnectiveDescr (org.drools.compiler.lang.descr.ConstraintConnectiveDescr)60 Test (org.junit.Test)29 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)23 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)17 AnnotatedBaseDescr (org.drools.compiler.lang.descr.AnnotatedBaseDescr)16 AtomicExprDescr (org.drools.compiler.lang.descr.AtomicExprDescr)15 RelationalExprDescr (org.drools.compiler.lang.descr.RelationalExprDescr)12 AnnotationDescr (org.drools.compiler.lang.descr.AnnotationDescr)8 DrlExprParser (org.drools.compiler.compiler.DrlExprParser)6 MVELDumperContext (org.drools.compiler.lang.MVELDumper.MVELDumperContext)5 PredicateConstraint (org.drools.core.rule.PredicateConstraint)4 EvaluatorConstraint (org.drools.core.rule.constraint.EvaluatorConstraint)4 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)4 NegConstraint (org.drools.core.rule.constraint.NegConstraint)4 XpathConstraint (org.drools.core.rule.constraint.XpathConstraint)4 Constraint (org.drools.core.spi.Constraint)4 ArrayList (java.util.ArrayList)3 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)3 DroolsParserException (org.drools.compiler.compiler.DroolsParserException)3 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)3