Public repository: timo / feel

Reader

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

feat(ingester): accept untyped function literals in the slice; add sort builtin

public

feat(ingester): accept untyped function literals in the slice; add sort builtin

Add `"sort"` to `_BUILTINS` so `sort(list, function(x,y) ...)` call heads
are recognised and not treated as free names.

Extend `fits_slice_grammar` with a function-literal extraction step: before
the free-name scan, find all `function(p1, p2)` heads with bare (untyped)
comma-separated parameter lists, collect the param names into `fn_params`,
add them to `allowed`, and blank the head from `scan`. The body is then
scanned with the params recognised as bound identifiers.

Typed parameter annotations (`function(a: number)`) do NOT match the pattern
and keep the expression outside the auto-ingested slice — 0013-sort and 1155
use only bare params, so this suffices. The closed-loop test is the backstop.

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

modified tools/ingest_tck.py +24 −2

@@ -92,7 +92,7 @@
9292
     "mode", "all", "any", "append", "concatenate", "union", "remove",
9393
     "reverse", "flatten", "sublist",
9494
     "list contains", "index of", "distinct values", "insert before",
95
-    "list replace",
95
+    "list replace", "sort",
9696
     # context
9797
     "get value", "get entries", "context", "context put", "context merge",
9898
     # numeric
@@ -383,7 +383,29 @@
383383
     # (DMN §10.3.2.5). It is only in scope inside a `[…]`, but allowing it globally
384384
     # here is a safe over-approximation: an `item` used outside a filter would just
385385
     # evaluate to null, and the TCK filter cases all reference it inside `[…]`.
386
-    allowed = _KEYWORDS | {"item"} | bound | set(input_names)
386
+    # Untyped function literals `function(p1, p2) body` (FEEL rule 55, ADR-23):
387
+    # formal parameter names are not free identifiers — they are bound by the literal.
388
+    # Collect them, add to `allowed`, and blank the `function(…)` head so the body
389
+    # can be scanned with the params treated as bound names.
390
+    #
391
+    # Only bare (untyped) comma-separated identifiers are accepted: a `:` in the
392
+    # parameter list (`function(a: number)`) does NOT match and keeps the expression
393
+    # outside the auto-ingested slice (TCK suites 0013-sort and 1155 use only bare
394
+    # params, so this suffices). Zero-param `function()` blanks the head without
395
+    # adding any names. `function` as a *call head* (not a literal) is not a built-in
396
+    # and never appears in auto-ingestible expressions, so the pattern exclusively
397
+    # targets literal `function(...)` bodies.
398
+    _fn_literal_pat = (
399
+        r"\bfunction\s*\(\s*([A-Za-z_]\w*(?:\s*,\s*[A-Za-z_]\w*)*\s*)?\)"
400
+    )
401
+    fn_params: set = set()
402
+    for _m in re.finditer(_fn_literal_pat, scan):
403
+        _ps = (_m.group(1) or "").strip()
404
+        if _ps:
405
+            for _p in _ps.split(","):
406
+                fn_params.add(_p.strip())
407
+    scan = re.sub(_fn_literal_pat, " ", scan)
408
+    allowed = _KEYWORDS | {"item"} | bound | set(input_names) | fn_params
387409
     idents = re.findall(r"[A-Za-z_]\w*", scan)
388410
     if any(tok not in allowed for tok in idents):
389411
         return False