Public repository: timo / feel

Reader

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

docs: ADR-47 special-character names — decision record and shipped status

draft feat/special-char-names

docs: ADR-47 special-character names — decision record and shipped status

- DECISIONS.md ADR-47: context (ADR-17's predicted name oracle, the
  measured TCK reality - no hyphen inputData, 0007 behind the DRG
  boundary), decision (parse-time scope probe; lexer pass 2.5 after
  join_names; compile probe-free policy; has_name_runs +
  name_run_candidates; the pg candidate-check guards incl. the
  IMMUTABLE loud rejection), v1 deviations (declaration slots,
  Profit-and-loss adjacency, ?/non-XID starts) with their rationale,
  and consequences (suite 3145 -> 3153 / 111 files).
- README: feature bullet for special-character names; the out-of-scope
  list now names the actual deferrals instead of the whole feature.
- ROADMAP: the planned section becomes the shipped record (incl. the
  corrections made during implementation: pass ordering after
  join_names, the candidate check instead of a blanket cache skip, the
  adjacency deferral), coverage numbers updated.
- research doc: outcome banner pointing at ADR-47 as authoritative.
Changesetfa1c0cd5c62171efabb9da33543525d743dbfc16
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parentsd3afab3ac0d4
Children
Pushlog
by timo via ssh

modified DECISIONS.md +94 −0

@@ -2244,3 +2244,97 @@
22442244
   (cyclic dict + cyclic class instance), feel-lua (cyclic table), feel-wasm (cyclic object),
22452245
   feel-pg (jsonb tree — terminates by construction). All non-pg suites pass; feel-pg is
22462246
   exercised via `cargo pgx test` (the pgrx harness, not runnable without a managed Postgres).
