api #

syntax styling utilities and components for TypeScript, Svelte, Markdown, and more

22 modules · 62 declarations

Modules
#

advance_probe
#

lexer.ts view source

(text: string, cached: number, from: number, ch: string): number import {advance_probe} from '@fuzdev/fuz_code/lexer.js';

Returns the cached next occurrence of ch at or after from, re-probing with indexOf only when the cached position has fallen behind. Infinity when the text has no further occurrence — a monotonic probe that keeps delimiter scans linear across a construct that is dense in ch.

text

type string

cached

type number

from

type number

ch

type string

returns

number

Code
#

Code.svelte view source

accepts children

import Code from '@fuzdev/fuz_code/Code.svelte';

lang?

type string
optional default 'svelte'

children?

type Snippet<[]> & Snippet<[markup: string]>
optional

content?

The source code to syntax highlight.

type string
optional

dangerous_raw_html?

type string
optional

inline?

Whether to render as inline code instead of a block.

type boolean
optional default false

wrap?

Whether to wrap long lines in block code (white-space: pre-wrap instead of pre). Wraps at whitespace — long unbroken tokens (URLs, hashes) still scroll horizontally. Ignored for inline code.

type boolean
optional default false

nomargin?

Whether to disable the default margin-bottom on block code (var(--space_lg) when not :last-child).

type boolean
optional default false

syntax_styler?

Custom SyntaxStyler instance, e.g. with different languages registered.

optional default syntax_styler_global

intersects

SvelteHTMLElements['code']

CodeHighlight
#

CodeHighlight.svelte view source

accepts children

import CodeHighlight from '@fuzdev/fuz_code/CodeHighlight.svelte';

lang?

type string
optional default 'svelte'

children?

type Snippet<[]> & Snippet<[markup: string]>
optional

content

The source code to syntax highlight.

type string

mode?

Highlighting mode: 'auto' uses the CSS Custom Highlight API when supported and falls back to HTML, 'ranges' forces the Highlight API (requires browser support), 'html' forces HTML generation with CSS classes. The Highlight API has limited browser support and requires theme_highlight.css instead of theme.css.

optional default 'auto'

inline?

Whether to render as inline code instead of a block.

type boolean
optional default false

wrap?

Whether to wrap long lines in block code (white-space: pre-wrap instead of pre). Wraps at whitespace — long unbroken tokens (URLs, hashes) still scroll horizontally. Ignored for inline code.

type boolean
optional default false

syntax_styler?

Custom SyntaxStyler instance, e.g. with different languages registered.

optional default syntax_styler_global

intersects

SvelteHTMLElements['code']

CodeSample
#

code_sample.ts view source

CodeSample import type {CodeSample} from '@fuzdev/fuz_code/code_sample.js';

name

type string

lang

type string

content

type string

CodeTextarea
#

CodeTextarea.svelte view source

accepts children

import CodeTextarea from '@fuzdev/fuz_code/CodeTextarea.svelte';

value?

type string | (string[] & string)
optional bindable default ''

lang?

type string
optional default 'svelte'

syntax_styler?

Custom SyntaxStyler instance (defaults to the global one).

optional default syntax_styler_global

wrapper_attrs?

Attributes for the wrapper <div> — the layout box that the textarea fills and resize grows. Use it for sizing/layout classes, style, id, or container-level handlers. Its class is merged with the internal code_textarea class; data-lang stays component-controlled. (...rest spreads onto the <textarea>; the backdrop <pre> is internal and intentionally not exposed.)

type HTMLAttributes<HTMLDivElement>
optional

intersects

SvelteHTMLElements['textarea']

create_markup_probe_cache
#

lexer_markup.ts view source

(): MarkupProbeCache import {create_markup_probe_cache} from '@fuzdev/fuz_code/lexer_markup.js';

returns

MarkupProbeCache

create_range_highlighting
#

range_highlighting.svelte.ts view source

(options: RangeHighlightingOptions): RangeHighlighting import {create_range_highlighting} from '@fuzdev/fuz_code/range_highlighting.svelte.js';

Wires up CSS Custom Highlight API range highlighting for a single element's text node, shared by CodeHighlight and CodeTextarea. Creates a HighlightManager, memoizes tokenization, applies/clears ranges in an effect, emits DEV warnings for unsupported languages, and tears down on destroy.

Must be called during component initialization (it uses $effect/onDestroy).

options

returns

RangeHighlighting

highlight_priorities
#

HighlightManager
#

highlight_manager.ts view source

