Search in sources :

Example 1 with CEDescrBuilder

use of org.drools.drl.ast.dsl.CEDescrBuilder in project drools by kiegroup.

the class CEDescrBuilderImpl method not.

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

Example 2 with CEDescrBuilder

use of org.drools.drl.ast.dsl.CEDescrBuilder 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 3 with CEDescrBuilder

use of org.drools.drl.ast.dsl.CEDescrBuilder in project drools by kiegroup.

the class DRL6StrictParser method breakingNamedConsequence.

/**
 * breakingNamedConsequence := BREAK LEFT_SQUARE ID RIGHT_SQUARE
 */
private BaseDescr breakingNamedConsequence(CEDescrBuilder<?, ?> ce, NamedConsequenceDescrBuilder<?> namedConsequence) throws RecognitionException {
    if (namedConsequence == null) {
        namedConsequence = helper.start((DescrBuilder<?, ?>) ce, NamedConsequenceDescrBuilder.class, null);
    }
    try {
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.BREAK, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        match(input, DRL6Lexer.LEFT_SQUARE, null, null, DroolsEditorType.SYMBOL);
        if (state.failed)
            return null;
        Token label = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.SYMBOL);
        if (state.failed)
            return null;
        namedConsequence.name(label.getText());
        namedConsequence.breaking(true);
        match(input, DRL6Lexer.RIGHT_SQUARE, null, null, DroolsEditorType.SYMBOL);
        if (state.failed)
            return null;
    } finally {
        helper.end(NamedConsequenceDescrBuilder.class, namedConsequence);
    }
    return namedConsequence.getDescr();
}
Also used : Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) FunctionDescrBuilder(org.drools.drl.ast.dsl.FunctionDescrBuilder) DescrBuilder(org.drools.drl.ast.dsl.DescrBuilder) AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) 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) UnitDescrBuilder(org.drools.drl.ast.dsl.UnitDescrBuilder) 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) NamedConsequenceDescrBuilder(org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder)

Example 4 with CEDescrBuilder

use of org.drools.drl.ast.dsl.CEDescrBuilder in project drools by kiegroup.

the class DRL5Parser method breakingNamedConsequence.

/**
 * breakingNamedConsequence := BREAK LEFT_SQUARE ID RIGHT_SQUARE
 */
private BaseDescr breakingNamedConsequence(CEDescrBuilder<?, ?> ce, NamedConsequenceDescrBuilder<?> namedConsequence) throws RecognitionException {
    if (namedConsequence == null) {
        namedConsequence = helper.start((DescrBuilder<?, ?>) ce, NamedConsequenceDescrBuilder.class, null);
    }
    try {
        match(input, DRL5Lexer.ID, DroolsSoftKeywords.BREAK, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        match(input, DRL5Lexer.LEFT_SQUARE, null, null, DroolsEditorType.SYMBOL);
        if (state.failed)
            return null;
        Token label = match(input, DRL5Lexer.ID, null, null, DroolsEditorType.SYMBOL);
        if (state.failed)
            return null;
        namedConsequence.name(label.getText());
        namedConsequence.breaking(true);
        match(input, DRL5Lexer.RIGHT_SQUARE, null, null, DroolsEditorType.SYMBOL);
        if (state.failed)
            return null;
    } finally {
        helper.end(NamedConsequenceDescrBuilder.class, namedConsequence);
    }
    return namedConsequence.getDescr();
}
Also used : 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) NamedConsequenceDescrBuilder(org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder)

Example 5 with CEDescrBuilder

use of org.drools.drl.ast.dsl.CEDescrBuilder in project drools by kiegroup.

the class DRL6StrictParser method lhsAccumulate.

