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…
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
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.
Scoped to this part · feeds back into the world's score.