Public repository: timo / feel

Reader

An interpreter of FEEL, written in Rust, with integrations for PostgreSQL, WASM, Lua, and Python.

feat(core): `not(tests)` test negation on RHS of `in` (DMN rule 49)

public

feat(core): `not(tests)` test negation on RHS of `in` (DMN rule 49)

`x in not([1,2,3])` / `x in not(<5)` / `x in not([1..10])`. In the unary-test
context after `in`, `not(…)` is ALWAYS test negation (`x in not(t)` ≡
`not(x satisfies t)`, Kleene), never the boolean `not(…)` built-in.

Resolves the token-role fork: `NbPrimary` drops the boolean `"not" "(" Expr ")"`
so the bare `in`-RHS branch can never start with `not`, and a dedicated
`InRhs → "not" "(" Comma<UnaryTestElem> ")"` production is then the sole `not`
shift target after `in` (LR(1)-clean, build.rs gate). A new
`UnaryTest::Not(Vec<UnaryTest>)` OR-folds the inner tests and negates the result
three-valued via `not3` (`not(true)=false`, `not(null)=null`, tainted unknowns
stay error-null). See ADR-30.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Changeset85b172fed8ab4ed6092b35e612500dce6e5775f4
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parentsc352959c2fec
Children
Pushlog
by timo via ssh

modified crates/feel-core/src/ast.rs +16 −5

@@ -63,8 +63,9 @@
6363
     /// Membership test `value in <tests>` (DMN §10.3.2.6, grammar rule 49). The
6464
     /// right-hand side is one or more *positive unary tests* (an interval, an
6565
     /// `<op> endpoint` comparison, or a bare expression meaning equality), combined
66
-    /// with OR. See [`UnaryTest`]. (`not(...)` negation of unary tests is not in
67
-    /// this slice — it collides with the `not(…)` boolean built-in.)
66
+    /// with OR. See [`UnaryTest`]. A `not(…)` on the RHS is *test* negation
67
+    /// ([`UnaryTest::Not`]), `x in not(t)` ≡ `not(x satisfies t)` (Kleene), never the
68
+    /// boolean `not(…)` built-in.
6869
     In(Box<Expr>, Vec<UnaryTest>),
6970
     /// Type predicate `value instance of type` (DMN §10.3.2.9, grammar rule 51).
7071
     /// The right operand is a [`FeelType`] resolved at parse time (it carries no
@@ -197,6 +198,15 @@
197198
     /// literal `[a..b]` keeps the dedicated [`UnaryTest::Interval`] form instead (see
198199
     /// [`unary_test_from_expr`]), so existing interval tests are unchanged.
199200
     Endpoint(Box<Expr>),
201
+    /// Negation of a positive unary-test list, `x in not(t1, t2, …)` (DMN §10.3.2.6,
202
+    /// grammar rule 49). In the unary-test context `not(…)` is **always** test
203
+    /// negation — `x in not(t)` ≡ `not(x satisfies t)`, three-valued/Kleene — and is
204
+    /// *not* the boolean `not(…)` built-in. The inner tests are OR-folded (the same
205
+    /// disjunction as a bare list) and the result negated, so `x in not(1,2,3)` ≡
206
+    /// `not(x = 1 or x = 2 or x = 3)`. Each inner endpoint becomes a test via
207
+    /// [`unary_test_from_expr`], so `not(5)` is the negation of the `= 5` test and
208
+    /// `not(< 5)` / `not([1..10])` negate a comparison / interval test.
209
+    Not(Vec<UnaryTest>),
200210
 }
201211
 
202212
 /// Build the unary test for a bare RHS expression `x in e`. A written interval
@@ -388,6 +398,7 @@
388398
         match self {
389399
             UnaryTest::Compare(_, e) | UnaryTest::Endpoint(e) => e.is_clock_free(),
390400
             UnaryTest::Interval(iv) => iv.start.is_clock_free() && iv.end.is_clock_free(),
391
-        }
392
-    }
393
-}
401
+            UnaryTest::Not(tests) => tests.iter().all(UnaryTest::is_clock_free),
402
+        }
403
+    }
404
+}

