Search in sources :

Example 71 with BaseDescr

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

the class DRL6Expressions method andRestriction.

// $ANTLR end "orRestriction"
// $ANTLR start "andRestriction"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:419:1: andRestriction returns [BaseDescr result] : left= singleRestriction ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )* ;
public final BaseDescr andRestriction() 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/DRL6Expressions.g:420:3: (left= singleRestriction ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )* )
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:420:5: left= singleRestriction ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )*
        {
            pushFollow(FOLLOW_singleRestriction_in_andRestriction1963);
            left = singleRestriction();
            state._fsp--;
            if (state.failed)
                return result;
            if (state.backtracking == 0) {
                if (buildDescr) {
                    result = left;
                }
            }
            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:421:3: ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )*
            loop42: while (true) {
                int alt42 = 2;
                int LA42_0 = input.LA(1);
                if ((LA42_0 == DOUBLE_AMPER)) {
                    int LA42_9 = input.LA(2);
                    if ((synpred11_DRL6Expressions())) {
                        alt42 = 1;
                    }
                }
                switch(alt42) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:421:5: ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction
                        {
                            lop = (Token) match(input, DOUBLE_AMPER, FOLLOW_DOUBLE_AMPER_in_andRestriction1983);
                            if (state.failed)
                                return result;
                            if (state.backtracking == 0) {
                                if (isNotEOF())
                                    helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR);
                            }
                            // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:423:13: (args= fullAnnotation[null] )?
                            int alt41 = 2;
                            int LA41_0 = input.LA(1);
                            if ((LA41_0 == AT)) {
                                alt41 = 1;
                            }
                            switch(alt41) {
                                case 1:
                                    // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:423:13: args= fullAnnotation[null]
                                    {
                                        pushFollow(FOLLOW_fullAnnotation_in_andRestriction2004);
                                        args = fullAnnotation(null);
                                        state._fsp--;
                                        if (state.failed)
                                            return result;
                                    }
                                    break;
                            }
                            pushFollow(FOLLOW_singleRestriction_in_andRestriction2009);
                            right = singleRestriction();
                            state._fsp--;
                            if (state.failed)
                                return result;
                            if (state.backtracking == 0) {
                                if (buildDescr) {
                                    ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newAnd();
                                    descr.addOrMerge(result);
                                    descr.addOrMerge(right);
                                    if (args != null) {
                                        descr.addAnnotation(args);
                                    }
                                    result = descr;
                                }
                            }
                        }
                        break;
                    default:
                        break loop42;
                }
            }
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BaseDescr(org.drools.drl.ast.descr.BaseDescr) ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) AnnotationDescr(org.drools.drl.ast.descr.AnnotationDescr)

Example 72 with BaseDescr

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

the class DRL6Expressions method unaryExpression.

