1.2.4. DSL Grammars in Drools 4.0

1.2.4. DSL Grammars in Drools 4.0

It is important to note that the DSL template engine was rewritten from scratch to improve flexibility. One of the new features of DSL grammars is the support of regular expressions.

Now you can write your mappings using regular expressions to have additional flexibility, as explained in the DSL chapter. There are a number of characters which have special meanings in regular expressions such as [ and *. If you use these characters as part of a mapping without the intent of using the regular expression effect you will need to prefix each of those characters with a \. This is referred to as 'escaping' the characters. Note that character \ itself must be escaped unless you are using it to 'escape' another character.

For example if you previously had a mapping like:

[when][]- the {attr} is in [ {values} ]={attr} in ({values})
Example 1.5. Drools 3.0.x mapping

Now, you need to 'escape' [ and ] characters. So, the same mapping in Drools 4.0 would be:

[when][]- the {attr} is in \[ {values} \]={attr} in ({values})
Example 1.6. Drools 4.0.x mapping with escaped characters