Skip to content

Commit

Permalink
[DROOLS-7294] Implement forall (apache#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkobayas committed Feb 15, 2024
1 parent fad4c7d commit 0388d4d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ DRL_REVERSE : 'reverse';
DRL_RESULT : 'result';
DRL_ENTRY_POINT : 'entry-point';
DRL_EVAL : 'eval';
DRL_FORALL : 'forall';

DRL_SALIENCE : 'salience';
DRL_ENABLED : 'enabled';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ lhsUnary : (
lhsExists
| lhsNot
| lhsEval
| lhsForall
| lhsAccumulate
| lhsPatternBind
) ;
) SEMI? ;

lhsPatternBind : label? ( LPAREN lhsPattern (DRL_OR lhsPattern)* RPAREN | lhsPattern ) ;

Expand Down Expand Up @@ -330,6 +331,12 @@ lhsNot : DRL_NOT lhsPatternBind ;
*/
lhsEval : DRL_EVAL LPAREN conditionalOrExpression RPAREN ;

/**
* lhsForall := FORALL LEFT_PAREN lhsPatternBind+ RIGHT_PAREN
*/

lhsForall : DRL_FORALL LPAREN lhsPatternBind+ RPAREN ;

/**
* lhsAccumulate := (ACCUMULATE|ACC) LEFT_PAREN lhsAnd (COMMA|SEMICOLON)
* accumulateFunctionBinding (COMMA accumulateFunctionBinding)*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.drools.drl.ast.descr.EvalDescr;
import org.drools.drl.ast.descr.ExistsDescr;
import org.drools.drl.ast.descr.ExprConstraintDescr;
import org.drools.drl.ast.descr.ForallDescr;
import org.drools.drl.ast.descr.FromDescr;
import org.drools.drl.ast.descr.FunctionDescr;
import org.drools.drl.ast.descr.FunctionImportDescr;
Expand Down Expand Up @@ -262,6 +263,13 @@ public PatternDescr visitLhsPattern(DRLParser.LhsPatternContext ctx) {
return patternDescr;
}

@Override
public ForallDescr visitLhsForall(DRLParser.LhsForallContext ctx) {
ForallDescr forallDescr = new ForallDescr();
visitDescrChildren(ctx).forEach(forallDescr::addDescr);
return forallDescr;
}

@Override
public PatternDescr visitLhsAccumulate(DRLParser.LhsAccumulateContext ctx) {
AccumulateDescr accumulateDescr = new AccumulateDescr();
Expand Down Expand Up @@ -398,7 +406,7 @@ public BaseDescr visitLhsAndForAccumulate(DRLParser.LhsAndForAccumulateContext c

@Override
public BaseDescr visitLhsUnary(DRLParser.LhsUnaryContext ctx) {
return (BaseDescr) visitChildren(ctx);
return visitDescrChildren(ctx).get(0);
}

private void populateStartEnd(BaseDescr descr, ParserRuleContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,6 @@ public void parse_NestedCEs() throws Exception {
assertThat("Cheese").isEqualTo(cheese3.getObjectType());
}

@Disabled("Priority : High | Implement forall")
@Test
public void parse_Forall() throws Exception {
final PackageDescr pkg = parseAndGetPackageDescrFromFile(
Expand All @@ -2147,7 +2146,6 @@ public void parse_Forall() throws Exception {
assertThat(cheese.getObjectType()).isEqualTo("Cheese");
}

@Disabled("Priority : High | Implement forall")
@Test
public void parse_ForallWithFrom() throws Exception {
final PackageDescr pkg = parseAndGetPackageDescrFromFile(
Expand Down

0 comments on commit 0388d4d

Please sign in to comment.