Skip to content

Commit

Permalink
- Add warnings for deprecated DRL syntax when used in DRL6
Browse files Browse the repository at this point in the history
- WIP docs
  • Loading branch information
tkobayas committed Jan 31, 2025
1 parent 37a218d commit 8de5212
Show file tree
Hide file tree
Showing 11 changed files with 1,815 additions and 1,531 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
////
[id='language-level_drl-rules']
= Language Level
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
////
== 10.1.0 release notes
=== Language Level DRL10
New language level DRL10 has been added. DRL10 is handled by the new parser based on ANTLR4.
DRL10 introduces the following changes mainly to reduce ambiguity:
* Require a prefix '##' to custom operators
* Drop half constraint syntax
* Drop double ampersand as infix and
* Drop double pipe as infix or
* Drop annotation inside LHS except @watch
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,14 @@ public DescrBuilder<P, T> endLocation( int line,
* @return
*/
public P end();

/**
* Returns the parent container of this descr builder.
* Example: ruleDescrBuilder.getParent() will return the
* PackageDescrBuilder as that is its parent container
* without ending the current construction.
*
* @return
*/
public P getParent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ public P end() {
return parent;
}

@Override
public P getParent() {
return parent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,48 @@ void newBigDecimal() {
assertThat(bind.getVariable()).isEqualTo("$bd");
assertThat(bind.getExpression()).isEqualTo("new BigDecimal(30)");
}

@Test
void halfConstraintAnd() {
String source = "age > 10 && < 20";
parser.parse(source);

if (DrlParser.ANTLR4_PARSER_ENABLED) {
// half constraint is dropped in DRL10
assertThat(parser.hasErrors()).isTrue();
} else {
assertThat(parser.hasErrors()).as(parser.getErrors().toString()).isFalse();
}
}

@Test
void halfConstraintOr() {
String source = "name == \"John\" || == \"Paul\"";
parser.parse(source);

if (DrlParser.ANTLR4_PARSER_ENABLED) {
// half constraint is dropped in DRL10
assertThat(parser.hasErrors()).isTrue();
} else {
assertThat(parser.hasErrors()).as(parser.getErrors().toString()).isFalse();
}
}

@Test
void customOperator() {
Operator.addOperatorToRegistry("supersetOf", false);
// prefix '##' is required for custom operators in DRL10
String source = DrlParser.ANTLR4_PARSER_ENABLED ? "this ##supersetOf $list" : "this supersetOf $list";
ConstraintConnectiveDescr result = parser.parse(source);
assertThat(parser.hasErrors()).as(parser.getErrors().toString()).isFalse();

RelationalExprDescr rel = (RelationalExprDescr) result.getDescrs().get(0);
assertThat(rel.getOperator()).isEqualTo("supersetOf");

AtomicExprDescr left = (AtomicExprDescr) rel.getLeft();
assertThat(left.getExpression()).isEqualTo("this");

AtomicExprDescr right = (AtomicExprDescr) rel.getRight();
assertThat(right.getExpression()).isEqualTo("$list");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5320,4 +5320,24 @@ void typeDeclarationWithTypeToken() {
TypeFieldDescr typeFieldDescr = typeDeclarationDescr.getFields().get("id");
assertThat(typeFieldDescr.getPattern().getObjectType()).isEqualTo("int");
}

@Test
void agendaGroup() {
final String drl = "rule R1\n" +
" agenda-group \"group1\"\n" +
" when\n" +
" then\n" +
"end";
PackageDescr pkg = parseAndGetPackageDescrWithoutErrorCheck(drl);
if (DrlParser.ANTLR4_PARSER_ENABLED) {
// agenda-group is dropped in DRL10
assertThat(parser.hasErrors()).isTrue();
} else {
RuleDescr rule = pkg.getRules().get(0);
assertThat(rule).isNotNull();
final AttributeDescr att = rule.getAttributes().get("agenda-group");
assertThat(att.getValue()).isEqualTo("group1");
assertThat(att.getName()).isEqualTo("agenda-group");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public DrlParser() {

public DrlParser(LanguageLevelOption languageLevel) {
this.languageLevel = languageLevel;

if (languageLevel == LanguageLevelOption.DRL5 || languageLevel == LanguageLevelOption.DRL6_STRICT) {
LOG.warn("{} is deprecated and will be removed in future versions. Please use the default {} or newly introduced {} instead.",
languageLevel, LanguageLevelOption.DRL6, LanguageLevelOption.DRL10);
}
}

/** Parse a rule from text */
Expand Down
Loading

0 comments on commit 8de5212

Please sign in to comment.