Tey.Docgen.Highlight
A small syntax highlighter for Kex source, ported from kex-run-site's src/lib/highlight.ts: a "good enough" tokenizer rather than a full grammar. Emits <span class="tok-*"> HTML at docgen build time, so the docs carry no client-side JavaScript. Runs over [Char] lists; pure recursion, no state.
Fidelity note: backtick raw strings are not tracked inside interpolation braces, and and/or are colored as keywords even where the compiler treats them as identifiers — same trade-offs as the site version.
module Tey.Docgen.Highlight
lexAll
lexAll(cs: [Char], out: [Tok]) -> [Tok]
out accumulates newest-first; the final reverse restores source order.
lexString
lexString(cs: [Char], acc: [Tok]) -> ([Tok], [Char])
cs starts after the opening quote; acc is newest-first tokens so far.
takeStringText
takeStringText(cs: [Char], acc: [Char]) -> (String, [Char])
Collect literal string text up to (not including) the closing quote, an interpolation opener, or the end of input. Backslash escapes are opaque.
balancedBraces
balancedBraces(cs: [Char], depth: Integer, acc: [Char]) -> ([Char], [Char])
From just after "${", collect the interpolation body up to its matching "}" (which is consumed but not collected). Embedded "..." strings are skipped whole so braces inside them do not count.
skipString
skipString(cs: [Char]) -> ([Char], [Char])
Consume a whole "..." literal starting at the opening quote; returns the consumed characters (both quotes included) and the remainder.
skipStringBody
skipStringBody(cs: [Char], acc: [Char]) -> ([Char], [Char])
exponentLength
exponentLength(cs: [Char]) -> Integer
lexIdentifier
lexIdentifier(cs: [Char], out: [Tok]) -> ([Tok], [Char])
classifyWord
classifyWord(word: String, prevDot: Bool, nextCh: Char) -> String
previousIsDot
previousIsDot(out: [Tok]) -> Bool
The most recent token that is not whitespace: out is newest-first, so a plain find walks backwards in time.
identChar?
identChar?(c: Char) -> Bool
lexOperator
lexOperator(cs: [Char]) -> ([Tok], [Char])
keywords
keywords : [String]
Functions rather than module constants: on BEAM, method calls on a module-level constant fail to dispatch.
renderTokens
renderTokens(toks: [Tok]) -> String
esc
esc(s: String) -> String
Local copy of Tey.Docgen.Html.esc — duplicating four replaces keeps the modules acyclic (Html calls Highlight for code blocks).
startsWithChars
startsWithChars(cs: [Char], s: String) -> Bool