Log
85b172fed8ab
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>
modified
crates/feel-core/src/ast.rs
+16 −5
@@ -63,8 +63,9 @@
63 63 /// Membership test `value in <tests>` (DMN §10.3.2.6, grammar rule 49). The 64 64 /// right-hand side is one or more *positive unary tests* (an interval, an 65 65 /// `<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. 68 69 In(Box < Expr> , Vec < UnaryTest> ), 69 70 /// Type predicate `value instance of type` (DMN §10.3.2.9, grammar rule 51). 70 71 /// The right operand is a [`FeelType`] resolved at parse time (it carries no
@@ -197,6 +198,15 @@
197 198 /// literal `[a..b]` keeps the dedicated [`UnaryTest::Interval`] form instead (see 198 199 /// [`unary_test_from_expr`]), so existing interval tests are unchanged. 199 200 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> ), 200 210 } 201 211 202 212 /// Build the unary test for a bare RHS expression `x in e`. A written interval
@@ -388,6 +398,7 @@
388 398 match self { 389 399 UnaryTest::Compare(_, e) | UnaryTest::Endpoint(e) = > e.is_clock_free(), 390 400 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 @@
561 561 } 562 562 t = > eval_compare(CmpOp::Eq , o, & t), 563 563 }, 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 + } 564 575 }) 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)), 565 587 } 566 588 } 567 589
modified
crates/feel-core/src/feel.lalrpop
+16 −1
@@ -341,6 +341,16 @@
341 341 vec![UnaryTest::Interval(Interval { start_open: true, start: Box::new(lo), end: Box::new(hi), end_open: eo })], 342 342 "[" <ts:Comma<UnaryTestElem>> "]" => ts, 343 343 "(" <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)], 344 354 }; 345 355 346 356 // One element of a bracketed / parenthesised test-list: a comparison test (`< 5`,
@@ -403,7 +413,12 @@
403 413 "false" => Expr::Bool(false), 404 414 "null" => Expr::Null, 405 415 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`. 407 422 Name => Expr::Var(<>), 408 423 }; 409 424