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

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 (…

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

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

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.

Interface

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

conforms to

zero/source-extract/v2

ZuiHighlightLua Module Luau syntax highlighter. Pure `(text) -> { Segment }`: one walk over the bytes of the source, every byte landing in exactly one segment, so the segments concatenate back to the text. The walk knows the shapes Luau has — line and block comments, `--!` directives, quoted, interpolated and long-bracket strings with their escapes, decimal, hex, binary and exponent numbers — and reads each identifier where it stands: a keyword, a literal, a builtin, the name a call is made through, a member reached by `.` or `:`, the name of a function being declared, or a type after `:`, `->`, `::` and `type`. Colors flow from the active theme's `code.*` tokens (`ui.getToken("code.keyword")` etc.), read once per highlighter call. The fallbacks below stand in when no theme is active. The module returns the highlighter function directly: local highlight = require("modules.highlight.lua") local segments = highlight("local x = 1")

token(role: string) → string

Resolve `code.<role>` from the active theme, or the fallback.

argtypedescription
rolestring

isDigit(b: number) → boolean

argtypedescription
bnumber

isAlpha(b: number) → boolean

argtypedescription
bnumber

isAlnum(b: number) → boolean

argtypedescription
bnumber

isHex(b: number) → boolean

argtypedescription
bnumber

isSpace(b: number) → boolean

argtypedescription
bnumber

push(segments: { Segment }, text: string, color: string) → void

Append `text` in `color`; a run in the colour of the previous segment joins it, so a line of plain code is one segment rather than one per byte.

argtypedescription
segments{ Segment }
textstring
colorstring

longBracketLevel(text: string, i: number) → number

The `=` count of a long bracket opening at `i` (`[[` → 0, `[==[` → 2), or nil when no long bracket opens there.

argtypedescription
textstring
inumber

longBracketEnd(text: string, i: number, level: number) → number

The index just past the long bracket that closes a level-`level` one, searching from `i`; the end of the text when it never closes.

argtypedescription
textstring
inumber
levelnumber

nextSignificant(text: string, i: number) → void

The first non-blank byte at or after `i`, and where it is.

argtypedescription
textstring
inumber

highlightLua(text: string) →

Tokenize a Luau source string into colored text segments for the zui code renderer. One walk over the bytes: comments, directives, strings of every shape, numbers, and identifiers read in context — a keyword, a literal, a builtin, a called function, a member, a declared function name, or a type. defaults to `""` when nil. concatenate back to the source byte for byte.

argtypedescription
textstringThe Luau source to highlight. Coerced via `tostring` and

examples

local segments = highlight("local x = 1 -- pi-ish")
⌬ Types
Segment = { text: string, color: string, monospace: boolean }

Sub-parts

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

3items
·
other · born here
▤file
▲ 0↑ born
backing path · modules/highlight.module/lua.module

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.