Public repository: timo / feel

Reader

An interpreter of FEEL, written in Rust, with integrations for PostgreSQL, WASM, Lua, and Python.

docs: record ADR-24 (list filter, index & projection); update README

public

docs: record ADR-24 (list filter, index & projection); update README

Convert the deferred "Array index access" roadmap entry into ADR-24 (postfix
`[…]` index/filter + `.field` projection, grammar-conflict resolution, runtime
number/boolean disambiguation, `item` binding + context spread, singleton
coercion, projection-over-lists, ingester relaxation) and add a "Lists &
filters" bullet to the README feature list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Changesetc923cf634f9035b52390c36e3d0c0bd96ba4114f
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parents62c38c444a15
Children
Pushlog
by timo via ssh

modified DECISIONS.md +49 −5

@@ -726,6 +726,49 @@
726726
   out of scope (documented): typed parameters `function(a: string)`, general invocation on
727727
   an arbitrary expression (`expr(args)`, `lib.fn(args)`), and external/imported functions.
728728
 
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
+
729772
 ## Adding a wrapper — the host-binding contract
730773
 
731774
 The four wrappers (feel-pg, feel-wasm, feel-py, planned feel-lua) implement the same
@@ -1118,8 +1161,9 @@
11181161
   0032-conditionals (cases 001–003, after the `if`-semantics decision in ADR-13).
11191162
   0012-list-functions is now unlocked too (list built-ins landed in ADR-15).
11201163
 
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`.

modified README.md +6 −0

@@ -28,6 +28,12 @@
2828
 - **Control flow:** `if … then … else …`, `for v in src return …`,
2929
   `some/every v in src satisfies …` (over list literals and integer ranges
3030
   `a..b`), and variable references.
31
+- **Lists & filters (§10.3.2.5):** member / path access `a.b`; the postfix
32
+  `[…]` operator — 1-based index `list[1]` / `list[-1]` (negative-from-end,
33
+  out-of-range → `null`) and Boolean filter `list[item > 5]` (the element is
34
+  `item`; a context element's entries read without the `item.` prefix); and
35
+  `.field` projection over a list of contexts (`[{x:1},{x:2}].x = [1, 2]`;
36
+  ADR-24).
3137
 - **Built-in functions:** single- and multi-word string / list / numeric /
3238
   context functions (`abs`, `string length`, `distinct values`, `get value`, …;
3339
   ADR-15/ADR-17), callable positionally or with named arguments