// $ANTLR end "multiplicativeExpression"
// $ANTLR start "unaryExpression"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:480:1: unaryExpression returns [BaseDescr result] : ( PLUS ue= unaryExpression | MINUS ue= unaryExpression | INCR primary | DECR primary |left= unaryExpressionNotPlusMinus );
public final BaseDescr unaryExpression() throws RecognitionException {
    BaseDescr result = null;
    BaseDescr ue = null;
    ParserRuleReturnScope left = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:481:5: ( PLUS ue= unaryExpression | MINUS ue= unaryExpression | INCR primary | DECR primary |left= unaryExpressionNotPlusMinus )
        int alt49 = 5;
        switch(input.LA(1)) {
            case PLUS:
                {
                    alt49 = 1;
                }
                break;
            case MINUS:
                {
                    alt49 = 2;
                }
                break;
            case INCR:
                {
                    alt49 = 3;
                }
                break;
            case DECR:
                {
                    alt49 = 4;
                }
                break;
            case BOOL:
            case DECIMAL:
            case DIV:
            case DOT:
            case FLOAT:
            case HEX:
            case ID:
            case LEFT_PAREN:
            case LEFT_SQUARE:
            case LESS:
            case NEGATION:
            case NULL:
            case QUESTION_DIV:
            case STAR:
            case STRING:
            case TILDE:
            case TIME_INTERVAL:
                {
                    alt49 = 5;
                }
                break;
            default:
                if (state.backtracking > 0) {
                    state.failed = true;
                    return result;
                }
                NoViableAltException nvae = new NoViableAltException("", 49, 0, input);
                throw nvae;
        }
        switch(alt49) {
            case 1:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:481:9: PLUS ue= unaryExpression
                {
                    match(input, PLUS, FOLLOW_PLUS_in_unaryExpression2351);
                    if (state.failed)
                        return result;
                    pushFollow(FOLLOW_unaryExpression_in_unaryExpression2355);
                    ue = unaryExpression();
                    state._fsp--;
                    if (state.failed)
                        return result;
                    if (state.backtracking == 0) {
                        if (buildDescr) {
                            result = ue;
                            if (result instanceof AtomicExprDescr) {
                                ((AtomicExprDescr) result).setExpression("+" + ((AtomicExprDescr) result).getExpression());
                            }
                        }
                    }
                }
                break;
            case 2:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:488:7: MINUS ue= unaryExpression
                {
                    match(input, MINUS, FOLLOW_MINUS_in_unaryExpression2373);
                    if (state.failed)
                        return result;
                    pushFollow(FOLLOW_unaryExpression_in_unaryExpression2377);
                    ue = unaryExpression();
                    state._fsp--;
                    if (state.failed)
                        return result;
                    if (state.backtracking == 0) {
                        if (buildDescr) {
                            result = ue;
                            if (result instanceof AtomicExprDescr) {
                                ((AtomicExprDescr) result).setExpression("-" + ((AtomicExprDescr) result).getExpression());
                            }
                        }
                    }
                }
                break;
            case 3:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:495:9: INCR primary
                {
                    match(input, INCR, FOLLOW_INCR_in_unaryExpression2397);
                    if (state.failed)
                        return result;
                    pushFollow(FOLLOW_primary_in_unaryExpression2399);
                    primary();
                    state._fsp--;
                    if (state.failed)
                        return result;
                }
                break;
            case 4:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:496:9: DECR primary
                {
                    match(input, DECR, FOLLOW_DECR_in_unaryExpression2409);
                    if (state.failed)
                        return result;
                    pushFollow(FOLLOW_primary_in_unaryExpression2411);
                    primary();
                    state._fsp--;
                    if (state.failed)
                        return result;
                }
                break;
            case 5:
                // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:497:9: left= unaryExpressionNotPlusMinus
                {
                    pushFollow(FOLLOW_unaryExpressionNotPlusMinus_in_unaryExpression2423);
                    left = unaryExpressionNotPlusMinus();
                    state._fsp--;
                    if (state.failed)
                        return result;
                    if (state.backtracking == 0) {
                        if (buildDescr) {
                            result = (left != null ? ((DRL6Expressions.unaryExpressionNotPlusMinus_return) left).result : null);
                        }
                    }
                }
                break;
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BaseDescr(org.drools.drl.ast.descr.BaseDescr) AtomicExprDescr(org.drools.drl.ast.descr.AtomicExprDescr)

Example 73 with BaseDescr

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

the class DRL6Expressions method parExpression.

// $ANTLR end "mapEntry"
// $ANTLR start "parExpression"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:627:1: parExpression returns [BaseDescr result] : LEFT_PAREN expr= expression RIGHT_PAREN ;
public final BaseDescr parExpression() throws RecognitionException {
    BaseDescr result = null;
    ParserRuleReturnScope expr = null;
    try {
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:628:5: ( LEFT_PAREN expr= expression RIGHT_PAREN )
        // src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:628:7: LEFT_PAREN expr= expression RIGHT_PAREN
        {
            match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_parExpression3643);
            if (state.failed)
                return result;
            pushFollow(FOLLOW_expression_in_parExpression3647);
            expr = expression();
            state._fsp--;
            if (state.failed)
                return result;
            match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_parExpression3649);
            if (state.failed)
                return result;
            if (state.backtracking == 0) {
                if (buildDescr) {
                    result = (expr != null ? ((DRL6Expressions.expression_return) expr).result : null);
                    if (result instanceof AtomicExprDescr) {
                        ((AtomicExprDescr) result).setExpression("(" + ((AtomicExprDescr) result).getExpression() + ")");
                    }
                }
            }
        }
    } catch (RecognitionException re) {
        throw re;
    } finally {
    // do for sure before leaving
    }
    return result;
}
Also used : BaseDescr(org.drools.drl.ast.descr.BaseDescr) AtomicExprDescr(org.drools.drl.ast.descr.AtomicExprDescr)

