Search in sources :

Example 6 with OrDescr

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

the class RuleParserTest method testNestedCEs.

@Test
public void testNestedCEs() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "nested_conditional_elements.drl");
    assertNotNull(rule);
    final AndDescr root = rule.getLhs();
    final NotDescr not1 = (NotDescr) root.getDescrs().get(0);
    final AndDescr and1 = (AndDescr) not1.getDescrs().get(0);
    final PatternDescr state = (PatternDescr) and1.getDescrs().get(0);
    final NotDescr not2 = (NotDescr) and1.getDescrs().get(1);
    final AndDescr and2 = (AndDescr) not2.getDescrs().get(0);
    final PatternDescr person = (PatternDescr) and2.getDescrs().get(0);
    final PatternDescr cheese = (PatternDescr) and2.getDescrs().get(1);
    final PatternDescr person2 = (PatternDescr) root.getDescrs().get(1);
    final OrDescr or = (OrDescr) root.getDescrs().get(2);
    final PatternDescr cheese2 = (PatternDescr) or.getDescrs().get(0);
    final PatternDescr cheese3 = (PatternDescr) or.getDescrs().get(1);
    assertEquals(state.getObjectType(), "State");
    assertEquals(person.getObjectType(), "Person");
    assertEquals(cheese.getObjectType(), "Cheese");
    assertEquals(person2.getObjectType(), "Person");
    assertEquals(cheese2.getObjectType(), "Cheese");
    assertEquals(cheese3.getObjectType(), "Cheese");
}
Also used : NotDescr(org.drools.drl.ast.descr.NotDescr) PatternDescr(org.drools.drl.ast.descr.PatternDescr) AndDescr(org.drools.drl.ast.descr.AndDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) OrDescr(org.drools.drl.ast.descr.OrDescr) Test(org.junit.Test)

Example 7 with OrDescr

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

the class RuleParserTest method testExpanderLineSpread.

@Test
public void testExpanderLineSpread() throws Exception {
    final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
    final PackageDescr pkg = parser.parse(this.getReader("expander_spread_lines.dslr"), this.getReader("complex.dsl"));
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule.getLhs().getDescrs().size());
    final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(0);
    assertEquals(2, or.getDescrs().size());
    assertNotNull((String) rule.getConsequence());
}
Also used : RuleDescr(org.drools.drl.ast.descr.RuleDescr) DrlParser(org.drools.drl.parser.DrlParser) PackageDescr(org.drools.drl.ast.descr.PackageDescr) OrDescr(org.drools.drl.ast.descr.OrDescr) Test(org.junit.Test)

Example 8 with OrDescr

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

the class RuleParserTest method testRuleWithLHSNesting.

@Test
public void testRuleWithLHSNesting() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "Rule_with_nested_LHS.drl");
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    RuleDescr rule = pkg.getRules().get(0);
    assertEquals("test", rule.getName());
    AndDescr lhs = rule.getLhs();
    assertNotNull(lhs);
    assertEquals(2, lhs.getDescrs().size());
    PatternDescr a = (PatternDescr) lhs.getDescrs().get(0);
    assertEquals("A", a.getObjectType());
    OrDescr or = (OrDescr) lhs.getDescrs().get(1);
    assertEquals(3, or.getDescrs().size());
    AndDescr and1 = (AndDescr) or.getDescrs().get(0);
    assertEquals(2, and1.getDescrs().size());
    PatternDescr b = (PatternDescr) and1.getDescrs().get(0);
    PatternDescr c = (PatternDescr) and1.getDescrs().get(1);
    assertEquals("B", b.getObjectType());
    assertEquals("C", c.getObjectType());
    AndDescr and2 = (AndDescr) or.getDescrs().get(1);
    assertEquals(2, and2.getDescrs().size());
    PatternDescr d = (PatternDescr) and2.getDescrs().get(0);
    PatternDescr e = (PatternDescr) and2.getDescrs().get(1);
    assertEquals("D", d.getObjectType());
    assertEquals("E", e.getObjectType());
    AndDescr and3 = (AndDescr) or.getDescrs().get(2);
    assertEquals(2, and3.getDescrs().size());
    PatternDescr f = (PatternDescr) and3.getDescrs().get(0);
    PatternDescr g = (PatternDescr) and3.getDescrs().get(1);
    assertEquals("F", f.getObjectType());
    assertEquals("G", g.getObjectType());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) AndDescr(org.drools.drl.ast.descr.AndDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) OrDescr(org.drools.drl.ast.descr.OrDescr) Test(org.junit.Test)

Example 9 with OrDescr

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

the class RuleParserTest method testBracketsPrecedence.

/**
 */
@Test
public void testBracketsPrecedence() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "brackets_precedence.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    final AndDescr rootAnd = (AndDescr) rule.getLhs();
    assertEquals(2, rootAnd.getDescrs().size());
    final OrDescr leftOr = (OrDescr) rootAnd.getDescrs().get(0);
    assertEquals(2, leftOr.getDescrs().size());
    final NotDescr not = (NotDescr) leftOr.getDescrs().get(0);
    final PatternDescr foo1 = (PatternDescr) not.getDescrs().get(0);
    assertEquals("Foo", foo1.getObjectType());
    final PatternDescr foo2 = (PatternDescr) leftOr.getDescrs().get(1);
    assertEquals("Foo", foo2.getObjectType());
    final OrDescr rightOr = (OrDescr) rootAnd.getDescrs().get(1);
    assertEquals(2, rightOr.getDescrs().size());
    final PatternDescr shoes = (PatternDescr) rightOr.getDescrs().get(0);
    assertEquals("Shoes", shoes.getObjectType());
    final PatternDescr butt = (PatternDescr) rightOr.getDescrs().get(1);
    assertEquals("Butt", butt.getObjectType());
}
Also used : NotDescr(org.drools.drl.ast.descr.NotDescr) PatternDescr(org.drools.drl.ast.descr.PatternDescr) AndDescr(org.drools.drl.ast.descr.AndDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) OrDescr(org.drools.drl.ast.descr.OrDescr) Test(org.junit.Test)

Example 10 with OrDescr

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

Aggregations

OrDescr (org.drools.drl.ast.descr.OrDescr)25 Test (org.junit.Test)16 RuleDescr (org.drools.drl.ast.descr.RuleDescr)14 PatternDescr (org.drools.drl.ast.descr.PatternDescr)13 AndDescr (org.drools.drl.ast.descr.AndDescr)10 PackageDescr (org.drools.drl.ast.descr.PackageDescr)10 BaseDescr (org.drools.drl.ast.descr.BaseDescr)8 ConditionalElementDescr (org.drools.drl.ast.descr.ConditionalElementDescr)5 NotDescr (org.drools.drl.ast.descr.NotDescr)4 CommonToken (org.antlr.runtime.CommonToken)3 Token (org.antlr.runtime.Token)3 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)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 CEDescrBuilder (org.drools.drl.ast.dsl.CEDescrBuilder)3 CollectDescrBuilder (org.drools.drl.ast.dsl.CollectDescrBuilder)3 ConditionalBranchDescrBuilder (org.drools.drl.ast.dsl.ConditionalBranchDescrBuilder)3