Search code examples
droolsdsldslr

How to use not() in a dslr rule?


I want to express a rule like

rule "R"
when
    a: A()
    c: C(a.timestamp<timestamp)

    not(B(a.timestamp<timestamp && timestamp<c.timestamp))
then
    // error no B between A and C
end

but using a DSL

how can I express the not?

rule "R"
when
    there is an A a
    there is a C c
      - with timestamp greater than a.timestamp

    there is NOT a B
      - with id between a.timestamp and b.timestamp
then
    // error no B between A and C
end
[condition][]there is an A {a}={a}: A()
[condition][]there is a C {c}={c}: C()
[condition][]there is NOT a B=not(B())
[condition][]- with timestamp greater than {timestamp}=timestamp > {timestamp}
[condition][]- with timestamp between {lower} and {upper}={lower}<timestamp && timestamp<{upper}

Solution

  • rdslr

    rule "R"
    when
        There is an A
        There is a C
          - with timestamp greater than $A.timestamp
        There is a B
          - not with timestamp between $A.timestamp and $C.timestamp
    then
        // error no B between A and C
    end
    

    dsl

    [when]There (is( an?)?|are) {entityType}s?( that)? = ${entityType}: {entityType}()
    [when]with timestamp greater than {timestamp}=(timestamp > {timestamp})
    [when]with timestamp between {lower} and {upper}=({lower} < timestamp && timestamp < {upper})
    
    [when]{prefix}?\s*(?<![\w])not(?! (in|matches|contains|memberOf|soundslike|str))(\s+an?)?(?![\w])\s*\({suffix}? = {prefix} false == (true && {suffix}
    [when]{prefix}?\s*(?<![\w])not(?! (in|matches|contains|memberOf|soundslike|str))(\s+an?)?(?![\w])\s*{suffix}? = {prefix} !{suffix}
    [when](?<![^\(,])\s*- =