| @@ -1078,71 +1078,74 @@ |
| 1078 | 1078 | purely semantic-value work, not grammar: unbounded omitted-endpoint ranges `[1..]` / |
| 1079 | 1079 | `[..10]` and the opaque comparison-test value `(< 10)` in value position (both ADR-29). |
| 1080 | 1080 | |
| 1081 | | -## ADR-31: Unbounded omitted-endpoint ranges — `[1..]` / `[..10]` (DMN §10.3.4.6) |
| 1081 | +## ADR-31: Unbounded omitted-endpoint ranges — `[1..)` / `(..10]` (DMN §10.3.4.6) |
| 1082 | 1082 | |
| 1083 | 1083 | - **Context:** the most invasive of the three range deferrals (ADR-27 → ADR-30). A range |
| 1084 | | - endpoint may be *omitted*, denoting an **unbounded** bound, `±∞`: `[1..]` is everything |
| 1085 | | - `≥ 1`, `[..10]` everything `≤ 10`, `[..]` everything. This is **semantically distinct** |
| 1084 | + endpoint may be *omitted*, denoting an **unbounded** bound, `±∞`: `[1..)` is everything |
| 1085 | + `≥ 1`, `(..10]` everything `≤ 10`, `(..)` everything. This is **semantically distinct** |
| 1086 | 1086 | from a *present* `null` endpoint: `[null..10]` keeps the three-valued "unknown" membership |
| 1087 | | - (`5 in [null..10]` ⇒ null, per DMN-TCK 0072), while `[..10]` is a definite bound |
| 1088 | | - (`5 in [..10]` ⇒ true). The two must never collapse to the same representation. Unlike the |
| 1087 | + (`5 in [null..10]` ⇒ null, per DMN-TCK 0072), while `(..10]` is a definite bound |
| 1088 | + (`5 in (..10]` ⇒ true). The two must never collapse to the same representation. Unlike the |
| 1089 | 1089 | earlier range work this ripples through *every* layer — AST, value, eval, builtins, |
| 1090 | 1090 | grammar, the host wrappers — because both endpoints become optional everywhere. |
| 1091 | | -- **Decision:** model an omitted endpoint as `None`, kept rigorously apart from `Some(null)`. |
| 1091 | +- **Decision:** model an omitted endpoint as `None`, kept rigorously apart from `Some(null)`, |
| 1092 | + and require — everywhere, literal *and* `range()` — an **open bracket** on the omitted side |
| 1093 | + (FEEL grammar rule 66, §10.3.2.7: an unbounded bound has its inclusivity flag false). |
| 1092 | 1094 | - **AST `Interval.start`/`.end` → `Option<Box<Expr>>`; value `RangeVal.start`/`.end` → |
| 1093 | 1095 | `Option<Value>`** (`None` = unbounded). `RangeVal` is still boxed behind |
| 1094 | 1096 | `Value::Range(Box<RangeVal>)`, so `Value` stays 40 bytes (the `value_size_did_not_grow` |
| 1095 | 1097 | guard is untouched). A present `null` bound evaluates to `Some(Value::Null)`; only a |
| 1096 | 1098 | *syntactically* omitted endpoint is `None`. |
| 1097 | | - - **Openness of an unbounded side is meaningless and ignored.** `±∞` is never a member, so |
| 1098 | | - the bracket written there carries no semantics. Equality compares the openness flag only |
| 1099 | | - where a side is *bounded* (`[1..]` = `[1..)`, both `[1, +∞)`; but `[1..]` ≠ `[1..10]`, and |
| 1100 | | - `[..10]` ≠ `[null..10]`); `.start included`/`.end included` of an unbounded side is |
| 1101 | | - `false`; `.start`/`.end` of it is `null`. The flag is *stored* as written only so |
| 1102 | | - `string([1..])` can echo the user's bracket. |
| 1099 | + - **An omitted endpoint requires an OPEN bracket on that side (rule 66).** `[1..)`, |
| 1100 | + `(..10]`, `]1..)` are valid; `[1..]` / `[..10]` (a *closed* bracket with no value) are |
| 1101 | + **parse errors**, exactly as `range("[1..]")` is null (next-but-one bullet). Since only an |
| 1102 | + open bracket is writable there, an unbounded side's openness flag is always "open" — and |
| 1103 | + is in any case ignored by every semantic operation (`±∞` is no member): equality compares |
| 1104 | + the flag only where a side is *bounded* (`[1..)` ≠ `[1..10]`, `(..10]` ≠ `[null..10]`); |
| 1105 | + `.start included`/`.end included` of an unbounded side is `false`; `.start`/`.end` of it |
| 1106 | + is `null`. The flag is *stored* as written only so `string([1..))` echoes the bracket. |
| 1103 | 1107 | - **Eval.** `range_contains` takes `Option<&Value>` per side — a `None` side is satisfied |
| 1104 | | - unconditionally (so `5 in [1..]`/`5 in [..10]` are true), a `Some(null)` side still goes |
| 1108 | + unconditionally (so `5 in [1..)`/`5 in (..10]` are true), a `Some(null)` side still goes |
| 1105 | 1109 | three-valued. `instance of range<T>` treats an unbounded side as vacuously conforming |
| 1106 | 1110 | (the bounded side types the range, like a null/empty slot). The §10.3.4.6 Allen relations |
| 1107 | 1111 | view each operand through a `Bound { NegInf, Val, PosInf }` (an omitted lower = `NegInf`, |
| 1108 | 1112 | upper = `PosInf`); `±∞` compares below/above every value and two same-sign `±∞` are equal, |
| 1109 | | - so `before([..5],[10..])`, `includes([..],[3..7])`, `coincides([..5],(..5])` need no |
| 1113 | + so `before((..5],[10..))`, `includes((..),[3..7])`, `coincides((..5],]..5])` need no |
| 1110 | 1114 | further special-casing. |
| 1111 | | - - **Grammar (LR(1)-clean, build.rs gate).** Endpoints become optional via `Sum?` for the |
| 1112 | | - low side (`..` ∉ FIRST(Sum), and `[` after the opener is still the empty `List`) and a |
| 1113 | | - new `HiEnd` nonterminal for the high side: `Endpoint IntervalEnd` (bounded) **or** a bare |
| 1114 | | - `]`/`)` (unbounded). The unbounded-high case deliberately omits the reverse-close `[` |
| 1115 | | - (`[` ∈ FIRST(Endpoint), so after `..` a `[` always shifts into a nested-endpoint parse); |
| 1116 | | - the rare `[1..[` is simply spelt `[1..)`. Reused verbatim by `RangeLit` (value position) |
| 1117 | | - and the `InRhs` interval *tests*. |
| 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). |
| 1131 | | -- **Tests:** the unit test `unbounded_ranges` covers membership (incl. the `[..10]` ≠ |
| 1132 | | - `[null..10]` distinction both ways), value-position equality, range properties, `instance |
| 1133 | | - of`, `string(...)` rendering, and the Allen relations over unbounded operands. |
| 1134 | | - `range_builtin` keeps `range("[..2]")`/`range("[1..]")` as null cases (matching 1156). The |
| 1135 | | - ingester's structural `..`-scan already admitted unbounded forms (the `..` still sits inside |
| 1136 | | - its bracket group); 0072 / 1156 re-ingest produced **no** fixture change, and the closed |
| 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). |
| 1115 | + - **Grammar (LR(1)-clean, build.rs gate).** A new `HiEnd` nonterminal carries the part after |
| 1116 | + `..`: `Endpoint IntervalEnd` (bounded, any close bracket) **or** the bare open `")"` |
| 1117 | + (unbounded high). The *closed* opener `"["` keeps its low endpoint **mandatory** (`Sum`); |
| 1118 | + the *open* openers `"("` / `]`(RBracketOpen) take it optional (`Sum?`). So a closed bracket |
| 1119 | + on an omitted side has no production — `[1..]` / `[..10]` simply don't parse. The |
| 1120 | + unbounded-high form is `")"` only: no `"]"` (closed) and no reverse-close `"["` (`[` ∈ |
| 1121 | + FIRST(Endpoint), so after `..` a `[` always shifts into a nested-endpoint parse — the rare |
| 1122 | + `[1..[` is spelt `[1..)`). Reused verbatim by `RangeLit` (value position) and the `InRhs` |
| 1123 | + interval *tests*. (`..` ∉ FIRST(Sum) keeps the optional-low choice one-token-clean.) |
| 1124 | + - **`range()` string builtin follows the SAME rule 66.** Rule 66 alternatives: (a) both |
| 1125 | + endpoints present, (b) `open start ".." endpoint end`, (c) `start ".." endpoint open end`. |
| 1126 | + So `range("[2..)")` ≡ `>=2` and `range("(..2)")` ≡ `<2` are valid (spec §10.3.4.6 |
| 1127 | + examples), while a closed bracket with no value, or *both* endpoints omitted, is null: |
| 1128 | + `range("[..2]")` / `range("[1..]")` (DMN-TCK 1156 `004_e`/`004_f`, "closed … endpoint with |
| 1129 | + no value is not valid") plus `range("[..]")` / `range("(..)")`. (range() additionally |
| 1130 | + rejects `(..)`/both-omitted, which has no rule-66 alternative; the *literal* `(..)` — the |
| 1131 | + universal range — is the one deliberate lenience, see below.) |
| 1132 | +- **One uniform rule, one small lenience.** Literal *and* `range()` now obey rule 66's |
| 1133 | + open-bracket requirement, so there is no `[1..]`-parses-but-`range("[1..]")`-is-null |
| 1134 | + surprise. The single difference: the *literal* `(..)` (both endpoints omitted, both open) is |
| 1135 | + accepted as the universal range `(-∞,+∞)` — harmless and occasionally handy — whereas |
| 1136 | + `range("(..)")` is null (rule 66 has no both-omitted alternative, and the function mirrors |
| 1137 | + the string grammar exactly). Note the spec's *canonical* unbounded value is actually the |
| 1138 | + comparison `>= 1` / `< 10` (mapped to a one-endpoint range, §10.3.2.7); the bracket spelling |
| 1139 | + is rule-66 sugar that feel-core makes available in value/test position too. |
| 1140 | +- **Tests:** `unbounded_ranges` covers membership (incl. the `(..10]` ≠ `[null..10]` |
| 1141 | + distinction both ways), value-position equality, range properties, `instance of`, |
| 1142 | + `string(...)` rendering, and the Allen relations over unbounded operands; |
| 1143 | + `unbounded_closed_bracket_is_a_parse_error` pins the rule-66 rejection of `[1..]` / `[..10]`. |
| 1144 | + `range_builtin` covers the open-bracket `range("[2..)")` ≡ `>=2` plus the closed-bracket / |
| 1145 | + both-omitted null cases (1156). The ingester's structural `..`-scan still admits unbounded |
| 1146 | + forms (the open-bracket requirement is the parser's job, and the DMN-TCK has no |
| 1147 | + value-position unbounded literal — `range("…")` strings are blanked); 0072 / 1156 re-ingest |
| 1148 | + produced **no** fixture change, and the closed loop (`fixtures_test`) stays green. |
| 1146 | 1149 | - **Consequence:** every §10.3.4.6 range *grammar* form is now in. The only remaining range |
| 1147 | 1150 | deferral is the opaque comparison-test *value* `(< 10)` in value position (ADR-28's measured |
| 1148 | 1151 | semantics; needs a new `Value` variant), which is unrelated to endpoints — and which, once |