Public repository: timo / feel

Reader

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

feat!: default name resolution is `quoted` (ADR-48 revision)

draft feat/name-resolution-v2

feat!: default name resolution is `quoted` (ADR-48 revision)

`a-b` is now subtraction and `` `a-b` `` the name unless `symbols` is chosen
explicitly — the meaning comes from the text, never from the data, as in
Camunda. Under `symbols` the root-vs-local asymmetry (root names resolve,
loop variables/parameters/filter elements do not) is not explainable to
users, and a row gaining a key flips `unit - price` into a lookup.

- feel-core: `NameResolution::default()` is `Quoted`; spec tests and the
  fixture harness opt into `Symbols` (only the 8 hand-written 0007 cases
  need it — all other fixtures pass under `Quoted`).
- feel-pg: `name_resolution DEFAULT 'quoted'`.
- py/lua/wasm: `names` defaults to quoted; docs and tests updated; one
  test per surface pins the default.
- names bench keeps measuring `Symbols`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Changesetda382279c66c4c72ad01310614fb7558b5515d07
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parents7690f6d5c4ed
Children
Pushlog
by timo via ssh

modified DECISIONS.md +19 −2

@@ -2416,14 +2416,15 @@
24162416
 
24172417
   2. **Name-resolution level as a parse option.** `#[non_exhaustive] enum NameResolution`:
24182418
      - `Quoted` — backticks only; no run fusion, no candidates. Camunda semantics; cheapest.
2419
-     - `Symbols` (**default**) — backticks plus ADR-47 runs over `- + * / .`.
2419
+       **Default since the revision below** (originally `Symbols`).
2420
+     - `Symbols` — backticks plus ADR-47 runs over `- + * / .` (the spec mode).
24202421
      - `Full` — additionally keyword-joined names (`Profit and loss`); **deferred** (see
24212422
        below), the variant is reserved so it can land without an API break.
24222423
 
24232424
      API: `ParseOptions { names: NameResolution }` on `compile`/`evaluate` variants in
24242425
      feel-core; a keyword argument in the wrappers (`feel.compile(expr, names="quoted")`);