2247
+
2248
+## ADR-47: Special-character names — parse-time scope probe (grammar rules 25–30, §10.3.1.6)
2249
+
2250
+- **Context:** A FEEL name may contain the *additional name symbols* `- + * / .` (rule 30) and
2251
+  reserved words as name parts, so `a-b`, `Date-Time`, `x.y`, `if-then` are token sequences that
2252
+  are indistinguishable from arithmetic/path access at the token level. §10.3.1.6 resolves the
2253
+  ambiguity **against the scope**: "name tokens are matched from left to right against the
2254
+  names in-scope, and the longest match is preferred"; spaces are *not* part of the name
2255
+  (`a - b` is the same candidate as `a-b`), and `(a)-(b)` — punctuation that cannot occur in a
2256
+  name — is the escape hatch. ADR-17's unconditional name-join predicted exactly this need:
2257
+  "a scope-aware 'name oracle'" was listed as the deferred follow-up. Until now such names
2258
+  silently misparsed (`Date-Time2.hour` as `Date - (Time2.hour)`).
2259
+
2260
+  Measurement first: the DMN-TCK's only special-characters suite (`0007-date-time`, literally
2261
+  labeled "FEEL Special-character Names") has **no hyphen-named `inputData`** — its `Date-Time`
2262
+  /`Date-Time2` are *decisions* (DRG references), so the 15-of-28 skips there are blocked by
2263
+  the ingester's DRG boundary, not by the name charset. Name support alone unlocks zero
2264
+  auto-ingested cases; its TCK proof is a hand-written fixture (the 0092 pattern) binding the
2265
+  recorded `<resultNode>` values as context keys, and its real unlock is the separate
2266
+  decision-result-binding ingester increment.
2267
+
2268
+- **Decision:** Parse-time scope probe (the ADR-17 oracle), not an eval-time reinterpretation.
2269
+  The eval-time alternative (parse to operator trees, reinterpret against context at
2270
+  evaluation) was rejected: by then the token structure is already mis-shaped (a fused
2271
+  `Date-Time2.hour` never exists as one node), the ambiguity also sits in *syntactic* slots
2272
+  (path bases, call heads) that are not deferrable, and it would need resolution at every
2273
+  reference site rather than one fusion point.
2274
+
2275
+  1. **`ScopeProbe`** — a std-only trait `contains(name) -> bool` (cardinal-rule safe), the
2276
+     seam a host exposes to the *parser*. The canonical `impl ScopeProbe for Context` mirrors
2277
+     `Expr::Var` resolution exactly — a context binding or a built-in name — because parse
2278
+     and eval must agree on what "in scope" means. Since ADR-21/RD-11 every wrapper already
2279
+     materializes exactly the root level into `Context` and traverses the rest lazily, the
2280
+     oracle needs no new input traversal and no laziness regression.
2281
+  2. **Lexer pass 2.5** — `fuse_special_names` runs *after* `join_names` (so a multi-word part
2282
+     like `total price` is already one word unit — `total price-total` is reachable) and before
2283
+     `mark_reverse_open` (a fused `Name` completes a value for the `]`-role classifier). It
2284
+     scans maximal runs `word ((-|+|*|/|.) word)*`, where a word is a joined `Name` payload or
2285
+     a keyword's spelling (`tok_word`; keywords are legal name parts — this is what makes
2286
+     `if-then` reachable). Candidate prefixes are tried **longest first** against the probe;
2287
+     the first in-scope prefix fuses into one `Name` spanning it, the scan resumes *after* the
2288
+     fused name (`Date-Time - Date-Time2` fuses both names and keeps the minus an operator —
2289
+     the subtraction the TCK expects), and after a miss it resumes *inside* the run
2290
+     (`a-b-c` with only `b-c` bound parses as `a - b-c`). Multi-char operators (`..`, `...`,
2291
+     `**`, `->`) are not name symbols, so ranges, descendants and exponents never fuse.
2292
+     Without a probe the pass is a no-op.
2293
+  3. **API policy** — `compile_with_probe(expr, probe)` and probe-aware one-shot `evaluate`
2294
+     (the context is the scope) in feel-core and every wrapper; `compile()` and the
2295
+     `CompiledExpr` classes stay **probe-free** — a compiled program must not pin one scope,
2296
+     and existing parses are byte-identical (all 3145 fixture cases re-verified). Two flags
2297
+     cover the hosts:
2298
+     - `CompiledExpr::has_name_runs()` — *this parse* consulted the scope (fused or not);
2299
+     - `name_run_candidates(expr)` — probe-free, AST-free: every fusable candidate of the text
2300
+       (`a-b-c` → `a-b-c`, `a-b`, `b-c`), i.e. "could *some* scope change this parse".
2301
+  4. **feel-pg guards** — the `fn_extra` parse cache is probe-free, so a cached parse could
2302
+     mis-read a row that binds the joined name. Both SQL functions check the cached candidates
2303
+     per row (ns-cheap key lookups — the RD-10 fast path, plain path access, is unaffected):
2304
+     `feel_eval` re-parses such a row against its keys (a name reading and an arithmetic
2305
+     reading coexist across rows of one query); `feel_eval_immutable` raises a loud ERROR
2306
+     instead — an index expression must parse identically for every row, never silently flip
2307
+     its meaning (the RD-10 guard style). The guard fires only on the *actual* ambiguity, so
2308
+     `feel_eval_immutable('applicant.age >= 18', data)` indexes exactly as before.
2309
+  5. **Ingestion** — the slice scanner's input-name blanker now covers `+ - * /` names
2310
+     (longest-first), so a future bound `Date-Time` counts as one name, not the free idents
2311
+     `Date`/`Time`; a partially-covered run stays conservatively skipped. The TCK proof is the
2312
+     hand-written `0007-date-time-names.json` (8 cases from testCase 001's recorded results,
2313
+     incl. the `Date-Time - Date-Time2` subtraction and `Date-Time2.time offset`), which
2314
+     survives re-ingest; auto-ingesting the remaining 0007 cases lands with decision-result
2315
+     binding.
2316
+
2317
+  **Deviations (v1 scope), all deliberate:**
2318
+  - *Declaration slots* (`for a-b in …`, formal parameters, context keys) are deferred: they
2319
+    declare names, so no oracle knows them, and an in-grammar `DeclName` production is not
2320
+    LR(1)-conflict-free in call args (`f(a-b: 1)` vs `f(a-b)` shift/reduce on `-`). No TCK
2321
+    shape needs them.
2322
+  - *Space-joined reserved-word names* (`Profit and loss`, §10.3.1.6's own example) are
2323
+    deferred: sound support means treating keyword adjacency as a run, which would make every
2324
+    `a and b` / `for x in y` scope-dependent — the sound cache guard would then disable
2325
+    feel-pg's parse cache for nearly every nontrivial expression. The engine keeps Tier 1/2
2326
+    (unconditional joins) as documented scope-blindness and defers the gated form.
2327
+  - *`?` and non-XID name starts* (rule 28, `what if?`) stay deferred with the 0083-feel-unicode
2328
+    widening.
2329
+
2330
+- **Consequence:** `a-b`, `Date-Time`, `x.y` and `if-then` resolve per §10.3.1.6 in the
2331
+  one-shot paths of feel-core/feel-py/feel-wasm/feel-lua and per row in feel-pg; `compile`
2332
+  remains the deterministic parse-once contract. Fixture suite 3145 → 3153 cases / 110 → 111
2333
+  files (the hand-written 0007-date-time-names fixture). Tests added: feel-core (6 test fns:
2334
+  scope resolution, longest-match/left-to-right incl. the TCK subtraction and `(a)-(b)`
2335
+  escape, name-vs-path/member interplay, probe-free-compile policy + both flags/candidates,
2336
+  run-free shapes incl. the deferred `for a-b` parse error), feel-py (2), feel-lua (2),
2337
+  feel-wasm (smoke), feel-pg (5, incl. the same-expression-different-rows cache test and the
2338
+  IMMUTABLE rejection). All suites pass (feel-pg via `cargo pgrx test pg18`). The research
2339
+  record is `docs/special-char-names-research.md`; the follow-up increment is decision-result
2340
+  binding in the ingester, which stands on its own feet (hyphen-free DRG chains need it too).

modified README.md +14 −3

@@ -51,6 +51,14 @@
5151
 - **String literals** decode the FEEL escapes (`\n \r \t \" \' \\`, `\uXXXX`
5252
   incl. UTF-16 surrogate pairs, `\UXXXXXX`); an unrecognised escape (e.g. a regex
5353
   `\d`) is preserved verbatim so it reaches the regex provider untouched.
54
+- **Special-character names (§10.3.1.6, ADR-47):** a name may contain the
55
+  additional name symbols `- + * / .` (`a-b`, `Date-Time`, `x.y` — including
56
+  reserved words as parts, `if-then`). The ambiguity against arithmetic and path
57
+  access is resolved against the **scope**: longest in-scope match preferred,
58
+  left to right; spaces are not part of the name (`a - b` is the same candidate
59
+  as `a-b`); `(a)-(b)` forces the operator reading. One-shot `evaluate` resolves
60
+  names this way (the context is the scope); `compile` is probe-free — a compiled
61
+  program pins no scope (ADR-47).
5462
 - **User-defined functions:** FEEL `function(a, b) a + b` closures, and
5563
   host-provided functions — a Python callable, JS function or Lua function passed in
5664
   the context (or an ambient `functions` registry) and invoked from the expression,
@@ -66,8 +74,11 @@
6674
   `wasm-pack build crates/feel-wasm --target nodejs -- --features iana-tz` (~723 KB
6775
   vs the ~479 KB offset-only default, where a named zone evaluates to null).
6876
 
69
-Still out of scope: unary tests (the non-interval `in` forms), special characters
70
-in names, typed function parameters, and general invocation on an arbitrary
77
+Still out of scope: unary tests (the non-interval `in` forms), names in
78
+*declaration* slots (`for a-b in …`, formal parameters, context keys) and
79
+space-joined reserved-word names (`Profit and loss`) and `?`/non-XID name
80
+starts (`what if?`, grammar rule 28 — see ADR-47's deviations), typed
81
+function parameters, and general invocation on an arbitrary
7182
 expression that *holds* a function (`var(args)`, imported `lib.fn(args)`) — invoking
7283
 a non-function literal yields null per spec (ADR-38). See [DECISIONS.md](DECISIONS.md) for the
7384
 architecture decisions, the deferred-scope roadmap, and accepted deviations
@@ -137,7 +148,7 @@
137148
 `context put` *overloads* whose name is absent from the single-row table
138149
 (`date(from: …)`, `context put(…, keys: …)`; see `NAMED_ARG_OVERLOAD_SKIPS`).
139150
 
140
-The fixtures used by the test (110 files, ~3145 self-contained cases) are
151
+The fixtures used by the test (111 files, ~3153 self-contained cases) are
141152
 regenerated by pointing the script at each TCK dir, e.g.:
142153
 
143154
 ```sh

modified ROADMAP.md +91 −105

@@ -7,7 +7,7 @@
77
 without re-deriving the analysis.
88
 
99
 Coverage figures are case counts from `tools/ingest_tck.py` over the DMN-TCK
10
-compliance-level-3 suites. Today the fixture suite is **3145 cases / 110 files**
10
+compliance-level-3 suites. Today the fixture suite is **3153 cases / 111 files**
1111
 (`cargo test -p feel-core --test fixtures_test -- --nocapture`).
1212
 
1313
 ---
@@ -243,13 +243,11 @@
243243
 
244244
 ## Special-character names (`a-b`, `Date-Time`, …) — scope-dependent parsing
245245
 
246
-**Status:** 🔍 **researched + planned, not built.** Full analysis and design-space
247
-comparison (incl. the rejected eval-time alternative):
248
-[docs/special-char-names-research.md](docs/special-char-names-research.md).
249
-Planned branch: **`feat/special-char-names`**, cut from `feat/descendant-expressions`
250
-(or `main` once that merges — no dependency between the two, it is purely a
251
-linearity choice). Design: **parse-time scope probe** (the "name oracle" ADR-17
252
-foresaw), *not* an eval-time reinterpretation.
246
+**Status:** ✅ **shipped (ADR-47).** Branch `feat/special-char-names`. Full
247
+analysis and design-space comparison (incl. the rejected eval-time alternative):
248
+[docs/special-char-names-research.md](docs/special-char-names-research.md);
249
+decision record: [DECISIONS.md](DECISIONS.md) ADR-47. **Suite 3145 → 3153 cases /
250
+110 → 111 files** (hand-written fixture; see below).
253251
 
254252
 ### What it is
255253
 
@@ -257,107 +255,95 @@
257255
 `- + * / .` (plus `?` and non-XID starts, rule 28); §10.3.1.6 resolves the
258256
 ambiguity against the **scope**, left-to-right, longest match preferred — spaces
259257
 are not part of the token sequence (`a - b` and `a-b` are the same candidate),
260
-and `(a)-(b)` is the escape hatch that forces subtraction. Today such names
261
-silently mis-parse (`Date-Time2.hour` parses as `Date - (Time2.hour)`), which
262
-the ingester's free-name scan rejects. Key architectural fact: since ADR-21/RD-11
258
+and `(a)-(b)` is the escape hatch that forces subtraction. Until ADR-47 such
259
+names silently mis-parsed (`Date-Time2.hour` as `Date - (Time2.hour)`), which the
260
+ingester's free-name scan rejected. Key architectural fact: since ADR-21/RD-11
263261
 every wrapper materialises exactly the **root level** of the context and
264262
 traverses the rest lazily — so the scope the oracle needs (root keys + builtins)
265263
 is already in hand at `evaluate()` entry, with no laziness regression.
266264
 
267
-### Implementation steps (entry points, in order)
268
-
269
-1. **feel-core seam** — `pub trait ScopeProbe { fn contains(&self, name: &str) -> bool; }`
270
-   (std-only, ADR-1-safe) + `impl ScopeProbe for Context` answering exactly what
271
-   `Expr::Var` resolution answers (`ctx.get(name)` → `builtins::is_builtin`;
272
-   [eval.rs:106-114](crates/feel-core/src/eval.rs)) — parse and eval must agree
273
-   on what "in scope" means. New `pub fn compile_with_probe(expr, &dyn ScopeProbe)`
274
-   in [lib.rs](crates/feel-core/src/lib.rs); `compile(expr)` stays probe-free
275
-   (byte-identical behavior). `CompiledExpr::has_name_runs()` — set when the
276
-   probed parse saw any `Name op Name` run (fused or not), so wrappers can guard
277
-   caches/IMMUTABLE.
278
-2. **Lexer pass** — `fuse_special_names(&mut Vec<Tok>, probe)` in
279
-   [lexer.rs](crates/feel-core/src/lexer.rs), running **before** `join_names`:
280
-   scan maximal runs `word ((-|+|*|/|.) word)+` where a word is a `Name` payload
281
-   or a keyword's spelling (`tok_word` — this is what makes spec examples like
282
-   `Profit and loss` reachable); at each run start try candidate prefixes
283
-   **longest-first** against the probe; fuse the first hit into one `Name` token
284
-   (payload space-normalised, as today); continue after it. Probe-gated ⇒
285
-   `a and b` / `a - b` are untouched unless the joined candidate is in scope.
286
-   Same fuse-the-tokens mechanics as `match_keyword_phrase`/`mark_instance_of`;
287
-   the dot form covers `Date-Time2.hour` (whole-run candidate rejected by the
288
-   probe → `Date-Time2` fuses, `.hour` stays a path). Without a probe the pass
289
-   is a no-op.
290
-3. **Evaluator / grammar: no change.** The LR(1) parser never sees the ambiguity;
291
-   every reference slot (call args, operands, path bases) gets the feature for
292
-   free. **Declaration slots (`for Date-Time in …`, formal params, context keys)
293
-   are deferred from v1**: they declare names so no oracle knows them, and the
294
-   in-grammar production is not LR(1)-conflict-free in call-args (`f(a-b: 1)` vs
295
-   `f(a-b)`) — needs a slot-aware lexer pass (bounded by `in`/`:`/`,`/`) later.
296
-   No TCK shape needs them.
297
-4. **Wrappers** — one-shot `evaluate(expr, ctx)`/`evaluate_strict` become
298
-   probe-aware (they already hold the root `Context`; `compile_with_probe(expr,
299
-   &ctx)` then `evaluate`). `compile()` classes stay probe-free and documented
300
-   (a compiled prog must not pin one scope). py/wasm/lua: mechanical; feel-pg:
301
-   `feel_eval` skips the `fn_extra` parse cache for `has_name_runs` expressions
302
-   (parse per row against that row's jsonb keys — µs-cheap, only ambiguous
303
-   expressions pay it) and `feel_eval_immutable` **rejects** them (a row-shaped
304
-   parse must never feed an expression index) — same loud-guard style as the
305
-   named-zone ban (RD-10).
306
-5. **Test ingestion** — see below.
307
-6. **Docs** — ADR-47 (ADR-17 successor): the decision, the compile-once policy,
308
-   the pg guards, the declaration-slot deferral, deviations; README out-of-scope
309
-   paragraph updated; this entry marked shipped at the end.
310
-
311
-### Test ingestion change (its own plan)
312
-
313
-- **Coverage reality (measured):** the TCK has **no hyphen-named `inputData`
314
-  anywhere**; the 0007 hyphen expressions reference *decisions* (DRG), so the
315
-  15-of-28 skips there are blocked by the DRG boundary first. Name support
316
-  alone unlocks zero auto-ingested cases — the coverage proof is the
317
-  **`0092-feel-lambda` pattern**: a hand-written fixture
318
-  `tests/fixtures/0007-date-time-names.json` with the 0007 expressions
319
-  (`Date-Time - Date-Time2`, `Date-Time2.hour`, `Date-Time2.time offset`,
320
-  `time(Date-Time2)`, `years and months duration(Date-Time2, Date-Time)`)
321
-  against hyphen-keyed contexts derived from testCase-001's recorded
322
-  `<resultNode>` values. Survives re-ingest (the ingester writes only
323
-  `0007-date-time.json`).
324
-- **`fits_slice_grammar` alignment** ([tools/ingest_tck.py:451-464](
325
-  tools/ingest_tck.py)): extend the input-name blanker (today: multi-word
326
-  names only) to **special-char names** — blank bound names containing
327
-  `- + * /` longest-first before the free-ident scan, so `Date-Time` counts as
328
-  one bound name, not the free idents `Date`/`Time`. Genuine subtraction
329
-  `a-b` with bound `a`,`b` stays in-slice (both blanked, `-` remains) and the
330
-  probe correctly falls back to subtraction. This is what makes the hyphen
331
-  cases ingestible once their names are bound at all.
332
-- **Harness** — [fixtures_test.rs](crates/feel-core/tests/fixtures_test.rs)
333
-  `assert_case` builds the `Context` already; switch its one-shot `evaluate`
334
-  to `compile_with_probe(expr, &ctx)` + `evaluate` (one-line change).
335
-- **Follow-up increment (separate, ~1–2 d): decision-result binding** — bind
336
-  the testCase's `<resultNode>` values into the case context (expected-as-input,
337
-  the boxed-context stance). This is what actually auto-ingests the ~9–11
338
-  hyphen cases of `0007-date-time` (suite 3145 → ~3154) and any other
339
-  DRG-chained suite; it stands on its own feet even before name support
340
-  (hyphen-free DRG chains like `sumDurations` need it too).
341
-
342
-### Acceptance
343
-
344
-- Unit tests: longest-match (`a-b` vs `a-b-c`), `(a)-(b)` escape, spaces-
345
-  irrelevance (`a - b` resolves to the name when in scope), keyword-run
346
-  (`Profit and loss`), path-base hyphen names, probe-free `compile` regression
347
-  (existing tests byte-identical), `has_name_runs` guards (pg cache-skip +
348
-  IMMUTABLE rejection).
349
-- Fixture: `0007-date-time-names.json` green; full suite stays green (3145 + the
350
-  new hand-written cases).
351
-- `cargo test` across feel-core / feel-py / feel-wasm / feel-lua / feel-pg.
352
-
353
-### Risks
354
-
355
-- Probe/eval disagreement (a name fused at parse but unresolvable at eval, or
356
-  vice versa) — pinned by `impl ScopeProbe for Context` mirroring `Expr::Var`.
357
-- Compile-once regressions in wrappers — pinned by policy + the `has_name_runs`
358
-  guard tests.
359
-- ~3–4 d estimated for the names increment; the decision-result-binding
360
-  follow-up adds ~1–2 d.
265
+### What shipped (parse-time scope probe — the "name oracle" ADR-17 foresaw)
266
+
267
+- **feel-core** — std-only `ScopeProbe` trait (`contains(name)`), impl for
268
+  `Context` mirroring `Expr::Var` resolution (a context binding or a built-in
269
+  name — parse and eval must agree on what "in scope" means). Lexer pass 2.5
270
+  `fuse_special_names` runs **after** `join_names` (a multi-word part like
271
+  `total price` must already be one word unit — `total price-total` is reachable)
272
+  and before `mark_reverse_open`: it scans maximal runs
273
+  `word ((-|+|*|/|.) word)*` — a word is a joined `Name` payload or a keyword's
274
+  spelling (`tok_word`; keywords are legal name parts, `if-then` is reachable) —
275
+  tries candidate prefixes **longest-first** against the probe, and fuses the
276
+  first hit. The scan resumes *after* a fused name (`Date-Time - Date-Time2`
277
+  keeps the minus an operator — the TCK 0007 expectation) and *inside* the run
278
+  after a miss (`a-b-c` with only `b-c` bound parses as `a - b-c`). Multi-char
279
+  operators (`..` `...` `**` `->`) are not name symbols. API:
280
+  `compile_with_probe` + probe-aware one-shot `evaluate` (the context is the
281
+  scope); `compile()` stays probe-free (byte-identical; all 3145 pre-existing
282
+  cases re-verified). Metadata: `CompiledExpr::has_name_runs()` (this parse
283
+  consulted the scope) and `name_run_candidates(expr)` (probe-free: every
284
+  fusable candidate of the text — the "could some scope change this parse" set).
285
+- **Wrappers** — one-shot `evaluate`/`evaluate_strict` in py/wasm/lua build the
286
+  context first and parse with it as the probe; the `compile`/`CompiledExpr`
287
+  classes stay probe-free (a compiled program pins no scope) and are documented
288
+  as such.
289
+- **feel-pg** — the `fn_extra` parse cache is probe-free, so both SQL functions
290
+  check the cached candidates per row (ns-cheap key lookups): no candidate bound
291
+  → the cached parse is already scope-correct (the RD-10 fast path; plain
292
+  `applicant.age` path access is unaffected); a candidate bound → `feel_eval`
293
+  re-parses against that row's jsonb keys (a name reading and an arithmetic
294
+  reading coexist across rows of one query), while `feel_eval_immutable` raises
295
+  a loud ERROR — an index expression must parse identically for every row
296
+  (RD-10 guard style), so `feel_eval_immutable('a-b', '{"a-b": 5}')` is rejected
297
+  but `feel_eval_immutable('applicant.age >= 18', data)` indexes exactly as
298
+  before.
299
+- **Grammar/evaluator: no change.** The LR(1) parser never sees the ambiguity;
300
+  every reference slot (call args, operands, path bases) gets the feature for
301
+  free.
302
+
303
+**Deviations (v1 scope, deliberate — ADR-47):** declaration slots (`for a-b in …`,
304
+formal params, context keys — the in-grammar production is not LR(1)-clean in
305
+call args, `f(a-b: 1)` vs `f(a-b)`; no TCK shape needs them); space-joined
306
+reserved-word names (`Profit and loss` — sound support would make every
307
+`a and b` / `for x in y` scope-dependent, disabling feel-pg's parse cache for
308
+nearly every nontrivial expression; Tier 1/2 unconditional joins stay the
309
+documented scope-blindness); `?`/non-XID name starts (`what if?`, rule 28 — the
310
+0083-feel-unicode bucket).
311
+
312
+### Test ingestion (measured reality, and the hand-written fixture)
313
+
314
+- The TCK has **no hyphen-named `inputData` anywhere**; 0007's hyphen expressions
315
+  reference *decisions* (DRG), so those skips are blocked by the DRG boundary
316
+  first — name support alone unlocks zero auto-ingested cases. The coverage proof
317
+  is the **`0092-feel-lambda` pattern**: a hand-written
318
+  `tests/fixtures/0007-date-time-names.json` (8 cases) binding testCase-001's
319
+  recorded `<resultNode>` values as context keys, lifting the 0007 expressions
320
+  verbatim — `Date-Time - Date-Time2` (the maximal-ambiguity subtraction,
321
+  `P367DT6H58M59S`), `Date-Time2.hour`, `Date-Time2.time offset`,
322
+  `time(Date-Time2)`, `date(Date-Time)`,
323
+  `years and months duration(Date-Time2, Date-Time)`, `Date.fromString`,
324
+  `Date.fromString.day`. Survives re-ingest (the ingester writes only
325
+  `0007-date-time.json`). The harness needed no change (`evaluate` became
326
+  probe-aware).
327
+- `fits_slice_grammar`'s input-name blanker now covers `+ - * /` names (longest
328
+  first), so a future bound `Date-Time` counts as one name; a partially covered
329
+  run (`a-b-c` with only `a-b` bound → free ident `c`) stays conservatively
330
+  skipped. Verified byte-identical on a full re-ingest of an existing suite.
331
+- **Follow-up increment (separate, ~1–2 d): decision-result binding** — bind the
332
+  testCase's `<resultNode>` values into the case context (expected-as-input, the
333
+  boxed-context stance). This is what actually auto-ingests the remaining 0007
334
+  cases and any other DRG-chained suite; it stands on its own feet even before
335
+  name support (hyphen-free DRG chains like `sumDurations` need it too).
336
+
337
+### Verification
338
+
339
+feel-core: 6 new test fns (scope resolution across all five symbols + keyword
340
+parts + multi-word parts; longest-match/left-to-right incl. the TCK subtraction
341
+and the `(a)-(b)` escape; name-vs-path/member interplay; the probe-free
342
+`compile` policy + both flags + the candidate list; run-free shape regressions
343
+incl. the deferred `for a-b` parse error). Wrappers: feel-py 2, feel-lua 2,
344
+feel-wasm smoke, feel-pg 5 (incl. the same-expression-different-rows cache test
345
+and the IMMUTABLE rejection). All suites green; feel-pg via `cargo pgrx test
346
+pg18`; fixtures 3153/111.
361347
 
