Skip to content

Commit

Permalink
[DROOLS-7292] Implement eval (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkobayas authored and rgdoliveira committed Oct 24, 2024
1 parent 757be74 commit 1521e05
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ DRL_ACTION : 'action';
DRL_REVERSE : 'reverse';
DRL_RESULT : 'result';
DRL_ENTRY_POINT : 'entry-point';
DRL_EVAL : 'eval';

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

lhsPatternBind : label? ( LPAREN lhsPattern (DRL_OR lhsPattern)* RPAREN | lhsPattern ) ;
Expand Down Expand Up @@ -139,6 +140,7 @@ drlKeywords
: DRL_UNIT
| DRL_FUNCTION
| DRL_GLOBAL
| DRL_DECLARE
| DRL_RULE
| DRL_QUERY
| DRL_WHEN
Expand All @@ -151,6 +153,13 @@ drlKeywords
| DRL_IN
| DRL_FROM
| DRL_MATCHES
| DRL_ACCUMULATE
| DRL_INIT
| DRL_ACTION
| DRL_REVERSE
| DRL_RESULT
| DRL_ENTRY_POINT
| DRL_EVAL
| DRL_SALIENCE
| DRL_ENABLED
| DRL_NO_LOOP
Expand Down Expand Up @@ -182,6 +191,7 @@ drlExpression
| explicitGenericInvocation
)
| drlExpression LBRACK drlExpression RBRACK
| DRL_EVAL LPAREN conditionalOrExpression RPAREN
| methodCall
| NEW drlCreator
| LPAREN annotation* typeType (BITAND typeType)* RPAREN drlExpression
Expand Down Expand Up @@ -267,9 +277,9 @@ mapEntry
| fromWindow
| fromExpression )
*/
patternSource : fromExpression
| fromAccumulate
patternSource : fromAccumulate
| fromEntryPoint
| fromExpression
;

fromExpression : conditionalOrExpression ;
Expand Down Expand Up @@ -315,6 +325,11 @@ lhsExists : DRL_EXISTS lhsPatternBind ;
*/
lhsNot : DRL_NOT lhsPatternBind ;

/**
* lhsEval := EVAL LEFT_PAREN conditionalExpression RIGHT_PAREN
*/
lhsEval : DRL_EVAL LPAREN conditionalOrExpression 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 @@ -16,6 +16,7 @@
import org.drools.drl.ast.descr.AttributeDescr;
import org.drools.drl.ast.descr.BaseDescr;
import org.drools.drl.ast.descr.EntryPointDescr;
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.FromDescr;
Expand Down Expand Up @@ -357,6 +358,11 @@ public NotDescr visitLhsNot(DRLParser.LhsNotContext ctx) {
return notDescr;
}

@Override
public EvalDescr visitLhsEval(DRLParser.LhsEvalContext ctx) {
return new EvalDescr(getTextPreservingWhitespace(ctx.conditionalOrExpression()));
}

@Override
public BaseDescr visitLhsExpressionEnclosed(DRLParser.LhsExpressionEnclosedContext ctx) {
return (BaseDescr) visit(ctx.lhsExpression());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,6 @@ void parenthesesAndOrOrOrAnd() throws Exception {
assertThat(bar3.getObjectType()).isEqualTo("Bar");
}

@Disabled("Priority : High | Implement eval")
@Test
public void parse_EvalMultiple() throws Exception {
final PackageDescr pkg = parseAndGetPackageDescrFromFile(
Expand All @@ -1537,7 +1536,6 @@ public void parse_EvalMultiple() throws Exception {

}

@Disabled("Priority : High | Implement eval")
@Test
public void parse_WithEval() throws Exception {
final PackageDescr pkg = parseAndGetPackageDescrFromFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ rule simple_rule
Bar()
eval(abc("foo"))
then
Kapow
end

0 comments on commit 1521e05

Please sign in to comment.