import {HighlightManager} from '@fuzdev/fuz_code/highlight_manager.js';

Manages CSS Custom Highlight API ranges for a single element's text node. Tracks ranges per element and only removes its own ranges when clearing, cooperating with other managers that share the global CSS.highlights registry.

Experimental — limited browser support. Use Code.svelte for production block code; this powers the experimental CodeHighlight and CodeTextarea.

examples

const manager = new HighlightManager(); manager.highlight_from_lexed(element, syntax_styler_global.lex(text, 'ts'));

element_ranges

This manager's ranges, keyed by prefixed highlight name (e.g. token_keyword). A single range object may be shared across several names (a token type plus its aliases), since one range can belong to multiple Highlight sets.

type Map<string, Array<AbstractRange>>

constructor

type new (): HighlightManager

highlight_from_lexed

Highlights element's text node from a lexed event stream. Ranges come straight from event offsets — no position reconstruction. Clears this manager's previous ranges first.

A missing text node is a no-op. Offsets past the text node's length are clamped (a DOM/source mismatch is the caller's concern, not a throw here).

type (element: Element, lexed: LexedSyntax): void

element

type Element

lexed

returns void

clear_element_ranges

Clears only this manager's ranges from the shared highlights. Defensive: a highlight may already be gone (e.g. another manager removed the last range, or HMR reset the registry), which is a valid state, not an error.

type (): void

returns void

destroy

type (): void

returns void

HighlightMode
#

HighlightTokenName
#

is_ascii_alnum
#

lexer.ts view source

(c: number): boolean import {is_ascii_alnum} from '@fuzdev/fuz_code/lexer.js';

c

type number

returns

boolean

is_ascii_word
#

lexer.ts view source

(c: number): boolean import {is_ascii_word} from '@fuzdev/fuz_code/lexer.js';

A \w word char — ASCII letters, digits, and _.

c

type number

returns

boolean

is_digit
#

lexer.ts view source

(c: number): boolean import {is_digit} from '@fuzdev/fuz_code/lexer.js';

c

type number

returns

boolean

is_hex_digit
#

lexer.ts view source

(c: number): boolean import {is_hex_digit} from '@fuzdev/fuz_code/lexer.js';

c

type number

returns

boolean

is_ident
#

lexer.ts view source

(c: number): boolean import {is_ident} from '@fuzdev/fuz_code/lexer.js';

c

type number

returns

boolean

is_ident_start
#

lexer.ts view source

(c: number): boolean import {is_ident_start} from '@fuzdev/fuz_code/lexer.js';

c

type number

returns

boolean

is_space
#

lexer.ts view source

(c: number): boolean import {is_space} from '@fuzdev/fuz_code/lexer.js';

c

type number

returns

boolean

lex_markup_construct
#

lexer_markup.ts view source

(l: Lexer, i: number, end: number, mode: MarkupLexMode, cache: MarkupProbeCache): number import {lex_markup_construct} from '@fuzdev/fuz_code/lexer_markup.js';

Lexes one <… construct at i, returning the next scan position. Exported for lexer_md, which dispatches raw markup out of markdown text.

l

type Lexer

i

type number

end

type number

mode

cache

returns

number

lex_markup_window
#

lexer_markup.ts view source

(l: Lexer, mode: MarkupLexMode): void import {lex_markup_window} from '@fuzdev/fuz_code/lexer_markup.js';

The shared markup window lexer — lexes [l.pos, l.end) per mode. The entry point for the html/xml registrations here and for lexer_svelte.

l

type Lexer

mode

returns

void

lex_syntax
#

lexer.ts view source

(text: string, lang: SyntaxLang, langs?: Map<string, SyntaxLang> | undefined, types?: TokenTypeRegistry): LexedSyntax import {lex_syntax} from '@fuzdev/fuz_code/lexer.js';

Lexes text with lang, returning the flat token event stream.

text

type string

lang

langs?

registry used to resolve embedded languages by id

type Map<string, SyntaxLang> | undefined
optional

types

token-type registry stamped on the result; must be the one lang (and any embedded language) interned its type ids into

default token_types_global

returns

LexedSyntax

LexedSyntax
#

lexer.ts view source

LexedSyntax import type {LexedSyntax} from '@fuzdev/fuz_code/lexer.js';

The result of lexing: the source text plus its flat token event stream.

text

type string

events

type Int32Array

events_len

type number

types

The registry that interned the type ids in events — consumers resolve ids through it, so a stream can never be rendered against the wrong id space.