/**
 * lhsAccumulate := (ACCUMULATE|ACC) LEFT_PAREN lhsAnd (COMMA|SEMICOLON)
 *                      accumulateFunctionBinding (COMMA accumulateFunctionBinding)*
 *                      (SEMICOLON constraints)?
 *                  RIGHT_PAREN SEMICOLON?
 *
 * @param ce
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
private BaseDescr lhsAccumulate(PatternContainerDescrBuilder<?, ?> ce) throws RecognitionException {
    PatternDescrBuilder<?> pattern = null;
    BaseDescr result = null;
    pattern = helper.start((DescrBuilder<?, ?>) ce, PatternDescrBuilder.class, null);
    if (pattern != null) {
        result = pattern.getDescr();
    }
    try {
        if (state.backtracking == 0) {
            pattern.type("Object[]");
            pattern.isQuery(false);
        // might have to add the implicit bindings as well
        }
        AccumulateDescrBuilder<?> accumulate = helper.start(pattern, AccumulateDescrBuilder.class, null);
        try {
            if (helper.validateIdentifierKey(DroolsSoftKeywords.ACCUMULATE)) {
                match(input, DRL6Lexer.ID, DroolsSoftKeywords.ACCUMULATE, null, DroolsEditorType.KEYWORD);
            } else {
                // might be using the short mnemonic
                match(input, DRL6Lexer.ID, DroolsSoftKeywords.ACC, null, DroolsEditorType.KEYWORD);
            }
            if (state.failed)
                return null;
            if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE);
            }
            match(input, DRL6Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
            CEDescrBuilder<?, AndDescr> source = accumulate.source();
            try {
                helper.start(source, CEDescrBuilder.class, null);
                lhsAnd(source, false);
                if (state.failed)
                    return null;
                if (source.getDescr() != null && source.getDescr() instanceof ConditionalElementDescr) {
                    ConditionalElementDescr root = (ConditionalElementDescr) source.getDescr();
                    BaseDescr[] descrs = root.getDescrs().toArray(new BaseDescr[root.getDescrs().size()]);
                    root.getDescrs().clear();
                    for (int i = 0; i < descrs.length; i++) {
                        root.addOrMerge(descrs[i]);
                    }
                }
            } finally {
                helper.end(CEDescrBuilder.class, source);
            }
            if (input.LA(1) == DRL6Lexer.COMMA) {
                match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
            } else if (input.LA(-1) != DRL6Lexer.SEMICOLON) {
                // lhsUnary will consume an optional SEMICOLON, so we need to check if it was consumed already
                // or if we must fail consuming it now
                match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
            }
            // accumulate functions
            accumulateFunctionBinding(accumulate);
            if (state.failed)
                return null;
            while (input.LA(1) == DRL6Lexer.COMMA) {
                match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
                accumulateFunctionBinding(accumulate);
                if (state.failed)
                    return null;
            }
            if (input.LA(1) == DRL6Lexer.SEMICOLON) {
                match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
                constraints(pattern);
            }
            match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
        } finally {
            helper.end(AccumulateDescrBuilder.class, accumulate);
            if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
            }
        }
    } finally {
        helper.end(PatternDescrBuilder.class, pattern);
    }
    if (input.LA(1) == DRL6Lexer.SEMICOLON) {
        match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
        if (state.failed)
            return null;
    }
    return result;
}
Also used : PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) AndDescr(org.drools.drl.ast.descr.AndDescr) AnnotatedBaseDescr(org.drools.drl.ast.descr.AnnotatedBaseDescr) BaseDescr(org.drools.drl.ast.descr.BaseDescr) FunctionDescrBuilder(org.drools.drl.ast.dsl.FunctionDescrBuilder) DescrBuilder(org.drools.drl.ast.dsl.DescrBuilder) AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) 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) UnitDescrBuilder(org.drools.drl.ast.dsl.UnitDescrBuilder) 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) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Aggregations

CEDescrBuilder (org.drools.drl.ast.dsl.CEDescrBuilder)16 RuleDescrBuilder (org.drools.drl.ast.dsl.RuleDescrBuilder)14 AccumulateDescrBuilder (org.drools.drl.ast.dsl.AccumulateDescrBuilder)13 AttributeDescrBuilder (org.drools.drl.ast.dsl.AttributeDescrBuilder)13 DeclareDescrBuilder (org.drools.drl.ast.dsl.DeclareDescrBuilder)13 EntryPointDeclarationDescrBuilder (org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder)13 EnumDeclarationDescrBuilder (org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder)13 EnumLiteralDescrBuilder (org.drools.drl.ast.dsl.EnumLiteralDescrBuilder)13 FieldDescrBuilder (org.drools.drl.ast.dsl.FieldDescrBuilder)13 ForallDescrBuilder (org.drools.drl.ast.dsl.ForallDescrBuilder)13 FunctionDescrBuilder (org.drools.drl.ast.dsl.FunctionDescrBuilder)13 GlobalDescrBuilder (org.drools.drl.ast.dsl.GlobalDescrBuilder)13 ImportDescrBuilder (org.drools.drl.ast.dsl.ImportDescrBuilder)13 NamedConsequenceDescrBuilder (org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder)13 PackageDescrBuilder (org.drools.drl.ast.dsl.PackageDescrBuilder)13 PatternDescrBuilder (org.drools.drl.ast.dsl.PatternDescrBuilder)13 QueryDescrBuilder (org.drools.drl.ast.dsl.QueryDescrBuilder)13 TypeDeclarationDescrBuilder (org.drools.drl.ast.dsl.TypeDeclarationDescrBuilder)13 WindowDeclarationDescrBuilder (org.drools.drl.ast.dsl.WindowDeclarationDescrBuilder)13 AnnotatedDescrBuilder (org.drools.drl.ast.dsl.AnnotatedDescrBuilder)12