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".[condition][File]file where=$f : File()So if the user requests specifies jpg's owned by Bob, I can generate:
[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}
...
file whereWhich generates appropriate 'when' syntax in DRL:
- file_name matches "*.jpg"
- user_name matches "Bob"
$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.
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