feat(core): unbounded omitted-endpoint ranges `[1..]` / `[..10]` (ADR-31)
public
feat(core): unbounded omitted-endpoint ranges `[1..]` / `[..10]` (ADR-31)
An omitted interval endpoint now denotes an UNBOUNDED bound (±∞), kept
rigorously distinct from a present `null` endpoint: `[..10]` includes
everything ≤ 10, while `[null..10]` stays three-valued "unknown" (DMN-TCK
0072). The change ripples through every layer:
- AST `Interval` and value `RangeVal` endpoints → `Option<…>` (`None` =
unbounded). `RangeVal` stays boxed, so `Value` is still 40 bytes.
- eval: `range_contains` takes `Option<&Value>` per side (a `None` side is
satisfied unconditionally; a `Some(null)` side stays Kleene); range equality
ignores openness on an unbounded side (`[1..]` = `[1..)`, ≠ `[1..10]`,
≠ `[null..10]`); `.start`/`.end` of an unbounded side is null and never
`included`; `instance of range<T>` treats an unbounded side as vacuous.
- builtins: the §10.3.4.6 Allen relations view operands through a
`NegInf`/`Val`/`PosInf` bound; `string(...)` echoes the written bracket. The
`range()` STRING builtin stays strict — `range("[..2]")`/`range("[1..]")` are
null per DMN-TCK 1156 (004_e/004_f), so the function/literal asymmetry is the
TCK's, not ours.
- grammar: optional `Sum?` low endpoint + a new `HiEnd` nonterminal (bounded
`Endpoint IntervalEnd`, or a bare `]`/`)` for unbounded-high). LR(1)-clean,
proven by the build.rs no-conflict gate.
- feel-lua / feel-py: an unbounded endpoint maps to host null and is never
`included`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| Changeset | 71d393c0292eefba32116ef1676710ff8576c4d1 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | ad89b0592d43 |
| Children | |
| Pushlog | by timo via ssh |
modified crates/feel-core/src/ast.rs +18 −4
| @@ -173,11 +173,18 @@ | ||
| 173 | 173 | /// |
| 174 | 174 | /// `start_open`/`end_open` encode the bracket: `[`/`]` are closed (inclusive), |
| 175 | 175 | /// `(`/`)` are open (exclusive). |
| 176 | +/// | |
| 177 | +/// An endpoint is `None` when it was **syntactically omitted** — an *unbounded* | |
| 178 | +/// bound, `±∞` (`[1..]` is everything `≥ 1`, `[..10]` everything `≤ 10`; ADR-31). | |
| 179 | +/// This is semantically distinct from a *present* `null` endpoint (`Some(Expr::Null)`), | |
| 180 | +/// which keeps the three-valued "unknown" membership of `[null..10]`. The openness | |
| 181 | +/// flag of an omitted endpoint is meaningless (`±∞` is never a member); every | |
| 182 | +/// semantic operation ignores it on the unbounded side. | |
| 176 | 183 | #[derive(Debug, Clone, PartialEq)] |
| 177 | 184 | pub struct Interval { |
| 178 | 185 | pub start_open: bool, |
| 179 | - pub start: Box<Expr>, | |
| 180 | - pub end: Box<Expr>, | |
| 186 | + pub start: Option<Box<Expr>>, | |
| 187 | + pub end: Option<Box<Expr>>, | |
| 181 | 188 | pub end_open: bool, |
| 182 | 189 | } |
| 183 | 190 | |
| @@ -344,7 +351,7 @@ | ||
| 344 | 351 | | Expr::Null |
| 345 | 352 | | Expr::Var(_) => true, |
| 346 | 353 | Expr::List(items) => items.iter().all(Expr::is_clock_free), |
| 347 | - Expr::RangeLit(iv) => iv.start.is_clock_free() && iv.end.is_clock_free(), | |
| 354 | + Expr::RangeLit(iv) => interval_is_clock_free(iv), | |
| 348 | 355 | Expr::ContextLit(entries) => entries.iter().all(|(_, e)| e.is_clock_free()), |
| 349 | 356 | Expr::Path(target, _) => target.is_clock_free(), |
| 350 | 357 | Expr::Filter(source, bracket) => { |
| @@ -393,11 +400,18 @@ | ||
| 393 | 400 | } |
| 394 | 401 | } |
| 395 | 402 | |
| 403 | +/// Both endpoints of an interval are clock-free — an omitted (unbounded, `None`) | |
| 404 | +/// endpoint is trivially clock-free (ADR-31). | |
| 405 | +fn interval_is_clock_free(iv: &Interval) -> bool { | |
| 406 | + iv.start.as_ref().is_none_or(|e| e.is_clock_free()) | |
| 407 | + && iv.end.as_ref().is_none_or(|e| e.is_clock_free()) | |
| 408 | +} | |
| 409 | + | |
| 396 | 410 | impl UnaryTest { |
| 397 | 411 | fn is_clock_free(&self) -> bool { |
| 398 | 412 | match self { |
| 399 | 413 | UnaryTest::Compare(_, e) | UnaryTest::Endpoint(e) => e.is_clock_free(), |
| 400 | - UnaryTest::Interval(iv) => iv.start.is_clock_free() && iv.end.is_clock_free(), | |
| 414 | + UnaryTest::Interval(iv) => interval_is_clock_free(iv), | |
| 401 | 415 | UnaryTest::Not(tests) => tests.iter().all(UnaryTest::is_clock_free), |
| 402 | 416 | } |
| 403 | 417 | } |
modified crates/feel-core/src/builtins.rs +60 −26
| @@ -614,7 +614,14 @@ | ||
| 614 | 614 | // *evaluates* to a date but is not a literal, so the spec wants it to be null. |
| 615 | 615 | match compiled.ast() { |
| 616 | 616 | crate::ast::Expr::RangeLit(iv) => { |
| 617 | - if !range_endpoint_is_literal(&iv.start) || !range_endpoint_is_literal(&iv.end) { | |
| 617 | + // The `range()` string builtin requires BOTH endpoints present and literal. | |
| 618 | + // Unlike the unbounded *literal* `[..2]` (ADR-31), the function rejects an | |
| 619 | + // omitted endpoint: DMN-TCK 1156 `004_e`/`004_f` make `range("[..2]")` and | |
| 620 | + // `range("[1..]")` null. So a `None` endpoint here is already an error. | |
| 621 | + let lit_ok = |e: &Option<Box<crate::ast::Expr>>| { | |
| 622 | + e.as_ref().is_some_and(|e| range_endpoint_is_literal(e)) | |
| 623 | + }; | |
| 624 | + if !lit_ok(&iv.start) || !lit_ok(&iv.end) { | |
| 618 | 625 | return Value::Error; |
| 619 | 626 | } |
| 620 | 627 | } |
| @@ -627,9 +634,12 @@ | ||
| 627 | 634 | _ => return Value::Error, |
| 628 | 635 | }; |
| 629 | 636 | // A well-formed range has two comparable (same orderable type, non-null) endpoints |
| 630 | - // in non-descending order. `feel_order` returns `None` for null/mismatched types. | |
| 631 | - match feel_order(&r.start, &r.end) { | |
| 632 | - Some(ord) if ord != Ordering::Greater => Value::Range(r), | |
| 637 | + // in non-descending order. Both are present (the literal gate above rejected any | |
| 638 | + // unbounded side). `feel_order` returns `None` for null/mismatched types. | |
| 639 | + match (&r.start, &r.end) { | |
| 640 | + (Some(s), Some(e)) if matches!(feel_order(s, e), Some(ord) if ord != Ordering::Greater) => { | |
| 641 | + Value::Range(r) | |
| 642 | + } | |
| 633 | 643 | _ => Value::Error, |
| 634 | 644 | } |
| 635 | 645 | } |
| @@ -653,41 +663,56 @@ | ||
| 653 | 663 | } |
| 654 | 664 | } |
| 655 | 665 | |
| 666 | +/// One endpoint of an interval for the §10.3.4.6 relations: a concrete value, or an | |
| 667 | +/// *unbounded* bound (`±∞`; ADR-31). A range's lower bound is `NegInf` when omitted, | |
| 668 | +/// its upper bound `PosInf`; `±∞` compares below/above every concrete value, so the | |
| 669 | +/// Allen formulas below need no further special-casing. | |
| 670 | +#[derive(Clone, Copy)] | |
| 671 | +enum Bound<'a> { | |
| 672 | + NegInf, | |
| 673 | + Val(&'a Value), | |
| 674 | + PosInf, | |
| 675 | +} | |
| 676 | + | |
| 656 | 677 | /// A point or range viewed uniformly as an interval with two endpoints and their |
| 657 | 678 | /// inclusion. A *point* `p` is the degenerate closed interval `[p..p]`, which makes |
| 658 | 679 | /// the range/range relation formulas below cover every point/range overload of the |
| 659 | 680 | /// §10.3.4.6 relations with a single definition each (verified against `1130`). |
| 660 | 681 | struct Iv<'a> { |
| 661 | - start: &'a Value, | |
| 662 | - /// Lower bound *excluded* (the `(`/`]` openness flag). | |
| 682 | + start: Bound<'a>, | |
| 683 | + /// Lower bound *excluded* (the `(`/`]` openness flag). Canonically `false` when | |
| 684 | + /// the bound is unbounded, where openness is meaningless (ADR-31). | |
| 663 | 685 | start_open: bool, |
| 664 | - end: &'a Value, | |
| 665 | - /// Upper bound *excluded* (the `)`/`[` openness flag). | |
| 686 | + end: Bound<'a>, | |
| 687 | + /// Upper bound *excluded* (the `)`/`[` openness flag). Canonically `false` when | |
| 688 | + /// unbounded. | |
| 666 | 689 | end_open: bool, |
| 667 | 690 | } |
| 668 | 691 | |
| 669 | -/// View a value as an interval: a range as itself, an orderable scalar (number, | |
| 670 | -/// string, or any temporal) as the closed point interval `[v..v]`. Anything else | |
| 671 | -/// (boolean, list, context, null, …) has no order, so it is not a valid relation | |
| 672 | -/// operand -> `None` (an error-null at the call site). | |
| 692 | +/// View a value as an interval: a range as itself (an omitted endpoint becoming | |
| 693 | +/// `±∞`), an orderable scalar (number, string, or any temporal) as the closed point | |
| 694 | +/// interval `[v..v]`. Anything else (boolean, list, context, null, …) has no order, | |
| 695 | +/// so it is not a valid relation operand -> `None` (an error-null at the call site). | |
| 696 | +/// The openness flag of an unbounded side is forced to `false` so the formulas treat | |
| 697 | +/// two `±∞` of the same sign as coinciding regardless of the brackets written. | |
| 673 | 698 | fn as_interval(v: &Value) -> Option<Iv<'_>> { |
| 674 | 699 | match v { |
| 675 | 700 | Value::Range(r) => Some(Iv { |
| 676 | - start: &r.start, | |
| 677 | - start_open: r.start_open, | |
| 678 | - end: &r.end, | |
| 679 | - end_open: r.end_open, | |
| 701 | + start: r.start.as_ref().map_or(Bound::NegInf, Bound::Val), | |
| 702 | + start_open: r.start.is_some() && r.start_open, | |
| 703 | + end: r.end.as_ref().map_or(Bound::PosInf, Bound::Val), | |
| 704 | + end_open: r.end.is_some() && r.end_open, | |
| 680 | 705 | }), |
| 681 | 706 | Value::Number(_) | Value::String(_) => Some(Iv { |
| 682 | - start: v, | |
| 707 | + start: Bound::Val(v), | |
| 683 | 708 | start_open: false, |
| 684 | - end: v, | |
| 709 | + end: Bound::Val(v), | |
| 685 | 710 | end_open: false, |
| 686 | 711 | }), |
| 687 | 712 | _ if crate::temporal::is_temporal(v) => Some(Iv { |
| 688 | - start: v, | |
| 713 | + start: Bound::Val(v), | |
| 689 | 714 | start_open: false, |
| 690 | - end: v, | |
| 715 | + end: Bound::Val(v), | |
| 691 | 716 | end_open: false, |
| 692 | 717 | }), |
| 693 | 718 | _ => None, |
| @@ -732,9 +757,16 @@ | ||
| 732 | 757 | } |
| 733 | 758 | } |
| 734 | 759 | |
| 735 | -/// Order two endpoint values, `None` if incomparable (different types or a `null`). | |
| 736 | -fn ep_cmp(x: &Value, y: &Value) -> Option<Ordering> { | |
| 737 | - feel_order(x, y) | |
| 760 | +/// Order two endpoints, `None` if incomparable (different types or a `null`). An | |
| 761 | +/// unbounded bound (`±∞`; ADR-31) compares below/above every concrete value; two | |
| 762 | +/// `±∞` of the same sign are equal (so e.g. `coincides([..5], [..5])` holds). | |
| 763 | +fn ep_cmp(x: Bound, y: Bound) -> Option<Ordering> { | |
| 764 | + match (x, y) { | |
| 765 | + (Bound::NegInf, Bound::NegInf) | (Bound::PosInf, Bound::PosInf) => Some(Ordering::Equal), | |
| 766 | + (Bound::NegInf, _) | (_, Bound::PosInf) => Some(Ordering::Less), | |
| 767 | + (Bound::PosInf, _) | (_, Bound::NegInf) => Some(Ordering::Greater), | |
| 768 | + (Bound::Val(a), Bound::Val(b)) => feel_order(a, b), | |
| 769 | + } | |
| 738 | 770 | } |
| 739 | 771 | |
| 740 | 772 | // The base relations (DMN §10.3.4.6), each over inclusion-aware endpoints. `?` on the |
| @@ -853,12 +885,14 @@ | ||
| 853 | 885 | // A function value has no FEEL string form; render an opaque marker (ADR-23). |
| 854 | 886 | Value::Function(_) => "function".to_string(), |
| 855 | 887 | // A range renders in interval notation, e.g. `[1..10)` / `["a".."c"]`; the |
| 856 | - // endpoints are quoted as list members are (so strings keep their quotes). | |
| 888 | + // endpoints are quoted as list members are (so strings keep their quotes). An | |
| 889 | + // unbounded endpoint (`None`; ADR-31) renders as nothing, echoing the bracket | |
| 890 | + // the user wrote: `[1..]`, `[..10)`, `[..]`. | |
| 857 | 891 | Value::Range(r) => format!( |
| 858 | 892 | "{}{}..{}{}", |
| 859 | 893 | if r.start_open { '(' } else { '[' }, |
| 860 | - render_member(&r.start), | |
| 861 | - render_member(&r.end), | |
| 894 | + r.start.as_ref().map(render_member).unwrap_or_default(), | |
| 895 | + r.end.as_ref().map(render_member).unwrap_or_default(), | |
| 862 | 896 | if r.end_open { ')' } else { ']' }, |
| 863 | 897 | ), |
| 864 | 898 | Value::Null | Value::Error => "null".to_string(), |
modified crates/feel-core/src/eval.rs +93 −32
| @@ -76,8 +76,10 @@ | ||
| 76 | 76 | // built-in, a *literal* is taken at face value — no ordering/type check — |
| 77 | 77 | // mirroring the interval *test* form, which also evaluates endpoints lazily. |
| 78 | 78 | Expr::RangeLit(iv) => { |
| 79 | - let start = self.eval(&iv.start, ctx)?.forced(); | |
| 80 | - let end = self.eval(&iv.end, ctx)?.forced(); | |
| 79 | + // An omitted endpoint stays `None` (unbounded, ±∞; ADR-31) — distinct | |
| 80 | + // from a present `null` bound, which evaluates to `Some(Value::Null)`. | |
| 81 | + let start = self.eval_opt_endpoint(&iv.start, ctx)?; | |
| 82 | + let end = self.eval_opt_endpoint(&iv.end, ctx)?; | |
| 81 | 83 | Ok(Value::Range(Box::new(crate::value::RangeVal { |
| 82 | 84 | start, |
| 83 | 85 | end, |
| @@ -462,17 +464,16 @@ | ||
| 462 | 464 | } |
| 463 | 465 | result |
| 464 | 466 | } |
| 465 | - // Ranges are equal iff both bracket-openness flags match and both endpoints | |
| 466 | - // are FEEL-equal (DMN §10.3.4.6). A type-mismatched endpoint makes the whole | |
| 467 | - // comparison error-null (`None`), unless an openness/endpoint difference has | |
| 468 | - // already made it a definite `false`. | |
| 467 | + // Ranges are equal iff each *side* matches: same boundedness, same openness | |
| 468 | + // (only where the side is bounded), and FEEL-equal endpoints (DMN §10.3.4.6). | |
| 469 | + // An unbounded side ignores the openness flag — `[1..]` equals `[1..)` (both | |
| 470 | + // `[1, +∞)`), and `[1..]` differs from a bounded `[1..10]` (ADR-31). A | |
| 471 | + // type-mismatched endpoint makes the whole comparison error-null (`None`), | |
| 472 | + // unless a definite difference has already made it `false`. | |
| 469 | 473 | (Value::Range(x), Value::Range(y)) => { |
| 470 | - if x.start_open != y.start_open || x.end_open != y.end_open { | |
| 471 | - return Some(false); | |
| 472 | - } | |
| 473 | 474 | match ( |
| 474 | - feel_equal_depth(&x.start, &y.start, depth + 1), | |
| 475 | - feel_equal_depth(&x.end, &y.end, depth + 1), | |
| 475 | + range_side_eq(&x.start, x.start_open, &y.start, y.start_open, depth + 1), | |
| 476 | + range_side_eq(&x.end, x.end_open, &y.end, y.end_open, depth + 1), | |
| 476 | 477 | ) { |
| 477 | 478 | (Some(false), _) | (_, Some(false)) => Some(false), |
| 478 | 479 | (None, _) | (_, None) => None, |
| @@ -482,6 +483,29 @@ | ||
| 482 | 483 | // Temporal: same-type -> Some(bool); cross temporal type -> None (-> error-null). |
| 483 | 484 | (x, y) if temporal::is_temporal(x) && temporal::is_temporal(y) => temporal::equal(x, y), |
| 484 | 485 | _ => None, // different, non-null types |
| 486 | + } | |
| 487 | +} | |
| 488 | + | |
| 489 | +/// Three-valued equality of one *side* (start or end) of two ranges (ADR-31). Both | |
| 490 | +/// unbounded → equal (openness ignored, `±∞` has none); exactly one unbounded → | |
| 491 | +/// `false`; both bounded → openness must match *and* the endpoints be FEEL-equal. | |
| 492 | +fn range_side_eq( | |
| 493 | + xa: &Option<Value>, | |
| 494 | + xo: bool, | |
| 495 | + ya: &Option<Value>, | |
| 496 | + yo: bool, | |
| 497 | + depth: usize, | |
| 498 | +) -> Option<bool> { | |
| 499 | + match (xa, ya) { | |
| 500 | + (None, None) => Some(true), | |
| 501 | + (Some(_), None) | (None, Some(_)) => Some(false), | |
| 502 | + (Some(a), Some(b)) => { | |
| 503 | + if xo != yo { | |
| 504 | + Some(false) | |
| 505 | + } else { | |
| 506 | + feel_equal_depth(a, b, depth) | |
| 507 | + } | |
| 508 | + } | |
| 485 | 509 | } |
| 486 | 510 | } |
| 487 | 511 | |
| @@ -526,6 +550,21 @@ | ||
| 526 | 550 | } |
| 527 | 551 | |
| 528 | 552 | impl Evaluator<'_> { |
| 553 | + /// Evaluate an interval endpoint that may be omitted: `None` (unbounded, ±∞; | |
| 554 | + /// ADR-31) passes straight through, a present endpoint is evaluated and `forced` | |
| 555 | + /// (a present `null` bound becomes `Some(Value::Null)`, which downstream keeps | |
| 556 | + /// three-valued). | |
| 557 | + fn eval_opt_endpoint( | |
| 558 | + &self, | |
| 559 | + e: &Option<Box<Expr>>, | |
| 560 | + ctx: &Context, | |
| 561 | + ) -> Result<Option<Value>, FeelError> { | |
| 562 | + match e { | |
| 563 | + Some(e) => Ok(Some(self.eval(e, ctx)?.forced())), | |
| 564 | + None => Ok(None), | |
| 565 | + } | |
| 566 | + } | |
| 567 | + | |
| 529 | 568 | /// Membership test, interval inclusivity exactly per S-FEEL: |
| 530 | 569 | /// [a..b] -> a <= o <= b ; (a..b] -> a < o <= b ; [a..b) -> a <= o < b ; |
| 531 | 570 | /// (a..b) -> a < o < b |
| @@ -545,20 +584,24 @@ | ||
| 545 | 584 | Ok(match test { |
| 546 | 585 | UnaryTest::Compare(op, e) => eval_compare(*op, o, &self.eval(e, ctx)?.forced()), |
| 547 | 586 | // A *written* interval literal `[a..b]`: evaluate its endpoints in the |
| 548 | - // test context and check containment (unchanged from before ranges). | |
| 549 | - UnaryTest::Interval(iv) => range_contains( | |
| 550 | - o, | |
| 551 | - &self.eval(&iv.start, ctx)?.forced(), | |
| 552 | - iv.start_open, | |
| 553 | - &self.eval(&iv.end, ctx)?.forced(), | |
| 554 | - iv.end_open, | |
| 555 | - ), | |
| 587 | + // test context and check containment. An omitted endpoint is unbounded | |
| 588 | + // (`5 in [1..]`, `5 in [..10]`), satisfying that side unconditionally | |
| 589 | + // (ADR-31); a present `null` bound keeps three-valued membership. | |
| 590 | + UnaryTest::Interval(iv) => { | |
| 591 | + let start = self.eval_opt_endpoint(&iv.start, ctx)?; | |
| 592 | + let end = self.eval_opt_endpoint(&iv.end, ctx)?; | |
| 593 | + range_contains(o, start.as_ref(), iv.start_open, end.as_ref(), iv.end_open) | |
| 594 | + } | |
| 556 | 595 | // A bare endpoint expression `x in e`: range *membership* when `e` is a |
| 557 | 596 | // range value (e.g. `range("[1..3]")`), otherwise equality `x = e`. |
| 558 | 597 | UnaryTest::Endpoint(e) => match self.eval(e, ctx)?.forced() { |
| 559 | - Value::Range(r) => { | |
| 560 | - range_contains(o, &r.start, r.start_open, &r.end, r.end_open) | |
| 561 | - } | |
| 598 | + Value::Range(r) => range_contains( | |
| 599 | + o, | |
| 600 | + r.start.as_ref(), | |
| 601 | + r.start_open, | |
| 602 | + r.end.as_ref(), | |
| 603 | + r.end_open, | |
| 604 | + ), | |
| 562 | 605 | t => eval_compare(CmpOp::Eq, o, &t), |
| 563 | 606 | }, |
| 564 | 607 | // `x in not(t1, …)`: negate the OR-fold of the inner tests, three-valued |
| @@ -591,9 +634,25 @@ | ||
| 591 | 634 | /// `[a..b]` -> a <= o <= b ; `(a..b]` -> a < o <= b ; `[a..b)` -> a <= o < b ; |
| 592 | 635 | /// `(a..b)` -> a < o < b. Three-valued: a null/error endpoint makes the side it |
| 593 | 636 | /// bounds unknown, and `and3` combines the two sides with sticky error provenance. |
| 594 | -fn range_contains(o: &Value, start: &Value, start_open: bool, end: &Value, end_open: bool) -> Value { | |
| 595 | - let lower = eval_compare(if start_open { CmpOp::Lt } else { CmpOp::Le }, start, o); | |
| 596 | - let upper = eval_compare(if end_open { CmpOp::Lt } else { CmpOp::Le }, o, end); | |
| 637 | +/// | |
| 638 | +/// A `None` endpoint is *unbounded* (`±∞`; ADR-31): that side is satisfied | |
| 639 | +/// unconditionally (`true`), so `5 in [1..]` and `5 in [..10]` are `true`, while a | |
| 640 | +/// *present* `null` bound (`5 in [null..10]`) still yields the three-valued `null`. | |
| 641 | +fn range_contains( | |
| 642 | + o: &Value, | |
| 643 | + start: Option<&Value>, | |
| 644 | + start_open: bool, | |
| 645 | + end: Option<&Value>, | |
| 646 | + end_open: bool, | |
| 647 | +) -> Value { | |
| 648 | + let lower = match start { | |
| 649 | + Some(s) => eval_compare(if start_open { CmpOp::Lt } else { CmpOp::Le }, s, o), | |
| 650 | + None => Value::Boolean(true), | |
| 651 | + }; | |
| 652 | + let upper = match end { | |
| 653 | + Some(e) => eval_compare(if end_open { CmpOp::Lt } else { CmpOp::Le }, o, e), | |
| 654 | + None => Value::Boolean(true), | |
| 655 | + }; | |
| 597 | 656 | and3(lower, upper) |
| 598 | 657 | } |
| 599 | 658 | |
| @@ -860,14 +919,16 @@ | ||
| 860 | 919 | Value::Foreign(f) => f.0.get(name), |
| 861 | 920 | // Range properties (DMN §10.3.2.6 / TCK 0074): the two endpoint values and |
| 862 | 921 | // their inclusivity. `start included`/`end included` arrive as single joined |
| 863 | - // names (ADR-17). `start`/`end` clone the endpoint as-is, so an (eventual) | |
| 864 | - // unbounded endpoint surfaces as its stored null. An unknown property is a | |
| 865 | - // value-null, mirroring `temporal::get_property` (a range *has* properties). | |
| 922 | + // names (ADR-17). An *unbounded* endpoint (`None`; ADR-31) has no value — its | |
| 923 | + // `start`/`end` is `null` and it is never `included` (`±∞` is no member), so | |
| 924 | + // `[1..].end` is `null` and `[1..].end included` is `false` regardless of the | |
| 925 | + // (meaningless) bracket. An unknown property is a value-null, mirroring | |
| 926 | + // `temporal::get_property` (a range *has* properties). | |
| 866 | 927 | Value::Range(r) => match name { |
| 867 | - "start" => r.start.clone(), | |
| 868 | - "end" => r.end.clone(), | |
| 869 | - "start included" => Value::Boolean(!r.start_open), | |
| 870 | - "end included" => Value::Boolean(!r.end_open), | |
| 928 | + "start" => r.start.clone().unwrap_or(Value::Null), | |
| 929 | + "end" => r.end.clone().unwrap_or(Value::Null), | |
| 930 | + "start included" => Value::Boolean(r.start.is_some() && !r.start_open), | |
| 931 | + "end included" => Value::Boolean(r.end.is_some() && !r.end_open), | |
| 871 | 932 | _ => Value::Null, |
| 872 | 933 | }, |
| 873 | 934 | v if temporal::is_temporal(&v) => temporal::get_property(&v, name), |
modified crates/feel-core/src/feel.lalrpop +37 −13
| @@ -256,17 +256,37 @@ | ||
| 256 | 256 | // clashed with `List` on the bare `[` (build.rs's no-conflict gate proves this). |
| 257 | 257 | // The `in`-RHS *test* form keeps its own `Interval` rule below (a unary test, not a |
| 258 | 258 | // value), reachable only after `in`, so the two never share an LR state. |
| 259 | +// A range literal with optional, *unbounded* endpoints (ADR-31). The low endpoint is | |
| 260 | +// `Sum?`: present, or omitted when `..` follows the opener directly (`..` ∉ FIRST(Sum), | |
| 261 | +// so the choice is one-token-clean — and `]` after `[` is still the empty `List`). The | |
| 262 | +// high side is `HiEnd`, which carries either `Endpoint IntervalEnd` (bounded) or a bare | |
| 263 | +// `]`/`)` (unbounded high); see `HiEnd` for why the unbounded high cannot also take the | |
| 264 | +// reverse-close `[`. An omitted endpoint becomes `None` (≠ a present `null` bound). | |
| 259 | 265 | RangeLit: Expr = { |
| 260 | - "[" <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => | |
| 261 | - Expr::RangeLit(Interval { start_open: false, start: Box::new(lo), end: Box::new(hi), end_open: eo }), | |
| 262 | - "(" <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => | |
| 263 | - Expr::RangeLit(Interval { start_open: true, start: Box::new(lo), end: Box::new(hi), end_open: eo }), | |
| 266 | + "[" <lo:Sum?> ".." <hi:HiEnd> => | |
| 267 | + Expr::RangeLit(Interval { start_open: false, start: lo.map(Box::new), end: hi.0, end_open: hi.1 }), | |
| 268 | + "(" <lo:Sum?> ".." <hi:HiEnd> => | |
| 269 | + Expr::RangeLit(Interval { start_open: true, start: lo.map(Box::new), end: hi.0, end_open: hi.1 }), | |
| 264 | 270 | // Reverse-open `]a..b]` ≡ `(a..b]`: an exclusive lower bound spelt with a leading |
| 265 | 271 | // `]`. The lexer retags that opener to `RBracketOpen` (a distinct terminal), so |
| 266 | 272 | // this shares no LR state with the `]` closer — same start-openness as the `(` |
| 267 | - // form, the close bracket still chosen by `IntervalEnd`. | |
| 268 | - RBracketOpen <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => | |
| 269 | - Expr::RangeLit(Interval { start_open: true, start: Box::new(lo), end: Box::new(hi), end_open: eo }), | |
| 273 | + // form, the close bracket still chosen by `HiEnd`. | |
| 274 | + RBracketOpen <lo:Sum?> ".." <hi:HiEnd> => | |
| 275 | + Expr::RangeLit(Interval { start_open: true, start: lo.map(Box::new), end: hi.0, end_open: hi.1 }), | |
| 276 | +}; | |
| 277 | + | |
| 278 | +// The part of an interval *after* the `..`: the (optional) high endpoint together with | |
| 279 | +// the closing bracket's openness. Either a bounded endpoint followed by `IntervalEnd` | |
| 280 | +// (`]`/`)`/`[`), or — for an *unbounded* high (`[1..]`, `[1..)`; ADR-31) — a bare `]` | |
| 281 | +// or `)`. The unbounded case deliberately omits the reverse-close `[`: `[` is in | |
| 282 | +// FIRST(Endpoint) (a nested list/range high endpoint, `[1..[2..3]]`), so after `..` a | |
| 283 | +// `[` always shifts into `Endpoint`. That keeps the fork LR(1)-clean (build.rs gate); | |
| 284 | +// the rare `[1..[` is simply spelt `[1..)`. The bare `]`/`)` never clash with `Endpoint` | |
| 285 | +// (neither token is in FIRST(Endpoint)). | |
| 286 | +HiEnd: (Option<Box<Expr>>, bool) = { | |
| 287 | + <hi:Endpoint> <eo:IntervalEnd> => (Some(Box::new(hi)), eo), | |
| 288 | + "]" => (None, false), | |
| 289 | + ")" => (None, true), | |
| 270 | 290 | }; |
| 271 | 291 | |
| 272 | 292 | // Context literal `{a: 1, b: a + 1}`. Keys are a bare Name or a string literal |
| @@ -331,14 +351,18 @@ | ||
| 331 | 351 | InRhs: Vec<UnaryTest> = { |
| 332 | 352 | <op:CmpOp> <e:Sum> => vec![UnaryTest::Compare(op, Box::new(e))], |
| 333 | 353 | <e:NbSum> => vec![unary_test_from_expr(e)], |
| 334 | - "[" <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => | |
| 335 | - vec![UnaryTest::Interval(Interval { start_open: false, start: Box::new(lo), end: Box::new(hi), end_open: eo })], | |
| 336 | - "(" <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => | |
| 337 | - vec![UnaryTest::Interval(Interval { start_open: true, start: Box::new(lo), end: Box::new(hi), end_open: eo })], | |
| 354 | + // Interval *tests* with optional unbounded endpoints (ADR-31): `x in [1..]`, | |
| 355 | + // `x in [..10]`, `x in [..]`. Same `Sum?` / `HiEnd` factoring as the value-position | |
| 356 | + // `RangeLit` above; an omitted endpoint becomes `None` (an unconditionally-satisfied | |
| 357 | + // side), distinct from a present `null` bound (three-valued). | |
| 358 | + "[" <lo:Sum?> ".." <hi:HiEnd> => | |
| 359 | + vec![UnaryTest::Interval(Interval { start_open: false, start: lo.map(Box::new), end: hi.0, end_open: hi.1 })], | |
| 360 | + "(" <lo:Sum?> ".." <hi:HiEnd> => | |
| 361 | + vec![UnaryTest::Interval(Interval { start_open: true, start: lo.map(Box::new), end: hi.0, end_open: hi.1 })], | |
| 338 | 362 | // Reverse-open interval *test* `x in ]a..b]` (exclusive lower, ≡ `(a..b]`); the |
| 339 | 363 | // lexer's `RBracketOpen` opener keeps this off the `]`-closer LR state. |
| 340 | - RBracketOpen <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => | |
| 341 | - vec![UnaryTest::Interval(Interval { start_open: true, start: Box::new(lo), end: Box::new(hi), end_open: eo })], | |
| 364 | + RBracketOpen <lo:Sum?> ".." <hi:HiEnd> => | |
| 365 | + vec![UnaryTest::Interval(Interval { start_open: true, start: lo.map(Box::new), end: hi.0, end_open: hi.1 })], | |
| 342 | 366 | "[" <ts:Comma<UnaryTestElem>> "]" => ts, |
| 343 | 367 | "(" <ts:Comma<UnaryTestElem>> ")" => ts, |
| 344 | 368 | // Negation of a positive unary-test list, `x in not(t1, …)` (DMN rule 49). In the |
modified crates/feel-core/src/types.rs +6 −3
| @@ -27,11 +27,14 @@ | ||
| 27 | 27 | // concrete value here. |
| 28 | 28 | FeelType::Null | FeelType::Unknown => false, |
| 29 | 29 | // `range<T>`: a range value whose *both* endpoints conform to `T` (DMN |
| 30 | - // §10.3.4.6). Endpoints go through `conforms_nested`, so a null endpoint | |
| 31 | - // conforms to any `T` (Null <: T), matching the list/context rules. | |
| 30 | + // §10.3.4.6). Each present endpoint goes through `conforms_nested`, so a null | |
| 31 | + // endpoint conforms to any `T` (Null <: T), matching the list/context rules. | |
| 32 | + // An *unbounded* endpoint (`None`; ADR-31) has no type, so it conforms | |
| 33 | + // vacuously — `[1..] instance of range<number>` is true. | |
| 32 | 34 | FeelType::Range(elem) => match v { |
| 33 | 35 | Value::Range(r) => { |
| 34 | - conforms_nested(&r.start, elem) && conforms_nested(&r.end, elem) | |
| 36 | + r.start.as_ref().is_none_or(|s| conforms_nested(s, elem)) | |
| 37 | + && r.end.as_ref().is_none_or(|e| conforms_nested(e, elem)) | |
| 35 | 38 | } |
| 36 | 39 | _ => false, |
| 37 | 40 | }, |
modified crates/feel-core/src/value.rs +25 −11
| @@ -58,17 +58,28 @@ | ||
| 58 | 58 | Error, |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | -/// The payload of a [`Value::Range`]: two same-typed endpoints plus each bracket's | |
| 62 | -/// openness. A *well-formed* range has `start <= end` and both endpoints non-null of | |
| 63 | -/// the same orderable type; the constructors ([`crate::builtins`] `range`, the | |
| 64 | -/// `[a..b]` literal) enforce that, so consumers may assume it. | |
| 61 | +/// The payload of a [`Value::Range`]: two endpoints plus each bracket's openness. | |
| 62 | +/// | |
| 63 | +/// An endpoint is `None` when it is **unbounded** — `±∞`, a syntactically omitted | |
| 64 | +/// bound (`[1..]` is everything `≥ 1`, `[..10]` everything `≤ 10`; ADR-31). This is | |
| 65 | +/// distinct from a *present* `null` endpoint (`Some(Value::Null)`), which keeps the | |
| 66 | +/// three-valued "unknown" membership of `[null..10]`. The openness flag of an | |
| 67 | +/// unbounded side is meaningless (`±∞` is never a member) and is ignored by every | |
| 68 | +/// semantic operation (equality, `.start included`, the Allen relations); it is kept | |
| 69 | +/// only so `string([1..])` can echo the bracket the user wrote. | |
| 70 | +/// | |
| 71 | +/// A *well-formed* range has `start <= end` and any present endpoint non-null of the | |
| 72 | +/// same orderable type; the constructors ([`crate::builtins`] `range`, the `[a..b]` | |
| 73 | +/// literal) enforce that, so consumers may assume it. | |
| 65 | 74 | #[derive(Debug, Clone, PartialEq)] |
| 66 | 75 | pub struct RangeVal { |
| 67 | - pub start: Value, | |
| 68 | - pub end: Value, | |
| 69 | - /// `true` if the lower bound is *exclusive* (`(`/`]` start). | |
| 76 | + pub start: Option<Value>, | |
| 77 | + pub end: Option<Value>, | |
| 78 | + /// `true` if the lower bound is *exclusive* (`(`/`]` start). Meaningless when | |
| 79 | + /// `start` is `None` (unbounded). | |
| 70 | 80 | pub start_open: bool, |
| 71 | - /// `true` if the upper bound is *exclusive* (`)`/`[` end). | |
| 81 | + /// `true` if the upper bound is *exclusive* (`)`/`[` end). Meaningless when `end` | |
| 82 | + /// is `None` (unbounded). | |
| 72 | 83 | pub end_open: bool, |
| 73 | 84 | } |
| 74 | 85 | |
| @@ -80,7 +91,10 @@ | ||
| 80 | 91 | Value::Error => true, |
| 81 | 92 | Value::List(items) => items.iter().any(Value::contains_error), |
| 82 | 93 | Value::Context(map) => map.values().any(Value::contains_error), |
| 83 | - Value::Range(r) => r.start.contains_error() || r.end.contains_error(), | |
| 94 | + Value::Range(r) => { | |
| 95 | + r.start.as_ref().is_some_and(Value::contains_error) | |
| 96 | + || r.end.as_ref().is_some_and(Value::contains_error) | |
| 97 | + } | |
| 84 | 98 | _ => false, |
| 85 | 99 | } |
| 86 | 100 | } |
| @@ -114,8 +128,8 @@ | ||
| 114 | 128 | .collect(), |
| 115 | 129 | ), |
| 116 | 130 | Value::Range(r) => Value::Range(Box::new(RangeVal { |
| 117 | - start: r.start.into_lenient(), | |
| 118 | - end: r.end.into_lenient(), | |
| 131 | + start: r.start.map(Value::into_lenient), | |
| 132 | + end: r.end.map(Value::into_lenient), | |
| 119 | 133 | ..*r |
| 120 | 134 | })), |
| 121 | 135 | other => other, |
modified crates/feel-lua/src/lib.rs +6 −4
| @@ -380,11 +380,13 @@ | ||
| 380 | 380 | // A range has no native Lua type; hand it back as a table carrying DMN's |
| 381 | 381 | // four range properties (§10.3.4.6), so `r["start included"]` reads naturally. |
| 382 | 382 | Value::Range(r) => { |
| 383 | + // An unbounded endpoint (`[1..]`/`[..10]`; ADR-31) maps to host `null` and | |
| 384 | + // is never `included` (`±∞` is no member), regardless of the bracket. | |
| 383 | 385 | let t = lua.create_table()?; |
| 384 | - t.set("start", value_to_lua(lua, &r.start)?)?; | |
| 385 | - t.set("end", value_to_lua(lua, &r.end)?)?; | |
| 386 | - t.set("start included", !r.start_open)?; | |
| 387 | - t.set("end included", !r.end_open)?; | |
| 386 | + t.set("start", value_to_lua(lua, r.start.as_ref().unwrap_or(&Value::Null))?)?; | |
| 387 | + t.set("end", value_to_lua(lua, r.end.as_ref().unwrap_or(&Value::Null))?)?; | |
| 388 | + t.set("start included", r.start.is_some() && !r.start_open)?; | |
| 389 | + t.set("end included", r.end.is_some() && !r.end_open)?; | |
| 388 | 390 | LuaValue::Table(t) |
| 389 | 391 | } |
| 390 | 392 | Value::Date(_) |
modified crates/feel-py/src/lib.rs +6 −4
| @@ -470,11 +470,13 @@ | ||
| 470 | 470 | // A range has no native Python type; hand it back as a dict carrying DMN's |
| 471 | 471 | // four range properties (§10.3.4.6), so `r["start included"]` reads naturally. |
| 472 | 472 | Value::Range(r) => { |
| 473 | + // An unbounded endpoint (`[1..]`/`[..10]`; ADR-31) maps to host `None` and | |
| 474 | + // is never `included` (`±∞` is no member), regardless of the bracket. | |
| 473 | 475 | let dict = PyDict::new(py); |
| 474 | - dict.set_item("start", value_to_py(py, &r.start)?)?; | |
| 475 | - dict.set_item("end", value_to_py(py, &r.end)?)?; | |
| 476 | - dict.set_item("start included", !r.start_open)?; | |
| 477 | - dict.set_item("end included", !r.end_open)?; | |
| 476 | + dict.set_item("start", value_to_py(py, r.start.as_ref().unwrap_or(&Value::Null))?)?; | |
| 477 | + dict.set_item("end", value_to_py(py, r.end.as_ref().unwrap_or(&Value::Null))?)?; | |
| 478 | + dict.set_item("start included", r.start.is_some() && !r.start_open)?; | |
| 479 | + dict.set_item("end included", r.end.is_some() && !r.end_open)?; | |
| 478 | 480 | dict.into_any() |
| 479 | 481 | } |
| 480 | 482 | Value::Date(d) => { |