Skip to content

Commit

Permalink
[incubator-kie-drools#5742] [new-parser] Broken inline cast (apache#5806
Browse files Browse the repository at this point in the history
)

* [incubator-kie-drools#5742] [new-parser] Broken inline cast

* fixed duplicate test
  • Loading branch information
tkobayas committed Oct 2, 2024
1 parent 87b7fff commit 630d372
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3870,4 +3870,43 @@ void ooPathMixedWithStandardConstraint() {
assertThat(constraintDescr.toString())
.isEqualToIgnoringWhitespace("/wife[$age : age] && age > $age");
}

@Test
void inlineCast() {
final String text = "package org.drools\n" +
"rule R1\n" +
"when\n" +
" $a : ICA( someB#ICB.onlyConcrete() == \"Hello\" )\n" +
"then\n" +
"end\n";
PackageDescr packageDescr = parser.parse(text);
ExprConstraintDescr constraintDescr = getFirstExprConstraintDescr(packageDescr);
assertThat(constraintDescr.toString()).isEqualToIgnoringWhitespace("someB#ICB.onlyConcrete() == \"Hello\"");
}

@Test
void inlineCastMultiple() {
final String text = "package org.drools\n" +
"rule R1\n" +
"when\n" +
" $a : ICA( someB#ICB.someC#ICC.onlyConcrete() == \"Hello\" )\n" +
"then\n" +
"end\n";
PackageDescr packageDescr = parser.parse(text);
ExprConstraintDescr constraintDescr = getFirstExprConstraintDescr(packageDescr);
assertThat(constraintDescr.toString()).isEqualToIgnoringWhitespace("someB#ICB.someC#ICC.onlyConcrete() == \"Hello\"");
}

@Test
void inlineCastThis() {
final String text = "package org.drools\n" +
"rule R1\n" +
"when\n" +
" $o : Object( this#Person.name == \"Mark\" )\n" +
"then\n" +
"end\n";
PackageDescr packageDescr = parser.parse(text);
ExprConstraintDescr constraintDescr = getFirstExprConstraintDescr(packageDescr);
assertThat(constraintDescr.toString()).isEqualToIgnoringWhitespace("this#Person.name == \"Mark\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ drlIdentifier returns [Token token]
| PERMITS
| RECORD
| VAR
| THIS
;

// --------------------------------------------------------
Expand Down Expand Up @@ -671,7 +672,6 @@ primary returns [BaseDescr result]
: expr=parExpression { if( buildDescr ) { $result = $expr.result; } }
| nonWildcardTypeArguments (explicitGenericInvocationSuffix | this_key arguments)
| literal { if( buildDescr ) { $result = new AtomicExprDescr( $literal.text, true ); } }
| this_key (DOT drlIdentifier)* identifierSuffix?
| super_key superSuffix
| new_key creator
| primitiveType (LBRACK RBRACK)* DOT class_key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ drlIdentifier
| PERMITS
| RECORD
| VAR
| THIS
;

drlKeywords
Expand Down Expand Up @@ -258,6 +259,7 @@ drlExpression
| NEW nonWildcardTypeArguments? innerCreator
| SUPER superSuffix
| explicitGenericInvocation
| inlineCast
)
| drlExpression NULL_SAFE_DOT ( drlIdentifier | drlMethodCall )
| drlExpression LBRACK drlExpression RBRACK
Expand Down Expand Up @@ -321,8 +323,11 @@ drlPrimary
| nonWildcardTypeArguments (explicitGenericInvocationSuffix | THIS arguments)
| inlineListExpression
| inlineMapExpression
| inlineCast
;

inlineCast : drlIdentifier HASH drlIdentifier ;

/* extending JavaParser literal */
drlLiteral
: integerLiteral
Expand Down

0 comments on commit 630d372

Please sign in to comment.