| @@ -776,6 +776,43 @@ |
| 776 | 776 | (the non-interval `in` forms), `instance of`, and `sort`/matching-`list replace` (need a |
| 777 | 777 | function-valued comparator — feasible now that function values exist, ADR-23). |
| 778 | 778 | |
| 779 | +## ADR-25: Multiple iteration contexts — `for`/`some`/`every` (FEEL rules 44/46) |
| 780 | + |
| 781 | +- **Context:** `for`, `some` and `every` were single-context only (`for i in a return …`). |
| 782 | + FEEL allows one *or more* comma-separated iteration contexts (`for i in a, j in b |
| 783 | + return …`; rules 44 & 46), iterating the Cartesian product of the sources. DMN-TCK |
| 784 | + `0033-for-loops` (`for h in heights, w in widths return h * w` → `[20,30,40,60,60,90]`) |
| 785 | + exercises it and was being skipped by the ingester. |
| 786 | +- **Decision:** `Expr::For` and `Expr::Quantified` now hold `bindings: Vec<(String, |
| 787 | + IterSource)>` (the tuple idiom already used by `ContextLit`) instead of a single |
| 788 | + `var`/`source`. |
| 789 | + - **Grammar:** one new `IterCtx` rule (`name in source`) fed through the existing |
| 790 | + `Comma<T>` helper over the shared `IterSrc`. A top-level `,` is consumed only by |
| 791 | + `Comma<IterCtx>` — `IterSrc` (`Sum ".." Sum` | `Disjunction`) never eats one — so |
| 792 | + after each context the lookahead is `,` (more) or `return`/`satisfies`, keeping it |
| 793 | + LR(1). The `build.rs` lalrpop gate fails on any conflict; it builds clean, and |
| 794 | + single-context input still parses unchanged. |
| 795 | + - **Semantics (eval):** `eval_for`/`eval_quantified` recurse over the bindings. The |
| 796 | + body/predicate runs over the Cartesian product in declaration order with the |
| 797 | + **rightmost context varying fastest**; each source is resolved in the scope of the |
| 798 | + contexts to its **left**, so a later source may reference an earlier variable |
| 799 | + (`for i in [1,2], j in i..3 return j` = `[1,2,3,2,3]`). `iter_values` is reused |
| 800 | + unchanged (one source, one scope) — the recursion supplies the per-level scope. |
| 801 | + - **Edge cases (parity with single context):** a non-iterable source at *any* level |
| 802 | + makes the whole expression an error-null; the quantifier short-circuit (`some`→true / |
| 803 | + `every`→false on the first dominating tuple) and the sticky error-provenance |
| 804 | + (`saw_unknown`/`tainted`) are preserved across the full product via a small |
| 805 | + `QuantOutcome` enum. |
| 806 | + - **Slice detector:** `fits_slice_grammar` dropped its multi-context reject, now |
| 807 | + captures the subsequent `, name in` variables as bound names, and recognises a |
| 808 | + `, name in` clause as an iterator `in` (not an unsupported membership form). |
| 809 | +- **Tests:** feel-core unit tests for `for`/`some`/`every` multi-context (product order, |
| 810 | + left-to-right source scoping, empty-source product, short-circuit), plus the ingested |
| 811 | + DMN-TCK multi-context for-loop cases now kept by the slice detector. |
| 812 | +- **Consequence:** rules 44/46 are complete except the `for`-body special variable |
| 813 | + `partial` (the partial result list), which stays out of scope — it is unsupported for a |
| 814 | + single context too, and TCK cases using it remain skipped by the free-identifier scan. |
| 815 | + |
| 779 | 816 | ## Adding a wrapper — the host-binding contract |
| 780 | 817 | |
| 781 | 818 | The four wrappers (feel-pg, feel-wasm, feel-py, planned feel-lua) implement the same |