<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<blockquote cite="mid:390606.63397.qm@web32101.mail.mud.yahoo.com"
 type="cite">
  <pre wrap="">
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

  </pre>
</blockquote>
Thanks for the strategies on
writing DSL.&nbsp; 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.&nbsp; The example is too simple for my
needs, however.&nbsp; 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.&nbsp; How do I write DSL for that?&nbsp; 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".<br>
<br>
Let me get into specifics and leave the theoretical example behind.&nbsp; In
my app, the user specifies any number of
file attributes with which a file will be classified.&nbsp; 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.&nbsp; With
input from the user, it generates rules in a Domain Specific Language
(that gets converted to DRL using our DSL file).&nbsp; The point of using
DSL in this case is to isolate user-level concepts from actual
implementation details.<br>
<br>
Snippet from my DSL file:<br>
<blockquote><tt>[condition][File]file where=$f : File()</tt><br>
  <tt>[condition][File]- file_name matches {expr}=fileName matches
{expr}</tt><br>
  <tt>[condition][File]- dir_name matches {expr}=dirName matches {expr}</tt><br>
  <tt>[condition][File]- group_name matches {expr}=gName matches {expr}</tt><br>
  <tt>[condition][File]- user_name matches {expr}=uName matches {expr}</tt><br>
  <tt>...</tt><br>
</blockquote>
So if the user requests specifies jpg's owned by Bob, I can generate:<br>
<blockquote><tt>file where</tt><br>
  <tt>- file_name matches "*.jpg"<br>
- user_name matches "Bob"<br>
  </tt></blockquote>
Which generates appropriate 'when' syntax in DRL:<br>
<blockquote><tt>$f : File(fileName matches </tt><tt>"*.jpg", uName
matches </tt><tt>"bob")</tt></blockquote>
but I haven't figured out a good way to get ORs with the dash syntax to
get something like this:<br>
<blockquote><tt>$f : File(fileName matches "*.jpg" || uName matches
"bob")</tt><br>
</blockquote>
Please let me know if there is a good way to do this.<br>
<br>
reid<br>
<blockquote cite="mid:390606.63397.qm@web32101.mail.mud.yahoo.com"
 type="cite">
  <pre wrap="">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
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
  </pre>
</blockquote>
</body>
</html>