Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-drools-5909] [new-parser] Accumulate parsed incorrectl… #5965

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5122,4 +5122,25 @@ void javaKeywordsInPackage(String keyword) {

assertThat(pkg.getRules().get(0).getName()).isEqualTo("R");
}

@Test
void accumulateEmptyChunks() {
ParserTestUtils.enableOldParser();
tkobayas marked this conversation as resolved.
Show resolved Hide resolved
String text = "rule R\n" +
"when\n" +
" $totalAmount : Number() from accumulate( Cheese( $price : price ),\n" +
" init( ),\n" +
" action( ),\n" +
" result( null ) );\n" +
"then\n" +
"end";
RuleDescr rule = parseAndGetFirstRuleDescr(text);

final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
final AccumulateDescr accumulateDescr = (AccumulateDescr) outPattern.getSource();
assertThat(accumulateDescr.getInitCode()).isEmpty();
assertThat(accumulateDescr.getActionCode()).isEmpty();
assertThat(accumulateDescr.getReverseCode()).isNull();
assertThat(accumulateDescr.getResultCode()).isEqualTo( "null");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fromAccumulate := ACCUMULATE LEFT_PAREN lhsAnd (COMMA|SEMICOLON)
) RIGHT_PAREN
*/
fromAccumulate : (DRL_ACCUMULATE|DRL_ACC) LPAREN lhsAndDef (COMMA|SEMI)
( DRL_INIT LPAREN initBlockStatements=chunk RPAREN COMMA? DRL_ACTION LPAREN actionBlockStatements=chunk RPAREN COMMA? ( DRL_REVERSE LPAREN reverseBlockStatements=chunk RPAREN COMMA?)? DRL_RESULT LPAREN expression RPAREN
( DRL_INIT LPAREN initBlockStatements=chunk? RPAREN COMMA? DRL_ACTION LPAREN actionBlockStatements=chunk? RPAREN COMMA? ( DRL_REVERSE LPAREN reverseBlockStatements=chunk? RPAREN COMMA?)? DRL_RESULT LPAREN resultBlockStatements=chunk RPAREN
| accumulateFunction
)
RPAREN (SEMI)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ private Antlr4ParserStringUtils() {
* Get text from ParserRuleContext's CharStream without trimming whitespace
*/
public static String getTextPreservingWhitespace(ParserRuleContext ctx) {
if (ctx == null) {
return "";
}
// Using raw CharStream
int startIndex = ctx.start.getStartIndex();
int stopIndex = ctx.stop.getStopIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public AccumulateDescr visitFromAccumulate(DRLParser.FromAccumulateContext ctx)
if (ctx.DRL_REVERSE() != null) {
accumulateDescr.setReverseCode(getTextPreservingWhitespace(ctx.reverseBlockStatements));
}
accumulateDescr.setResultCode(getTextPreservingWhitespace(ctx.expression()));
accumulateDescr.setResultCode(getTextPreservingWhitespace(ctx.resultBlockStatements));
} else {
// accumulate function
accumulateDescr.addFunction(visitAccumulateFunction(ctx.accumulateFunction()));
Expand Down
Loading