diff --git a/.changeset/perky-plums-dig.md b/.changeset/perky-plums-dig.md new file mode 100644 index 00000000..0c475a0b --- /dev/null +++ b/.changeset/perky-plums-dig.md @@ -0,0 +1,5 @@ +--- +'@fuzdev/fuz_code': minor +--- + +feat: add rust lexer diff --git a/CLAUDE.md b/CLAUDE.md index 5105a2bb..720edcd4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -44,7 +44,7 @@ fuz_code is a **syntax highlighting library**: - Runtime HTML generation with CSS classes - Hand-written single-pass lexers (zero regex), one per language -- 8 built-in languages (TS, JS, CSS, HTML, JSON, Svelte, Markdown, Bash) +- 9 built-in languages (TS, JS, CSS, HTML, JSON, Svelte, Markdown, Shell, Rust) - Extensible by writing a lexer (`SyntaxLang`) - Optional Svelte component (`Code.svelte`) @@ -69,7 +69,7 @@ src/ │ ├── syntax_styler.ts # SyntaxStyler class: registry + lex/stylize facade │ ├── syntax_styler_global.ts # pre-configured global instance │ ├── lexer.ts # lexer substrate: Lexer, TokenTypeRegistry, flat events, HTML render -│ ├── lexer_*.ts # hand-written lexers (json, ts, css, bash, markup, svelte, md) +│ ├── lexer_*.ts # hand-written lexers (json, ts, css, bash, markup, svelte, md, rust) │ ├── Code.svelte # main Svelte component │ ├── CodeHighlight.svelte # experimental CSS Highlight API │ ├── CodeTextarea.svelte # experimental live-highlighted textarea @@ -141,6 +141,11 @@ One `SyntaxLang` lexer per language, registered via `add_lang`: info matching and any-length closers, headings, blockquotes, lists, hr) with a per-block inline scan (emphasis, inline code, links, entities, raw markup via the markup scanner); fences embed their languages +- `lexer_rust.ts` - Rust, registered as `rust` with `rs` as an alias: one + flat scan loop (nested block comments and raw strings resolve with counters; + attribute interiors lex inline under an `[`/`]` depth counter — no frame + machine), lifetime-vs-char `'` disambiguation, `name!` macros, doc-vs-plain + comment split, the r/b/c string prefixes Embedded languages resolve lazily by name through the registry (markdown fences → any language, markup `