Public repository: timo / feel

Reader

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

feat(core): value-invocation of a literal callee → null (ADR-38)

public

feat(core): value-invocation of a literal callee → null (ADR-38)

Adds `Expr::Invoke(Box<Expr>, CallArgs)` as the AST node for invoking a
literal callee such as `null()`, `123()`, `"abs"(-1)`, `@"2023-11-11"()`
or `true()`/`false()`. Distinct from `Expr::FnCall` (by-name dispatch) so
named built-in calls are completely unaffected.

Grammar: a new `Invocable` nonterminal covers the six literal forms and
feeds two new `Postfix` productions `<e:Invocable> "(" … ")"` that build
`Invoke` nodes. `Name` is excluded from `Invocable` so the `FnCall` path
keeps its monopoly on named dispatch.

Eval: the `Invoke` arm evaluates the callee; a `Value::Function` is
invoked normally, any other value produces `Value::Error` (→ null at the
lenient boundary), satisfying DMN §10.3.2.13.2 "invoking a non-function".

Tests: `invoke_non_function_yields_null` in `lib.rs::function_tests`
covers all eight 1131 expression shapes plus a regression check that
`abs(-1)` still routes through the unmodified `FnCall` path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Changeset634f19df41a9906677751c38ae851da967291177
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parents820ab8a62c7f
Children
Pushlog
by timo via ssh

modified crates/feel-core/src/ast.rs +12 −0

@@ -41,6 +41,13 @@
4141
     /// named arguments. Dispatch (context function / built-in / host registry) is
4242
     /// resolved at evaluation (ADR-23).
4343
     FnCall(String, CallArgs),
44
+    /// Invocation of a *value* callee, e.g. `123()`, `"abs"(-1)`, `null()` (ADR-38).
45
+    /// Distinct from [`FnCall`]: here the callee expression is evaluated first; if it
46
+    /// is not a [`Value::Function`] the call yields null (DMN §10.3.2.13.2). The
47
+    /// grammar only produces this for literal callees (never for a `Name`), so today
48
+    /// every `Invoke` evaluates to null; the function branch is the correct general
49
+    /// semantics should the callee grammar widen in future.
50
+    Invoke(Box<Expr>, CallArgs),
4451
     /// A FEEL function literal `function(a, b) body` — an anonymous closure that
4552
     /// captures the scope it is defined in (ADR-23). `params` are the formal
4653
     /// parameter names in order.
@@ -373,6 +380,11 @@
373380
                     && args.positional.iter().all(Expr::is_clock_free)
374381
                     && args.named.iter().all(|(_, e)| e.is_clock_free())
375382
             }
383
+            Expr::Invoke(callee, args) => {
384
+                callee.is_clock_free()
385
+                    && args.positional.iter().all(Expr::is_clock_free)
386
+                    && args.named.iter().all(|(_, e)| e.is_clock_free())
387
+            }
376388
             Expr::FnDef { body, .. } => body.is_clock_free(),
377389
             Expr::Neg(e) | Expr::Not(e) | Expr::UnaryTestVal(_, e) => e.is_clock_free(),
378390
             Expr::Arith(_, a, b) | Expr::Compare(_, a, b) | Expr::And(a, b) | Expr::Or(a, b) => {

modified crates/feel-core/src/eval.rs +11 −0

@@ -126,6 +126,17 @@
126126
             })
127127
             .into_value()),
128128
             Expr::FnCall(name, args) => self.eval_call(name, args, ctx),
129
+            // Value-invocation: evaluate the callee, invoke if it is a function, else
130
+            // error-null (DMN §10.3.2.13.2; ADR-38). Args are skipped for non-functions
131
+            // — FEEL has no side-effects, so this is observably identical to evaluating
132
+            // them.
133
+            Expr::Invoke(callee, args) => match self.eval(callee, ctx)?.forced() {
134
+                Value::Function(f) => {
135
+                    let a = self.eval_args(args, ctx)?;
136
+                    self.invoke(&f, a)
137
+                }
138
+                _ => Ok(Value::Error),
139
+            },
129140
 
130141
             // --- arithmetic ---
131142
             // Operands are `forced()` so a lazy host value is materialised before

modified crates/feel-core/src/feel.lalrpop +19 −0

@@ -216,7 +216,26 @@
216216
     <e:Postfix> "[" <idx:Expr> "]" => Expr::Filter(Box::new(e), Box::new(idx)),
217217
     <n:Name> "(" ")" => Expr::FnCall(n, CallArgs::default()),
218218
     <n:Name> "(" <a:Comma<Arg>> ")" => Expr::FnCall(n, callargs_from(a)),
219
+    // Value-invocation of a *literal* callee (DMN §10.3.2.13.2, ADR-38). `Name` is
220
+    // excluded so named calls stay on the FnCall path (builtin/host/scope dispatch).
221
+    // LR(1)-clean: each alternative reduces to `Invocable` on a lookahead other than
222
+    // `(`, or shifts into the call on `(`; `Name` is in `Primary` not `Invocable`, so
223
+    // this production never competes with `Name "(" … ")"`.
224
+    <e:Invocable> "(" ")" => Expr::Invoke(Box::new(e), CallArgs::default()),
225
+    <e:Invocable> "(" <a:Comma<Arg>> ")" => Expr::Invoke(Box::new(e), callargs_from(a)),
219226
     Primary,
227
+};
228
+
229
+// Literal expressions that may appear as a value-invocation callee (ADR-38). Every
230
+// element here is a non-function, so `Invoke` always evaluates to null (DMN
231
+// §10.3.2.13.2). `Name` is deliberately absent — named calls use `FnCall`.
232
+Invocable: Expr = {
233
+    Num => Expr::Number(<>),
234
+    Str => Expr::Str(<>),
235
+    TemporalLit => Expr::TemporalLit(<>),
236
+    "true" => Expr::Bool(true),
237
+    "false" => Expr::Bool(false),
238
+    "null" => Expr::Null,
220239
 };
221240
 
222241
 // One call argument: positional (`expr`) or named (`name: expr`). Both start with

modified crates/feel-core/src/lib.rs +19 −0

@@ -2560,6 +2560,25 @@
25602560
         );
25612561
     }
25622562
 
2563
+    // --- value-invocation of a non-function → null (ADR-38, 1131) ----------- //
2564
+
2565
+    #[test]
2566
+    fn invoke_non_function_yields_null() {
2567
+        // unknown name → error-null (FnCall path, unchanged)
2568
+        assert_eq!(ev("non_existing_function()"), Value::Null);
2569
+        // null, string, number, boolean, date — all non-functions → null
2570
+        assert_eq!(ev("null()"), Value::Null);
2571
+        assert_eq!(ev("\"some_func\"()"), Value::Null);
2572
+        assert_eq!(ev("\"abs\"(-1)"), Value::Null);
2573
+        assert_eq!(ev("123()"), Value::Null);
2574
+        assert_eq!(ev("true()"), Value::Null);
2575
+        assert_eq!(ev("false()"), Value::Null);
2576
+        assert_eq!(ev("@\"2023-11-11\"()"), Value::Null);
2577
+        // Named calls to built-ins must be unaffected (FnCall path still works).
2578
+        assert_eq!(ev("abs(-1)"), Value::Number(1.0));
2579
+        assert_eq!(ev("abs(n: -2)"), Value::Number(2.0));
2580
+    }
2581
+
25632582
     // --- host callables (ForeignFunction) ------------------------------------ //
25642583
 
25652584
     /// A host function that sums all of its numeric arguments (positional + named),