Skip to main content

Module syntax_highlighting

Module syntax_highlighting 

Source
Expand description

Token-based syntax highlighting for the REPL input bar and output.

Lexes the input with the real rl lexer and maps each TokenType to a ratatui [Style]. Gaps between token spans are emitted as unstyled raw spans to preserve whitespace exactly. On lex failure the entire input is returned as a single red span.

§Color scheme

Token groupColor / modifier
Control flowCyan bold
DeclarationsCyan italic
Import keywordsCyan dim
Type keywordsLight blue italic
Logical operatorsYellow bold
Number literalsMagenta
String literalsYellow
Char literalsLight yellow
Bool literalsMagenta italic
nullDark gray italic
Comparison opsLight cyan
Punctuation/bracesDark gray
IdentifiersWhite

Functions§

highlight
Lexes input and returns a vec of syntax-highlighted [Span]s.
token_color 🔒
Returns the ratatui [Style] for a given TokenType.