24252426
      in feel-pg a **function argument with a default** (`name_resolution text DEFAULT
2426
-     'symbols'`) — **never a GUC**: a session setting would make `feel_eval_immutable`'s
2427
+     'quoted'` since the revision; planned as `'symbols'`) — **never a GUC**: a session setting would make `feel_eval_immutable`'s
24272428
      result depend on something other than its arguments and silently break expression
24282429
      indexes. The level is stored in `CompiledExpr`, shown in its `Debug`/`repr`, and part
24292430
      of every cache key. "Who wants spec compatibility pays with performance": `Full` costs
@@ -2567,3 +2568,19 @@
25672568
   rows got 21 % faster (no per-row re-parse), the formula 27 % faster (no 190 lookups per
25682569
   row). `'quoted'` buys nothing extra once the pre-check applies; it matters for contexts
25692570
   that do carry special keys.
2571
+
2572
+- **Revision (2026-10-14): the default is `Quoted`.** After A–C, the remaining `Symbols`
2573
+  behaviour is consistent but not *explainable* without knowing the implementation: names
2574
+  bound at the root and paths from there are resolved, names the expression binds itself
2575
+  (loop variables, parameters, context entries, filter elements) and computed bases are not —
2576
+  because the decision is made at parse time, when only the root scope exists. A user reads
2577
+  FEEL as "a name counts where it is in scope", and under `Symbols` a row gaining a key
2578
+  (`unit-price` next to `unit`, `price`) silently turns `unit - price` into a lookup. The
2579
+  default therefore becomes the one-sentence rule *"`-` is always minus; names with special
2580
+  characters or keywords go in backticks"* — data-independent, zero-cost, valid in every name
2581
+  slot, identical to Camunda. `Symbols` stays the explicit spec mode (third-party DMN models,
2582
+  the TCK). Measured: of the fixture suite, only the 8 hand-written `0007-date-time-names`
2583
+  cases need `Symbols`; all other ≈ 3145 cases pass under `Quoted`. The fixture harness runs
2584
+  in `Symbols` (it *is* the spec); feel-core's spec tests opt in explicitly; each surface has a
2585
+  test pinning the `Quoted` default. A spec-faithful alternative that decides at evaluation
2586
+  time (per arithmetic chain, with the live scope) is being prototyped separately.

modified README.md +10 −7

@@ -58,14 +58,16 @@
5858
   **scope**: longest in-scope match preferred, left to right; spaces are not
5959
   part of the name (`a - b` is the same candidate as `a-b`); `(a)-(b)` forces
6060
   the operator reading. On a static path the navigated value is the scope
61
-  (`applicant.first-name`). Both `evaluate` and `compile` resolve per context —
62
-  a compiled program caches one parse per distinct scope reading.
61
+  (`applicant.first-name`). This is the **opt-in** `"symbols"` mode; both
62
+  `evaluate` and `compile` then resolve per context — a compiled program
63
+  caches one parse per distinct scope reading.
6364
 - **Backtick-quoted names** (`` `a-b` ``, `` `Profit and loss` ``,
6465
   `` applicant.`first-name` `` — a non-standard extension with feel-scala's
6566
   syntax, so Camunda expressions run unchanged): one name, decided by the text,
66
-  in every name slot. A `names` option selects `"symbols"` (default) or
67
-  `"quoted"` (backticks only, `a-b` always subtraction — Camunda semantics);
68
-  feel-pg takes it as the `name_resolution` argument (ADR-48). Inside
67
+  in every name slot. A `names` option selects `"quoted"` (**the default** —
68
+  backticks only, `a-b` always subtraction, Camunda semantics) or `"symbols"`
69
+  (the DMN spec's scope-dependent reading); feel-pg takes it as the
70
+  `name_resolution` argument (ADR-48). Inside
6971
   backticks every character counts, spaces included: `` `a  b` `` is the key
7072
   with two spaces, `` ` a` `` the one with a leading space — unlike unquoted
7173
   multi-word names, whose spaces collapse to one.
@@ -77,8 +79,9 @@
7779
   with `unit`, `price` and `unit-price` all in the context, both `unit-price`
7880
   and `unit - price` read the key `unit-price`, so adding that key to a row
7981
   silently turns a subtraction into a lookup; `(unit)-(price)` forces the
80
-  subtraction. For data you do not control (external jsonb), `"quoted"` makes
81
-  `-` always mean minus.
82
+  subtraction. That is why `"quoted"` is the default: `-` always means minus,
83
+  whatever the data; choose `"symbols"` for third-party DMN models written
84
+  with unquoted special names.
8285
 
8386
   | context `unit`, `price`, `unit-price` | `"symbols"` | `"quoted"` |
8487
   |---|---|---|

modified ROADMAP.md +4 −1

@@ -319,7 +319,10 @@
319319
 ### v2: levels, backticks, adaptive compile, path members (ADR-48 — A–C ✅ shipped, D open)
320320
 
321321
 **Status:** A–C implemented on branch `feat/name-resolution-v2` (stacked on
322
-`feat/special-char-names`); measurements, deviations from the plan (trace-keyed
322
+`feat/special-char-names`); default level revised to `quoted` (backticks only —
323
+`symbols` is the opt-in spec mode; see ADR-48 "Revision"). An evaluation-time
324
+alternative for a spec-faithful `symbols` is being prototyped on a stacked
325
+branch. Measurements, deviations from the plan (trace-keyed
323326
 cache, O(1) special-key pre-check, member runs stop at `.`) and two
324327
 pre-existing list-selection bugs fixed on the way (feel-pg jsonb arrays, Lua
325328
 sequences) are recorded in [DECISIONS.md](DECISIONS.md) ADR-48. Remaining v1

modified crates/feel-core/benches/names.rs +16 −5

@@ -3,17 +3,28 @@
33
 //! a 190-candidate name-only formula, a bound hyphen name, a nested hyphen
44
 //! member, and one compiled program alternating between two scopes.
55
 //!
6
-//! Uses only API present since ADR-47 (`compile`, `evaluate`,
7
-//! `CompiledExpr::evaluate`), so the same file benches both branches.
8
-//! Note: before ADR-48 `compile` was probe-free, so its `eval` numbers for the
9
-//! bound/member workloads measure the *arithmetic* (wrong) reading.
6
+//! Runs at `NameResolution::Symbols` (the spec mode; the crate default became
7
+//! `Quoted` after the ADR-48 measurements, which used this file with the
8
+//! then-default `compile`/`evaluate`).
109
 //!
1110
 //! Run with: `cargo bench -p feel-core --bench names`.
1211
 
1312
 use std::collections::BTreeMap;
1413
 
1514
 use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
16
-use feel_core::{compile, evaluate, Context, Value};
15
+use feel_core::{CompiledExpr, Context, FeelError, NameResolution, ParseOptions, Value};
16
+
17
+fn symbols() -> ParseOptions {
18
+    ParseOptions::names(NameResolution::Symbols)
19
+}
20
+
21
+fn compile(src: &str) -> Result<CompiledExpr, FeelError> {
22
+    feel_core::compile_with(src, &symbols())
23
+}
24
+
25
+fn evaluate(src: &str, ctx: &Context) -> Result<Value, FeelError> {
26
+    feel_core::evaluate_with(src, ctx, &symbols())
27
+}
1728
 
1829
 fn ctx_of(pairs: &[(&str, Value)]) -> Context {
1930
     let mut c = Context::empty();

modified crates/feel-core/src/lib.rs +48 −14

@@ -210,15 +210,23 @@
210210
 /// How far the parser goes in reading FEEL's ambiguous names (ADR-48) — a parse
211211
 /// option ([`ParseOptions`]). Backtick-quoted names (`` `a-b` ``, the feel-scala
212212
 /// extension) work at every level.
213
+///
214
+/// The default is [`Quoted`](NameResolution::Quoted): the meaning of an
215
+/// expression then comes from its text alone, never from the data. Opt into
216
+/// [`Symbols`](NameResolution::Symbols) for the DMN spec's scope-dependent
217
+/// reading (unquoted names from third-party DMN models, the TCK).
213218
 #[non_exhaustive]
214219
 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
215220
 pub enum NameResolution {
216221
     /// Only backtick-quoted names are special; `a-b` is always subtraction —
217
-    /// Camunda/feel-scala semantics. No scope checks at all: the cheapest level.
222
+    /// Camunda/feel-scala semantics. No scope checks at all: the cheapest level,
223
+    /// and the default.
224
+    #[default]
218225
     Quoted,
219
-    /// Backticks plus §10.3.1.6 runs over `- + * / .`, resolved against the
220
-    /// scope (ADR-47) and, on static paths, against the navigated value (ADR-48).
221
-    #[default]
226
+    /// The spec mode (§10.3.1.6): backticks plus runs over `- + * / .`,
227
+    /// resolved against the root scope (ADR-47) and, on static paths, against
228
+    /// the navigated value (ADR-48). Names bound inside the expression (loop
229
+    /// variables, parameters, filter elements) are not consulted.
222230
     Symbols,
223231
 }
224232
 
@@ -238,7 +246,7 @@
238246
 #[non_exhaustive]
239247
 #[derive(Debug, Default, Clone, PartialEq, Eq)]
240248
 pub struct ParseOptions {
241
-    /// The name-resolution level (default [`NameResolution::Symbols`]).
249
+    /// The name-resolution level (default [`NameResolution::Quoted`]).
242250
     pub names: NameResolution,
243251
 }
244252
 
@@ -524,13 +532,15 @@
524532
 }
525533
 
526534
 /// Parse a FEEL expression into a reusable [`CompiledExpr`] without evaluating
527
-/// it, at the default [`NameResolution::Symbols`] level.
535
+/// it, at the default [`NameResolution::Quoted`] level: `a-b` is subtraction,
536
+/// `` `a-b` `` the name.
528537
 ///
529538
 /// Returns [`FeelError::Parse`] if the expression is syntactically invalid.
530539
 ///
531
-/// **Scope-adaptive** (ADR-48): special-character names (`a-b`, `Date-Time`,
540
+/// With [`compile_with`] at [`NameResolution::Symbols`] the result is
541
+/// **scope-adaptive** (ADR-48): special-character names (`a-b`, `Date-Time`,
532542
 /// `applicant.first-name`) resolve per evaluation against the context, exactly
533
-/// like the one-shot [`evaluate`] — see [`CompiledExpr`].
543
+/// like the one-shot [`evaluate_with`] — see [`CompiledExpr`].
534544
 ///
535545
 /// `ExprParser::new()` is now cheap (the external `logos` lexer builds no runtime
536546
 /// matcher — see `lexer.rs`), so there is no parser to cache; the cost is the
@@ -586,10 +596,11 @@
586596
 
587597
 /// Parse and evaluate a FEEL expression against a context.
588598
 ///
589
-/// One parse, pinned to `context` as the §10.3.1.6 scope (ADR-47): a name like
590
-/// `a-b` resolves to the context binding when one exists, and to subtraction
591
-/// otherwise. Prefer [`compile`] when evaluating the same expression more than
592
-/// once.
599
+/// At the default [`NameResolution::Quoted`] level `a-b` is subtraction and
600
+/// `` `a-b` `` the name. With [`evaluate_with`] at [`NameResolution::Symbols`]
601
+/// the context is the §10.3.1.6 scope (ADR-47): `a-b` resolves to the context
602
+/// binding when one exists. Prefer [`compile`] when evaluating the same
603
+/// expression more than once.
593604
 ///
594605
 /// ```
