You should be able to write something close to
There is a person with {color} hair or with {color} eyes or that is {height} inches tall or that is {age} years old
Thanks for the strategies on
writing DSL. I'm actually having good luck converting my domain
specific code into DRL (using eclipse to play with it) and can see how
I'd form DSL for the example above. The example is too simple for my
needs, however. The user has to be able to specify any of the
attributes or any combination thereof and not necessarily in any order
or all of them. How do I write DSL for that? I think answer is adding
constraints with the dash syntax, which I brought up in my last email,
BUT that doesn't help me if the user needs to specify "There is a
person with {color} hair OR with {color} eyes".
Let me get into specifics and leave the theoretical example behind. In
my app, the user specifies any number of
file attributes with which a file will be classified. For example, the
user can create a policy that applies to files that are greater than 50
MB, or another that applies to files in directory abc OR xyz. With
input from the user, it generates rules in a Domain Specific Language
(that gets converted to DRL using our DSL file). The point of using
DSL in this case is to isolate user-level concepts from actual
implementation details.
Snippet from my DSL file:
[condition][File]file where=$f : File()
[condition][File]- file_name matches {expr}=fileName matches
{expr}
[condition][File]- dir_name matches {expr}=dirName matches {expr}
[condition][File]- group_name matches {expr}=gName matches {expr}
[condition][File]- user_name matches {expr}=uName matches {expr}
...
So if the user requests specifies jpg's owned by Bob, I can generate:
file where
- file_name matches "*.jpg"
- user_name matches "Bob"
Which generates appropriate 'when' syntax in DRL:
$f : File(fileName matches "*.jpg", uName
matches "bob")
but I haven't figured out a good way to get ORs with the dash syntax to
get something like this:
$f : File(fileName matches "*.jpg" || uName matches
"bob")
Please let me know if there is a good way to do this.
reid
You *might* have to use the variable typing feature new to Drools 5.0, but you may not.
A couple approaches that may help you out are...
1. Write a unit test, and pass your DSL code through the DSLExpander and see what DRL code it generates (which may or may not be valid, but at least you'll see what the DSL engine is doing to your DSL rule).
2. Download the source and use a step-through debugger with a breakpoint so you can examine the consequences of every match attempted against the RHS of the rule, and the consequent results of the replacement if a match is found.
3. If you don't want to run a debugger, you could write some AOP code to emit the results of the RHS with each step of the expansion, but this approach would be more work than just running a debugger.
If you'd like to write a self-contained unit test with your DRL rule (the one that looks like the one I provided above, but verified to work), I can take a look at it and see what I'd do DSL-wise.
Matt
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users