From ed979009a636d96758b82c3942c3fac380bec6a7 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Thu, 23 May 2024 19:13:31 +0900 Subject: [PATCH 1/2] [incubator-kie-drools-5938] [new-parser] Tests using wrong duration attribute format --- .../drl/parser/antlr4/MiscDRLParserTest.java | 14 ++++++++++++++ .../org/drools/drl/parser/antlr4/DRLParser.g4 | 2 +- .../drools/drl/parser/antlr4/DRLVisitorImpl.java | 15 --------------- 3 files changed, 15 insertions(+), 16 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 e81bfb21f0c..f496e792ad6 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 @@ -5216,4 +5216,18 @@ void doubleAmpersandInfixAndInAccumulate() { assertThat(accumulateFunction.getFunction()).isEqualTo("average"); assertThat(accumulateFunction.getParams()).containsExactly("$a + $b"); } + + @Test + void durationChunk() { + final String text = + "rule R\n" + + " duration (30s 10s) \n" + + "when\n" + + "then\n" + + "end"; + RuleDescr rule = parseAndGetFirstRuleDescr(text); + assertThat(rule.getAttributes()).containsKey("duration"); + assertThat(rule.getAttributes().get("duration").getType()).isEqualTo(AttributeDescr.Type.EXPRESSION); + assertThat(rule.getAttributes().get("duration").getValue()).isEqualTo("30s 10s"); + } } 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 251f73f2508..cf1afb97862 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 @@ -445,7 +445,7 @@ attribute : name=( 'salience' | 'enabled' ) conditionalAttributeValue #expressio | 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 | TIME_INTERVAL | LPAREN TIME_INTERVAL RPAREN ) #durationAttribute + | name='duration' ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute ; conditionalAttributeValue : ( LPAREN conditionalExpression RPAREN | conditionalExpression ) ; diff --git a/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java b/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java index 4e6192ecad6..39aa5e930e8 100644 --- a/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java +++ b/drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/DRLVisitorImpl.java @@ -514,21 +514,6 @@ public AttributeDescr visitIntOrChunkAttribute(DRLParser.IntOrChunkAttributeCont return attributeDescr; } - @Override - public AttributeDescr visitDurationAttribute(DRLParser.DurationAttributeContext ctx) { - AttributeDescr attributeDescr = BaseDescrFactory.builder(new AttributeDescr(ctx.name.getText())) - .withParserRuleContext(ctx) - .build(); - if (ctx.DECIMAL_LITERAL() != null) { - attributeDescr.setValue(ctx.DECIMAL_LITERAL().getText()); - attributeDescr.setType(AttributeDescr.Type.NUMBER); - } else { - attributeDescr.setValue(unescapeJava(safeStripStringDelimiters(ctx.TIME_INTERVAL().getText()))); - attributeDescr.setType(AttributeDescr.Type.EXPRESSION); - } - return attributeDescr; - } - /** * entry point for LHS */ From 4a6381082acecce6e7c5259112c8358ac72dd226 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Fri, 24 May 2024 18:34:41 +0900 Subject: [PATCH 2/2] - Use explicit test value --- .../org/drools/drl/parser/antlr4/MiscDRLParserTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 f496e792ad6..ab2f7070606 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 @@ -5221,13 +5221,15 @@ void doubleAmpersandInfixAndInAccumulate() { void durationChunk() { final String text = "rule R\n" + - " duration (30s 10s) \n" + + " duration (wrong input) \n" + "when\n" + "then\n" + "end"; RuleDescr rule = parseAndGetFirstRuleDescr(text); assertThat(rule.getAttributes()).containsKey("duration"); assertThat(rule.getAttributes().get("duration").getType()).isEqualTo(AttributeDescr.Type.EXPRESSION); - assertThat(rule.getAttributes().get("duration").getValue()).isEqualTo("30s 10s"); + + // At the moment, the parser accepts any input and let the compile phase validate it. + assertThat(rule.getAttributes().get("duration").getValue()).isEqualTo("wrong input"); } }