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#5708] [new-parser] function definition causes a… #5793

Merged

Conversation

tkobayas
Copy link
Contributor

…n error

Issue:

How to replicate CI configuration locally?

Build Chain tool does "simple" maven build(s), the builds are just Maven commands, but because the repositories relates and depends on each other and any change in API or class method could affect several of those repositories there is a need to use build-chain tool to handle cross repository builds and be sure that we always use latest version of the code for each repository.

build-chain tool is a build tool which can be used on command line locally or in Github Actions workflow(s), in case you need to change multiple repositories and send multiple dependent pull requests related with a change you can easily reproduce the same build by executing it on Github hosted environment or locally in your development environment. See local execution details to get more information about it.

How to retest this PR or trigger a specific build:
  • for pull request and downstream checks

    • Push a new commit to the PR. An empty commit would be enough.
  • for a full downstream build

    • for github actions job: add the label run_fdb
  • for Jenkins PR check only

@tkobayas
Copy link
Contributor Author

tkobayas commented Mar 18, 2024

org.drools.model.codegen.execmodel.MvelOperatorsTest#testMatchesWithFunction is fixed.

Before PR
drools-model-codegen

[ERROR] Tests run: 2433, Failures: 419, Errors: 2, Skipped: 9

After PR
drools-model-codegen

[ERROR] Tests run: 2433, Failures: 409, Errors: 2, Skipped: 9

@@ -512,3 +512,37 @@ drlVariableInitializer
drlArrayInitializer
: LBRACE (drlVariableInitializer (COMMA drlVariableInitializer)* (COMMA)? )? RBRACE
;

/* extending JavaParser block */
drlBlock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String literal (e.g. "*") is DRL_STRING_LITERAL, so we need to extend JavaParser rules to accept it (eventually. DRL_STRING_LITERAL is in drlLiteral)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick thought: we keep overriding the JavaParser rules again and again... that adds a lot of duplicate code. Is it possible to remove the original rule from JavaParser every time we override one? Simply remove JavaParser rules that are no longer being used since we use the overriding rules.

We could end up with a pretty minimal JavaParser at the end or perhaps get rid of it completely.

Or is this impossible because we still need to parse plain old Java code in the RHS?

Copy link
Contributor Author

@tkobayas tkobayas Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurloc That's a great point. Let me try...

Or is this impossible because we still need to parse plain old Java code in the RHS?

It's okay. RHS is just retrieved as text by the parser. For RHS execution, non-exec-model uses JavaParser.java in drools-compiler, exec-model uses the java code directly with some modification.

For DRL editor, we may need another parser rules specific to RHS, but it would be a later story.

Copy link
Contributor Author

@tkobayas tkobayas Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurloc Ahh, I can't. For example, if I remove block in JavaParser.g4, other rules in JavaParser.g4 which depend on block fail to process. Even if I use the same name block in DRLParser.g4, the result is the same because JavaParser.g4doesn't look at DRLParser.g4.

A possible approach would be to fully copy the content of JavaParser.g4 into DRLParser.g4 and modify rules in the single file. It would be worth trying, but it would be another separate issue, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. We could only remove "entry-point" rules that are not depended on by other rules, which is currently not the case.

Let's revisit this idea when we're done fixing the failing tests and we see the final shape of DRLParser and JavaParser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #5799

@tkobayas
Copy link
Contributor Author

@yurloc @mariofusco @gitgabrio Please review, thanks!

@tkobayas tkobayas force-pushed the incubator-kie-drools-5708-function branch from 3dbdb6d to 81e97dd Compare March 19, 2024 02:57
@tkobayas
Copy link
Contributor Author

Rebased to resolve conflicts.

@@ -193,7 +194,7 @@ public FunctionDescr visitFunctiondef(DRLParser.FunctiondefContext ctx) {
functionDescr.addParameter(typeTypeContext.getText(), variableDeclaratorIdContext.getText());
});
}
functionDescr.setBody(getTextPreservingWhitespace(ctx.block()));
functionDescr.setBody(stripBracesFromBlock(getTextPreservingWhitespace(ctx.drlBlock())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
functionDescr.setBody(stripBracesFromBlock(getTextPreservingWhitespace(ctx.drlBlock())));
functionDescr.setBody(getTextPreservingWhitespace(ctx.drlBlock().drlBlockStatement()));

@tkobayas by using block statements instead of the whole block, we could avoid "manually" trimming away the braces.

Of course, this requires a new whitespace-text-preserving function that works on a list of contexts, something like this:

    public static String getTextPreservingWhitespace(List<? extends ParserRuleContext> ctx) {
        return ctx.stream().map(Antlr4ParserStringUtils::getTextPreservingWhitespace).collect(Collectors.joining());
    }

I find this simpler to understand and less error-prone (and maybe also reusable for other use cases) than the low-level string manipulation in stripBracesFromBlock().

Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurloc Thank you! Applied the suggestion.

Copy link
Contributor

@yurloc yurloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion to avoid low-level string manipulation. Otherwise LGTM.

@tkobayas tkobayas merged commit 6f74f07 into apache:dev-new-parser Mar 21, 2024
0 of 3 checks passed
@yurloc
Copy link
Contributor

yurloc commented Mar 21, 2024

Overall fixing progress: There were 396 failed tests.

tkobayas added a commit to tkobayas/drools that referenced this pull request Jun 11, 2024
apache#5793)

* [incubator-kie-drools#5708] [new-parser] function definition causes an error

* - enhance getTextPreservingWhitespace to avoid string manipulation
tkobayas added a commit to tkobayas/drools that referenced this pull request Oct 2, 2024
apache#5793)

* [incubator-kie-drools#5708] [new-parser] function definition causes an error

* - enhance getTextPreservingWhitespace to avoid string manipulation
tkobayas added a commit to tkobayas/drools that referenced this pull request Oct 11, 2024
apache#5793)

* [incubator-kie-drools#5708] [new-parser] function definition causes an error

* - enhance getTextPreservingWhitespace to avoid string manipulation
tkobayas added a commit that referenced this pull request Oct 11, 2024
#5793)

* [incubator-kie-drools#5708] [new-parser] function definition causes an error

* - enhance getTextPreservingWhitespace to avoid string manipulation
rgdoliveira pushed a commit to rgdoliveira/drools that referenced this pull request Oct 24, 2024
apache#5793)

* [incubator-kie-drools#5708] [new-parser] function definition causes an error

* - enhance getTextPreservingWhitespace to avoid string manipulation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants