Search in sources :

Example 6 with ConditionalElementDescr

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

the class CEDescrBuilderImpl method exists.

/**
 * {@inheritDoc}
 */
public CEDescrBuilder<CEDescrBuilder<P, T>, ExistsDescr> exists() {
    CEDescrBuilder<CEDescrBuilder<P, T>, ExistsDescr> exists = new CEDescrBuilderImpl<CEDescrBuilder<P, T>, ExistsDescr>(this, new ExistsDescr());
    ((ConditionalElementDescr) descr).addDescr(exists.getDescr());
    return exists;
}
Also used : CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) ExistsDescr(org.drools.drl.ast.descr.ExistsDescr) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 7 with ConditionalElementDescr

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

the class CEDescrBuilderImpl method or.

/**
 * {@inheritDoc}
 */
public CEDescrBuilder<CEDescrBuilder<P, T>, OrDescr> or() {
    OrDescr orDescr = new OrDescr();
    ((ConditionalElementDescr) descr).addDescr(orDescr);
    return new CEDescrBuilderImpl<CEDescrBuilder<P, T>, OrDescr>(this, orDescr);
}
Also used : OrDescr(org.drools.drl.ast.descr.OrDescr) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 8 with ConditionalElementDescr

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

the class PatternHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final PatternDescr patternDescr = (PatternDescr) parser.getCurrent();
    final Object parent = parser.getParent();
    if (parent instanceof PatternDestinationDescr) {
        final PatternDestinationDescr parentDescr = (PatternDestinationDescr) parent;
        parentDescr.setInputPattern(patternDescr);
    } else {
        final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent;
        parentDescr.addDescr(patternDescr);
    }
    return patternDescr;
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) PatternDestinationDescr(org.drools.drl.ast.descr.PatternDestinationDescr) Element(org.w3c.dom.Element) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 9 with ConditionalElementDescr

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

the class DRL5Parser method lhsAnd.

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

Example 10 with ConditionalElementDescr

use of org.drools.drl.ast.descr.ConditionalElementDescr 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)

Aggregations

ConditionalElementDescr (org.drools.drl.ast.descr.ConditionalElementDescr)30 BaseDescr (org.drools.drl.ast.descr.BaseDescr)16 AndDescr (org.drools.drl.ast.descr.AndDescr)11 Element (org.w3c.dom.Element)10 AnnotatedBaseDescr (org.drools.drl.ast.descr.AnnotatedBaseDescr)5 CEDescrBuilder (org.drools.drl.ast.dsl.CEDescrBuilder)5 OrDescr (org.drools.drl.ast.descr.OrDescr)4 FromDescr (org.drools.drl.ast.descr.FromDescr)3 PatternDescr (org.drools.drl.ast.descr.PatternDescr)3 AccumulateDescrBuilder (org.drools.drl.ast.dsl.AccumulateDescrBuilder)3 AnnotatedDescrBuilder (org.drools.drl.ast.dsl.AnnotatedDescrBuilder)3 AnnotationDescrBuilder (org.drools.drl.ast.dsl.AnnotationDescrBuilder)3 AttributeDescrBuilder (org.drools.drl.ast.dsl.AttributeDescrBuilder)3 BehaviorDescrBuilder (org.drools.drl.ast.dsl.BehaviorDescrBuilder)3 CollectDescrBuilder (org.drools.drl.ast.dsl.CollectDescrBuilder)3 ConditionalBranchDescrBuilder (org.drools.drl.ast.dsl.ConditionalBranchDescrBuilder)3 DeclareDescrBuilder (org.drools.drl.ast.dsl.DeclareDescrBuilder)3 DescrBuilder (org.drools.drl.ast.dsl.DescrBuilder)3 EntryPointDeclarationDescrBuilder (org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder)3 EnumDeclarationDescrBuilder (org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder)3