Public repository: timo / feel

Reader

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

docs: record ADR-17 (full FEEL names + multi-word built-ins)

public

docs: record ADR-17 (full FEEL names + multi-word built-ins)

Add ADR-17 (two-tier lexer name-join: generic whitespace merge + a fixed
keyword-phrase built-in dictionary, explicitly not scope-aware) with its
deviations (no special characters in names, keyword-containing variables out,
the date-and-time collision resolved toward the built-in phrase). Update ADR-15's
deferred note and the roadmap to mark the multi-word slice done, and refresh the
README fixture count and ingested-dir list.

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

modified DECISIONS.md +72 −11

@@ -298,10 +298,11 @@
298298
   `xsd:string` value was mis-typed as a number (`string(2) = "2"`), and string
299299
   results were whitespace-stripped (`substring("foob r", -2, 1) = " "`). Unlocked
300300
   20 `feel-*-function` / list / string TCK dirs (303 → 541 fixture cases).
301
-- **Deferred (still out of scope):** space-containing names (`string length`),
302
-  temporal functions and `abs` on durations (await ADR temporal types),
303
-  `sort`/`list replace` (need function values), range relations and `is` (need
304
-  first-class ranges / temporal identity), and a full XPath-regex dialect bridge.
301
+- **Deferred (still out of scope):** *space-containing names (`string length`) are
302
+  now done — see ADR-17.* Temporal functions and `abs` on durations (await ADR
303
+  temporal types), `sort` and the matching-function form of `list replace` (need
304
+  function values), range relations and `is` (need first-class ranges / temporal
305
+  identity), and a full XPath-regex dialect bridge.
305306
 
306307
 ## ADR-16: Host-environment regex dialect (per-target `FeelRegex` provider)
307308
 
@@ -345,6 +346,64 @@
345346
   invalid pattern produces, so the strict boundary surfaces it (ADR-14). ADR-15's
346347
   `regex-xpath-dialect` deviation is now per-target rather than global.
347348
 
349
+## ADR-17: Full FEEL names (whitespace) + multi-word built-ins via a two-tier lexer join
350
+
351
+- **Context:** FEEL names may contain spaces — both user names (`full name`,
352
+  `year of birth`) and built-ins (`string length`, `list contains`, `date and
353
+  time`). ADR-15 deferred these because the single-`Name`-token lexer cannot form
354
+  them. The spec resolves the ambiguity they create (`a + b` = a name or an
355
+  addition?) with a *name oracle*: the parser must know the names in scope and
356
+  take the longest match. That couples parsing to the evaluation context — a large
357
+  lift we did not want for this increment (temporal *values* stay out, too).
358
+- **Decision:** Join multi-word names in a second pass over the token stream
359
+  (`lexer::join_names`), so the grammar is **unchanged** — the `Name` terminal just
360
+  carries a space-normalised payload now. No name oracle is needed: soundness
361
+  comes from FEEL having no juxtaposition of two expressions, so two adjacent
362
+  `Name` tokens can only be one name. Two tiers:
363
+  - **Tier 1 (generic):** greedily merge a run of adjacent `Name` tokens. Keywords
364
+    are separate tokens (the `keyword()` remap already ran) and stop the run, so
365
+    `x and y` stays boolean — the join is backward-compatible (it only turns the
366
+    previously-invalid `a b` into a name). Covers user names and every
367
+    keyword-free multi-word built-in.
368
+  - **Tier 2 (the built-in exception):** a fixed, closed dictionary of *keyword-
369
+    containing* built-in phrases (`builtins::KEYWORD_PHRASE_BUILTINS`: `date and
370
+    time`, `years and months duration`) matched only in **call position**
371
+    (immediately followed by `(`). It needs no oracle because the set is finite
372
+    and holds only built-in names, never user variables — this is the bounded
373
+    "exception for built-ins" that lets `date and time(…)` parse without
374
+    scope-aware parsing.
375
+
376
+  The non-temporal multi-word built-ins are implemented (per spec §10.3.4): string
377
+  `string length`/`upper case`/`lower case`/`substring before`/`substring after`/
378
+  `starts with`/`ends with`/`string join`; list `list contains`/`index of`/
379
+  `distinct values`/`insert before`/`list replace` (positional form); context
380
+  `get value`/`get entries`. Dispatch is the same `match name` as ADR-15 (a
381
+  normalised single-space key), so single- and multi-word calls share one path.
382
+  - **Error policy (ADR-14)** is unchanged: wrong arity/type/domain → error-null;
383
+    spec-legitimate empties (`string join([]) = ""`, `index of(l, x) = []`,
384
+    `get entries({}) = []`) → value-null/empty. `string join` skips null items and
385
+    treats a scalar as a one-element list; `get value` returns null for an absent
386
+    *or* present-null entry; `list replace` truncates a fractional position. The
387
+    keyword-phrase temporals parse but dispatch to error-null until temporal types
388
+    land (the *name* machinery is what lands here).
389
+  - **Ingestion** widened in lockstep: multi-word call heads and multi-word free
390
+    names fit the slice predicate, and `parse_expected_node` learns context
391
+    (`<component>`) results so `get entries`' `{key, value}` list is no longer
392
+    degraded to `[null]`. Unlocked 1104-1108/1140 (string), 0011/1155/0012 (list),
393
+    0080/0081 (context); 541 → 672 fixture cases.
394
+- **Consequence:** No grammar change and no new lalrpop conflict — the token set is
395
+  identical, only `Name` payloads grew. ADR-1 holds: names are strings and the
396
+  JSON boundary already carries arbitrary keys, so the wrappers are untouched.
397
+- **Deviations (deliberate, documented):**
398
+  - **Special characters in names** (`+ - * / . '` and the `?` name-part char) are
399
+    out — a name is whitespace-joined words only. These are what reintroduce the
400
+    arithmetic ambiguity, so supporting them would need the oracle.
401
+  - **Keyword-containing *variables*** (`date and time` as a free name) are out;
402
+    only the fixed built-in phrases are recognised, and only in call position.
403
+  - The `date and time(x)` vs `date and (time(x))` collision is resolved toward the
404
+    built-in phrase (the oracle case). Both are temporal-adjacent and yield null
405
+    today, so the choice is observable only once temporal types exist.
406
+
348407
 ## Revisable design decisions
