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>
| Changeset | 7cb5fe8a93eb92329cee7c7ca47704250854a6ee |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | c8ff352aa500 |
| Children | |
| Pushlog | by timo via ssh |
modified crates/feel-core/src/lexer.rs +11 −0
| @@ -21,6 +21,10 @@ | ||
| 21 | 21 | //! recognises *keyword-containing* reserved phrases (`date and time`, the two |
| 22 | 22 | //! durations) wherever they occur — they are atomic temporal type/constructor |
| 23 | 23 | //! 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. | |
| 24 | 28 | |
| 25 | 29 | use core::fmt; |
| 26 | 30 | |
| @@ -46,6 +50,12 @@ | ||
| 46 | 50 | #[derive(Logos, Clone, Debug, PartialEq)] |
| 47 | 51 | #[logos(skip r"[ \t\r\n]+", error = LexError)] |
| 48 | 52 | 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 | + | |
| 49 | 59 | // --- word keywords (never emitted by logos directly; see `keyword`) --- |
| 50 | 60 | For, |
| 51 | 61 | In, |
| @@ -568,6 +578,7 @@ | ||
| 568 | 578 | Tok::Str(s) => return write!(f, "{s:?}"), |
| 569 | 579 | Tok::TemporalLit(s) => return write!(f, "@{s:?}"), |
| 570 | 580 | Tok::Name(s) => return write!(f, "{s}"), |
| 581 | + Tok::Comment => unreachable!("Comment is logos::skip — never emitted"), | |
| 571 | 582 | }; |
| 572 | 583 | f.write_str(s) |
| 573 | 584 | } |