Public repository: timo / feel

Reader

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

feat(core): skip Java-style comments in the lexer

public

feat(core): skip Java-style comments in the lexer

Add `//…` (EOL) and `/*…*/` (block) comment skipping at the logos
pass-1 level. Uses a `logos::skip` callback on a `Comment` enum
variant so `allow_greedy = true` can be applied to the EOL pattern.
Maximal munch ensures `//`/`/*` win over the single-char `/` (Slash),
leaving division and the `->` arrow unaffected.

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

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

@@ -21,6 +21,10 @@
2121
 //! recognises *keyword-containing* reserved phrases (`date and time`, the two
2222
 //! durations) wherever they occur — they are atomic temporal type/constructor
2323
 //! names (ADR-26). Spaces in names are normalised to a single space.
24
+//!
25
+//! Java-style comments (`// … \n` and `/* … */`) are skipped at the logos level
26
+//! (pass 1). `logos` maximal munch makes `//` / `/*` win over the single `/`
27
+//! (`Slash`), so a bare `/` used as division or in `->` is unaffected.
2428
 
2529
 use core::fmt;
2630
 
@@ -46,6 +50,12 @@
4650
 #[derive(Logos, Clone, Debug, PartialEq)]
4751
 #[logos(skip r"[ \t\r\n]+", error = LexError)]
4852
 pub enum Tok {
53
+    // FEEL Java-style comments — skipped at the logos level (never emitted).
54
+    // Maximal munch: `//`/`/*` beat the 1-char `/` Slash, so bare `/` is unaffected.
55
+    #[regex(r"//[^\n]*", logos::skip, priority = 5, allow_greedy = true)]
56
+    #[regex(r"/\*([^*]|\*[^/])*\*/", logos::skip, priority = 5)]
57
+    Comment,
58
+
4959
     // --- word keywords (never emitted by logos directly; see `keyword`) ---
5060
     For,
5161
     In,
@@ -568,6 +578,7 @@
568578
             Tok::Str(s) => return write!(f, "{s:?}"),
569579
             Tok::TemporalLit(s) => return write!(f, "@{s:?}"),
570580
             Tok::Name(s) => return write!(f, "{s}"),
581
+            Tok::Comment => unreachable!("Comment is logos::skip — never emitted"),
571582
         };
572583
         f.write_str(s)
573584
     }