Search in sources :

Example 1 with RuleDescrBuilder

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

the class DRL5Parser method rule.

/* ------------------------------------------------------------------------------------------------
     *                         RULE STATEMENT
     * ------------------------------------------------------------------------------------------------ */
/**
 * rule := RULE stringId (EXTENDS stringId)? annotation* attributes? lhs? rhs END
 *
 * @return
 * @throws RecognitionException
 */
public RuleDescr rule(PackageDescrBuilder pkg) throws RecognitionException {
    RuleDescrBuilder rule = null;
    try {
        rule = helper.start(pkg, RuleDescrBuilder.class, null);
        // 'rule'
        match(input, DRL5Lexer.ID, DroolsSoftKeywords.RULE, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        if (helper.validateIdentifierKey(DroolsSoftKeywords.WHEN) || helper.validateIdentifierKey(DroolsSoftKeywords.THEN) || helper.validateIdentifierKey(DroolsSoftKeywords.END)) {
            failMissingTokenException();
            // in case it is backtracking
            return null;
        }
        String name = stringId();
        if (state.failed)
            return null;
        if (state.backtracking == 0) {
            rule.name(name);
            helper.setParaphrasesValue(DroolsParaphraseTypes.RULE, "\"" + name + "\"");
            helper.emit(Location.LOCATION_RULE_HEADER);
        }
        if (helper.validateIdentifierKey(DroolsSoftKeywords.EXTENDS)) {
            // 'extends'
            match(input, DRL5Lexer.ID, DroolsSoftKeywords.EXTENDS, null, DroolsEditorType.KEYWORD);
            if (state.failed)
                return null;
            String parent = stringId();
            if (state.backtracking == 0)
                rule.extendsRule(parent);
            if (state.failed)
                return null;
        }
        if (state.backtracking == 0 && input.LA(1) != DRL5Lexer.EOF) {
            helper.emit(Location.LOCATION_RULE_HEADER);
        }
        while (input.LA(1) == DRL5Lexer.AT) {
            // annotation*
            annotation(rule);
            if (state.failed)
                return null;
        }
        attributes(rule);
        if (helper.validateIdentifierKey(DroolsSoftKeywords.WHEN)) {
            lhs(rule);
        } else {
            // creates an empty LHS
            rule.lhs();
        }
        rhs(rule);
        match(input, DRL5Lexer.ID, DroolsSoftKeywords.END, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
    } catch (RecognitionException re) {
        reportError(re);
    } finally {
        helper.end(RuleDescrBuilder.class, rule);
    }
    return (rule != null) ? rule.getDescr() : null;
}
Also used : RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) RecognitionException(org.antlr.runtime.RecognitionException)

Example 2 with RuleDescrBuilder

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

the class PackageDescrBuilderImpl method newRule.

public RuleDescrBuilder newRule() {
    RuleDescrBuilder rule = new RuleDescrBuilderImpl(this);
    descr.addRule(initDescr(rule));
    rule.getDescr().setUnit(descr.getUnit());
    return rule;
}
Also used : RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder)

Example 3 with RuleDescrBuilder

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

the class RuleDescrBuilderImpl method lhs.

public CEDescrBuilder<RuleDescrBuilder, AndDescr> lhs() {
    CEDescrBuilder<RuleDescrBuilder, AndDescr> ce = new CEDescrBuilderImpl<RuleDescrBuilder, AndDescr>(this, new AndDescr());
    descr.setLhs(ce.getDescr());
    return ce;
}
Also used : RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) AndDescr(org.drools.drl.ast.descr.AndDescr)

Example 4 with RuleDescrBuilder

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

the class DRL6Parser method rule.

/* ------------------------------------------------------------------------------------------------
     *                         RULE STATEMENT
     * ------------------------------------------------------------------------------------------------ */
