See inline.
On 27 May 2011 20:19, jstroup <jstroup(a)regenstrief.org> wrote:
Hi Droolers,
Regarding this blurb from the 5.2 DSL reference:
[snip]
Given this DSL (test_expander.dsl)
[when](C|c)heese is "{type}"=Cheese(type=="{type}")
[when](is|hails|comes) from {country}=Cheese(country=="{country}")
[then]Add the message {message}=System.out.println({message});
And this DSLR
package com.sample
import com.sample.DroolsTest.Cheese;
expander test_expander.dsl
rule "rule_1"
when
Cheese is "cheddar" and is from Italy
then
Add the message "Cheddar IS from Italy"
end
This will not do what the text implies because the expansion is
Cheese(type=="cheddar") Cheese(country==="Italy")
and there is nothing that links these Cheese facts, which could
be one and the same but also any other pair matching the
individual constraints.
I know that rule_2 fails because I removed the “distinctive characters” so
ANTLR is confused on what to capture.
ANTLR has nothing to do with DSL expansion, which is entirely based on
regular expressions.
It just seems so unnatural for a rule
author to have to somehow magically know to add quotes in order to merge
different DSL expressions to generate a composite DRL pattern.
The DSL designer has a range of options (characters, buzz words,...) but at
the
end of the day (s)he will have to document it for the rule authors. There's
no
way they'll know what to write, out of the blue.
2) We can no longer just write “Cheese is cheddar” by itself but are
forced to write “Cheese is cheddar and” if we want to match only the
first
expression. You might as well just combined the two expressions into one
since there is no real advantage now to having two expressions!
There is a feature for adding arbitrary constraints into a preceding
pattern.
One nice thing would be for the Guvnor DSL editor to
1)try the capture greedily first,
2)get the annoying “no viable alternative error”,
3)CATCH the error instead of just giving up,
4)capture non-greedily and match only the first word,
5)then search for matching DSL expressions beyond that.
Or something like that.
Exactly. There is the fundamental problem of different levels of grammars
for DRL and natural languages, and this can't be overcome easily.
The only time you should have to add quotes is if
the text you are matching actually contains multiple words. Anything else
is
counter-intuitive.
The DSL designer can avoid this, at the cost of slightly more verbose
phrases.
Please tell me the planned replacement for DSL addresses
this!
Feel free to contribute proposals (but not "something like that", please).
Wolfgang
Jeff