Public repository: timo / feel

Reader

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

feat(core): lex leading-dot & exponent number literals (§10.3.2.3.1)

public

feat(core): lex leading-dot & exponent number literals (§10.3.2.3.1)

FEEL grammar rule 35 allows a numeric literal to start with a dot
(`".872"`) and to carry an optional exponent (`"1.2e3"`). The previous
logos regex only covered digit-led mantissas without exponents.

Widen the Num token regex to:

  ([0-9]+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?

The leading-dot branch requires at least one digit after the dot, so it
never overlaps with `..` (DotDot) or a lone `.` (Dot); logos's maximal-
munch resolves any ambiguity without a priority annotation.  Negatives
continue to be produced by unary minus over the literal (consistent with
0099-arithmetic-negation).

Add direct unit tests (`number_literals_rule35`) covering `.872`, `-.872`,
exponent forms (`1.2e3`, `1E-3`, `.5e2`), and regression on the digit-led
mantissa.  All 91 lib tests pass.

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

modified crates/feel-core/src/lexer.rs +7 −1

@@ -139,7 +139,13 @@
139139
     Colon,
140140
 
141141
     // --- value-carrying terminals ---
142
-    #[regex(r"[0-9]+(\.[0-9]+)?", |lex| lex.slice().parse::<f64>().ok())]
142
+    // FEEL grammar rule 35 / §10.3.2.3.1: a numeric literal is an optional
143
+    // leading-dot mantissa OR a digit-led mantissa, with an optional exponent.
144
+    // The leading-dot branch (`\.[0-9]+`) requires at least one digit after the
145
+    // dot, so it never overlaps with `..` (DotDot, two chars) or a lone `.`
146
+    // (Dot, one char); logos's maximal-munch resolves any tie. Negatives are
147
+    // produced by unary minus over the literal — there is no signed-literal token.
148
+    #[regex(r"([0-9]+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?", |lex| lex.slice().parse::<f64>().ok())]
143149
     Num(f64),
144150
 
145151
     // A double-quoted string. The body is any run of non-quote/non-backslash

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

@@ -412,6 +412,25 @@
412412
         assert_eq!(ev("null"), Value::Null);
413413
         assert_eq!(ev("[1, 2, 3]"), list(vec![num(1.0), num(2.0), num(3.0)]));
414414
         assert_eq!(ev("[]"), list(vec![]));
415
+    }
416
+
417
+    // FEEL grammar rule 35 / §10.3.2.3.1: leading-dot mantissa and exponent forms.
418
+    // These are exercised by the 0101-feel-constants TCK suite and checked here
419
+    // directly so the lexer widening has coverage independent of the fixtures.
420
+    #[test]
421
+    fn number_literals_rule35() {
422
+        // leading-dot mantissa (.digits)
423
+        assert_eq!(ev(".872"), num(0.872));
424
+        assert_eq!(ev("-.872"), num(-0.872));
425
+        // exponent forms
426
+        assert_eq!(ev("1.2e3"), num(1200.0));
427
+        assert_eq!(ev("1.2E3"), num(1200.0));
428
+        assert_eq!(ev("1E-3"), num(0.001));
429
+        assert_eq!(ev("1e+2"), num(100.0));
430
+        // leading-dot + exponent
431
+        assert_eq!(ev(".5e2"), num(50.0));
432
+        // unchanged: digit-led mantissa still works
433
+        assert_eq!(ev("3.5"), num(3.5));
415434
     }
416435
 
417436
     #[test]