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..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 @@ -5216,4 +5216,20 @@ void doubleAmpersandInfixAndInAccumulate() { assertThat(accumulateFunction.getFunction()).isEqualTo("average"); assertThat(accumulateFunction.getParams()).containsExactly("$a + $b"); } + + @Test + void durationChunk() { + final String text = + "rule R\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); + + // At the moment, the parser accepts any input and let the compile phase validate it. + assertThat(rule.getAttributes().get("duration").getValue()).isEqualTo("wrong input"); + } } 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 */