Public repository: timo / feel

Reader

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

feat(core): allow Unicode letters in identifiers

public

feat(core): allow Unicode letters in identifiers

The `Name` token was ASCII-only (`[A-Za-z_][A-Za-z_0-9]*`), so variable
references with umlauts or other Unicode letters failed to parse. Widen it to
`[\p{L}_][\p{L}\p{N}_]*` (LALRPOP's lexer uses the regex crate, which supports
`\p{…}` classes). Keyword precedence is unaffected: string-literal keywords
still win, and longest-match keeps e.g. `fortune` an identifier, not `for`.

Adds a `variable_resolution` test that binds a populated context and resolves
both an ASCII and an umlaut name — also the first test exercising top-level
`Expr::Var` resolution and unbound-name -> null.

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

modified crates/feel-core/src/feel.lalrpop +4 −1

@@ -139,4 +139,7 @@
139139
 // variable references. (Full FEEL names with spaces are only needed for
140140
 // built-in function names, which are out of scope.) Keyword string-literals
141141
 // take lexer precedence, so `and`/`in`/`for`/`true`/… are never parsed as names.
142
-Name: String = <s:r"[A-Za-z_][A-Za-z_0-9]*"> => s.to_string();
142
+// Unicode-aware: any Unicode letter starts a name, and letters/digits continue
143
+// it (so `über`, `preis`, `naïve` parse). Longest-match keeps `fortune` an
144
+// identifier rather than the keyword `for`.
145
+Name: String = <s:r"[\p{L}_][\p{L}\p{N}_]*"> => s.to_string();

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

@@ -255,6 +255,25 @@
255255
     }
256256
 
257257
     #[test]
258
+    fn variable_resolution() {
259
+        let mut ctx = Context::empty();
260
+        ctx.insert("preis", num(10.0));
261
+        ctx.insert("über", num(3.0)); // Unicode identifier (umlaut)
262
+        let ev = |src: &str| evaluate(src, &ctx).unwrap_or_else(|e| panic!("`{src}` failed: {e}"));
263
+
264
+        assert_eq!(ev("preis"), num(10.0));
265
+        assert_eq!(ev("preis + über"), num(13.0));
266
+        assert_eq!(ev("über * 2"), num(6.0));
267
+        // Unbound names resolve to null (FEEL-friendly), not an error.
268
+        assert_eq!(ev("unbekannt"), Value::Null);
269
+        // Loop variable still shadows correctly alongside context vars.
270
+        assert_eq!(
271
+            ev("for preis in [1,2] return preis + über"),
272
+            list(vec![num(4.0), num(5.0)])
273
+        );
274
+    }
275
+
276
+    #[test]
258277
     fn parse_error_is_reported() {
259278
         assert!(matches!(evaluate("1 +", &Context::empty()), Err(FeelError::Parse(_))));
260279
         assert!(matches!(evaluate("if x then", &Context::empty()), Err(FeelError::Parse(_))));