fix(core): range() honours grammar rule 66 — open bracket on omitted endpoint
public
fix(core): range() honours grammar rule 66 — open bracket on omitted endpoint
The `range()` string builtin was rejecting *every* unbounded endpoint, but FEEL
grammar rule 66 (b)/(c) allows an omitted endpoint with an OPEN bracket on that
side: `range("[2..)")` ≡ `>=2`, `range("(..2)")` ≡ `<2` (spec §10.3.4.6
examples). Only a CLOSED bracket with no value, or both endpoints omitted, is
invalid: `range("[..2]")`/`range("[1..]")` (DMN-TCK 1156 004_e/004_f),
`range("[..]")`, `range("(..)")`. The committed 1156 fixture only exercises the
closed-bracket null cases, so the over-strict behaviour was TCK-invisible.
Clarify the subset/superset story in ADR-31: the bracket-with-omitted-endpoint
spelling is rule-66-only (the language proper writes `>= 1`); feel-core lifts it
into value/`in`-test literals as a deliberate, lenient superset, while range()
stays a faithful rule-66 subset.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| Changeset | 919af3c77f9a0a5b7bc320bbc270885286473c27 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | 3122be328901 |
| Children | |
| Pushlog | by timo via ssh |
modified DECISIONS.md +23 −6
| @@ -1115,11 +1115,19 @@ | ||
| 1115 | 1115 | (`[` ∈ FIRST(Endpoint), so after `..` a `[` always shifts into a nested-endpoint parse); |
| 1116 | 1116 | the rare `[1..[` is simply spelt `[1..)`. Reused verbatim by `RangeLit` (value position) |
| 1117 | 1117 | and the `InRhs` interval *tests*. |
| 1118 | - - **`range()` string builtin stays STRICT — it rejects an omitted endpoint.** This is the | |
| 1119 | - one surprise: DMN-TCK 1156 `004_e`/`004_f` make `range("[..2]")` and `range("[1..]")` | |
| 1120 | - **null**. So the unbounded feature lives in *literal/value* position and membership, but | |
| 1121 | - the `range()` function still requires both endpoints present (the closed loop is ground | |
| 1122 | - truth; the function-vs-literal asymmetry is the TCK's, not ours). | |
| 1118 | + - **`range()` string builtin follows FEEL grammar rule 66 exactly — an omitted endpoint | |
| 1119 | + needs an OPEN bracket.** Rule 66 has three alternatives: (a) both endpoints present, | |
| 1120 | + (b) `open start ".." endpoint end` (lower omitted, open start), (c) `start ".." endpoint | |
| 1121 | + open end` (upper omitted, open end). So `range("[2..)")` ≡ `>=2` and `range("(..2)")` ≡ | |
| 1122 | + `<2` are valid (spec §10.3.4.6 examples), while a *closed* bracket with no value, or | |
| 1123 | + *both* endpoints omitted, is null: `range("[..2]")` / `range("[1..]")` (DMN-TCK 1156 | |
| 1124 | + `004_e`/`004_f`, described as "closed … endpoint with no value is not valid") plus | |
| 1125 | + `range("[..]")` / `range("(..)")`. This is **stricter** than the lenient unbounded | |
| 1126 | + *literal* `[..2]` in value position (which accepts any bracket): the spec's grammar for | |
| 1127 | + bracket-with-omitted-endpoint lives only inside the `range()` string (rule 66) — the | |
| 1128 | + language proper expresses an unbounded range via a comparison operator (`>= 1`, mapped to | |
| 1129 | + a one-endpoint range, spec §10.3.2.7), not a bracket literal. feel-core lifting the | |
| 1130 | + bracket spelling into value/test position is the superset (next bullet). | |
| 1123 | 1131 | - **Tests:** the unit test `unbounded_ranges` covers membership (incl. the `[..10]` ≠ |
| 1124 | 1132 | `[null..10]` distinction both ways), value-position equality, range properties, `instance |
| 1125 | 1133 | of`, `string(...)` rendering, and the Allen relations over unbounded operands. |
| @@ -1127,9 +1135,18 @@ | ||
| 1127 | 1135 | ingester's structural `..`-scan already admitted unbounded forms (the `..` still sits inside |
| 1128 | 1136 | its bracket group); 0072 / 1156 re-ingest produced **no** fixture change, and the closed |
| 1129 | 1137 | loop (`fixtures_test`) stays green. |
| 1138 | +- **Subset vs. superset:** the spec proper has *no* bracket-with-omitted-endpoint literal in | |
| 1139 | + value/test position — an unbounded range there is written `>= 1` / `< 10` (a comparison that | |
| 1140 | + maps to a one-endpoint range, §10.3.2.7). The bracket spelling `[1..]` / `(..2)` is only the | |
| 1141 | + `range()`-string grammar (rule 66). feel-core therefore **leniently extends** that bracket | |
| 1142 | + spelling into value-position and `in`-test literals (`[1..]`, `[..10]`, even `[..]`, any | |
| 1143 | + bracket) — a deliberate *superset* for ergonomics, with the spec's semantics (an unbounded | |
| 1144 | + side's inclusivity flag is false, §10.3.2.7). The `range()` *function* stays a faithful | |
| 1145 | + *subset*-tight implementation of rule 66 (open-bracket required, ≤ one omitted endpoint). | |
| 1130 | 1146 | - **Consequence:** every §10.3.4.6 range *grammar* form is now in. The only remaining range |
| 1131 | 1147 | deferral is the opaque comparison-test *value* `(< 10)` in value position (ADR-28's measured |
| 1132 | - semantics; needs a new `Value` variant), which is unrelated to endpoints. | |
| 1148 | + semantics; needs a new `Value` variant), which is unrelated to endpoints — and which, once | |
| 1149 | + built, is the spec-canonical *value* form of an unbounded range. | |
| 1133 | 1150 | |
| 1134 | 1151 | ## Adding a wrapper — the host-binding contract |
| 1135 | 1152 | |
modified crates/feel-core/src/builtins.rs +30 −15
| @@ -614,14 +614,24 @@ | ||
| 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 | - // 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)) | |
| 617 | + // The `range()` string follows FEEL grammar rule 66 ("range literal") to the | |
| 618 | + // letter: a *present* endpoint must be a self-contained literal, and an | |
| 619 | + // *omitted* endpoint is allowed only with an OPEN bracket on that side — | |
| 620 | + // alternatives (b) `open start ".." endpoint end` and (c) `start ".." | |
| 621 | + // endpoint open end`. So `range("[2..)")` (≡ `>=2`) and `range("(..2)")` | |
| 622 | + // (≡ `<2`) are valid, but a CLOSED bracket with no value, or BOTH endpoints | |
| 623 | + // omitted (no rule-66 alternative), is null: `range("[..2]")` / `range("[1..]")` | |
| 624 | + // (DMN-TCK 1156 004_e/004_f) and `range("[..]")` / `range("(..)")`. This is | |
| 625 | + // stricter than the lenient unbounded *literal* `[..2]` in value position | |
| 626 | + // (ADR-31), which accepts any bracket. | |
| 627 | + let side_ok = |e: &Option<Box<crate::ast::Expr>>, open: bool| match e { | |
| 628 | + Some(e) => range_endpoint_is_literal(e), | |
| 629 | + None => open, // omitted ⇒ the bracket on that side must be open | |
| 623 | 630 | }; |
| 624 | - if !lit_ok(&iv.start) || !lit_ok(&iv.end) { | |
| 631 | + if matches!((&iv.start, &iv.end), (None, None)) | |
| 632 | + || !side_ok(&iv.start, iv.start_open) | |
| 633 | + || !side_ok(&iv.end, iv.end_open) | |
| 634 | + { | |
| 625 | 635 | return Value::Error; |
| 626 | 636 | } |
| 627 | 637 | } |
| @@ -633,14 +643,19 @@ | ||
| 633 | 643 | Ok(Value::Range(r)) => r, |
| 634 | 644 | _ => return Value::Error, |
| 635 | 645 | }; |
| 636 | - // A well-formed range has two comparable (same orderable type, non-null) endpoints | |
| 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 | - } | |
| 643 | - _ => Value::Error, | |
| 646 | + // A well-formed range has, for every *present* endpoint, an orderable non-null | |
| 647 | + // value, and — when both are present — the two in non-descending order. An | |
| 648 | + // unbounded side imposes no ordering. `feel_order` returns `None` for | |
| 649 | + // null/mismatched types, so `range("[null..)")` and `range("[1..\"b\"]")` stay null. | |
| 650 | + let ok = match (&r.start, &r.end) { | |
| 651 | + (Some(s), Some(e)) => matches!(feel_order(s, e), Some(ord) if ord != Ordering::Greater), | |
| 652 | + (Some(v), None) | (None, Some(v)) => feel_order(v, v).is_some(), | |
| 653 | + (None, None) => false, // gated above; unreachable | |
| 654 | + }; | |
| 655 | + if ok { | |
| 656 | + Value::Range(r) | |
| 657 | + } else { | |
| 658 | + Value::Error | |
| 644 | 659 | } |
| 645 | 660 | } |
| 646 | 661 | |
modified crates/feel-core/src/lib.rs +17 −5
| @@ -554,6 +554,14 @@ | ||
| 554 | 554 | b(true) |
| 555 | 555 | ); |
| 556 | 556 | assert_eq!(ev(r#"range("[@\"P1D\"..@\"P2D\"]") instance of range<days and time duration>"#), b(true)); |
| 557 | + // Unbounded via the OPEN-bracket spelling is valid per FEEL grammar rule 66 | |
| 558 | + // (b)/(c): `range("[2..)")` ≡ `>=2`, `range("(..2)")` ≡ `<2` (spec §10.3.4.6 | |
| 559 | + // examples). A CLOSED bracket on the omitted side is invalid (the null cases | |
| 560 | + // below). See ADR-31. | |
| 561 | + assert_eq!(ev(r#"range("[2..)") = [2..)"#), b(true)); | |
| 562 | + assert_eq!(ev(r#"range("(..2)") = (..2)"#), b(true)); | |
| 563 | + assert_eq!(ev(r#"5 in range("[2..)")"#), b(true)); | |
| 564 | + assert_eq!(ev(r#"5 in range("(..2)")"#), b(false)); | |
| 557 | 565 | |
| 558 | 566 | // --- error/null cases (lenient view collapses error-null to null) --- |
| 559 | 567 | for src in [ |
| @@ -566,11 +574,15 @@ | ||
| 566 | 574 | r#"range("[1..\"b\"]")"#, // mismatched endpoint types |
| 567 | 575 | r#"range("[3..1]")"#, // reversed |
| 568 | 576 | r#"range("[null..null]")"#, // null endpoints |
| 569 | - // Unbounded endpoints: the `range()` string builtin requires BOTH endpoints | |
| 570 | - // (DMN-TCK 1156 004_e/004_f) — unlike the unbounded *literal* `[..2]` | |
| 571 | - // (ADR-31, exercised in `unbounded_ranges`), the function stays strict. | |
| 572 | - r#"range("[..2]")"#, // unbounded lower → null in range() | |
| 573 | - r#"range("[1..]")"#, // unbounded upper → null in range() | |
| 577 | + // Omitted endpoint with a CLOSED bracket is invalid (rule 66 needs an OPEN | |
| 578 | + // bracket on the unbounded side); both-omitted has no rule-66 alternative. | |
| 579 | + // Unlike the lenient unbounded *literal* `[..2]` (ADR-31, in | |
| 580 | + // `unbounded_ranges`), the `range()` string is strict here. | |
| 581 | + r#"range("[..2]")"#, // closed start, no value → null (TCK 004_e) | |
| 582 | + r#"range("[1..]")"#, // closed end, no value → null (TCK 004_f) | |
| 583 | + r#"range("[..]")"#, // both omitted, both closed → null | |
| 584 | + r#"range("(..)")"#, // both omitted → null (no rule-66 case) | |
| 585 | + r#"range("[null..)")"#, // present null lower bound → null | |
| 574 | 586 | r#"range("[date(string(\"1970-01-01\"))..date(\"1970-01-02\")]")"#, // non-literal endpoint |
| 575 | 587 | r#"range(fron: "[1..3]")"#, // unknown named parameter |
| 576 | 588 | ] { |