Search in sources :

Example 26 with BaseDescr

use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.

the class DRL5Parser method lhsOr.

/**
 * lhsOr := LEFT_PAREN OR lhsAnd+ RIGHT_PAREN
 *        | lhsAnd (OR lhsAnd)*
 *
 * @param ce
 * @param allowOr
 * @throws RecognitionException
 */
private BaseDescr lhsOr(final CEDescrBuilder<?, ?> ce, boolean allowOr) throws RecognitionException {
    BaseDescr result = null;
    if (allowOr && input.LA(1) == DRL5Lexer.LEFT_PAREN && helper.validateLT(2, DroolsSoftKeywords.OR)) {
        // prefixed OR
        CEDescrBuilder<?, OrDescr> or = null;
        if (state.backtracking == 0) {
            or = ce.or();
            result = or.getDescr();
            helper.start(or, CEDescrBuilder.class, null);
        }
        try {
            match(input, DRL5Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
            match(input, DRL5Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
            if (state.failed)
                return null;
            while (input.LA(1) == DRL5Lexer.AT) {
                // annotation*
                annotation(or);
                if (state.failed)
                    return null;
            }
            if (state.backtracking == 0) {
                helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
            }
            while (input.LA(1) != DRL5Lexer.RIGHT_PAREN) {
                lhsAnd(or, allowOr);
                if (state.failed)
                    return null;
            }
            match(input, DRL5Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
        } finally {
            if (state.backtracking == 0) {
                helper.end(CEDescrBuilder.class, or);
            }
        }
    } else {
        // infix OR
        // create an OR anyway, as if it is not an OR we remove it later
        CEDescrBuilder<?, OrDescr> or = null;
        if (state.backtracking == 0) {
            or = ce.or();
            result = or.getDescr();
            helper.start(or, CEDescrBuilder.class, null);
        }
        try {
            lhsAnd(or, allowOr);
            if (state.failed)
                return null;
            if (allowOr && (helper.validateIdentifierKey(DroolsSoftKeywords.OR) || input.LA(1) == DRL5Lexer.DOUBLE_PIPE)) {
                while (helper.validateIdentifierKey(DroolsSoftKeywords.OR) || input.LA(1) == DRL5Lexer.DOUBLE_PIPE) {
                    if (input.LA(1) == DRL5Lexer.DOUBLE_PIPE) {
                        match(input, DRL5Lexer.DOUBLE_PIPE, null, null, DroolsEditorType.SYMBOL);
                    } else {
                        match(input, DRL5Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
                    }
                    if (state.failed)
                        return null;
                    while (input.LA(1) == DRL5Lexer.AT) {
                        // annotation*
                        annotation(or);
                        if (state.failed)
                            return null;
                    }
                    if (state.backtracking == 0) {
                        helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
                    }
                    lhsAnd(or, allowOr);
                    if (state.failed)
                        return null;
                }
            } else if (allowOr) {
                if (state.backtracking == 0) {
                    // if no OR present, then remove it and add children to parent
                    ((ConditionalElementDescr) ce.getDescr()).getDescrs().remove(or.getDescr());
                    for (BaseDescr base : or.getDescr().getDescrs()) {
                        ((ConditionalElementDescr) ce.getDescr()).addDescr(base);
                    }
                    result = ce.getDescr();
                }
            }
        } finally {
            if (state.backtracking == 0) {
                helper.end(CEDescrBuilder.class, or);
            }
        }
    }
    return result;
}
Also used : BaseDescr(org.drools.drl.ast.descr.BaseDescr) OrDescr(org.drools.drl.ast.descr.OrDescr) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 27 with BaseDescr

use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.

the class DRL6Expressions method xpathPrimary.

// $ANTLR end "xpathSeparator"
// $ANTLR start "xpathPrimary"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:569:1: xpathPrimary returns [BaseDescr result] : ( xpathChunk )+ ;
public final BaseDescr xpathPrimary() throws RecognitionException {
    BaseDescr result = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:570:5: ( ( xpathChunk )+ )
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:570:7: ( xpathChunk )+
        {
            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:570:7: ( xpathChunk )+
            int cnt58 = 0;
            loop58: while (true) {
                int alt58 = 2;
                int LA58_0 = input.LA(1);
                if ((LA58_0 == DIV)) {
                    int LA58_2 = input.LA(2);
                    if ((LA58_2 == ID)) {
                        alt58 = 1;
                    }
                } else if ((LA58_0 == QUESTION_DIV)) {
                    alt58 = 1;
                }
                switch(alt58) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:570:7: xpathChunk
                        {
                            pushFollow(FOLLOW_xpathChunk_in_xpathPrimary2930);
                            xpathChunk();
                            state._fsp--;
                            if (state.failed)
                                return result;
                        }
                        break;
                    default:
                        if (cnt58 >= 1)
                            break loop58;
                        if (state.backtracking > 0) {
                            state.failed = true;
                            return result;
                        }
                        EarlyExitException eee = new EarlyExitException(58, input);
                        throw eee;
                }
                cnt58++;
            }
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BaseDescr(org.drools.drl.ast.descr.BaseDescr)

Example 28 with BaseDescr

use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.

the class DRL6Expressions method singleRestriction.

// $ANTLR end "andRestriction"
// $ANTLR start "singleRestriction"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:435:1: singleRestriction returns [BaseDescr result] : (op= operator ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression ) | LEFT_PAREN or= orRestriction RIGHT_PAREN );
public final BaseDescr singleRestriction() throws RecognitionException {
    BaseDescr result = null;
    ParserRuleReturnScope op = null;
    java.util.List<String> sa = null;
    ParserRuleReturnScope value = null;
    BaseDescr or = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:436:3: (op= operator ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression ) | LEFT_PAREN or= orRestriction RIGHT_PAREN )
        int alt44 = 2;
        int LA44_0 = input.LA(1);
        if ((LA44_0 == EQUALS || (LA44_0 >= GREATER && LA44_0 <= GREATER_EQUALS) || (LA44_0 >= LESS && LA44_0 <= LESS_EQUALS) || LA44_0 == NOT_EQUALS || LA44_0 == TILDE)) {
            alt44 = 1;
        } else if ((LA44_0 == ID) && ((((helper.validateIdentifierKey(DroolsSoftKeywords.NOT))) || ((helper.isPluggableEvaluator(false)))))) {
            alt44 = 1;
        } else if ((LA44_0 == LEFT_PAREN)) {
            alt44 = 2;
        } else {
            if (state.backtracking > 0) {
                state.failed = true;
                return result;
            }
            NoViableAltException nvae = new NoViableAltException("", 44, 0, input);
            throw nvae;
        }
        switch(alt44) {
            case 1:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:436:6: op= operator ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression )
                {
                    pushFollow(FOLLOW_operator_in_singleRestriction2045);
                    op = operator();
                    state._fsp--;
                    if (state.failed)
                        return result;
                    if (state.backtracking == 0) {
                        helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
                    }
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:438:6: ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression )
                    int alt43 = 2;
                    int LA43_0 = input.LA(1);
                    if ((LA43_0 == LEFT_SQUARE)) {
                        int LA43_1 = input.LA(2);
                        if ((synpred12_DRL6Expressions())) {
                            alt43 = 1;
                        } else if ((true)) {
                            alt43 = 2;
                        }
                    } else if ((LA43_0 == BOOL || (LA43_0 >= DECIMAL && LA43_0 <= DIV) || LA43_0 == DOT || LA43_0 == FLOAT || LA43_0 == HEX || (LA43_0 >= ID && LA43_0 <= INCR) || LA43_0 == LEFT_PAREN || LA43_0 == LESS || LA43_0 == MINUS || LA43_0 == NEGATION || LA43_0 == NULL || LA43_0 == PLUS || LA43_0 == QUESTION_DIV || (LA43_0 >= STAR && LA43_0 <= TIME_INTERVAL))) {
                        alt43 = 2;
                    } else {
                        if (state.backtracking > 0) {
                            state.failed = true;
                            return result;
                        }
                        NoViableAltException nvae = new NoViableAltException("", 43, 0, input);
                        throw nvae;
                    }
                    switch(alt43) {
                        case 1:
                            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:438:8: ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression
                            {
                                pushFollow(FOLLOW_squareArguments_in_singleRestriction2074);
                                sa = squareArguments();
                                state._fsp--;
                                if (state.failed)
                                    return result;
                                pushFollow(FOLLOW_shiftExpression_in_singleRestriction2078);
                                value = shiftExpression();
                                state._fsp--;
                                if (state.failed)
                                    return result;
                            }
                            break;
                        case 2:
                            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:439:10: value= shiftExpression
                            {
                                pushFollow(FOLLOW_shiftExpression_in_singleRestriction2091);
                                value = shiftExpression();
                                state._fsp--;
                                if (state.failed)
                                    return result;
                            }
                            break;
                    }
                    if (state.backtracking == 0) {
                        if (buildDescr) {
                            BaseDescr descr = ((value != null ? ((DRL6Expressions.shiftExpression_return) value).result : null) != null && ((!((value != null ? ((DRL6Expressions.shiftExpression_return) value).result : null) instanceof AtomicExprDescr)) || ((value != null ? input.toString(value.start, value.stop) : null).equals(((AtomicExprDescr) (value != null ? ((DRL6Expressions.shiftExpression_return) value).result : null)).getExpression())))) ? (value != null ? ((DRL6Expressions.shiftExpression_return) value).result : null) : new AtomicExprDescr((value != null ? input.toString(value.start, value.stop) : null));
                            result = new RelationalExprDescr((op != null ? ((DRL6Expressions.operator_return) op).opr : null), (op != null ? ((DRL6Expressions.operator_return) op).negated : false), sa, relationalExpression_stack.peek().lsd, descr);
                            if (relationalExpression_stack.peek().lsd instanceof BindingDescr) {
                                relationalExpression_stack.peek().lsd = new AtomicExprDescr(((BindingDescr) relationalExpression_stack.peek().lsd).getExpression());
                            }
                        }
                        helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_END);
                    }
                }
                break;
            case 2:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:454:6: LEFT_PAREN or= orRestriction RIGHT_PAREN
                {
                    match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_singleRestriction2116);
                    if (state.failed)
                        return result;
                    pushFollow(FOLLOW_orRestriction_in_singleRestriction2120);
                    or = orRestriction();
                    state._fsp--;
                    if (state.failed)
                        return result;
                    match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_singleRestriction2122);
                    if (state.failed)
                        return result;
                    if (state.backtracking == 0) {
                        result = or;
                    }
                }
                break;
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BindingDescr(org.drools.drl.ast.descr.BindingDescr) AtomicExprDescr(org.drools.drl.ast.descr.AtomicExprDescr) RelationalExprDescr(org.drools.drl.ast.descr.RelationalExprDescr) BaseDescr(org.drools.drl.ast.descr.BaseDescr)

Example 29 with BaseDescr

use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.

the class DRL6Expressions method conditionalExpression.

// $ANTLR end "expression"
// $ANTLR start "conditionalExpression"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:168:1: conditionalExpression returns [BaseDescr result] : left= conditionalOrExpression ( ternaryExpression )? ;
public final BaseDescr conditionalExpression() throws RecognitionException {
    BaseDescr result = null;
    BaseDescr left = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:169:5: (left= conditionalOrExpression ( ternaryExpression )? )
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:169:9: left= conditionalOrExpression ( ternaryExpression )?
        {
            pushFollow(FOLLOW_conditionalOrExpression_in_conditionalExpression820);
            left = conditionalOrExpression();
            state._fsp--;
            if (state.failed)
                return result;
            if (state.backtracking == 0) {
                if (buildDescr) {
                    result = left;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:170:9: ( ternaryExpression )?
            int alt17 = 2;
            int LA17_0 = input.LA(1);
            if ((LA17_0 == QUESTION)) {
                alt17 = 1;
            }
            switch(alt17) {
                case 1:
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:170:9: ternaryExpression
                    {
                        pushFollow(FOLLOW_ternaryExpression_in_conditionalExpression832);
                        ternaryExpression();
                        state._fsp--;
                        if (state.failed)
                            return result;
                    }
                    break;
            }
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BaseDescr(org.drools.drl.ast.descr.BaseDescr)

Example 30 with BaseDescr

use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.

the class DRL6Expressions method xpathChunk.

// $ANTLR end "xpathPrimary"
// $ANTLR start "xpathChunk"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:573:1: xpathChunk returns [BaseDescr result] : ( xpathSeparator ID )=> xpathSeparator ID ( DOT ID )* ( HASH ID )? ( LEFT_SQUARE xpathExpressionList RIGHT_SQUARE )? ;
public final BaseDescr xpathChunk() throws RecognitionException {
    BaseDescr result = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:574:5: ( ( xpathSeparator ID )=> xpathSeparator ID ( DOT ID )* ( HASH ID )? ( LEFT_SQUARE xpathExpressionList RIGHT_SQUARE )? )
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:574:7: ( xpathSeparator ID )=> xpathSeparator ID ( DOT ID )* ( HASH ID )? ( LEFT_SQUARE xpathExpressionList RIGHT_SQUARE )?
        {
            pushFollow(FOLLOW_xpathSeparator_in_xpathChunk2959);
            xpathSeparator();
            state._fsp--;
            if (state.failed)
                return result;
            match(input, ID, FOLLOW_ID_in_xpathChunk2961);
            if (state.failed)
                return result;
            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:574:47: ( DOT ID )*
            loop59: while (true) {
                int alt59 = 2;
                int LA59_0 = input.LA(1);
                if ((LA59_0 == DOT)) {
                    int LA59_2 = input.LA(2);
                    if ((LA59_2 == ID)) {
                        alt59 = 1;
                    }
                }
                switch(alt59) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:574:48: DOT ID
                        {
                            match(input, DOT, FOLLOW_DOT_in_xpathChunk2964);
                            if (state.failed)
                                return result;
                            match(input, ID, FOLLOW_ID_in_xpathChunk2966);
                            if (state.failed)
                                return result;
                        }
                        break;
                    default:
                        break loop59;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:574:57: ( HASH ID )?
            int alt60 = 2;
            int LA60_0 = input.LA(1);
            if ((LA60_0 == HASH)) {
                alt60 = 1;
            }
            switch(alt60) {
                case 1:
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:574:58: HASH ID
                    {
                        match(input, HASH, FOLLOW_HASH_in_xpathChunk2971);
                        if (state.failed)
                            return result;
                        match(input, ID, FOLLOW_ID_in_xpathChunk2973);
                        if (state.failed)
                            return result;
                    }
                    break;
            }
            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:574:68: ( LEFT_SQUARE xpathExpressionList RIGHT_SQUARE )?
            int alt61 = 2;
            int LA61_0 = input.LA(1);
            if ((LA61_0 == LEFT_SQUARE)) {
                alt61 = 1;
            }
            switch(alt61) {
                case 1:
                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:574:69: LEFT_SQUARE xpathExpressionList RIGHT_SQUARE
                    {
                        match(input, LEFT_SQUARE, FOLLOW_LEFT_SQUARE_in_xpathChunk2978);
                        if (state.failed)
                            return result;
                        pushFollow(FOLLOW_xpathExpressionList_in_xpathChunk2980);
                        xpathExpressionList();
                        state._fsp--;
                        if (state.failed)
                            return result;
                        match(input, RIGHT_SQUARE, FOLLOW_RIGHT_SQUARE_in_xpathChunk2982);
                        if (state.failed)
                            return result;
                    }
                    break;
            }
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BaseDescr(org.drools.drl.ast.descr.BaseDescr)

Aggregations

BaseDescr (org.drools.drl.ast.descr.BaseDescr)117 ConstraintConnectiveDescr (org.drools.drl.ast.descr.ConstraintConnectiveDescr)23 AndDescr (org.drools.drl.ast.descr.AndDescr)18 AtomicExprDescr (org.drools.drl.ast.descr.AtomicExprDescr)17 ConditionalElementDescr (org.drools.drl.ast.descr.ConditionalElementDescr)16 PatternDescr (org.drools.drl.ast.descr.PatternDescr)15 AnnotatedBaseDescr (org.drools.drl.ast.descr.AnnotatedBaseDescr)14 BindingDescr (org.drools.drl.ast.descr.BindingDescr)13 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)11 Test (org.junit.Test)10 RelationalExprDescr (org.drools.drl.ast.descr.RelationalExprDescr)9 DeclareDescrBuilder (org.drools.drl.ast.dsl.DeclareDescrBuilder)9 AnnotationDescr (org.drools.drl.ast.descr.AnnotationDescr)8 CEDescrBuilder (org.drools.drl.ast.dsl.CEDescrBuilder)7 OrDescr (org.drools.drl.ast.descr.OrDescr)6 AccumulateDescrBuilder (org.drools.drl.ast.dsl.AccumulateDescrBuilder)6 AnnotatedDescrBuilder (org.drools.drl.ast.dsl.AnnotatedDescrBuilder)6 AnnotationDescrBuilder (org.drools.drl.ast.dsl.AnnotationDescrBuilder)6 AttributeDescrBuilder (org.drools.drl.ast.dsl.AttributeDescrBuilder)6 BehaviorDescrBuilder (org.drools.drl.ast.dsl.BehaviorDescrBuilder)6