Example 74 with BaseDescr

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

the class DRL5Parser method lhsPatternBind.

/**
 * lhsPatternBind := label?
 *                ( LEFT_PAREN lhsPattern (OR lhsPattern)* RIGHT_PAREN
 *                | lhsPattern )
 *
 * @param ce
 * @return
 * @throws RecognitionException
 */
@SuppressWarnings("unchecked")
private BaseDescr lhsPatternBind(PatternContainerDescrBuilder<?, ?> ce, final boolean allowOr) throws RecognitionException {
    PatternDescrBuilder<?> pattern = null;
    CEDescrBuilder<?, OrDescr> or = null;
    BaseDescr result = null;
    Token first = input.LT(1);
    pattern = helper.start((DescrBuilder<?, ?>) ce, PatternDescrBuilder.class, null);
    if (pattern != null) {
        result = pattern.getDescr();
    }
    String label = null;
    boolean isUnification = false;
    if (input.LA(1) == DRL5Lexer.ID && input.LA(2) == DRL5Lexer.COLON && !helper.validateCEKeyword(1)) {
        label = label(DroolsEditorType.IDENTIFIER_PATTERN);
        if (state.failed)
            return null;
    } else if (input.LA(1) == DRL5Lexer.ID && input.LA(2) == DRL5Lexer.UNIFY && !helper.validateCEKeyword(1)) {
        label = unif(DroolsEditorType.IDENTIFIER_PATTERN);
        if (state.failed)
            return null;
        isUnification = true;
    }
    if (input.LA(1) == DRL5Lexer.LEFT_PAREN) {
        try {
            match(input, DRL5Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
            if (helper.validateCEKeyword(1)) {
                failMismatchedTokenException();
                // in case it is backtracking
                return null;
            }
            lhsPattern(pattern, label, isUnification);
            if (state.failed)
                return null;
            if (allowOr && helper.validateIdentifierKey(DroolsSoftKeywords.OR) && ce instanceof CEDescrBuilder) {
                if (state.backtracking == 0) {
                    // this is necessary because of the crappy bind with multi-pattern OR syntax
                    or = ((CEDescrBuilder<DescrBuilder<?, ?>, OrDescr>) ce).or();
                    result = or.getDescr();
                    helper.end(PatternDescrBuilder.class, pattern);
                    helper.start(or, CEDescrBuilder.class, null);
                    // adjust real or starting token:
                    helper.setStart(or, first);
                    // remove original pattern from the parent CE child list:
                    ((ConditionalElementDescr) ce.getDescr()).getDescrs().remove(pattern.getDescr());
                    // add pattern to the OR instead
                    or.getDescr().addDescr(pattern.getDescr());
                }
                while (helper.validateIdentifierKey(DroolsSoftKeywords.OR)) {
                    match(input, DRL5Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
                    if (state.failed)
                        return null;
                    pattern = helper.start(or, PatternDescrBuilder.class, null);
                    // new pattern, same binding
                    lhsPattern(pattern, label, isUnification);
                    if (state.failed)
                        return null;
                    helper.end(PatternDescrBuilder.class, pattern);
                }
            }
            match(input, DRL5Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
        } finally {
            if (or != null) {
                helper.end(CEDescrBuilder.class, or);
            } else {
                helper.end(PatternDescrBuilder.class, pattern);
            }
        }
    } else {
        try {
            lhsPattern(pattern, label, isUnification);
            if (state.failed)
                return null;
        } finally {
            helper.end(PatternDescrBuilder.class, pattern);
        }
    }
    return result;
}
Also used : CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) BaseDescr(org.drools.drl.ast.descr.BaseDescr) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) FunctionDescrBuilder(org.drools.drl.ast.dsl.FunctionDescrBuilder) DescrBuilder(org.drools.drl.ast.dsl.DescrBuilder) ForallDescrBuilder(org.drools.drl.ast.dsl.ForallDescrBuilder) NamedConsequenceDescrBuilder(org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder) DeclareDescrBuilder(org.drools.drl.ast.dsl.DeclareDescrBuilder) EvalDescrBuilder(org.drools.drl.ast.dsl.EvalDescrBuilder) AnnotationDescrBuilder(org.drools.drl.ast.dsl.AnnotationDescrBuilder) AccumulateDescrBuilder(org.drools.drl.ast.dsl.AccumulateDescrBuilder) WindowDeclarationDescrBuilder(org.drools.drl.ast.dsl.WindowDeclarationDescrBuilder) PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) FieldDescrBuilder(org.drools.drl.ast.dsl.FieldDescrBuilder) EntryPointDeclarationDescrBuilder(org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder) EnumDeclarationDescrBuilder(org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder) QueryDescrBuilder(org.drools.drl.ast.dsl.QueryDescrBuilder) CollectDescrBuilder(org.drools.drl.ast.dsl.CollectDescrBuilder) ImportDescrBuilder(org.drools.drl.ast.dsl.ImportDescrBuilder) AnnotatedDescrBuilder(org.drools.drl.ast.dsl.AnnotatedDescrBuilder) BehaviorDescrBuilder(org.drools.drl.ast.dsl.BehaviorDescrBuilder) EnumLiteralDescrBuilder(org.drools.drl.ast.dsl.EnumLiteralDescrBuilder) GlobalDescrBuilder(org.drools.drl.ast.dsl.GlobalDescrBuilder) PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) AttributeDescrBuilder(org.drools.drl.ast.dsl.AttributeDescrBuilder) CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) PatternContainerDescrBuilder(org.drools.drl.ast.dsl.PatternContainerDescrBuilder) ConditionalBranchDescrBuilder(org.drools.drl.ast.dsl.ConditionalBranchDescrBuilder) TypeDeclarationDescrBuilder(org.drools.drl.ast.dsl.TypeDeclarationDescrBuilder) RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) OrDescr(org.drools.drl.ast.descr.OrDescr)