type TokenTypeRegistry

Lexer
#

lexer.ts view source

import {Lexer} from '@fuzdev/fuz_code/lexer.js';

Shared lexing context passed to language lex functions. Holds the text window, the event buffer, and the language registry for embedding.

text

type string

pos

type number

end

type number

langs

Language registry for embed — set by lex_syntax.

type Map<string, SyntaxLang> | null

events

type Int32Array

events_len

type number

constructor

type new (capacity?: number): Lexer

capacity

type number
default 256

leaf

Emits a leaf token. Empty spans are dropped; a leaf adjacent to a preceding leaf of the same type extends it instead (span coalescing).

type (type_id: number, start: number, end: number): void

type_id

type number

start

type number

end

type number
returns void

open

Opens a container token at start. Must be balanced by a later close.

type (type_id: number, start: number): void

type_id

type number

start

type number
returns void

close

Closes the innermost open container at end.

type (end: number): void

end

type number
returns void

embed

Lexes [start, end) with the language registered as lang_id, restoring this lexer's window afterward. Returns false (leaving the region as plain text) when the language isn't registered or embedding is nested past MAX_EMBED_DEPTH.

type (lang_id: string, start: number, end: number): boolean

lang_id

type string

start

type number

end

type number
returns boolean

lexer_bash
#

lexer_bash.ts view source

SyntaxLang import {lexer_bash} from '@fuzdev/fuz_code/lexer_bash.js';

The shell (bash-family) language registration for the lexer engine.

Registered as sh; bash and shell alias it: POSIX sh is a syntactic subset of bash for highlighting purposes, and the bash-only constructs this lexer additionally recognizes don't occur in sh input, so running it on sh scripts is exact. There is no separate sh lexer.

lexer_css
#

lexer_css.ts view source

SyntaxLang import {lexer_css} from '@fuzdev/fuz_code/lexer_css.js';

The CSS language registration for the lexer engine.

lexer_json
#

lexer_json.ts view source

SyntaxLang import {lexer_json} from '@fuzdev/fuz_code/lexer_json.js';

The JSON language registration for the lexer engine.

lexer_markup
#

lexer_markup.ts view source

SyntaxLang import {lexer_markup} from '@fuzdev/fuz_code/lexer_markup.js';

The HTML markup language registration for the lexer engine.

lexer_md
#

lexer_md.ts view source

SyntaxLang import {lexer_md} from '@fuzdev/fuz_code/lexer_md.js';

The Markdown language registration for the lexer engine.

lexer_svelte
#

lexer_svelte.ts view source

SyntaxLang import {lexer_svelte} from '@fuzdev/fuz_code/lexer_svelte.js';

The Svelte language registration for the lexer engine.

lexer_ts
#

lexer_ts.ts view source

SyntaxLang import {lexer_ts} from '@fuzdev/fuz_code/lexer_ts.js';

The TypeScript language registration for the lexer engine.

JavaScript reuses this lexer via the js/javascript aliases: TypeScript is a syntactic superset, and the TS-only constructs the lexer recognizes (type annotations, as, generics before a call) can't appear in valid JS, so running the full TS lexer on JS is a no-op for those paths. There is no separate JS lexer.

lexer_xml
#

lexer_markup.ts view source

SyntaxLang import {lexer_xml} from '@fuzdev/fuz_code/lexer_markup.js';

The XML language registration — the same scanner without HTML's rawtext elements or style=/on*= attribute embedding.

MARKUP_MODE_HTML
#

lexer_markup.ts view source

MarkupLexMode import {MARKUP_MODE_HTML} from '@fuzdev/fuz_code/lexer_markup.js';

The html dialect mode — also used by lexer_md for raw markup embedded in markdown text.

MarkupLexMode
#

lexer_markup.ts view source

MarkupLexMode import type {MarkupLexMode} from '@fuzdev/fuz_code/lexer_markup.js';

Dialect configuration for the shared markup scanner — how html, xml, and svelte differ. Instances are module-level constants (one per dialect) so the scanner stays monomorphic.

script_embed

Language embedded in <script> rawtext regions (resolved through the lexer registry at lex time), or null to disable rawtext regions entirely (xml).

type string | null

script_container

Container type id wrapping script content — lang_js for html, lang_ts for svelte. Unused when script_embed is null.

type number

rcdata

RCDATA textarea/title regions (html only — svelte keeps expressions live inside them).

type boolean

special_attrs

style=/on*= attribute embedding (html only).

