Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·part ofmodule zui.module·originates fromworld 07158574-5…

highlight

Syntax-highlighting dispatch + per-language modules. Each language module exports `(text: string) -> { Segment }` where `Segment = { text, color, monospace?, italic? }`. `Z.codeEditor` calls into `dispatch` at update time and passes the resulting segments to TextInput, which buil…

byzero-proxy @ DESKTOP-DB3UJOJ·posted 2mo ago
What it does

highlight

Syntax-highlighting dispatch + per-language modules. Each language module exports (text: string) -> { Segment } where Segment = { text, color, monospace?, italic? }. Z.codeEditor calls into dispatch at update time and passes the resulting segments to TextInput, which builds the egui LayoutJob in pure Luau. Library authors can ship their own @author/zui_highlight_<lang> modules and slot them into Z.codeEditor via the same language opt.

Exports

  • M.dispatch(language: string, text: string) -> { Segment } — pick a per-language highlighter (with yml / md aliases) and tokenize; unknown languages fall through to a single plain segment.
  • M.lua: Highlighter — Lua highlighter.
  • M.json: Highlighter — JSON highlighter.
  • M.yaml: Highlighter — YAML highlighter.
  • M.wgsl: Highlighter — WGSL highlighter.
  • M.markdown: Highlighter — Markdown highlighter.

Types:

  • Segment = { text: string, color: string, monospace: boolean?, italic: boolean? }
  • Highlighter = (string) -> { Segment }

Usage

local Highlight = require("@builtin::modules.zui.highlight")

local segs = Highlight.dispatch("lua", source)
-- segs = { { text = "local", color = "#...", monospace = true }, ... }

-- Or call a specific language directly:
local segs2 = Highlight.json(jsonText)

Notes

  • Per-language colors come from the active theme's code.* tokens (ui.getToken("code.keyword") etc.). Switching themes (ui.setTheme("light")) automatically re-colors on the next call.
  • A single-slot LRU cache keyed by (language, text, theme) makes same-text re-emits free (focus-loss redraws, no-op editor pushes). Cache returns a shared array reference — callers must not mutate it.
  • Aliases: "yml" → yaml, "md" → markdown. Unknown languages return a single default-colored monospace segment so user input never crashes the dispatcher.

Roles the Lua highlighter reads

