refactor(core): reject the `(..)` both-unbounded literal too (rule 66 uniform)
public
refactor(core): reject the `(..)` both-unbounded literal too (rule 66 uniform)
Drop the last range inconsistency: the literal `(..)` (both endpoints omitted)
was accepted as a universal range while `range("(..)")` was null. FEEL grammar
rule 66 has no both-omitted alternative, so neither should exist — `(..)` is now
a parse error everywhere, exactly like the closed-bracket `[1..]`.
Grammar: each open opener `"("` / `]` splits into a present-low form (any
`HiEnd`) and an omitted-low form (`"(" ".."`) that takes an inline *bounded*
high (`Endpoint IntervalEnd`); there is thus no production pairing an omitted low
with an unbounded high. LR(1)-clean (build.rs gate). `range()` parses through the
same grammar, so `range("(..)")` already fails at compile; its in-fn check is now
defensive only.
One uniform rule, no exceptions: every malformed range literal is a parse error,
every malformed range() string is null. ADR-31 / ROADMAP updated;
`unbounded_closed_bracket_is_a_parse_error` now also pins `(..)`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| Changeset | bfa3526ce9511d2962300c5e8471b6b25f44e241 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | 4ba2d8c9764c |
| Children | |
| Pushlog | by timo via ssh |
modified DECISIONS.md +32 −26
| @@ -1082,7 +1082,7 @@ | ||
| 1082 | 1082 | |
| 1083 | 1083 | - **Context:** the most invasive of the three range deferrals (ADR-27 → ADR-30). A range |
| 1084 | 1084 | endpoint may be *omitted*, denoting an **unbounded** bound, `±∞`: `[1..)` is everything |
| 1085 | - `≥ 1`, `(..10]` everything `≤ 10`, `(..)` everything. This is **semantically distinct** | |
| 1085 | + `≥ 1`, `(..10]` everything `≤ 10`. This is **semantically distinct** | |
| 1086 | 1086 | from a *present* `null` endpoint: `[null..10]` keeps the three-valued "unknown" membership |
| 1087 | 1087 | (`5 in [null..10]` ⇒ null, per DMN-TCK 0072), while `(..10]` is a definite bound |
| 1088 | 1088 | (`5 in (..10]` ⇒ true). The two must never collapse to the same representation. Unlike the |
| @@ -1096,10 +1096,12 @@ | ||
| 1096 | 1096 | `Value::Range(Box<RangeVal>)`, so `Value` stays 40 bytes (the `value_size_did_not_grow` |
| 1097 | 1097 | guard is untouched). A present `null` bound evaluates to `Some(Value::Null)`; only a |
| 1098 | 1098 | *syntactically* omitted endpoint is `None`. |
| 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 | |
| 1099 | + - **An omitted endpoint requires an OPEN bracket on that side, and at most one may be | |
| 1100 | + omitted (rule 66).** `[1..)`, `(..10]`, `]1..)` are valid; `[1..]` / `[..10]` (a *closed* | |
| 1101 | + bracket with no value) and `(..)` (both omitted — no rule-66 alternative) are **parse | |
| 1102 | + errors**, exactly as `range("[1..]")` / `range("(..)")` are null (next-but-one bullet). | |
| 1103 | + Since only an open bracket is writable there, an unbounded side's openness flag is always | |
| 1104 | + "open" — and | |
| 1103 | 1105 | is in any case ignored by every semantic operation (`±∞` is no member): equality compares |
| 1104 | 1106 | the flag only where a side is *bounded* (`[1..)` ≠ `[1..10]`, `(..10]` ≠ `[null..10]`); |
| 1105 | 1107 | `.start included`/`.end included` of an unbounded side is `false`; `.start`/`.end` of it |
| @@ -1110,33 +1112,37 @@ | ||
| 1110 | 1112 | (the bounded side types the range, like a null/empty slot). The §10.3.4.6 Allen relations |
| 1111 | 1113 | view each operand through a `Bound { NegInf, Val, PosInf }` (an omitted lower = `NegInf`, |
| 1112 | 1114 | upper = `PosInf`); `±∞` compares below/above every value and two same-sign `±∞` are equal, |
| 1113 | - so `before((..5],[10..))`, `includes((..),[3..7])`, `coincides((..5],]..5])` need no | |
| 1115 | + so `before((..5],[10..))`, `includes((..7],[3..7])`, `coincides((..5],]..5])` need no | |
| 1114 | 1116 | further special-casing. |
| 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.) | |
| 1117 | + - **Grammar (LR(1)-clean, build.rs gate).** A `HiEnd` nonterminal carries the part after | |
| 1118 | + `..` for a *present-low* range: `Endpoint IntervalEnd` (bounded, any close bracket) **or** | |
| 1119 | + the bare open `")"` (unbounded high, rule 66 (c)). The *closed* opener `"["` keeps its low | |
| 1120 | + endpoint **mandatory** (`Sum`). Each *open* opener `"("` / `]`(RBracketOpen) **splits in | |
| 1121 | + two**: a *present* low (`Sum`) takes any `HiEnd`; an *omitted* low (`"(" ".."`) takes an | |
| 1122 | + inline *bounded* high (`Endpoint IntervalEnd`, rule 66 (b)). That split is what forbids the | |
| 1123 | + both-omitted `(..)` — there is simply no production for it — while a closed bracket on an | |
| 1124 | + omitted side (`[1..]` / `[..10]`) never had one. The unbounded-high `")"` carries no `"]"` | |
| 1125 | + (closed) and no reverse-close `"["` (`[` ∈ FIRST(Endpoint), so after `..` a `[` always | |
| 1126 | + shifts into a nested-endpoint parse — the rare `[1..[` is spelt `[1..)`). Reused verbatim by | |
| 1127 | + `RangeLit` (value position) and the `InRhs` interval *tests*. (`..` ∉ FIRST(Sum) keeps the | |
| 1128 | + present-vs-omitted-low choice one-token-clean.) | |
| 1124 | 1129 | - **`range()` string builtin follows the SAME rule 66.** Rule 66 alternatives: (a) both |
| 1125 | 1130 | endpoints present, (b) `open start ".." endpoint end`, (c) `start ".." endpoint open end`. |
| 1126 | 1131 | So `range("[2..)")` ≡ `>=2` and `range("(..2)")` ≡ `<2` are valid (spec §10.3.4.6 |
| 1127 | 1132 | examples), while a closed bracket with no value, or *both* endpoints omitted, is null: |
| 1128 | 1133 | `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. | |
| 1134 | + no value is not valid"), `range("[..]")`, `range("(..)")`. Because `range()` parses its | |
| 1135 | + string through the *same* value-position grammar, these strings already fail at `compile`; | |
| 1136 | + the in-`range_fn` checks are defensive belt-and-suspenders. | |
| 1137 | +- **One uniform rule, no exceptions.** Literal *and* `range()` obey rule 66 identically — an | |
| 1138 | + omitted endpoint needs an open bracket, and at most one endpoint may be omitted. So every | |
| 1139 | + malformed range *literal* is a parse error and every malformed `range()` *string* is null, | |
| 1140 | + with no `[1..]`-parses-but-`range("[1..]")`-is-null surprise and no special-cased `(..)`. (An | |
| 1141 | + earlier draft accepted the literal `(..)` as a universal-range convenience; it was dropped | |
| 1142 | + for this uniformity — the spec has no both-unbounded surface syntax anyway.) The spec's | |
| 1143 | + *canonical* unbounded value is in fact the comparison `>= 1` / `< 10` (mapped to a | |
| 1144 | + one-endpoint range, §10.3.2.7); the bracket spelling is rule-66 sugar that feel-core makes | |
| 1145 | + available in value/test position too. | |
| 1140 | 1146 | - **Tests:** `unbounded_ranges` covers membership (incl. the `(..10]` ≠ `[null..10]` |
| 1141 | 1147 | distinction both ways), value-position equality, range properties, `instance of`, |
| 1142 | 1148 | `string(...)` rendering, and the Allen relations over unbounded operands; |
modified ROADMAP.md +15 −14
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | ingester does not read). **Comma-list-of-tests `in` now also shipped (ADR-28)**, and |
| 25 | 25 | **reverse-bracket interval literals (`]a..b]` / `[a..b[`) + range properties (`.start` |
| 26 | 26 | / `.end` / `.start included` / `.end included`) now shipped (ADR-29)** — see below. |
| 27 | -**Unbounded omitted-endpoint ranges (`[1..)` / `(..10]` / `(..)`, distinct from a `null` | |
| 27 | +**Unbounded omitted-endpoint ranges (`[1..)` / `(..10]`, distinct from a `null` | |
| 28 | 28 | bound) now shipped (ADR-31)** — see below. **Still deferred:** only the |
| 29 | 29 | comparison-test-as-range *value* (`(< 10)` in value position) — reshaped by a TCK |
| 30 | 30 | measurement (below). |
| @@ -150,19 +150,20 @@ | ||
| 150 | 150 | |
| 151 | 151 | ### Shipped: unbounded omitted-endpoint ranges (ADR-31) |
| 152 | 152 | |
| 153 | -`[1..)` / `(..10]` / `(..)` — an omitted endpoint is `±∞`, kept **distinct** from a present | |
| 154 | -`null` bound (`(..10]` is a definite bound; `[null..10]` stays three-valued unknown). Per | |
| 155 | -FEEL grammar rule 66 an omitted endpoint requires an **open** bracket on that side, so | |
| 156 | -`[1..]` / `[..10]` (closed, no value) are parse errors — the same rule the `range()` string | |
| 157 | -obeys, so there is no literal-vs-`range()` surprise. AST `Interval` and value `RangeVal` | |
| 158 | -endpoints became `Option<…>` (`None` = unbounded); `Value` stays 40 bytes (`RangeVal` is | |
| 159 | -boxed). Grammar is LR(1)-clean: the closed opener `"["` keeps its low endpoint mandatory, | |
| 160 | -the open `"("`/`]` take it optional, and a new `HiEnd` nonterminal gives the high side | |
| 161 | -(bounded `Endpoint IntervalEnd` or the open `")"` for unbounded-high) — proven by the | |
| 162 | -build.rs gate. An unbounded side's openness is ignored (it has no member), and the Allen | |
| 163 | -relations view operands through a `NegInf`/`Val`/`PosInf` bound. `range()` follows the same | |
| 164 | -rule 66 — `range("[2..)")` ≡ `>=2`, while `range("[..2]")`/`range("[1..]")` are null (DMN-TCK | |
| 165 | -1156 `004_e`/`004_f`); the closed loop needed no fixture change. Exercised by the | |
| 153 | +`[1..)` / `(..10]` — an omitted endpoint is `±∞`, kept **distinct** from a present `null` | |
| 154 | +bound (`(..10]` is a definite bound; `[null..10]` stays three-valued unknown). Per FEEL | |
| 155 | +grammar rule 66 an omitted endpoint requires an **open** bracket on that side and at most | |
| 156 | +one endpoint may be omitted, so `[1..]` / `[..10]` (closed, no value) and `(..)` (both | |
| 157 | +omitted) are parse errors — the same rule the `range()` string obeys, so there is no | |
| 158 | +literal-vs-`range()` surprise. AST `Interval` and value `RangeVal` endpoints became | |
| 159 | +`Option<…>` (`None` = unbounded); `Value` stays 40 bytes (`RangeVal` is boxed). Grammar is | |
| 160 | +LR(1)-clean: the closed opener `"["` keeps its low endpoint mandatory; each open opener | |
| 161 | +`"("`/`]` splits present-low (any `HiEnd`) / omitted-low (bounded high) — which forbids | |
| 162 | +`(..)`; `HiEnd`'s unbounded form is the open `")"` only. Proven by the build.rs gate. An | |
| 163 | +unbounded side's openness is ignored (it has no member), and the Allen relations view | |
| 164 | +operands through a `NegInf`/`Val`/`PosInf` bound. `range()` follows the same rule 66 — | |
| 165 | +`range("[2..)")` ≡ `>=2`, while `range("[..2]")`/`range("[1..]")` are null (DMN-TCK 1156 | |
| 166 | +`004_e`/`004_f`); the closed loop needed no fixture change. Exercised by the | |
| 166 | 167 | `unbounded_ranges` and `unbounded_closed_bracket_is_a_parse_error` unit tests. |
| 167 | 168 | |
| 168 | 169 | ### Still deferred |
modified crates/feel-core/src/builtins.rs +12 −11
| @@ -614,16 +614,17 @@ | ||
| 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 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. | |
| 617 | + // The `range()` string follows FEEL grammar rule 66 ("range literal"), the | |
| 618 | + // same rule the value-position literal grammar enforces (ADR-31): a *present* | |
| 619 | + // endpoint must be a self-contained literal, an *omitted* endpoint is allowed | |
| 620 | + // only with an OPEN bracket on that side — alternatives (b) `open start ".." | |
| 621 | + // endpoint end` and (c) `start ".." endpoint open end` — and AT MOST one may | |
| 622 | + // be omitted. So `range("[2..)")` (≡ `>=2`) and `range("(..2)")` (≡ `<2`) are | |
| 623 | + // valid, but a CLOSED bracket with no value, or BOTH endpoints omitted (no | |
| 624 | + // rule-66 alternative), is null: `range("[..2]")` / `range("[1..]")` (DMN-TCK | |
| 625 | + // 1156 004_e/004_f), `range("[..]")` / `range("(..)")`. (For range() the | |
| 626 | + // value-position grammar already rejects the closed/both-omitted strings at | |
| 627 | + // `compile` above; these checks are the defensive belt-and-suspenders.) | |
| 627 | 628 | let side_ok = |e: &Option<Box<crate::ast::Expr>>, open: bool| match e { |
| 628 | 629 | Some(e) => range_endpoint_is_literal(e), |
| 629 | 630 | None => open, // omitted ⇒ the bracket on that side must be open |
| @@ -902,7 +903,7 @@ | ||
| 902 | 903 | // A range renders in interval notation, e.g. `[1..10)` / `["a".."c"]`; the |
| 903 | 904 | // endpoints are quoted as list members are (so strings keep their quotes). An |
| 904 | 905 | // unbounded endpoint (`None`; ADR-31) renders as nothing, echoing the bracket |
| 905 | - // the user wrote: `[1..)`, `(..10)`, `(..)`. | |
| 906 | + // the user wrote: `[1..)`, `(..10)`. | |
| 906 | 907 | Value::Range(r) => format!( |
| 907 | 908 | "{}{}..{}{}", |
| 908 | 909 | if r.start_open { '(' } else { '[' }, |
modified crates/feel-core/src/feel.lalrpop +48 −34
| @@ -257,35 +257,45 @@ | ||
| 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 | 259 | // A range literal with optional, *unbounded* endpoints, following FEEL grammar rule 66 |
| 260 | -// to the letter (ADR-31): an omitted endpoint is admissible ONLY behind an *open* | |
| 261 | -// bracket on that side — `[1..)` / `(..10]` / `]1..)`, never `[1..]` / `[..10]` (a | |
| 262 | -// closed bracket with no value is a parse error). So: | |
| 263 | -// * the *closed* opener `"["` keeps its low endpoint MANDATORY (`Sum`); | |
| 264 | -// * the *open* openers `"("` and `]`(RBracketOpen) allow it omitted (`Sum?`); | |
| 265 | -// * the high side is `HiEnd`, whose unbounded form is the *open* `")"` only. | |
| 266 | -// An omitted endpoint becomes `None` (≠ a present `null` bound). `..` ∉ FIRST(Sum) keeps | |
| 267 | -// the optional-low choice one-token-clean, and `]` after `[` is still the empty `List`. | |
| 260 | +// to the letter (ADR-31). Rule 66 has exactly three alternatives — (a) both endpoints | |
| 261 | +// present, (b) lower omitted behind an *open* start, (c) upper omitted behind an *open* | |
| 262 | +// end — so AT MOST ONE endpoint may be omitted, and only behind an OPEN bracket. Hence: | |
| 263 | +// * the *closed* opener `"["` keeps its low endpoint MANDATORY (`Sum`), with any | |
| 264 | +// `HiEnd` (bounded, or the open `")"` for an unbounded high → rule 66 (c)); | |
| 265 | +// * an *open* opener `"("` / `]`(RBracketOpen) splits in two: with a *present* low it | |
| 266 | +// takes any `HiEnd` (rule 66 a/c); with an *omitted* low (`"(" ".."`) it requires a | |
| 267 | +// *bounded* high `Endpoint IntervalEnd` (rule 66 b) — which is what forbids the | |
| 268 | +// both-omitted `(..)` (no rule-66 alternative; a parse error, like `range("(..)")` | |
| 269 | +// is null). | |
| 270 | +// `[1..]` / `[..10]` (closed bracket, no value) and `(..)` (both omitted) thus do not | |
| 271 | +// parse. An omitted endpoint becomes `None` (≠ a present `null` bound). `..` ∉ FIRST(Sum) | |
| 272 | +// keeps the present-vs-omitted-low choice one-token-clean; `]` after `[` is still `List`. | |
| 268 | 273 | RangeLit: Expr = { |
| 269 | 274 | "[" <lo:Sum> ".." <hi:HiEnd> => |
| 270 | 275 | Expr::RangeLit(Interval { start_open: false, start: Some(Box::new(lo)), end: hi.0, end_open: hi.1 }), |
| 271 | - "(" <lo:Sum?> ".." <hi:HiEnd> => | |
| 272 | - Expr::RangeLit(Interval { start_open: true, start: lo.map(Box::new), end: hi.0, end_open: hi.1 }), | |
| 276 | + "(" <lo:Sum> ".." <hi:HiEnd> => | |
| 277 | + Expr::RangeLit(Interval { start_open: true, start: Some(Box::new(lo)), end: hi.0, end_open: hi.1 }), | |
| 278 | + "(" ".." <hi:Endpoint> <eo:IntervalEnd> => | |
| 279 | + Expr::RangeLit(Interval { start_open: true, start: None, end: Some(Box::new(hi)), end_open: eo }), | |
| 273 | 280 | // Reverse-open `]a..b]` ≡ `(a..b]`: an exclusive lower bound spelt with a leading |
| 274 | - // `]`. The lexer retags that opener to `RBracketOpen` (a distinct terminal), so | |
| 275 | - // this shares no LR state with the `]` closer — same start-openness as the `(` | |
| 276 | - // form, and (being open) it likewise admits an omitted low endpoint. | |
| 277 | - RBracketOpen <lo:Sum?> ".." <hi:HiEnd> => | |
| 278 | - Expr::RangeLit(Interval { start_open: true, start: lo.map(Box::new), end: hi.0, end_open: hi.1 }), | |
| 279 | -}; | |
| 280 | - | |
| 281 | -// The part of an interval *after* the `..`: the (optional) high endpoint together with | |
| 282 | -// the closing bracket's openness. Either a bounded endpoint followed by `IntervalEnd` | |
| 283 | -// (`]`/`)`/`[`), or — for an *unbounded* high (`[1..)`, `(..)`; ADR-31, rule 66 (b)/(c)) | |
| 284 | -// — the bare *open* `")"`. There is deliberately NO unbounded-high `"]"` (a closed | |
| 285 | -// bracket with no value is invalid per rule 66) and no reverse-close `[`: `[` is in | |
| 286 | -// FIRST(Endpoint) (a nested high endpoint, `[1..[2..3]]`), so after `..` a `[` always | |
| 287 | -// shifts into `Endpoint`. That keeps the fork LR(1)-clean (build.rs gate). The bare `)` | |
| 288 | -// never clashes with `Endpoint` (`)` ∉ FIRST(Endpoint)). | |
| 281 | + // `]`. The lexer retags that opener to `RBracketOpen` (a distinct terminal), so this | |
| 282 | + // shares no LR state with the `]` closer — same start-openness as the `(` form, and | |
| 283 | + // likewise split into present-low / omitted-low (omitted ⇒ bounded high). | |
| 284 | + RBracketOpen <lo:Sum> ".." <hi:HiEnd> => | |
| 285 | + Expr::RangeLit(Interval { start_open: true, start: Some(Box::new(lo)), end: hi.0, end_open: hi.1 }), | |
| 286 | + RBracketOpen ".." <hi:Endpoint> <eo:IntervalEnd> => | |
| 287 | + Expr::RangeLit(Interval { start_open: true, start: None, end: Some(Box::new(hi)), end_open: eo }), | |
| 288 | +}; | |
| 289 | + | |
| 290 | +// The part of an interval *after* the `..` for a *present-low* range: the high endpoint | |
| 291 | +// plus closing-bracket openness. Either a bounded endpoint followed by `IntervalEnd` | |
| 292 | +// (`]`/`)`/`[`), or — for an *unbounded* high (`[1..)`; ADR-31, rule 66 (c)) — the bare | |
| 293 | +// *open* `")"`. There is deliberately NO unbounded-high `"]"` (a closed bracket with no | |
| 294 | +// value is invalid per rule 66) and no reverse-close `[`: `[` is in FIRST(Endpoint) (a | |
| 295 | +// nested high endpoint, `[1..[2..3]]`), so after `..` a `[` always shifts into | |
| 296 | +// `Endpoint`. That keeps the fork LR(1)-clean (build.rs gate). The bare `)` never clashes | |
| 297 | +// with `Endpoint` (`)` ∉ FIRST(Endpoint)). Only the present-low productions reach `HiEnd`; | |
| 298 | +// an omitted low takes the inline *bounded* high above, so `(..)` cannot be built. | |
| 289 | 299 | HiEnd: (Option<Box<Expr>>, bool) = { |
| 290 | 300 | <hi:Endpoint> <eo:IntervalEnd> => (Some(Box::new(hi)), eo), |
| 291 | 301 | ")" => (None, true), |
| @@ -354,19 +364,23 @@ | ||
| 354 | 364 | <op:CmpOp> <e:Sum> => vec![UnaryTest::Compare(op, Box::new(e))], |
| 355 | 365 | <e:NbSum> => vec![unary_test_from_expr(e)], |
| 356 | 366 | // Interval *tests* with optional unbounded endpoints (ADR-31): `x in [1..)`, |
| 357 | - // `x in (..10]`, `x in (..)`. Same rule-66 factoring as the value-position `RangeLit` | |
| 358 | - // above — an omitted endpoint needs an *open* bracket (`"["` keeps its low endpoint | |
| 359 | - // mandatory; `"("` / `]` allow it omitted; `HiEnd`'s unbounded form is `")"`). An | |
| 360 | - // omitted endpoint becomes `None` (an unconditionally-satisfied side), distinct from | |
| 361 | - // a present `null` bound (three-valued). | |
| 367 | + // `x in (..10]`. Same rule-66 factoring as the value-position `RangeLit` above — an | |
| 368 | + // omitted endpoint needs an *open* bracket and at most one may be omitted, so the | |
| 369 | + // open openers split into present-low (`HiEnd`) / omitted-low (bounded high). `[1..]`, | |
| 370 | + // `[..10]`, `(..)` are parse errors here too. An omitted endpoint becomes `None` (an | |
| 371 | + // unconditionally-satisfied side), distinct from a present `null` bound (three-valued). | |
| 362 | 372 | "[" <lo:Sum> ".." <hi:HiEnd> => |
| 363 | 373 | vec![UnaryTest::Interval(Interval { start_open: false, start: Some(Box::new(lo)), end: hi.0, end_open: hi.1 })], |
| 364 | - "(" <lo:Sum?> ".." <hi:HiEnd> => | |
| 365 | - vec![UnaryTest::Interval(Interval { start_open: true, start: lo.map(Box::new), end: hi.0, end_open: hi.1 })], | |
| 374 | + "(" <lo:Sum> ".." <hi:HiEnd> => | |
| 375 | + vec![UnaryTest::Interval(Interval { start_open: true, start: Some(Box::new(lo)), end: hi.0, end_open: hi.1 })], | |
| 376 | + "(" ".." <hi:Endpoint> <eo:IntervalEnd> => | |
| 377 | + vec![UnaryTest::Interval(Interval { start_open: true, start: None, end: Some(Box::new(hi)), end_open: eo })], | |
| 366 | 378 | // Reverse-open interval *test* `x in ]a..b]` (exclusive lower, ≡ `(a..b]`); the |
| 367 | 379 | // lexer's `RBracketOpen` opener keeps this off the `]`-closer LR state. |
| 368 | - RBracketOpen <lo:Sum?> ".." <hi:HiEnd> => | |
| 369 | - vec![UnaryTest::Interval(Interval { start_open: true, start: lo.map(Box::new), end: hi.0, end_open: hi.1 })], | |
| 380 | + RBracketOpen <lo:Sum> ".." <hi:HiEnd> => | |
| 381 | + vec![UnaryTest::Interval(Interval { start_open: true, start: Some(Box::new(lo)), end: hi.0, end_open: hi.1 })], | |
| 382 | + RBracketOpen ".." <hi:Endpoint> <eo:IntervalEnd> => | |
| 383 | + vec![UnaryTest::Interval(Interval { start_open: true, start: None, end: Some(Box::new(hi)), end_open: eo })], | |
| 370 | 384 | "[" <ts:Comma<UnaryTestElem>> "]" => ts, |
| 371 | 385 | "(" <ts:Comma<UnaryTestElem>> ")" => ts, |
| 372 | 386 | // Negation of a positive unary-test list, `x in not(t1, …)` (DMN rule 49). In the |
modified crates/feel-core/src/lib.rs +10 −7
| @@ -465,7 +465,6 @@ | ||
| 465 | 465 | assert_eq!(ev("5 in (..10]"), b(true)); // everything ≤ 10 |
| 466 | 466 | assert_eq!(ev("11 in (..10]"), b(false)); |
| 467 | 467 | assert_eq!(ev("10 in (..10)"), b(false)); // open upper excludes |
| 468 | - assert_eq!(ev("42 in (..)"), b(true)); // (-∞, +∞) contains everything | |
| 469 | 468 | |
| 470 | 469 | // The crux: UNBOUNDED is NOT a `null` bound. `(..10]` includes everything ≤ 10; |
| 471 | 470 | // `[null..10]` is a *present* null bound, so membership is three-valued unknown |
| @@ -502,12 +501,11 @@ | ||
| 502 | 501 | // string() echoes the written bracket, rendering an unbounded side as nothing. |
| 503 | 502 | assert_eq!(ev("string([1..))"), Value::String("[1..)".into())); |
| 504 | 503 | assert_eq!(ev("string((..10))"), Value::String("(..10)".into())); |
| 505 | - assert_eq!(ev("string((..))"), Value::String("(..)".into())); | |
| 506 | 504 | |
| 507 | 505 | // Allen relations (§10.3.4.6) over unbounded operands. |
| 508 | 506 | assert_eq!(ev("before( (..5], [10..) )"), b(true)); // (-∞,5] before [10,+∞) |
| 509 | 507 | assert_eq!(ev("before( (..5], [3..) )"), b(false)); // they overlap |
| 510 | - assert_eq!(ev("includes( (..), [3..7] )"), b(true)); // (-∞,+∞) includes all | |
| 508 | + assert_eq!(ev("includes( (..7], [3..7] )"), b(true)); // unbounded-below includes all ≤ 7 | |
| 511 | 509 | assert_eq!(ev("includes( [1..), [3..7] )"), b(true)); |
| 512 | 510 | assert_eq!(ev("includes( [1..), [0..7] )"), b(false)); // 0 < 1, escapes below |
| 513 | 511 | assert_eq!(ev("during( 5, [1..) )"), b(true)); |
| @@ -519,10 +517,15 @@ | ||
| 519 | 517 | |
| 520 | 518 | #[test] |
| 521 | 519 | fn unbounded_closed_bracket_is_a_parse_error() { |
| 522 | - // Rule 66: an omitted endpoint behind a CLOSED bracket is invalid — these do not | |
| 523 | - // parse (a hard error, not a silent misparse), consistent with `range("[1..]")` | |
| 524 | - // being null. The valid spellings are `[1..)` / `(..10]` (ADR-31). | |
| 525 | - for src in ["[1..]", "[..10]", "[..10)", "[..]", "5 in [1..]", "5 in [..10]"] { | |
| 520 | + // Rule 66: an omitted endpoint behind a CLOSED bracket is invalid, and AT MOST | |
| 521 | + // one endpoint may be omitted — these do not parse (a hard error, not a silent | |
| 522 | + // misparse), consistent with `range("[1..]")` / `range("(..)")` being null. The | |
| 523 | + // valid spellings are `[1..)` / `(..10]` (ADR-31). `(..)` (both omitted) has no | |
| 524 | + // rule-66 alternative, so it is rejected too. | |
| 525 | + for src in [ | |
| 526 | + "[1..]", "[..10]", "[..10)", "[..]", "5 in [1..]", "5 in [..10]", "(..)", | |
| 527 | + "5 in (..)", "(..)= (..)", | |
| 528 | + ] { | |
| 526 | 529 | assert!( |
| 527 | 530 | compile(src).is_err(), |
| 528 | 531 | "expected a parse error for closed-bracket unbounded `{src}`" |