| @@ -726,6 +726,49 @@ |
| 726 | 726 | out of scope (documented): typed parameters `function(a: string)`, general invocation on |
| 727 | 727 | an arbitrary expression (`expr(args)`, `lib.fn(args)`), and external/imported functions. |
| 728 | 728 | |
| 729 | +## ADR-24: List filter, index & projection — `list[…]` (DMN §10.3.2.5) |
| 730 | + |
| 731 | +- **Context:** the postfix `[…]` operator was the last missing piece of the "Lists and |
| 732 | + filters" section (§10.3.2.5) — both positional indexing (`list[1]`, `list[-1]`) and the |
| 733 | + Boolean filter (`list[item > 5]`). It was deferred for one round (see the roadmap entry, |
| 734 | + now resolved) with the grammar conflict flagged for deliberate checking. |
| 735 | +- **Decision:** one AST node `Expr::Filter(Box<Expr>, Box<Expr>)` for `source[bracket]`, |
| 736 | + parsed as a postfix production on the `Postfix` layer — the same precedence as path |
| 737 | + access (`a.b[1]` is `(a.b)[1]`, `xs.x[2]` is `(xs.x)[2]`). |
| 738 | + - **Grammar (conflict resolved):** a `[` in *primary* position is a list literal |
| 739 | + (`Primary → List`); a `[` directly after a completed `Postfix` is unambiguously a |
| 740 | + subscript; interval `[a..b]` only follows `in`. This is the identical |
| 741 | + shift-after-value pattern the `.` path rule already uses, so it stays LR(1) — lalrpop |
| 742 | + builds conflict-free (the `build.rs` gate would fail otherwise). |
| 743 | + - **Index vs. filter is decided at evaluation by the bracket's value type** (the |
| 744 | + spec leaves the form to the value): the bracket is evaluated once in the *outer* |
| 745 | + scope — a `Number` is a 1-based positional index (negative-from-end via the shared |
| 746 | + `resolve_index`; non-integer or out of range → value-null); anything else is a |
| 747 | + Boolean filter, re-evaluated per element. `item` is unbound in the outer scope, so a |
| 748 | + real predicate like `item > 2` is null there and correctly falls through to the |
| 749 | + filter path. |
| 750 | + - **Filter scope (`filter_scope`)** binds the current element as `item`; if the element |
| 751 | + is a context, its entries are also spread into scope so they read without an `item.` |
| 752 | + prefix (`[{x:1}][x = 1]`) — but a context that already carries an `item` key keeps |
| 753 | + that key as `item`. The element is forced for the entry-spread while the `item` |
| 754 | + binding stays the original value, preserving `Foreign` identity (ADR-21). Non-`true` |
| 755 | + predicate results (false / null / error) drop the element. |
| 756 | + - **Source coercion (implicit conversion §10.3.2.9.4):** a non-list, non-null source is |
| 757 | + a singleton (`5[1] = 5`, `5[item > 3] = [5]`); `null` source → `null`; error → error. |
| 758 | + - **Projection:** the `Expr::Path` arm gains a list case so `.field` over a list of |
| 759 | + contexts maps the access (`[{x:1},{x:2}].x = [1,2]`, missing key → null in that slot), |
| 760 | + sharing one `member_access` helper with the scalar case. The list is not forced first, |
| 761 | + so a single `Foreign` keeps the lazy-dot path (ADR-21). |
| 762 | +- **Tests:** feel-core unit tests for index/filter/projection (incl. singleton coercion, |
| 763 | + the `item`-key shadow, and composition), plus the ingested DMN-TCK `0001-filter` |
| 764 | + (`Employees[dept = 20].name`). The slice detector dropped its postfix-`[` reject, added |
| 765 | + `item` as an allowed implicit name, and now collects context-element keys from input |
| 766 | + data (`collect_context_keys`) so a filter referencing an element's entries fits the |
| 767 | + slice. |
| 768 | +- **Consequence:** §10.3.2.5 is complete. Still out of scope (documented): unary tests |
| 769 | + (the non-interval `in` forms), `instance of`, and `sort`/matching-`list replace` (need a |
| 770 | + function-valued comparator — feasible now that function values exist, ADR-23). |
| 771 | + |
| 729 | 772 | ## Adding a wrapper — the host-binding contract |
| 730 | 773 | |
| 731 | 774 | The four wrappers (feel-pg, feel-wasm, feel-py, planned feel-lua) implement the same |
| @@ -1118,8 +1161,9 @@ |
| 1118 | 1161 | 0032-conditionals (cases 001–003, after the `if`-semantics decision in ADR-13). |
| 1119 | 1162 | 0012-list-functions is now unlocked too (list built-ins landed in ADR-15). |
| 1120 | 1163 | |
| 1121 | | -- **Array index access** — FEEL `list[n]` is 1-based, supports negative-from-end |
| 1122 | | - indexing, and is `null` out of range; the same `[...]` syntax is also a boolean |
| 1123 | | - filter `list[predicate]`. Deferred (chosen this round). Implement later as a |
| 1124 | | - postfix operator on the `Postfix` layer (alongside path access); the grammar |
| 1125 | | - conflict with list literals / interval `in [a..b]` must be checked deliberately. |
| 1164 | +- **List filter, index & projection** — *done (ADR-24).* The postfix `[…]` operator |
| 1165 | + (1-based index with negative-from-end and out-of-range → null; Boolean filter |
| 1166 | + `list[item > 5]` with `item` binding + context-entry spread) and `.field` |
| 1167 | + projection over a list of contexts. Landed on the `Postfix` layer alongside path |
| 1168 | + access; the flagged grammar conflict with list literals / interval `in [a..b]` |
| 1169 | + was checked and is conflict-free (LR(1)). Unlocked DMN-TCK `0001-filter`. |