x-lang

← Index

x/tool/highlight

Lexical syntax highlighter for x-lang, emitting Rouge token classes.

Scanning is %-private; the Highlight class is the API. The scanner is lexical, so it renders fragments and transcripts that no parser would accept, and preserves the author’s own layout byte for byte.

Class Highlight

Lexical syntax highlighter for x-lang source and REPL transcripts.

Emits Rouge/Pygments token classes, so an existing Rouge stylesheet renders the output. The keyword set is supplied by the caller from lib/x/constructs.x – this class hardcodes no part of the language’s vocabulary.

source and transcript WRITE their result, like x/tool/fmt’s printers. The scanner rides cached byte prims rather than the class doors, which is what makes it affordable – 4KB of source costs about 290MB of resident memory above the boot baseline. Nothing is collected mid-run, so a caller highlighting a whole corpus chunks its work across processes.

(Highlight keywords constructs)

The construct names, as strings, for use as the keyword set.

Parameters:

Returns: LIST — Construct names as strings

(Highlight spans text keywords)

Write span markup for source text, WITHOUT the surrounding container.

Parameters:

Returns: ANY — nil (output via display)

(Highlight source text keywords)

Write x-lang source as a complete Rouge-shaped code block.

Parameters:

Returns: ANY — nil (output via display)

(Highlight transcript text keywords)

Write a REPL transcript – “> expr” prompts and “expr => result” lines – as a complete code block.

Parameters:

Returns: ANY — nil (output via display)

(Highlight escape text)

HTML-escape &, < and > in text.

Parameters:

Returns: STR — Escaped text