Matt,

    There are good and bad news for you.
    The good news is that you can define and use fragments in your sentences, since the DSL engine is a lot more flexible than it used to be in version 3. It will process the same sentence multiple times (for each matching fragment).
    The bad news is that it is not perfect, nor that easy to write such a grammar yet. What I miss the most is the ability to allow variables (or capture-groups as they are called in regexp) to be "typed". Something like being able to write a variable like {myVar:\d*}, so that it will match only digits and etc.
    For your specific case, you can try something like:

1. define the most restrictive fragments you are able to. It means you will probably need a keyword or symbol to introduce and close the fragment:

[condition][]where {attr} is "{value}"=where {attr} == "{value}"
[condition][]and {attr} is "{value}"=, {attr} == "{value}"

Note that you keep the keyword "where" even after the replacement, but you can replace "and" by a comma, since this is what you need in DRL.

2. define the sentence structure. Here you can see why keeping the keyword "where is important, since it will delimit where your matching starts.

[condition][]address is present where {constraints}=u : User() and exists (a: Address({constraints}) from u.addresses)

    I didn't tested this specific example, but should work. Just remember that the order of the mappings in the DSL grammar is important, since it WILL match them in order.
    You can use any regexp special symbols you want in the matching string.

    As you can see, typed variables (capturing groups) would increase a lot the flexibility of the DSL. Also, we have a few improvements that would be good to do, but at this point we have no one available to do it. Anyone interested in jumping aboard to help with that? It is a pretty isolated subsystem of drools and a quite simple one, so, anyone that knows regexp could help.

    []s
    Edson


2008/3/31, Matt Geis <mgeis@yahoo.com>:
Hey everyone -- I've got a problem around trying to create arbitrary DSL rules.  I asked a similar question about a year ago, and given the state of Drools at the time, it wasn't possible.  I'm not having much more success now, a year later, but I wanted to find out if what I'm trying to accomplish is even possible.  If yes, how can I pull it off?  If no, are there plans to have this level of flexibility with DSL's in the future?

My high-level goal is to allow non-programmers some flexibility in defining rules, without me calculating all possible permutations of a rule ahead of time and building an all-encompassing DSL definition.

What I want to do, in a DRL sense, if I were to fire a rule if a user asserted into memory has a house in San Francisco, could be expressed as follows, in java:

rule "rule1"
    when
        u : User( )
        exists(a : Address(type== "HOUSE", city == "San Francisco") from u.addresses)
    then
        System.out.println( "got a user with a house in San Francisco");
end


Next, to make it easier, I can "DSL-ify" it as follows...

in my DSL I add the following
[condition][]address is present where {}=u : User() and exists (a: Address({}) from u.addresses)

(Note the "{}" right after the declared constraint for "Address"... -- by the way, this works.  I've tested it out)

The problem is that while it does accept the constraints, Drools requires them to be in rule dialect format.
That's to say, the rule must look like this...

rule "rule1"
    when
        address is present where city=="San Francisco",  type=="HOUSE"
    then
        output "got a user with a house in San Francisco"
end

As soon as the first DSL entry is found, it's expanded into a DRL-typecondition, and everything else is considered to be a literal in the DRLdialect.  Normally, these would just be value constants, like TRUE,100, "foo", etc.  I've massaged the intent of the DSL a bit, it seems,by allowing some form of arbitrary rule definition, but all I've doneis gone and created a DSL/DRL hybrid.


What I WANT to be able to do is populate that {} with DSL text, so I can write a rule like...

rule "rule1"
    when
        address is present where city is "San Francisco" and address type is "HOUSE"
    then
        output "got a user with a house in San Francisco"
end




What I'd really like to do is create this rule and adhere 100% to the DSL I've defined.

Can I do this already in Drools (is there something I'm overlooking)?  Is there a way to tell the DSL expander to continue to perform substitutions on what it would normally treat as literal values?

Thanks!

Matt




      ____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



--
  Edson Tirelli
  JBoss Drools Core Development
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com