Skip to content

Commit

Permalink
[incubator-kie-drools-5911] [new-parser] Support optional type keywor…
Browse files Browse the repository at this point in the history
…d for backward compatibility (#5977)
  • Loading branch information
tkobayas committed Jun 4, 2024
1 parent e79e36e commit 8d468e4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5327,4 +5327,17 @@ void functionWithAnonymousClass() {
" }\n" +
" };");
}

@Test
void typeDeclarationWithTypeToken() {
final String drl = "declare type Foo\n" + // "type" is just optional
" id : int\n" +
"end";
final PackageDescr pkg = parseAndGetPackageDescr(drl);

TypeDeclarationDescr typeDeclarationDescr = pkg.getTypeDeclarations().get(0);
assertThat(typeDeclarationDescr.getTypeName()).isEqualTo("Foo");
TypeFieldDescr typeFieldDescr = typeDeclarationDescr.getFields().get("id");
assertThat(typeFieldDescr.getPattern().getObjectType()).isEqualTo("int");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ drlKeywords returns [Token token]
| DRL_GLOBAL
| DRL_DECLARE
| DRL_TRAIT
| DRL_TYPE
| DRL_RULE
| DRL_QUERY
| DRL_WHEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ DRL_FUNCTION : 'function';
DRL_GLOBAL : 'global';
DRL_DECLARE : 'declare';
DRL_TRAIT : 'trait';
DRL_TYPE : 'type';
DRL_RULE : 'rule';
DRL_QUERY : 'query';
DRL_WHEN : 'when';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ declaredef : DRL_DECLARE (
* END
*/

typeDeclaration : DRL_TRAIT? name=drlQualifiedName (EXTENDS superTypes+=drlQualifiedName (COMMA superTypes+=drlQualifiedName)* )? drlAnnotation* field* DRL_END ;
typeDeclaration : DRL_TRAIT? DRL_TYPE? name=drlQualifiedName (EXTENDS superTypes+=drlQualifiedName (COMMA superTypes+=drlQualifiedName)* )? drlAnnotation* field* DRL_END ;

// entryPointDeclaration := ENTRY-POINT stringId annotation* END

Expand Down

0 comments on commit 8d468e4

Please sign in to comment.