From e216b006d85d933123a969129259f839458d5e8e Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Fri, 7 Jun 2024 15:23:37 +0900 Subject: [PATCH] [incubator-kie-drools-5982] [new-parser] Enable alternative attributes test (#5983) --- .../drl/parser/antlr4/MiscDRLParserTest.java | 15 +++++++-------- .../drools/drl/parser/antlr4/DRL6Expressions.g4 | 1 + .../org/drools/drl/parser/antlr4/DRLLexer.g4 | 1 + .../org/drools/drl/parser/antlr4/DRLParser.g4 | 15 ++++++++------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java index 92df973dda8..4769ce9f3ba 100644 --- a/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java +++ b/drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/MiscDRLParserTest.java @@ -1964,9 +1964,8 @@ public void parse_Timer() throws Exception { assertThat(at.getValue()).isEqualTo("true"); } - @Disabled("Priority : Low | Not written in docs nor other unit tests. Drop the support?") @Test - public void parse_Attributes_alternateSyntax() throws Exception { + public void parse_Attributes_alternateSyntax() { final RuleDescr rule = parseAndGetFirstRuleDescrFromFile( "rule_attributes_alt.drl" ); assertThat(rule.getName()).isEqualTo("simple_rule"); @@ -1975,27 +1974,27 @@ public void parse_Attributes_alternateSyntax() throws Exception { final Map attrs = rule.getAttributes(); assertThat(attrs.size()).isEqualTo(6); - AttributeDescr at = (AttributeDescr) attrs.get( "salience" ); + AttributeDescr at = attrs.get( "salience" ); assertThat(at.getName()).isEqualTo("salience"); assertThat(at.getValue()).isEqualTo("42"); - at = (AttributeDescr) attrs.get( "agenda-group" ); + at = attrs.get( "agenda-group" ); assertThat(at.getName()).isEqualTo("agenda-group"); assertThat(at.getValue()).isEqualTo("my_group"); - at = (AttributeDescr) attrs.get( "no-loop" ); + at = attrs.get( "no-loop" ); assertThat(at.getName()).isEqualTo("no-loop"); assertThat(at.getValue()).isEqualTo("true"); - at = (AttributeDescr) attrs.get( "lock-on-active" ); + at = attrs.get( "lock-on-active" ); assertThat(at.getName()).isEqualTo("lock-on-active"); assertThat(at.getValue()).isEqualTo("true"); - at = (AttributeDescr) attrs.get( "duration" ); + at = attrs.get( "duration" ); assertThat(at.getName()).isEqualTo("duration"); assertThat(at.getValue()).isEqualTo("42"); - at = (AttributeDescr) attrs.get( "activation-group" ); + at = attrs.get( "activation-group" ); assertThat(at.getName()).isEqualTo("activation-group"); assertThat(at.getValue()).isEqualTo("my_activation_group"); } diff --git a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRL6Expressions.g4 b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRL6Expressions.g4 index 9819713fbb5..2efe8b1ec8e 100644 --- a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRL6Expressions.g4 +++ b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRL6Expressions.g4 @@ -264,6 +264,7 @@ drlKeywords returns [Token token] | DRL_EVAL | DRL_FORALL | DRL_OVER + | DRL_ATTRIBUTES | DRL_SALIENCE | DRL_ENABLED | DRL_NO_LOOP diff --git a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLLexer.g4 b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLLexer.g4 index 198dfccfc2a..2a433de8b06 100644 --- a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLLexer.g4 +++ b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLLexer.g4 @@ -89,6 +89,7 @@ DRL_STARTED_BY : 'startedby'; DRL_WINDOW : 'window'; // attributes +DRL_ATTRIBUTES : 'attributes'; DRL_SALIENCE : 'salience'; DRL_ENABLED : 'enabled'; DRL_NO_LOOP : 'no-loop'; diff --git a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 index 40b3bc66596..c1e399fd01c 100644 --- a/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 +++ b/drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/DRLParser.g4 @@ -440,13 +440,14 @@ drlAnnotation : {boolean buildState = buildDescr; buildDescr = true;} anno=fullAnnotation[null] {buildDescr = buildState;} // either standard Java annotation | AT name=drlQualifiedName (LPAREN chunk RPAREN)? ; // or support @watch(!*, age) etc. -attributes : attribute ( COMMA? attribute )* ; -attribute : name=( 'salience' | 'enabled' ) conditionalAttributeValue #expressionAttribute - | name=( 'no-loop' | 'auto-focus' | 'lock-on-active' | 'refract' | 'direct' ) BOOL_LITERAL? #booleanAttribute - | name=( 'agenda-group' | 'activation-group' | 'ruleflow-group' | 'date-effective' | 'date-expires' | 'dialect' ) DRL_STRING_LITERAL #stringAttribute - | name='calendars' DRL_STRING_LITERAL ( COMMA DRL_STRING_LITERAL )* #stringListAttribute - | name='timer' ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute - | name='duration' ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute +// attributes := (ATTRIBUTES COLON?)? [ attribute ( COMMA? attribute )* ] +attributes : (DRL_ATTRIBUTES COLON?)? attribute ( COMMA? attribute )* ; +attribute : name=( DRL_SALIENCE | DRL_ENABLED ) conditionalAttributeValue #expressionAttribute + | name=( DRL_NO_LOOP | DRL_AUTO_FOCUS | DRL_LOCK_ON_ACTIVE | DRL_REFRACT | DRL_DIRECT ) BOOL_LITERAL? #booleanAttribute + | name=( DRL_AGENDA_GROUP | DRL_ACTIVATION_GROUP | DRL_RULEFLOW_GROUP | DRL_DATE_EFFECTIVE | DRL_DATE_EXPIRES | DRL_DIALECT ) DRL_STRING_LITERAL #stringAttribute + | name=DRL_CALENDARS DRL_STRING_LITERAL ( COMMA DRL_STRING_LITERAL )* #stringListAttribute + | name=DRL_TIMER ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute + | name=DRL_DURATION ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute ; conditionalAttributeValue : ( LPAREN conditionalExpression RPAREN | conditionalExpression ) ;