/**
 * rule := RULE stringId (EXTENDS stringId)? annotation* attributes? lhs? rhs END
 *
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
public RuleDescr rule(PackageDescrBuilder pkg) throws RecognitionException {
    RuleDescrBuilder rule = null;
    try {
        rule = helper.start(pkg, RuleDescrBuilder.class, null);
        // 'rule'
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.RULE, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        if (helper.validateIdentifierKey(DroolsSoftKeywords.WHEN) || helper.validateIdentifierKey(DroolsSoftKeywords.THEN) || helper.validateIdentifierKey(DroolsSoftKeywords.END)) {
            failMissingTokenException();
            // in case it is backtracking
            return null;
        }
        String name = stringId();
        if (state.failed)
            return null;
        if (state.backtracking == 0) {
            rule.name(name);
            helper.setParaphrasesValue(DroolsParaphraseTypes.RULE, "\"" + name + "\"");
            helper.emit(Location.LOCATION_RULE_HEADER);
        }
        if (helper.validateIdentifierKey(DroolsSoftKeywords.EXTENDS)) {
            // 'extends'
            match(input, DRL6Lexer.ID, DroolsSoftKeywords.EXTENDS, null, DroolsEditorType.KEYWORD);
            if (state.failed)
                return null;
            String parent = stringId();
            if (state.backtracking == 0)
                rule.extendsRule(parent);
            if (state.failed)
                return null;
        }
        if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
            helper.emit(Location.LOCATION_RULE_HEADER);
        }
        while (input.LA(1) == DRL6Lexer.AT) {
            // annotation*
            annotation(rule);
            if (state.failed)
                return null;
        }
        attributes(rule);
        if (helper.validateIdentifierKey(DroolsSoftKeywords.WHEN)) {
            lhs(rule);
        } else {
            // creates an empty LHS
            rule.lhs();
        }
        rhs(rule);
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.END, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
    } catch (RecognitionException re) {
        reportError(re);
    } finally {
        helper.end(RuleDescrBuilder.class, rule);
    }
    return (rule != null) ? rule.getDescr() : null;
}
Also used : RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) RecognitionException(org.antlr.runtime.RecognitionException)

Example 5 with RuleDescrBuilder

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

the class KiePMMLDescrRulesFactory method declareRule.

protected void declareRule(final KiePMMLDroolsRule rule) {
    logger.trace("declareRule {}", rule);
    final RuleDescrBuilder ruleBuilder = builder.newRule().name(rule.getName());
    if (rule.getAgendaGroup() != null) {
        declareAgendaGroup(ruleBuilder, rule.getAgendaGroup());
    }
    if (rule.getActivationGroup() != null) {
        declareActivationGroup(ruleBuilder, rule.getActivationGroup());
    }
    KiePMMLDescrLhsFactory.factory(ruleBuilder.lhs()).declareLhs(rule);
    KiePMMLDescrRhsFactory.factory(ruleBuilder).declareRhs(rule);
}
Also used : RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder)

Aggregations

RuleDescrBuilder (org.drools.drl.ast.dsl.RuleDescrBuilder)10 RecognitionException (org.antlr.runtime.RecognitionException)3 CEDescrBuilder (org.drools.drl.ast.dsl.CEDescrBuilder)3 AndDescr (org.drools.drl.ast.descr.AndDescr)2 AccumulateDescrBuilder (org.drools.drl.ast.dsl.AccumulateDescrBuilder)2 NamedConsequenceDescrBuilder (org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder)2 PackageDescrBuilder (org.drools.drl.ast.dsl.PackageDescrBuilder)2 AttributeDescr (org.drools.drl.ast.descr.AttributeDescr)1 BaseDescr (org.drools.drl.ast.descr.BaseDescr)1 ExistsDescr (org.drools.drl.ast.descr.ExistsDescr)1 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)1 PatternDescr (org.drools.drl.ast.descr.PatternDescr)1 AbstractClassTypeDeclarationBuilder (org.drools.drl.ast.dsl.AbstractClassTypeDeclarationBuilder)1 AccumulateImportDescrBuilder (org.drools.drl.ast.dsl.AccumulateImportDescrBuilder)1 AttributeDescrBuilder (org.drools.drl.ast.dsl.AttributeDescrBuilder)1 BehaviorDescrBuilder (org.drools.drl.ast.dsl.BehaviorDescrBuilder)1 DeclareDescrBuilder (org.drools.drl.ast.dsl.DeclareDescrBuilder)1 EntryPointDeclarationDescrBuilder (org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder)1 EnumDeclarationDescrBuilder (org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder)1 EnumLiteralDescrBuilder (org.drools.drl.ast.dsl.EnumLiteralDescrBuilder)1