595606
 /// use feel_core::{evaluate, Context, Value};
@@ -641,6 +652,15 @@
641652
 
642653
 #[cfg(test)]
643654
 mod tests {
655
+    // The spec tests below exercise the scope-dependent reading: shadow the
656
+    // crate's `evaluate`/`compile` (default `Quoted`, ADR-48) with
657
+    // `Symbols`-mode versions. `default_level_is_quoted` uses `super::`.
658
+    fn evaluate(src: &str, ctx: &Context) -> Result<Value, FeelError> {
659
+        super::evaluate_with(src, ctx, &ParseOptions::names(NameResolution::Symbols))
660
+    }
661
+    fn compile(src: &str) -> Result<CompiledExpr, FeelError> {
662
+        super::compile_with(src, &ParseOptions::names(NameResolution::Symbols))
663
+    }
644664
     use super::*;
645665
 
646666
     /// Evaluate against an empty context, panicking on error, and collapse error
@@ -805,7 +825,7 @@
805825
         assert_eq!(prog.scoped_parses(), 1);
806826
 
807827
         // `compile_with_probe` PINS its probe's scope: no adaptation later.
808
-        let pinned = compile_with_probe("a-b", &bound, &ParseOptions::default()).unwrap();
828
+        let pinned = compile_with_probe("a-b", &bound, &ParseOptions::names(NameResolution::Symbols)).unwrap();
809829
         assert_eq!(pinned.evaluate(&bound).unwrap().into_lenient(), num(10.0));
810830
         assert_eq!(pinned.evaluate(&parts).unwrap().into_lenient(), Value::Null);
811831
 
@@ -1000,11 +1020,25 @@
10001020
             evaluate_with("applicant.first-name", &app, &quoted).unwrap().into_lenient(),
10011021
             Value::Null
10021022
         );
1003
-        // Symbols (the default) resolves against the scope.
1023
+        // Symbols resolves against the scope.
10041024
         assert_eq!(evaluate("a-b", &ctx).unwrap(), num(100.0));
10051025
         assert_eq!(NameResolution::from_name("Quoted"), Some(NameResolution::Quoted));
10061026
         assert_eq!(NameResolution::from_name("symbols"), Some(NameResolution::Symbols));
10071027
         assert_eq!(NameResolution::from_name("full"), None);
1028
+    }
1029
+
1030
+    #[test]
1031
+    fn default_level_is_quoted() {
1032
+        // ADR-48 (revised): the crate default reads the text, not the data.
1033
+        let ctx = ctx_of(&[("a", num(7.0)), ("b", num(3.0)), ("a-b", num(100.0))]);
1034
+        assert_eq!(super::evaluate("a-b", &ctx).unwrap(), num(4.0));
1035
+        assert_eq!(super::evaluate("`a-b`", &ctx).unwrap(), num(100.0));
1036
+        let prog = super::compile("a-b").unwrap();
1037
+        assert_eq!(prog.name_resolution(), NameResolution::Quoted);
1038
+        assert_eq!(prog.evaluate(&ctx).unwrap(), num(4.0));
1039
+        let app = ctx_of(&[("applicant", ctx_value(&[("first-name", s("Ada"))]))]);
1040
+        assert_eq!(super::evaluate("applicant.`first-name`", &app).unwrap(), s("Ada"));
1041
+        assert_eq!(ParseOptions::default().names, NameResolution::Quoted);
10081042
     }
10091043
 
10101044
     #[test]

modified crates/feel-core/tests/fixtures_test.rs +4 −2

@@ -13,7 +13,7 @@
1313
 use std::fs;
1414
 use std::path::{Path, PathBuf};
1515
 
16
-use feel_core::{coerce, evaluate, parse_type, Context, Value};
16
+use feel_core::{coerce, evaluate_with, parse_type, Context, NameResolution, ParseOptions, Value};
1717
 
