docs: ADR-27 — first-class range values
public
docs: ADR-27 — first-class range values Record the architecture: Value::Range (boxed), the LR(1)-clean range-literal grammar (shared "[" Sum prefix, no IntervalStart — LALR would not help), the bare-endpoint `in` form, the AST-shape-gated range() builtin, structural equality / instance of range<T>, the 13 Allen relations via point→[p..p] unification, and the wrapper mapping. Notes the still-deferred bracket-list forms and supersedes ADR-26's "instance of range<T> is always false". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| Changeset | 69676ca0fbded08a7e04d4eb3a8b6f5aa47789f7 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | 7935ebfd2558 |
| Children | |
| Pushlog | by timo via ssh |
modified DECISIONS.md +57 −2
| @@ -861,8 +861,63 @@ | ||
| 861 | 861 | Table 62 examples and the nested-null/`Null` edges. |
| 862 | 862 | - **Consequence:** §10.3.2.9 type-checking is supported for the self-contained type |
| 863 | 863 | language. Still out of scope (documented): model-defined `itemDefinition` types (need a |
| 864 | - type registry threaded from the embedder), and `range` *values* (no first-class range | |
| 865 | - value exists, so `instance of range<T>` is always `false`). | |
| 864 | + type registry threaded from the embedder). *(`range` values: see **ADR-27** — they are | |
| 865 | + now first-class, so `instance of range<T>` is no longer always `false`.)* | |
| 866 | + | |
| 867 | +## ADR-27: First-class range values (DMN §10.3.4.6) | |
| 868 | + | |
| 869 | +- **Context:** ranges were deferred from the start (ADR-7/ADR-8) as *tests* only — `[a..b]` | |
| 870 | + was reachable in the grammar solely after `in`, with no value of its own. The documented | |
| 871 | + blocker was the **interval-vs-list bracket ambiguity**: factoring `IntervalStart → "["` | |
| 872 | + as its own nonterminal clashes with the list literal on the bare `[`. Making ranges | |
| 873 | + first-class unlocks `1156-range-function`, the relation suite `1130-feel-interval`, and | |
| 874 | + the range cases in `0068-feel-equality` / `0072-feel-in`. | |
| 875 | +- **Decision:** add `Value::Range(Box<RangeVal>)` (two same-typed endpoints + per-bracket | |
| 876 | + openness), **boxed** so `Value` stays 40 bytes, and make a range a first-class value | |
| 877 | + end-to-end. | |
| 878 | + - **Grammar — no LR rewrite needed (LALR would not have helped; it is *weaker* than | |
| 879 | + lalrpop's default LR(1)).** A range literal is an ordinary `Primary` (`Expr::RangeLit`) | |
| 880 | + whose production *shares* the `"[" Sum` (resp. `"(" Sum`) prefix with the list literal | |
| 881 | + (resp. grouping) and branches on the next token — `..` ⇒ range, `]`/`,`/`)` ⇒ list / | |
| 882 | + grouping. The branch is on disjoint lookahead (`..` is unique), so it is LR(1)-clean | |
| 883 | + with **no** `IntervalStart` nonterminal — exactly the factoring that used to conflict. | |
| 884 | + `build.rs`'s no-conflict gate proves it. | |
| 885 | + - **`in` RHS — bare endpoint.** `InRhs` takes a bare `Sum`; `ast::unary_test_from_expr` | |
| 886 | + routes a *written* interval literal to the dedicated `UnaryTest::Interval` (byte-for- | |
| 887 | + byte the old membership test, no regression) and anything else to `UnaryTest::Endpoint`, | |
| 888 | + evaluated as equality `x = e` — or, when `e` is a range value, as range *membership* | |
| 889 | + (`2 in range("[1..3]")`). This also gives bare equality (`1 in 1`) for free. The | |
| 890 | + comma-*list-of-tests* forms (`x in [1,2,3]`, `x in [[a..b],[c..d]]`) stay deferred — | |
| 891 | + there the brackets are a list of tests, not one value (the genuine ambiguity). | |
| 892 | + - **`range(string)` built-in.** It compiles the string, then gates on the **AST shape**: | |
| 893 | + the expression must be a range literal whose endpoints are *literals* — a number / | |
| 894 | + string / `@"…"` / `null`, or a temporal constructor on a string literal. So | |
| 895 | + `range("[date(string(\"…\"))..…]")` is `null` even though it would *evaluate* fine | |
| 896 | + (the spec wants literals only). The evaluated endpoints must then be non-null, | |
| 897 | + same-typed and ascending (via `feel_order`), else `null`. | |
| 898 | + - **Equality & `instance of`.** `=`/`!=` compare ranges structurally (openness flags + | |
| 899 | + both endpoints, FEEL-equal); `instance of range<T>` requires both endpoints to conform | |
| 900 | + to `T` (reusing `conforms_nested`, so a null endpoint conforms). | |
| 901 | + - **Relations (Allen interval algebra).** The 13 §10.3.4.6 relations (`before`/`after`/ | |
| 902 | + `meets`/`met by`/`overlaps`/`overlaps before`/`overlaps after`/`finishes`/`finished | |
| 903 | + by`/`includes`/`during`/`starts`/`started by`/`coincides`) are built-ins. Each operand | |
| 904 | + is viewed uniformly as an interval — a point `p` is the degenerate closed `[p..p]` — so | |
| 905 | + one inclusion-aware formula per relation covers every point/range overload; six are the | |
| 906 | + swap of another (`after = before(b,a)`). Endpoint comparison uses `feel_order`; an | |
| 907 | + incomparable pair is an error-null. | |
| 908 | + - **Wrappers.** A range has no native host type, so feel-lua/feel-py map it to a | |
| 909 | + table/dict carrying DMN's four range properties (`start`, `end`, `start included`, | |
| 910 | + `end included`). | |
| 911 | +- **Tests:** ingested `1156-range-function` (41 cases) and re-ingested `0068`/`0072` | |
| 912 | + (+3 range equality, +8 range membership); suite 2598 → 2650. `1130-feel-interval`'s | |
| 913 | + decisions are *boxed contexts* the literalExpression-only ingester does not read, so its | |
| 914 | + full 132-case relation truth table (every openness edge) is exercised as a feel-core | |
| 915 | + unit test instead. | |
| 916 | +- **Consequence:** ranges are first-class — constructible, comparable, type-checkable, | |
| 917 | + usable in value position and as `in` membership. Still deferred (the bracket-ambiguity | |
| 918 | + forms): comma-list-of-tests `in`, the reverse-bracket interval notation `]a..b]` / | |
| 919 | + `[a..b[`, unbounded ranges (`[1..]`, `(null..10)`), and the comparison-test-as-range | |
| 920 | + value (`(< 10)`). See ROADMAP.md for entry points. | |
| 866 | 921 | |
| 867 | 922 | ## Adding a wrapper — the host-binding contract |
| 868 | 923 | |