362348
 ## Smaller, independent deferrals
363349
 

modified docs/special-char-names-research.md +15 −6

@@ -1,4 +1,10 @@
11
 # Research: names with `-` and other special characters (scope-dependent parsing)
2
+
3
+> **Outcome:** shipped as **ADR-47** (branch `feat/special-char-names`) —
4
+> Design A, v1 = reference slots. This document is the research record; where
5
+> it and ADR-47 differ, ADR-47 is authoritative (the fusion pass runs *after*
6
+> `join_names`; `Profit and loss`-style space-joined reserved-word names are a
7
+> documented deferral, not v1).
28
 
39
 Question: how much effort to support FEEL names containing `-` (and other
410
 "additional name symbols") that can only be parsed with context — and can the
@@ -106,14 +112,17 @@
106112
 mirroring eval's Var order — context binding, then builtins — is trivial).
107113
 Then:
108114
 
109
-- **Lexer**: one new pass before `join_names`: scan maximal runs
115
+- **Lexer**: one new pass *after* `join_names` (implemented order: a multi-word
116
+  part like `total price` must already be one word unit, or `total price-total`
117
+  would be unreachable — see ADR-47): scan maximal runs
110118
   `word (op word)*` with op ∈ {`-`, `+`, `*`, `/`} (and `.` for dot-names),
111119
   where a word is a `Name` or a keyword's spelling (`tok_word` already exists,
112
-  `lexer.rs:517-539` — this is what makes `Profit and loss` reachable). At each
113
-  run start, try candidates **longest-first** against the probe; fuse the
114
-  longest hit into one `Name` token (space-normalised payload, as today) and
115
-  continue after it. This is mechanically precedented: `match_keyword_phrase` /
116
-  `mark_instance_of` fuse tokens the same way. Est. ~100–200 lines + tests.
120
+  `lexer.rs` — keywords are legal name parts, which is what makes `if-then`
121
+  reachable). At each run start, try candidates **longest-first** against the
122
+  probe; fuse the longest hit into one `Name` token (space-normalised payload,
123
+  as today) and continue after it. This is mechanically precedented:
124
+  `match_keyword_phrase` / `mark_instance_of` fuse tokens the same way. Est.
125
+  ~100–200 lines + tests.
117126
 - **Grammar, AST, evaluator: unchanged.** The LR(1) parser never sees an
118127
   ambiguity — the same trick as the `instance of` fusion and the
119128
   `RBracketOpen` retag. Every `Name` slot (call heads, named-arg names, loop