1818
 fn fixtures_dir() -> PathBuf {
1919
     Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures")
@@ -75,7 +75,9 @@
7575
     let ctx = context_from_case(case, id);
7676
     // Collapse error provenance: TCK expectations are spec-shaped (a type error
7777
     // is just `null`), so we compare against the lenient view (ADR-14).
78
-    let evaluated = evaluate(expr, &ctx)
78
+    // The TCK is the DMN spec: unquoted special-character names resolve
79
+    // against the scope (§10.3.1.6), so run in `Symbols` mode (ADR-48).
80
+    let evaluated = evaluate_with(expr, &ctx, &ParseOptions::names(NameResolution::Symbols))
7981
         .unwrap_or_else(|e| panic!("[{id}] evaluating `{expr}` failed: {e}"))
8082
         .into_lenient();
8183
 

modified crates/feel-lua/src/lib.rs +9 −7

@@ -53,11 +53,12 @@
5353
 /// Rust integration tests call directly against an embedded VM. It registers
5454
 /// `evaluate`, `evaluate_strict` and `compile` on a fresh table and returns it.
5555
 ///
56
-/// Special-character names (§10.3.1.6): a name like `a-b` resolves to the table
57
-/// key `a-b` when present, and to subtraction otherwise — in the one-shot
58
-/// `evaluate`/`evaluate_strict` and, per call, in the scope-adaptive `compile`
59
-/// userdata (ADR-48). An optional last argument `names` selects the level:
60
-/// `"symbols"` (default) or `"quoted"` (backticks only; `` `a-b` `` always works).
56
+/// Special-character names (ADR-48): an optional last argument `names` selects
57
+/// the level. The default `"quoted"` reads `a-b` as subtraction and `` `a-b` ``
58
+/// as the name — the text decides, as in Camunda. `"symbols"` opts into the DMN
59
+/// spec's reading (§10.3.1.6): `a-b` resolves to the table key `a-b` when
60
+/// present — in the one-shot `evaluate`/`evaluate_strict` and, per call, in
61
+/// the scope-adaptive `compile` userdata.
6162
 pub fn build_module(lua: &Lua) -> mlua::Result<Table> {
6263
     let exports = lua.create_table()?;
6364
     exports.set(
@@ -108,8 +109,9 @@
108109
 
109110
 /// A parsed FEEL expression, reusable across many evaluations (the `feel.compile`
110111
 /// result). Exposed to Lua as userdata with `:evaluate` / `:evaluate_strict`.
111
-/// **Scope-adaptive** (ADR-48): each call resolves special-character names
112
-/// against its own context, with a small cache of per-scope parses.
112
+/// Compiled with `"symbols"` it is **scope-adaptive** (ADR-48): each call
113
+/// resolves special-character names against its own context, with a small
114
+/// cache of per-scope parses.
113115
 struct CompiledExpr {
114116
     inner: CoreCompiled,
115117
 }

modified crates/feel-lua/tests/feel.rs +18 −12

@@ -117,35 +117,35 @@
117117
     // `a-b` is the in-scope NAME when the table binds it, subtraction otherwise;
118118
     // `a - b` is the same candidate (spaces are not part of the name).
119119
     let n: f64 = lua
120
-        .load(r#"return feel.evaluate("a-b", { ["a-b"] = 5 })"#)
120
+        .load(r#"return feel.evaluate("a-b", { ["a-b"] = 5 }, nil, "symbols")"#)
121121
         .eval()
122122
         .unwrap();
123123
     assert_eq!(n, 5.0);
124124
     let n: f64 = lua
125
-        .load(r#"return feel.evaluate("a - b", { ["a-b"] = 5 })"#)
125
+        .load(r#"return feel.evaluate("a - b", { ["a-b"] = 5 }, nil, "symbols")"#)
126126
         .eval()
127127
         .unwrap();
128128
     assert_eq!(n, 5.0);
129129
     let n: f64 = lua
130
-        .load(r#"return feel.evaluate("a-b", { a = 7, b = 3 })"#)
130
+        .load(r#"return feel.evaluate("a-b", { a = 7, b = 3 }, nil, "symbols")"#)
131131
         .eval()
132132
         .unwrap();
133133
     assert_eq!(n, 4.0);
134134
     // `(a)-(b)` is the escape hatch: subtraction even when `a-b` is the name.
135135
     let n: f64 = lua
136
-        .load(r#"return feel.evaluate("(a)-(b)", { a = 7, b = 3, ["a-b"] = 100 })"#)
136
+        .load(r#"return feel.evaluate("(a)-(b)", { a = 7, b = 3, ["a-b"] = 100 }, nil, "symbols")"#)
137137
         .eval()
138138
         .unwrap();
139139
     assert_eq!(n, 4.0);
140140
     // A hyphen name as a path base: `x-y.hour` fuses `x-y`, `.hour` stays a member.
141141
     let n: i64 = lua
142
-        .load(r#"return feel.evaluate("x-y.hour", { ["x-y"] = { hour = 3 } })"#)
142
+        .load(r#"return feel.evaluate("x-y.hour", { ["x-y"] = { hour = 3 } }, nil, "symbols")"#)
143143
         .eval()
144144
         .unwrap();
145145
     assert_eq!(n, 3);
146146
     // A member word never fuses against the root scope: `x.y-z` is (x.y) - z.
147147
     let n: i64 = lua
148
-        .load(r#"return feel.evaluate("x.y-z", { x = { y = 10 }, z = 3, ["y-z"] = 1 })"#)
148
+        .load(r#"return feel.evaluate("x.y-z", { x = { y = 10 }, z = 3, ["y-z"] = 1 }, nil, "symbols")"#)
149149
         .eval()
150150
         .unwrap();
151151
     assert_eq!(n, 7);
@@ -157,12 +157,12 @@
157157
     // The ambient `functions` table is part of the parse-time scope (ADR-47): a
158158
     // hyphen-named host function is callable.
159159
     let n: i64 = lua
160
-        .load(r#"return feel.evaluate("my-fn(2)", {}, { ["my-fn"] = function(x) return x * 10 end })"#)
160
+        .load(r#"return feel.evaluate("my-fn(2)", {}, { ["my-fn"] = function(x) return x * 10 end }, "symbols")"#)
161161
         .eval()
162162
         .unwrap();
163163
     assert_eq!(n, 20);
164164
     let v: Value = lua
165
-        .load(r#"return feel.evaluate("my-fn(2)", {})"#)
165
+        .load(r#"return feel.evaluate("my-fn(2)", {}, nil, "symbols")"#)
166166
         .eval()
167167
         .unwrap();
168168
     assert!(matches!(v, Value::Nil));
@@ -173,12 +173,12 @@
173173
     let lua = vm();
174174
     // ADR-48: one compiled program follows each call's context.
175175
     let n: f64 = lua
176
-        .load(r#"local p = feel.compile("a-b"); return p:evaluate({ ["a-b"] = 5 })"#)
176
+        .load(r#"local p = feel.compile("a-b", "symbols"); return p:evaluate({ ["a-b"] = 5 })"#)
177177
         .eval()
178178
         .unwrap();
179179
     assert_eq!(n, 5.0);
180180
     let n: f64 = lua
181
-        .load(r#"local p = feel.compile("a-b"); return p:evaluate({ a = 7, b = 3 })"#)
181
+        .load(r#"local p = feel.compile("a-b", "symbols"); return p:evaluate({ a = 7, b = 3 })"#)
182182
         .eval()
183183
         .unwrap();
184184
     assert_eq!(n, 4.0);
@@ -187,6 +187,12 @@
187187
 #[test]
188188
 fn names_levels_backticks_and_members() {
189189
     let lua = vm();
190
+    // Default (ADR-48, revised): quoted — `a-b` is subtraction.
191
+    let n: f64 = lua
192
+        .load(r#"return feel.evaluate("a-b", { a = 7, b = 3, ["a-b"] = 100 })"#)
193
+        .eval()
194
+        .unwrap();
195
+    assert_eq!(n, 4.0);
190196
     let n: f64 = lua
191197
         .load(r#"return feel.evaluate("a-b", { a = 7, b = 3, ["a-b"] = 100 }, nil, "quoted")"#)
192198
         .eval()
@@ -203,7 +209,7 @@
203209
         .unwrap();
204210
     assert_eq!(n, 1.0);
205211
     let s: String = lua
206
-        .load(r#"return feel.evaluate("applicant.first-name", { applicant = { ["first-name"] = "Ada" } })"#)
212
+        .load(r#"return feel.evaluate("applicant.first-name", { applicant = { ["first-name"] = "Ada" } }, nil, "symbols")"#)
207213
         .eval()
208214
         .unwrap();
209215
     assert_eq!(s, "Ada");
@@ -214,7 +220,7 @@
214220
         .unwrap();
215221
     assert_eq!(n, 2);
216222
     let n: i64 = lua
217
-        .load(r#"return feel.evaluate("orders.unit-price", { orders = { { ["unit-price"] = 3 } } })[1]"#)
223
+        .load(r#"return feel.evaluate("orders.unit-price", { orders = { { ["unit-price"] = 3 } } }, nil, "symbols")[1]"#)
218224
         .eval()
219225
         .unwrap();
220226
     assert_eq!(n, 3);

modified crates/feel-pg/src/lib.rs +36 −17

@@ -16,8 +16,9 @@
1616
 //! Scope-dependent special-character names (`a-b`, `applicant.first-name`,
1717
 //! §10.3.1.6) resolve per row against the row's jsonb (ADR-47/48): the cached
1818
 //! [`CompiledExpr`] keeps one parse per distinct answer set, so neither function
19
-//! re-parses per row. A `name_resolution` argument selects the level (`'symbols'`,
20
-//! the default, or `'quoted'` — backticks only, no per-row name checks).
19
+//! re-parses per row. A `name_resolution` argument selects the level: `'quoted'`
20
+//! (the default — backticks only, `a-b` is always subtraction, no per-row name
21
+//! checks) or `'symbols'` (the spec's scope-dependent reading).
2122
 //!
2223
 //! The JSON/jsonb boundary mapping lives here (not in `feel-core`), per the
2324
 //! project's boundary-mapping decision. It uses PostgreSQL's **binary** jsonb C
@@ -75,7 +76,8 @@
7576
 /// a small per-call-site cache of parses keyed by those answers. A name and an
7677
 /// arithmetic reading thus coexist across rows of one query at no per-row parse
7778
 /// cost. `name_resolution => 'quoted'` (backticks only, Camunda semantics) skips
78
-/// the checks altogether; `'symbols'` is the default.
79
+/// the checks altogether and is the default; `'symbols'` opts into the spec's
80
+/// scope-dependent reading described here.
7981
 ///
8082
 /// Declared **STABLE** (not VOLATILE): the only non-argument input is the
8183
 /// transaction start timestamp behind `now()`/`today()`, constant within a
@@ -99,7 +101,7 @@
99101
     expr: &str,
100102
     context: default!(PgJsonb, "'{}'::jsonb"),
101103
     strict: default!(bool, "false"),
102
-    name_resolution: default!(&str, "'symbols'"),
104
+    name_resolution: default!(&str, "'quoted'"),
103105
     fcinfo: pg_sys::FunctionCallInfo,
104106
 ) -> PgJsonb {
105107
     let names = name_level(name_resolution, "feel_eval");
@@ -172,13 +174,13 @@
172174
 ///   change. Fixed offsets (`+02:00`) and `Z` are tzdb-independent and fully
173175
 ///   supported — all an index needs.
174176
 ///
175
-/// Special-character names resolve per row exactly as in [`feel_eval`] (ADR-48):
176
-/// a row binding `a-b` indexes the name, a row binding only `a` and `b` the
177
-/// difference — as §10.3.1.6 demands for each row. That is still IMMUTABLE: the
178
-/// parse is a pure function of the expression, the `name_resolution` argument and
179
-/// the row, so the result depends on the arguments alone. (Never a GUC: a session
180
-/// setting would break that.) `name_resolution => 'quoted'` gives one parse for
181
-/// every row.
177
+/// Special-character names follow `name_resolution` exactly as in [`feel_eval`]
178
+/// (ADR-48). The default `'quoted'` gives one parse for every row. Under
179
+/// `'symbols'` a row binding `a-b` indexes the name and a row binding only `a`
180
+/// and `b` the difference — as §10.3.1.6 demands for each row — which is still
181
+/// IMMUTABLE: the parse is a pure function of the expression, the
182
+/// `name_resolution` argument and the row, so the result depends on the
183
+/// arguments alone. (Never a GUC: a session setting would break that.)
182184
 ///
183185
 /// Math/regex builtins (`exp`/`log`/`sqrt`, `matches`/`replace`/`split`) are taken
184186
 /// as immutable; their results are stable except across a libc/`regex` upgrade —
@@ -196,7 +198,7 @@
196198
     expr: &str,
197199
     context: default!(PgJsonb, "'{}'::jsonb"),
198200
     strict: default!(bool, "false"),
199
-    name_resolution: default!(&str, "'symbols'"),
201
+    name_resolution: default!(&str, "'quoted'"),
200202
     fcinfo: pg_sys::FunctionCallInfo,
201203
 ) -> PgJsonb {
202204
     let names = name_level(name_resolution, "feel_eval_immutable");
@@ -655,7 +657,7 @@
655657
     #[pg_test]
656658
     fn special_char_name_resolves_from_jsonb_key() {
657659
         let matched = Spi::get_one::<bool>(
658
-            r#"SELECT feel_eval('a-b', '{"a-b": 5}'::jsonb) = '5'::jsonb"#,
660
+            r#"SELECT feel_eval('a-b', '{"a-b": 5}'::jsonb, name_resolution => 'symbols') = '5'::jsonb"#,
659661
         )
660662
         .expect("SPI query failed");
661663
         assert_eq!(matched, Some(true));
@@ -675,7 +677,7 @@
675677
         // `a-b` read the NAME, rows binding only `a`/`b` the difference — the
676678
         // adaptive CompiledExpr picks the parse per row (ADR-48).
677679
         let matched = Spi::get_one::<bool>(
678
-            r#"SELECT bool_and(feel_eval('a-b', c) = e)
680
+            r#"SELECT bool_and(feel_eval('a-b', c, name_resolution => 'symbols') = e)
679681
                  FROM (VALUES ('{"a-b": 5}'::jsonb, '5'::jsonb),
680682
                               ('{"a": 7, "b": 3}', '4'),
681683
                               ('{"a-b": 5, "a": 7, "b": 3}', '5'),
@@ -690,7 +692,7 @@
690692
         // ADR-48 drops ADR-47's ERROR: the parse is a pure function of
691693
         // (expr, name_resolution, row), so per-row names are still IMMUTABLE.
692694
         let matched = Spi::get_one::<bool>(
693
-            r#"SELECT bool_and(feel_eval_immutable('a-b', c) = e)
695
+            r#"SELECT bool_and(feel_eval_immutable('a-b', c, name_resolution => 'symbols') = e)
694696
                  FROM (VALUES ('{"a-b": 5}'::jsonb, '5'::jsonb),
695697
                               ('{"a": 7, "b": 3}', '4')) t(c, e)"#,
696698
         )
@@ -708,9 +710,11 @@
708710
         // The path-member probe navigates the lazy jsonb (ADR-48).
709711
         let matched = Spi::get_one::<bool>(
710712
             r#"SELECT feel_eval('applicant.first-name',
711
-                                '{"applicant": {"first-name": "Ada"}}'::jsonb) = '"Ada"'::jsonb
713
+                                '{"applicant": {"first-name": "Ada"}}'::jsonb,
714
+                                name_resolution => 'symbols') = '"Ada"'::jsonb
712715
                   AND feel_eval('orders.unit-price',
713
-                                '{"orders": [{"unit-price": 2}, {"unit-price": 3}]}'::jsonb)
716
+                                '{"orders": [{"unit-price": 2}, {"unit-price": 3}]}'::jsonb,
717
+                                name_resolution => 'symbols')
714718
                       = '[2, 3]'::jsonb"#,
715719
         )
716720
         .expect("SPI query failed");
@@ -726,6 +730,21 @@
726730
                       = '[1, 2, null]'::jsonb
727731
                   AND feel_eval('o.items.x', '{"o": {"items": [{"x": 1}]}}'::jsonb)
728732
                       = '[1]'::jsonb"#,
733
+        )
734
+        .expect("SPI query failed");
735
+        assert_eq!(matched, Some(true));
736
+    }
737
+
738
+    #[pg_test]
739
+    fn default_level_is_quoted() {
740
+        // ADR-48 (revised): without `name_resolution`, `a-b` is subtraction and
741
+        // `` `a-b` `` the key — the text decides, not the row.
742
+        let matched = Spi::get_one::<bool>(
743
+            r#"SELECT feel_eval('a-b', '{"a-b": 5, "a": 7, "b": 3}'::jsonb) = '4'::jsonb
744
+                  AND feel_eval('`a-b`', '{"a-b": 5}'::jsonb) = '5'::jsonb
745
+                  AND feel_eval('applicant.`first-name`',
746
+                                '{"applicant": {"first-name": "Ada"}}'::jsonb) = '"Ada"'::jsonb
747
+                  AND feel_eval_immutable('a-b', '{"a-b": 5, "a": 7, "b": 3}'::jsonb) = '4'::jsonb"#,
729748
         )
730749
         .expect("SPI query failed");
731750
         assert_eq!(matched, Some(true));

modified crates/feel-py/src/lib.rs +12 −12

@@ -52,14 +52,12 @@
5252
 /// A null arising from a type/domain error is returned as `None`; see
5353
 /// `evaluate_strict` to raise instead.
5454
 ///
55
-/// The context **is** the scope for §10.3.1.6 name resolution (ADR-47): a name
56
-/// like `a-b` resolves to the context binding `a-b` when one exists, and to
57
-/// subtraction otherwise. The ambient `functions` registry (ADR-23) counts as
58
-/// scope too — mirroring `eval_call`, which resolves a call head against
59
-/// context, built-ins and (third) the registry — so a hyphen-named host
60
-/// function is callable as `my-fn(1)`. `names` selects the level (ADR-48):
61
-/// `"symbols"` (default) or `"quoted"` — backticks only, `a-b` always
62
-/// subtraction (Camunda semantics); `` `a-b` `` works at every level.
55
+/// Special-character names (ADR-48): by default (`names="quoted"`) `a-b` is
56
+/// subtraction and `` `a-b` `` the name — the text decides, not the data, as in
57
+/// Camunda. `names="symbols"` opts into the DMN spec's reading (§10.3.1.6,
58
+/// ADR-47): the context is the scope, so `a-b` resolves to the binding `a-b`
59
+/// when one exists; the ambient `functions` registry (ADR-23) counts as scope
60
+/// too, so a hyphen-named host function is callable as `my-fn(1)`.
6361
 #[pyfunction]
6462
 #[pyo3(signature = (expr, context=None, functions=None, names=None))]
6563
 fn evaluate<'py>(
@@ -105,9 +103,10 @@
105103
 /// Parse a FEEL expression into a reusable `CompiledExpr` (raises `FeelError` on a
106104
 /// parse error). Does not evaluate.
107105
 ///
108
-/// **Scope-adaptive** (ADR-48): special-character names (`a-b`,
106
+/// `names` as for [`evaluate`]. With `names="symbols"` the result is
107
+/// **scope-adaptive** (ADR-48): special-character names (`a-b`,
109108
 /// `applicant.first-name`) resolve per evaluation against that call's context
110
-/// and `functions`, exactly like the one-shot [`evaluate`]. `names` as there.
109
+/// and `functions`.
111110
 #[pyfunction]
112111
 #[pyo3(signature = (expr, names=None))]
113112
 fn compile(expr: &str, names: Option<&str>) -> PyResult<CompiledExpr> {
@@ -120,8 +119,9 @@
120119
 /// A parsed FEEL expression, reusable across many evaluations: parsing happens
121120
 /// once, each call only maps the context across the boundary.
122121
 ///
123
-/// **Scope-adaptive** (ADR-48): each evaluation resolves special-character
124
-/// names against its own context, with a small cache of per-scope parses.
122
+/// Compiled with `names="symbols"` it is **scope-adaptive** (ADR-48): each
123
+/// evaluation resolves special-character names against its own context, with a
124
+/// small cache of per-scope parses.
125125
 #[pyclass(name = "CompiledExpr", module = "feel")]
126126
 struct CompiledExpr {
127127
     inner: CoreCompiled,

modified crates/feel-py/tests/test_feel.py +15 −14

@@ -271,40 +271,41 @@
271271
 def test_special_char_name_resolves_against_scope():
272272
     # `a-b` is the in-scope NAME when the dict binds it, subtraction otherwise;
273273
     # `a - b` is the same candidate (spaces are not part of the name).
274
-    assert feel.evaluate("a-b", {"a-b": 5}) == 5
275
-    assert feel.evaluate("a - b", {"a-b": 5}) == 5
276
-    assert feel.evaluate("a-b", {"a": 7, "b": 3}) == 4
274
+    assert feel.evaluate("a-b", {"a-b": 5}, names="symbols") == 5
275
+    assert feel.evaluate("a - b", {"a-b": 5}, names="symbols") == 5
276
+    assert feel.evaluate("a-b", {"a": 7, "b": 3}, names="symbols") == 4
277277
     # `(a)-(b)` is the escape hatch: subtraction even when `a-b` is the name.
278
-    assert feel.evaluate("(a)-(b)", {"a": 7, "b": 3, "a-b": 100}) == 4
278
+    assert feel.evaluate("(a)-(b)", {"a": 7, "b": 3, "a-b": 100}, names="symbols") == 4
279279
     # A hyphen name as a path base: `x-y.hour` fuses `x-y`, `.hour` stays a member.
280
-    assert feel.evaluate("x-y.hour", {"x-y": {"hour": 3}}) == 3
280
+    assert feel.evaluate("x-y.hour", {"x-y": {"hour": 3}}, names="symbols") == 3
281281
     # A member word never fuses against the root scope: `x.y-z` is (x.y) - z.
282
-    assert feel.evaluate("x.y-z", {"x": {"y": 10}, "z": 3, "y-z": 1}) == 7
282
+    assert feel.evaluate("x.y-z", {"x": {"y": 10}, "z": 3, "y-z": 1}, names="symbols") == 7
283283
 
284284
 
285285
 def test_special_char_name_resolves_host_function_from_registry():
286286
     # The ambient `functions` registry is part of the parse-time scope: a call
287287
     # head resolves against it (third, after context and built-ins), so a
288288
     # hyphen-named host function is callable (ADR-47).
289
-    assert feel.evaluate("my-fn(2)", {}, functions={"my-fn": lambda x: x * 10}) == 20
289
+    assert feel.evaluate("my-fn(2)", {}, functions={"my-fn": lambda x: x * 10}, names="symbols") == 20
290290
     # Without the registry entry the run stays arithmetic (`my - fn(2)` -> null).
291
-    assert feel.evaluate("my-fn(2)", {}) is None
291
+    assert feel.evaluate("my-fn(2)", {}, names="symbols") is None
292292
 
293293
 
294294
 def test_compile_class_is_scope_adaptive():
295295
     # ADR-48: one compiled program, both readings — it follows each context.
296
-    prog = feel.compile("a-b")
296
+    prog = feel.compile("a-b", names="symbols")
297297
     assert prog.evaluate({"a-b": 5}) == 5
298298
     assert prog.evaluate({"a": 7, "b": 3}) == 4
299299
     # The registry is part of the compiled path's scope too.
300
-    call = feel.compile("my-fn(2)")
300
+    call = feel.compile("my-fn(2)", names="symbols")
301301
     assert call.evaluate({}, functions={"my-fn": lambda x: x * 10}) == 20
302302
     assert call.evaluate({}) is None
303303
 
304304
 
305305
 def test_names_levels_and_backticks():
306306
     ctx = {"a": 7, "b": 3, "a-b": 100}
307
-    assert feel.evaluate("a-b", ctx) == 100
307
+    assert feel.evaluate("a-b", ctx, names="symbols") == 100
308
+    assert feel.evaluate("a-b", ctx) == 4  # default: quoted (ADR-48)
308309
     assert feel.evaluate("a-b", ctx, names="quoted") == 4
309310
     assert feel.compile("a-b", names="quoted").evaluate(ctx) == 4
310311
     assert feel.evaluate("`a-b`", ctx, names="quoted") == 100
@@ -315,9 +316,9 @@
315316
 
316317
 def test_nested_hyphen_members():
317318
     # The member probe navigates lazy host objects (ADR-48).
318
-    assert feel.evaluate("applicant.first-name", {"applicant": {"first-name": "Ada"}}) == "Ada"
319
-    assert feel.evaluate("orders.unit-price", {"orders": [{"unit-price": 2}, {"unit-price": 3}]}) == [2, 3]
320
-    assert feel.evaluate("o.items.x", {"o": {"items": [{"x": 1}, {"x": 2}]}}) == [1, 2]
319
+    assert feel.evaluate("applicant.first-name", {"applicant": {"first-name": "Ada"}}, names="symbols") == "Ada"
320
+    assert feel.evaluate("orders.unit-price", {"orders": [{"unit-price": 2}, {"unit-price": 3}]}, names="symbols") == [2, 3]
321
+    assert feel.evaluate("o.items.x", {"o": {"items": [{"x": 1}, {"x": 2}]}}, names="symbols") == [1, 2]
321322
 
322323
 
323324
 # --- host callables: Python functions invoked from FEEL (ADR-23) ---------- #

modified crates/feel-wasm/smoke.mjs +9 −6

@@ -188,7 +188,8 @@
188188
 }
189189
 prog.free();
190190
 
191
-// Special-character names (§10.3.1.6, ADR-47): the context is the scope. `a-b`
191
+// Special-character names (§10.3.1.6, ADR-47), in the spec mode "symbols"
192
+// (the default is "quoted", ADR-48): the context is the scope. `a-b`
192193
 // is the in-scope NAME when the object binds it, subtraction otherwise; `a - b`
193194
 // is the same candidate (spaces are not part of the name); `(a)-(b)` is the
194195
 // escape hatch; a hyphen name works as a path base. The compiled class is
@@ -203,7 +204,7 @@
203204
   ["x.y-z", { x: { y: 10 }, z: 3, "y-z": 1 }, 7],
204205
 ];
205206
 for (const [expr, ctx, expected] of nameCases) {
206
-  const got = evaluate(expr, ctx);
207
+  const got = evaluate(expr, ctx, undefined, "symbols");
207208
   console.log(`${expr} (special-char name) => ${JSON.stringify(got)}`);
208209
   if (!eq(got, expected)) {
209210
     console.error(`FAIL: expected ${JSON.stringify(expected)}, got ${JSON.stringify(got)}`);
@@ -213,7 +214,7 @@
213214
 {
214215
   // The ambient `functions` registry is part of the parse-time scope: a
215216
   // hyphen-named host function is callable.
216
-  const got = evaluate("my-fn(2)", {}, { "my-fn": (x) => x * 10 });
217
+  const got = evaluate("my-fn(2)", {}, { "my-fn": (x) => x * 10 }, "symbols");
217218
   if (!eq(got, 20)) {
218219
     console.error(`FAIL: my-fn(2) via registry expected 20, got ${JSON.stringify(got)}`);
219220
     ok = false;
@@ -224,8 +225,10 @@
224225
   [["`Profit and loss`", { "Profit and loss": 1 }], 1],
225226
   [["a-b", { a: 7, b: 3, "a-b": 100 }, undefined, "quoted"], 4],
226227
   [["`a-b`", { "a-b": 5 }, undefined, "quoted"], 5],
227
-  [["applicant.first-name", { applicant: { "first-name": "Ada" } }], "Ada"],
228
-  [["orders.unit-price", { orders: [{ "unit-price": 2 }, { "unit-price": 3 }] }], [2, 3]],
228
+  [["applicant.first-name", { applicant: { "first-name": "Ada" } }, undefined, "symbols"], "Ada"],
229
+  [["orders.unit-price", { orders: [{ "unit-price": 2 }, { "unit-price": 3 }] }, undefined, "symbols"], [2, 3]],
230
+  // Default (ADR-48, revised): quoted — `a-b` is subtraction.
231
+  [["a-b", { a: 7, b: 3, "a-b": 100 }], 4],
229232
   [["o.items.x", { o: { items: [{ x: 1 }, { x: 2 }] } }], [1, 2]],
230233
 ];
231234
 for (const [args, expected] of v2Cases) {
@@ -237,7 +240,7 @@
237240
   }
238241
 }
239242
 {
240
-  const prog2 = compile("a-b");
243
+  const prog2 = compile("a-b", "symbols");
241244
   const compiledNameCases = [
242245
     [{ "a-b": 5 }, 5], // scope-adaptive (ADR-48): the key, per call
243246
     [{ a: 7, b: 3 }, 4],

modified crates/feel-wasm/src/lib.rs +9 −9

@@ -37,11 +37,11 @@
3737
 /// returned as plain `null` (the spec-shaped result); see `evaluate_strict` to
3838
 /// surface such errors as a thrown exception instead.
3939
 ///
40
-/// The context **is** the scope for §10.3.1.6 name resolution (ADR-47): a name
41
-/// like `a-b` resolves to the context binding `a-b` when one exists, and to
42
-/// subtraction otherwise. `names` selects the level (ADR-48): `"symbols"`
43
-/// (default when omitted) or `"quoted"` — backticks only, `a-b` always
44
-/// subtraction (Camunda semantics); `` `a-b` `` works at every level.
40
+/// Special-character names (ADR-48): `names` selects the level. The default
41
+/// (omitted or `"quoted"`) reads `a-b` as subtraction and `` `a-b` `` as the
42
+/// name — the text decides, as in Camunda. `"symbols"` opts into the DMN spec's
43
+/// reading (§10.3.1.6, ADR-47): the context is the scope, so `a-b` resolves to
44
+/// the binding `a-b` when one exists.
4545
 #[wasm_bindgen]
4646
 pub fn evaluate(
4747
     expr: &str,
@@ -84,16 +84,16 @@
8484
 /// `FinalizationRegistry`, so the WASM-side memory is reclaimed on GC; calling
8585
 /// `free()` explicitly is an optional escape hatch, not required.
8686
 ///
87
-/// **Scope-adaptive** (ADR-48): each evaluation resolves special-character
88
-/// names against its own context, with a small cache of per-scope parses.
87
+/// Compiled with `"symbols"` it is **scope-adaptive** (ADR-48): each
88
+/// evaluation resolves special-character names against its own context, with a
89
+/// small cache of per-scope parses.
8990
 #[wasm_bindgen]
9091
 pub struct CompiledExpr {
9192
     inner: CoreCompiled,
9293
 }
9394
 
9495
 /// Parse a FEEL expression into a reusable [`CompiledExpr`] (throws on a parse
95
-/// error). Does not evaluate. Scope-adaptive — see [`CompiledExpr`]; `names`
96
-/// as for [`evaluate`].
96
+/// error). Does not evaluate. `names` as for [`evaluate`]; see [`CompiledExpr`].
9797
 #[wasm_bindgen]
9898
 pub fn compile(expr: &str, names: Option<String>) -> Result<CompiledExpr, JsError> {
9999
     let options = parse_options(names.as_deref())?;