type boolean

attr_comments

JS-style line and block comments between attributes emit comment leaves (svelte only — in html/xml a // inside a tag is ordinary bogus attribute text, not a comment).

type boolean

lex_expression

Lexes a {…} expression at from, returning the position after it — the svelte hook, null for html/xml. full enables block/each forms (top level); tag and attribute contexts get the simple form.

type ((l: Lexer, from: number, end: number, full: boolean) => number) | null

MarkupProbeCache
#

lexer_markup.ts view source

MarkupProbeCache import type {MarkupProbeCache} from '@fuzdev/fuz_code/lexer_markup.js';

Monotonic next-occurrence caches for the markup scanner's probes (see advance_probe). The scan visits constructs in increasing position order, but its probes (</{ between constructs, & in text gaps and attribute values) target chars the current construct doesn't consume — without the caches, input dense in one probe char but lacking another re-scans the document tail per construct, quadratic in document size. One cache spans a whole window scan (or a whole md document scan, threaded through lex_markup_construct); embedded guest windows create their own.

lt

type number

brace

type number

amp

type number

matches_ci
#

lexer.ts view source

(text: string, from: number, word: string): boolean import {matches_ci} from '@fuzdev/fuz_code/lexer.js';

Case-insensitive ASCII match of word (must be lowercase) at text[from..], via code | 0x20 folding — never allocates, unlike toLowerCase() comparisons.

text

type string

from

type number

word

type string

returns

boolean

PreprocessFuzCodeOptions
#

svelte_preprocess_fuz_code.ts view source

PreprocessFuzCodeOptions import type {PreprocessFuzCodeOptions} from '@fuzdev/fuz_code/svelte_preprocess_fuz_code.js';

exclude?

File patterns to exclude.

type Array<string | RegExp>

syntax_styler?

Custom SyntaxStyler instance.

type SyntaxStyler

default syntax_styler_global

cache?

Enable in-memory caching.

type boolean

default true

component_imports?

Import sources that resolve to the Code component. Used to verify that <Code> in templates actually refers to Code.svelte.

type Array<string>

default ['@fuzdev/fuz_code/Code.svelte']

on_error?

How to handle errors.

type 'log' | 'throw'

default 'throw' in CI, 'log' otherwise

RangeHighlighting
#

RangeHighlightingOptions
#

range_highlighting.svelte.ts view source

RangeHighlightingOptions import type {RangeHighlightingOptions} from '@fuzdev/fuz_code/range_highlighting.svelte.js';

Reactive inputs for create_range_highlighting. All values are getters so the helper can track the consuming component's reactive state across the call boundary (the Svelte 5 getter-injection pattern).

element

The element whose first text node receives the highlight ranges.

type () => Element | undefined

text

The text to tokenize. Must match the element's text node exactly (e.g. a textarea backdrop includes its trailing newline here too).

type () => string

lang

Language id; null disables highlighting.

type () => string | null

syntax_styler

The syntax styler whose registered languages back lang lookups.

type () => SyntaxStyler

enabled?

Extra gate — ranges are only applied when this returns true. Defaults to always-on.

type () => boolean

dev_label

Component name used in DEV warnings.

type string

render_syntax_html
#

lexer.ts view source

(lexed: LexedSyntax): string import {render_syntax_html} from '@fuzdev/fuz_code/lexer.js';

Renders a lexed token event stream to HTML in one forward pass. Gap text is copy-escaped; token spans use the precomputed open tags.

lexed

returns

string

sample_langs
#

code_sample.ts view source

readonly ["json", "css", "ts", "html", "svelte", "md", "sh"] import {sample_langs} from '@fuzdev/fuz_code/code_sample.js';

SampleLang
#

code_sample.ts view source

"html" | "json" | "css" | "ts" | "svelte" | "md" | "sh" import type {SampleLang} from '@fuzdev/fuz_code/code_sample.js';

scan_balanced_braces
#

lexer.ts view source

(text: string, i: number, end: number): number import {scan_balanced_braces} from '@fuzdev/fuz_code/lexer.js';

Finds the matching } for the { at i, skipping js-style strings, templates, and comments. Returns -1 when unbalanced within the window.

text

type string

i

type number

end

type number

returns

number

scan_entity_end
#

lexer_markup.ts view source

(text: string, i: number, end: number): number import {scan_entity_end} from '@fuzdev/fuz_code/lexer_markup.js';

Scans an entity reference at the & at i, returning its exclusive end or -1. Accepts a named form (1–8 case-insensitive alphanumerics, &…;) and a numeric form (&#…; or &#x…;, 1–8 hex digits allowed in both).

text

type string

i

type number

end

type number

returns

number

scan_ident
#

lexer.ts view source

(text: string, from: number, end: number): number import {scan_ident} from '@fuzdev/fuz_code/lexer.js';

Scans an identifier starting at from (assumed to be an identifier start), returning the exclusive end index.

text

type string

from

type number

end

type number

returns

number

scan_to_line_end
#

lexer.ts view source

(text: string, i: number, end: number): number import {scan_to_line_end} from '@fuzdev/fuz_code/lexer.js';

Returns the index of the next \n at or after i (exclusive end of the line's content, excluding a preceding \r), or end when there is none. Uses native indexOf — the fast path for line-oriented scans.

text

type string

i

type number

end

type number

returns

number

skip_quoted
#

lexer.ts view source

(text: string, from: number, end: number, quote: number): number import {skip_quoted} from '@fuzdev/fuz_code/lexer.js';

Skips a js-style quoted span from the quote at from (used inside balanced scans), returning the index after the closing quote. Unterminated '/" strings stop at the newline; templates (`` `) span lines.

text

type string

from

type number

end

type number

quote

type number

returns

number

skip_space
#

lexer.ts view source

(text: string, from: number, end: number): number import {skip_space} from '@fuzdev/fuz_code/lexer.js';

Skips whitespace (including newlines) from from, returning the next non-space index.

text

type string

from

type number

end

type number

returns

number

supports_css_highlight_api
#

highlight_manager.ts view source

(): boolean import {supports_css_highlight_api} from '@fuzdev/fuz_code/highlight_manager.js';

Checks for CSS Highlights API support.

returns

boolean

svelte_preprocess_fuz_code
#

svelte_preprocess_fuz_code.ts view source

(options?: PreprocessFuzCodeOptions): PreprocessorGroup import {svelte_preprocess_fuz_code} from '@fuzdev/fuz_code/svelte_preprocess_fuz_code.js';

Svelte preprocessor that compiles static Code component content at build time, replacing runtime syntax highlighting with pre-rendered HTML.

options

default {}

returns

PreprocessorGroup

a Svelte preprocessor group

examples

// svelte.config.js import {svelte_preprocess_fuz_code} from '@fuzdev/fuz_code/svelte_preprocess_fuz_code.ts'; export default { preprocess: [svelte_preprocess_fuz_code(), vitePreprocess()], };

syntax_events_to_tokens
#

lexer.ts view source

(lexed: LexedSyntax): SyntaxEventToken[] import {syntax_events_to_tokens} from '@fuzdev/fuz_code/lexer.js';

Flattens a lexed event stream to SyntaxEventTokens in document order (containers precede their children).

lexed

returns

SyntaxEventToken[]

syntax_styler_global
#

syntax_styler_global.ts view source

SyntaxStyler import {syntax_styler_global} from '@fuzdev/fuz_code/syntax_styler_global.js';

Pre-configured SyntaxStyler instance with all built-in languages registered.

examples

import {syntax_styler_global} from '@fuzdev/fuz_code/syntax_styler_global.ts'; const html = syntax_styler_global.stylize('const x = 1;', 'ts');

SyntaxEventToken
#

lexer.ts view source

SyntaxEventToken import type {SyntaxEventToken} from '@fuzdev/fuz_code/lexer.js';

A flattened token span, in document order with containers before their children. Used by fixtures, tests, and range building.

type

type string

start

type number

end

type number

SyntaxLang
#

lexer.ts view source

SyntaxLang import type {SyntaxLang} from '@fuzdev/fuz_code/lexer.js';

A lexer-based language registration.

id

Primary language id, e.g. 'ts'.

type string

aliases?

Alternate ids resolving to this language, e.g. ['typescript'].

type Array<string>

lex

Lexes the lexer's current [pos, end) window, emitting token events. Must never throw and must always terminate with lexer.pos === lexer.end.

type (lexer: Lexer) => void

SyntaxStyler
#

syntax_styler.ts view source

import {SyntaxStyler} from '@fuzdev/fuz_code/syntax_styler.js';

Registry and facade over the hand-written lexer engine (lexer.ts): registers languages, lexes text to a flat token event stream, and renders that stream to syntax-highlighted HTML.

examples

import {syntax_styler_global} from '@fuzdev/fuz_code/syntax_styler_global.ts'; const html = syntax_styler_global.stylize('const x = 1;', 'ts');

langs

Registered languages, keyed by id and by each alias.

type Map<string, SyntaxLang>

token_types

Token-type id space for this styler's languages. See SyntaxStylerOptions.token_types.

type TokenTypeRegistry

readonly

constructor

type new (options?: SyntaxStylerOptions): SyntaxStyler

options

default {}

add_lang

Registers a language (and its aliases).

type (lang: SyntaxLang): void

lang

returns void

has_lang

Whether a language is registered under id (its primary id or an alias).

type (id: string): boolean

id

type string
returns boolean

lex

Lexes text with the language registered as lang, returning the flat token event stream. Throws when lang is not registered — see has_lang.

type (text: string, lang: string): LexedSyntax

text

type string

lang

type string
returns LexedSyntax

stylize

Generates syntax-highlighted HTML (spans with .token_* classes) from text. Throws when lang is not registered — see has_lang.

type (text: string, lang: string): string

text

type string

lang

type string
returns string

SyntaxStylerOptions
#

syntax_styler.ts view source

SyntaxStylerOptions import type {SyntaxStylerOptions} from '@fuzdev/fuz_code/syntax_styler.js';

token_types?

Token-type id space used by the registered lexers. Defaults to the shared token_types_global, which the built-in lexers intern into — inject a separate registry only when every registered lexer interns into that same registry.

type TokenTypeRegistry

token_type
#

lexer.ts view source

(name: string, alias?: string | string[] | undefined): number import {token_type} from '@fuzdev/fuz_code/lexer.js';

Interns a token type into token_types_global — the zero-config authoring path used by the built-in lexers' module-load type constants.

name

type string

alias?

type string | string[] | undefined
optional

returns

number

token_types_global
#

lexer.ts view source

TokenTypeRegistry import {token_types_global} from '@fuzdev/fuz_code/lexer.js';

The shared default registry — the single id space used by the built-in lexers' module-load token_type constants and by any SyntaxStyler not given its own registry. The type vocabulary is global by design, mirroring the global .token_* CSS namespace; per-registry isolation exists for fully-custom stylers and tests, whose lexers must intern into the same registry they're rendered against.

TokenTypeInfo
#

lexer.ts view source

TokenTypeInfo import type {TokenTypeInfo} from '@fuzdev/fuz_code/lexer.js';

Interned metadata for a token type.

id

type number

name

type string

aliases

type Array<string>

classes

Space-separated CSS classes, e.g. 'token_null token_keyword'.

type string

open_tag

Precomputed HTML open tag, e.g. '<span class="token_null token_keyword">'.

type string

TokenTypeRegistry
#

lexer.ts view source

import {TokenTypeRegistry} from '@fuzdev/fuz_code/lexer.js';

An id space of interned token types with precomputed CSS classes and HTML open tags. Ids are only meaningful against the registry that interned them — a lexed event stream resolves back through the registry stamped on its LexedSyntax.

infos

Interned infos indexed by id. Hot loops hoist and index this directly; grow it only via intern.

type Array<TokenTypeInfo>

readonly

intern

Interns a token type by name (+ optional aliases) and returns its id. Repeated calls with the same name and aliases return the same id. The CSS class list and HTML open tag are precomputed here so emitters never build class strings at runtime.

type (name: string, alias?: string | string[] | undefined): number

name

type string

alias?

type string | string[] | undefined
optional
returns number

info

Looks up the interned info for a token type id.

type (id: number): TokenTypeInfo

id

type number

trim_space_end
#

lexer.ts view source

(text: string, from: number, to: number): number import {trim_space_end} from '@fuzdev/fuz_code/lexer.js';

Trims trailing whitespace from a [from, to) span, returning the new exclusive end.

text

type string

from

type number

to

type number

returns

number

validate_syntax_events
#

lexer.ts view source

(lexed: LexedSyntax): string[] import {validate_syntax_events} from '@fuzdev/fuz_code/lexer.js';

Validates a lexed event stream's structural invariants, returning a list of human-readable issues (empty when valid): records well-formed, offsets monotonic and in-bounds, containers balanced.

lexed

returns

string[]

words_map
#

lexer.ts view source

(...entries: [kind: number, words: string][]): Map<string, number> import {words_map} from '@fuzdev/fuz_code/lexer.js';

Builds a word→kind classification map from [kind, words] entries, where words is space-separated — the shared shape of the lexers' keyword tables.

entries

type [kind: number, words: string][]

returns

Map<string, number>