349408
 
350409
 Softer than the ADRs above: deliberate, **reversible** choices that are not
@@ -387,13 +446,15 @@
387446
 These were considered and deliberately deferred to keep the slice thin. Listed so
388447
 the rationale and entry points survive:
389448
 
390
-- **Built-in functions** — *single-word, non-temporal slice done (ADR-15):* a
391
-  `Name "(" … ")"` production in `Postfix`, a `builtins` dispatch table, and the
392
-  conversion/string/list/numeric functions listed there (incl. `regex`-backed
393
-  `replace`/`split`/`matches`). *Still deferred:* FEEL's space-containing names
394
-  (`string length`, `upper`/`lower case`, `distinct values`); `sort`/`list
395
-  replace` (need function values); range relations and `is`; the temporal
396
-  functions (await temporal types). Built-ins would also enable an explicit
449
+- **Built-in functions** — *single-word slice done (ADR-15); non-temporal
450
+  multi-word slice done (ADR-17):* a `Name "(" … ")"` production in `Postfix`, a
451
+  `builtins` dispatch table, the conversion/string/list/numeric functions (incl.
452
+  `regex`-backed `replace`/`split`/`matches`), and the multi-word string/list/
453
+  context functions (`string length`, `upper`/`lower case`, `distinct values`,
454
+  `get value`/`get entries`, …) reached via the lexer name-join. *Still deferred:*
455
+  `sort` and the matching-function form of `list replace` (need function values);
456
+  range relations and `is`; the temporal functions (await temporal types).
457
+  Built-ins would also enable an explicit
397458
   `assert non null(x)` tripwire — an in-expression complement to the strict
398459
   boundary policy (ADR-14) for surfacing error-nulls where the author wants them
399460
   loud.

modified README.md +6 −4

@@ -81,7 +81,7 @@
8181
 (the `decimal-vs-f64` rule switches numeric results to epsilon comparison), and
8282
 prints a summary of processed / skipped cases and which deviation rules fired.
8383
 
84
-The fixtures used by the test (10 files, ~300 self-contained cases) are
84
+The fixtures used by the test (~48 files, ~670 self-contained cases) are
8585
 regenerated by pointing the script at each TCK dir, e.g.:
8686
 
8787
 ```sh
@@ -98,9 +98,11 @@
9898
   -o crates/feel-core/tests/fixtures/0084-feel-for-loops.json
9999
 ```
100100
 
101
-The other ingested dirs are `0105-feel-math` (compliance-level-2),
102
-`0064`/`0065`/`0066` (and/or/not), `0071-feel-between`,
103
-`0075-feel-exponent`, and `0099-arithmetic-negation`. The script reports the
101
+The other ingested dirs include `0105-feel-math` (compliance-level-2),
102
+`0064`/`0065`/`0066` (and/or/not), `0071-feel-between`, `0075-feel-exponent`,
103
+`0099-arithmetic-negation`, the single-word `feel-*-function` dirs (ADR-15), and
104
+the multi-word string/list/context dirs reached via the lexer name-join (ADR-17:
105
+`1104`-`1108`/`1140`, `0011`/`1155`/`0012`, `0080`/`0081`). The script reports the
104106
 self-contained cases it kept and the out-of-scope ones it skipped.
105107
 
106108
 (The `tests/tck` submodule must be checked out: `git submodule update --init`.)