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

[new-parser] Support LHS pattern annotations #5797

Merged
merged 2 commits into from
Mar 21, 2024

Conversation

yurloc
Copy link
Contributor

@yurloc yurloc commented Mar 20, 2024

Fixes #5740.

This change replicates the old parser's behavior.

Multiple annotations can appear after an LHS pattern:

while (input.LA(1) == DRL6Lexer.AT) {
// annotation*
annotation(pattern);
if (state.failed)
return;
}

A DRL annotation can either contain Java-style key-value pairs, or a chunk:

/**
* annotation := fullAnnotation | AT ID chunk_(_)?
*/
void annotation( AnnotatedDescrBuilder<?> adb ) {
AnnotationDescrBuilder<?> annotation = null;
try {
if (speculateFullAnnotation()) {
boolean buildState = exprParser.isBuildDescr();
exprParser.setBuildDescr(true);
exprParser.fullAnnotation(adb);
exprParser.setBuildDescr(buildState);
} else {
// '@'
Token at = match(input,
DRL6Lexer.AT,
null,
null,
DroolsEditorType.SYMBOL);
if (state.failed)
return;
// identifier
String fqn = qualifiedIdentifier();
if (state.failed)
return;
if (state.backtracking == 0) {
annotation = adb.newAnnotation(fqn);
helper.setStart(annotation,
at);
}
try {
if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
String value = chunk(DRL6Lexer.LEFT_PAREN,
DRL6Lexer.RIGHT_PAREN,
-1).trim();
if (state.failed)
return;
if (state.backtracking == 0) {
if (annotation != null) {
annotation.value(value);
} else {
throw new RecognitionException();
}
}
}
} finally {
if (state.backtracking == 0) {
helper.setEnd(annotation);
}
}
}
} catch (RecognitionException re) {
reportError(re);
}
}

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

@@ -124,7 +124,7 @@ lhsPattern : xpathPrimary (OVER patternFilter)? |
( QUESTION? qualifiedIdentifier LPAREN positionalConstraints? constraints? RPAREN (OVER patternFilter)? (FROM patternSource)? ) ;
*/

lhsPattern : QUESTION? objectType=drlQualifiedName LPAREN positionalConstraints? constraints? RPAREN (DRL_OVER patternFilter)? (DRL_FROM patternSource)? ;
lhsPattern : QUESTION? objectType=drlQualifiedName LPAREN positionalConstraints? constraints? RPAREN drlAnnotation* (DRL_OVER patternFilter)? (DRL_FROM patternSource)? ;
Copy link
Contributor Author

@yurloc yurloc Mar 20, 2024

Choose a reason for hiding this comment

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

This allows an annotation to appear after a LHS pattern, for example, Person() @watch(!age).

@@ -459,7 +459,7 @@ type : (classOrInterfaceType | primitiveType) typeArguments? ( DOT IDENTIFIER ty
drlArguments : LPAREN drlArgument (COMMA drlArgument)* RPAREN ;
drlArgument : ( stringId | floatLiteral | BOOL_LITERAL | NULL_LITERAL ) ;

drlAnnotation : AT name=drlQualifiedName (LPAREN ( drlElementValuePairs | drlElementValue )? RPAREN)? ;
drlAnnotation : AT name=drlQualifiedName ((LPAREN ( drlElementValuePairs | drlElementValue )? RPAREN) | chunk)? ;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows an annotation value to be something that doesn't fit into the standard Java annotation key-value format, for example, @watch(!*, age).

}
}
return value;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is used by both the old parser and the new parser's visitor.

@yurloc
Copy link
Contributor Author

yurloc commented Mar 20, 2024

@tkobayas, @mariofusco, @gitgabrio please review.

@yurloc
Copy link
Contributor Author

yurloc commented Mar 21, 2024

org.drools.model.codegen.execmodel.PropertyReactivityTest is fixed.

Before PR
drools-model-codegen

[ERROR] Tests run: 2433, Failures: 334, Errors: 0, Skipped: 9

After PR
drools-model-codegen

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

Copy link
Contributor

@tkobayas tkobayas left a comment

Choose a reason for hiding this comment

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

Thanks!

@tkobayas
Copy link
Contributor

tkobayas commented Mar 21, 2024

@yurloc Please solve the conflict (likely because of recent other PR merge), thanks!

@yurloc yurloc force-pushed the new-parser-watch branch from 2e9d9a2 to 03a56a0 Compare March 21, 2024 10:58
@yurloc
Copy link
Contributor Author

yurloc commented Mar 21, 2024

@yurloc Please solve the conflict (likely because of recent other PR merge), thanks!

Done. @mariofusco please merge.

@mariofusco mariofusco merged commit 12545b9 into apache:dev-new-parser Mar 21, 2024
0 of 3 checks passed
@yurloc yurloc deleted the new-parser-watch branch March 21, 2024 18:50
@yurloc
Copy link
Contributor Author

yurloc commented Mar 21, 2024

Overall fixing progress: Error: There were 370 failed tests.

@tkobayas
Copy link
Contributor

Overall fixing progress: Error: There were 370 failed tests.

FYI) @yurloc , you seem to take the 370 from the GHA result, but note that several modules were SKIPPED because of other module's failure. Especially, drools-test-coverage was skipped, which has a significant number of tests. So at some point, we will find more test failures :)

tkobayas pushed a commit to tkobayas/drools that referenced this pull request Jun 11, 2024
* LHS patterns can have annotations

* LHS pattern annotations can contain chunks
tkobayas pushed a commit to tkobayas/drools that referenced this pull request Oct 2, 2024
* LHS patterns can have annotations

* LHS pattern annotations can contain chunks
tkobayas pushed a commit to tkobayas/drools that referenced this pull request Oct 11, 2024
* LHS patterns can have annotations

* LHS pattern annotations can contain chunks
tkobayas pushed a commit that referenced this pull request Oct 11, 2024
* LHS patterns can have annotations

* LHS pattern annotations can contain chunks
rgdoliveira pushed a commit to rgdoliveira/drools that referenced this pull request Oct 24, 2024
* LHS patterns can have annotations

* LHS pattern annotations can contain chunks
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