Example 75 with BaseDescr

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

the class DRL6StrictParser method constraint.

/**
 * constraint := nestedConstraint | conditionalOrExpression
 * @param pattern
 * @throws org.antlr.runtime.RecognitionException
 */
private void constraint(PatternDescrBuilder<?> pattern, boolean positional, String prefix) throws RecognitionException {
    if (speculateNestedConstraint()) {
        nestedConstraint(pattern, prefix);
        return;
    }
    if (state.backtracking == 0) {
        helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_START);
    }
    int first = input.index();
    // resetting
    exprParser.getHelper().setHasOperator(false);
    try {
        exprParser.conditionalOrExpression();
    } finally {
        if (state.backtracking == 0) {
            if (input.LA(1) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
            } else if (input.LA(1) != DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_END);
            } else if (!lastTokenWasWhiteSpace()) {
                int location = getCurrentLocation();
                if (location == Location.LOCATION_LHS_INSIDE_CONDITION_END) {
                    helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
                } else if (input.get(input.index()).getType() != DRL6Lexer.EOF) {
                    helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_START);
                }
            } else if (getCurrentLocation() == Location.LOCATION_LHS_INSIDE_CONDITION_START && !exprParser.getHelper().getHasOperator() && lastTokenWasWhiteSpace() && input.LA(1) == DRL6Lexer.EOF && input.LA(-1) == DRL6Lexer.ID) {
                helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR);
            }
        }
    }
    if (state.failed)
        return;
    if (state.backtracking == 0 && input.index() > first) {
        // expression consumed something
        int last = input.LT(-1).getTokenIndex();
        String expr = toExpression(prefix, first, last);
        pattern.constraint(expr, positional);
        BaseDescr constrDescr = pattern.getDescr().getDescrs().get(pattern.getDescr().getDescrs().size() - 1);
        constrDescr.setLocation(input.get(first).getLine(), input.get(first).getCharPositionInLine());
        constrDescr.setEndLocation(input.get(last).getLine(), input.get(last).getCharPositionInLine());
        constrDescr.setStartCharacter(((CommonToken) input.get(first)).getStartIndex());
        constrDescr.setEndCharacter(((CommonToken) input.get(last)).getStopIndex());
    }
}
Also used : AnnotatedBaseDescr(org.drools.drl.ast.descr.AnnotatedBaseDescr) 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