are "sentence fragments" possible w/DSL?
by Matt Geis
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
16 years, 7 months