(updated to Drools 5.0)
Drools 5 introduces the concept of Hard and Soft keywords.
Hard keywords are reserved, you cannot use any hard keyword when naming your domain objects, properties, methods, functions and other elements that are used in the rule text.
Here is a list of hard keywords that must be avoided as identifiers when writing rules:
true
false
accumulate
collect
from
null
over
then
when
Soft keywords are just recognized in their context, enabling you to use this words in any other place you wish. Here is a list of soft keywords:
lock-on-active
date-effective
date-expires
no-loop
auto-focus
activation-group
agenda-group
ruleflow-group
entry-point
duration
package
import
dialect
salience
enabled
attributes
rule
extend
template
query
declare
function
global
eval
not
in
or
and
exists
forall
action
reverse
result
end
init
Of course, you can have these (hard and soft) words as part of a method name in camel case, like notSomething() or accumulateSomething() - there are no issues with that scenario.
Another improvement on DRL language is the ability to escape hard keywords on rule text. This new feature enables you to use your existing domain objects without worring about keyword collision. To escape a word, simple type it between a grave accent, like this:
Holiday( `when` == "july" )
The escape should be used everywehere in rule text, except at code expressions in the LHS or RHS code block. Here are examples of usage:
rule "validate holiday by eval" dialect "mvel" when h1 : Holiday( ) eval( h1.when == "july" ) then System.out.println(h1.name + ":" + h1.when); end
rule "validate holiday" dialect "mvel" when h1 : Holiday( `when` == "july" ) then System.out.println(h1.name + ":" + h1.when); end