modified crates/feel-core/src/eval.rs +22 −0

@@ -561,7 +561,29 @@
561561
                 }
562562
                 t => eval_compare(CmpOp::Eq, o, &t),
563563
             },
564
+            // `x in not(t1, …)`: negate the OR-fold of the inner tests, three-valued
565
+            // (Kleene). `not(true) = false`, `not(false) = true`, `not(null) = null`;
566
+            // an error in an inner test stays an error-null through `not3` (so the
567
+            // negation never manufactures a definite truth from an unknown).
568
+            UnaryTest::Not(tests) => {
569
+                let mut acc = Value::Boolean(false);
570
+                for test in tests {
571
+                    acc = or3(acc, self.eval_unary_test(o, test, ctx)?);
572
+                }
573
+                not3(acc)
574
+            }
564575
         })
576
+    }
577
+}
578
+
579
+/// Kleene negation used by `x in not(…)` test negation: `not(true) = false`,
580
+/// `not(false) = true`, `not(null) = null`. A tainted unknown (error-null or a
581
+/// wrong-typed operand) stays an error-null, mirroring `and3`/`or3` provenance, so
582
+/// negating an unknown never produces a definite truth.
583
+fn not3(v: Value) -> Value {
584
+    match v {
585
+        Value::Boolean(b) => Value::Boolean(!b),
586
+        other => nullish(taints(&other)),
565587
     }
566588
 }
567589
 

modified crates/feel-core/src/feel.lalrpop +16 −1

@@ -341,6 +341,16 @@
341341
         vec![UnaryTest::Interval(Interval { start_open: true, start: Box::new(lo), end: Box::new(hi), end_open: eo })],
342342
     "[" <ts:Comma<UnaryTestElem>> "]" => ts,
343343
     "(" <ts:Comma<UnaryTestElem>> ")" => ts,
344
+    // Negation of a positive unary-test list, `x in not(t1, …)` (DMN rule 49). In the
345
+    // unary-test context `not(…)` is ALWAYS test negation (≡ `not(x satisfies t)`,
346
+    // Kleene), never the boolean `not(…)` built-in. A dedicated `InRhs` production
347
+    // (not reachable through the bare `NbSum` chain — `NbPrimary` deliberately drops
348
+    // the boolean `"not" "(" Expr ")"` so the bare branch can never start with `not`,
349
+    // which is what keeps this fork LR(1)-clean: after `in`, `not` has exactly ONE
350
+    // production here). The inner elements reuse `UnaryTestElem`, so `not(5)` is the
351
+    // negated `= 5` test, `not(<5)` a negated comparison, `not([1..10])` a negated
352
+    // interval — all via `unary_test_from_expr`, like a bare list.
353
+    "not" "(" <ts:Comma<UnaryTestElem>> ")" => vec![UnaryTest::Not(ts)],
344354
 };
345355
 
346356
 // One element of a bracketed / parenthesised test-list: a comparison test (`< 5`,
@@ -403,7 +413,12 @@
403413
     "false" => Expr::Bool(false),
404414
     "null" => Expr::Null,
405415
     Context,
406
-    "not" "(" <e:Expr> ")" => Expr::Not(Box::new(e)),
416
+    // NOTE: unlike `Primary`, the bare-`InRhs` `NbPrimary` deliberately OMITS the
417
+    // boolean `"not" "(" Expr ")"` production. In the unary-test context after `in`,
418
+    // `not(…)` is always *test* negation, handled by the dedicated `InRhs → "not" …`
419
+    // production above; dropping it here is what keeps that fork LR(1)-clean (the bare
420
+    // branch can no longer reach a competing `not`). A boolean `not(…)` is of course
421
+    // still reachable everywhere else through `Primary`.
407422
     Name => Expr::Var(<>),
408423
 };
409424