kex docs Tey

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

highlight

highlight(source: String) -> String

lexAll

lexAll(cs: [Char], out: [Tok]) -> [Tok]

out accumulates newest-first; the final reverse restores source order.

nextToken

nextToken(cs: [Char], out: [Tok]) -> ([Tok], [Char])

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])

lexNumber

lexNumber(cs: [Char]) -> ([Tok], [Char])

exponentLength

exponentLength(cs: [Char]) -> Integer

hexDigit?

hexDigit?(c: Char) -> Bool

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])

twoCharOp

twoCharOp(cs: [Char]) -> String

keywords

keywords : [String]

Functions rather than module constants: on BEAM, method calls on a module-level constant fail to dispatch.

constants

constants : [String]

typeNames

typeNames : [String]

renderTokens

renderTokens(toks: [Tok]) -> String

renderTok

renderTok(t: 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).

textOf

textOf(cs: [Char]) -> String

startsWithChars

startsWithChars(cs: [Char], s: String) -> Bool

record Tok

Fields

text
String