code.keyword, code.string, code.number, code.comment, code.bool (true / false / nil), code.attribute (--! directives), code.type (a name after :, ->, :: or type), code.function (a name a call is made through, or one function declares), code.property (a member reached by . that is not called), code.builtin (the standard library's globals), and code.default for the rest.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

ZuiHighlight Module Syntax-highlighting dispatch + per-language modules. Each language module exports `(text: string) -> { Segment }` where `Segment = { text: string, color: string, monospace: bool?, italic: bool? }`. `Z.codeEditor` calls into these modules at update time and passes the resulting segments down to TextInput, which builds the egui LayoutJob from segments instead of running a Rust highlighter. Library authors can ship their own `@author/zui_highlight_<lang>` modules and slot them into Z.codeEditor via the same `language="..."` opt. Per-language colors are read from the active theme's `code.*` tokens (`ui.getToken("code.keyword")` etc.). Switching themes (`ui.setTheme("light")`) automatically re-colors source code on the next highlighter call — no restart, no reset. Consumers: local Highlight = require("modules.highlight") local segments = Highlight.dispatch("lua", source)

activeThemeName( ) → string

Internal: read the current theme name (used as part of the cache key).

dispatch(language: string, text: string) →

Dispatch a highlighter by language name, with `yml` and `md` aliases matching the engine's pre-Phase-3 `parse_editor_language`. Unknown languages return a single default-colored segment so callers can pass arbitrary user input without crashing.

argtypedescription
languagestringLanguage name (`"lua"`, `"json"`, `"yaml"`, `"wgsl"`, `"markdown"`, or aliases `"yml"`/`"md"`).
textstringSource text to tokenize.

examples

local segs = Z.highlight.dispatch("lua", source)
local segs = Z.highlight.dispatch("md", readme)
⌬ Types
Segment = {Highlighter = (string) -> { Segment }

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

23items
·
other · born here
▤file
▲ 0↑ born
▣
module · born here
❒asset
# json JSON syntax highlighter. Pure `(text) -> { Segment }`. Mirrors the algorithm of the deleted Rust `highlight_json` (renderer.rs): emits object keys via lookahead-for-`:`, handles `\` escapes inside strings, recognises numbers with scientific notation, and colors structural punctuation (`{ } [ ] , :`). Colors flow from `ui.getToken("code.<role>")` via the active theme; hardcoded fallbacks match the deleted Rust values when no theme is registered. ## Exports - `highlight(text: string) -> { Segment }` — tokenize a JSON string into colored segments for the zui code renderer. The module returns this function directly. Types: - `Segment = { text: string, color: string, monospace: boolean }` ## Usage ```luau local highlight = require("@builtin::modules.zui.highlight.json") local segments = highlight('{"a": 1, "b": "two"}') ``` ## Notes - Pure function — no side effects, no state. Safe to call any time. - The `ui.getToken` lookup runs once per highlighter call (5 FFI calls) rather than per byte, so the inner tokenize loop is allocation-light. - Keys are disambiguated from string values by a lookahead past whitespace for `:` — matches the deleted Rust algorithm exactly.
▲ 0↑ born
▣
module · born here
❒asset
# lua Luau syntax highlighter. Pure `(text) -> { Segment }`. Mirrors the algorithm of the deleted Rust `highlight_lua` / `highlight_lua_code_part` pair (renderer.rs pre-Phase-3): `--`-line comments, single- and double-quoted strings (no escape handling), digit runs with optional dots (no exponent), and identifiers dispatched against the Luau keyword set. Colors flow from `ui.getToken("code.<role>")` via the active theme, with hardcoded fallbacks matching the deleted Rust constants. ## Exports - `highlight(text: string) -> { Segment }` — tokenize a Luau string into colored segments for the zui code renderer. The module returns this function directly. Types: - `Segment = { text: string, color: string, monospace: boolean }` ## Usage ```luau local highlight = require("@builtin::modules.zui.highlight.lua") local segments = highlight("local x = 1 -- pi-ish") ``` ## Notes - Pure function — no side effects, no state. Safe to call any time. - The `ui.getToken` lookup runs once per highlighter call (5 FFI calls), then locals are used in the hot tokenize loop — cost is per-call, not per-byte. - Strings have no escape handling (`"a\"b"` would terminate at the middle quote). This matches the deleted Rust implementation exactly.
▲ 0↑ born
▣
module · born here
❒asset
# markdown Markdown syntax highlighter. Pure `(text) -> { Segment }`. Mirrors the algorithm of the deleted Rust `highlight_markdown` / `highlight_markdown_inline` pair (renderer.rs pre-Phase-3): block-level pass over `split_inclusive('\n')` recognises fenced code (```), headings (#), blockquotes (>), bullet/ordered lists; an inline pass within each non-block line recognises inline code (`...`), bold (**...**), and links ([text](url)). ## Exports - `highlight(text: string) -> { Segment }` — tokenize a Markdown string into colored segments for the zui code renderer. The module returns this function directly. Types: - `Segment = { text: string, color: string, monospace: boolean }` ## Usage ```luau local highlight = require("@builtin::modules.zui.highlight.markdown") local segments = highlight("# Title\n**bold**\n") ``` ## Notes - The module-level color upvalues are reassigned at every highlighter entry so the inline helper sees the active palette without per-call args. Multiple concurrent calls are NOT safe — this module is designed for serial UI rendering. - Inline code reuses the `code.string` theme role; treat the two as the same colour band. - Fenced code (```) toggles a multi-line fence — the highlighter tracks fence state across the input.
▲ 0↑ born
▣
module · born here
❒asset
# wgsl WGSL syntax highlighter. Pure `(text) -> { Segment }`. Mirrors the algorithm of the deleted Rust `highlight_wgsl` (renderer.rs): `//` line comments, `/* ... */` block comments, `"..."` strings with `\` escapes, `@attribute` tokens, numeric literals (digits + dots + alphanumerics for suffixes like `1u`, `0xFF`, `1.0_f32`), and identifiers dispatched against the WGSL keyword and built-in type tables. Colors flow from `ui.getToken("code.<role>")` via the active theme; hardcoded fallbacks match the deleted Rust values when no theme is active. ## Exports - `highlight(text: string) -> { Segment }` — tokenize a WGSL string into colored segments for the zui code renderer. The module returns this function directly. Types: - `Segment = { text: string, color: string, monospace: boolean }` ## Usage ```luau local highlight = require("@builtin::modules.zui.highlight.wgsl") local segments = highlight("@vertex fn main() -> vec4<f32> {}") ``` ## Notes - Pure function — no side effects, no state. Safe to call any time. - Keyword and type tables match the deleted Rust constants verbatim (renderer.rs:6245-6263). - Strings are escape-aware (`"a\"b"` is one segment); WGSL has no single-quoted strings.
▲ 0↑ born
▣
module · born here
❒asset
# yaml YAML syntax highlighter. Pure `(text) -> { Segment }`. Mirrors the algorithm of the deleted Rust `highlight_yaml` / `highlight_yaml_content` / `highlight_yaml_scalar` trio (renderer.rs): per-line comment splitting, `key: value` recognition (split on first `:`), and scalar typing (quoted string / true|false|null / numeric / plain). Colors flow from `ui.getToken("code.<role>")` via the active theme; hardcoded fallbacks match the deleted Rust values when no theme is active. ## Exports - `highlight(text: string) -> { Segment }` — tokenize a YAML string into colored segments for the zui code renderer. The module returns this function directly. Types: - `Segment = { text: string, color: string, monospace: boolean }` ## Usage ```luau local highlight = require("@builtin::modules.zui.highlight.yaml") local segments = highlight("name: zero\n# comment\n") ``` ## Notes - The module-level color upvalues are reassigned at every highlighter entry so the inner scalar/content helpers see the active palette without per-call args. Multiple concurrent calls are NOT safe — this module is designed for serial UI rendering. - Numeric detection allows `.`, `-`, `+` alongside digits, so dotted versions and negatives parse as numbers (matches the Rust behaviour).
▲ 0↑ born
·
other · born here
▤file
▲ 0↑ born
·
other · born here
▤file
▲ 0↑ born
·
other · born here
▤file
▲ 0↑ born
·
other · born here
▤file
▲ 0↑ born
·
other · born here
▤file
▲ 0↑ born

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.