Token
struct TokenA run of source of one kind: bytes start to end.
Implements Copyable, Movable
- Fields
kind: StaticStringstart: Intend: Int
orca.highlightMojo source coloured for the UI's code-on-hover (_PEEK in orca.ui.layout), on the server, with no library: tokens splits source into runs of one kind, and highlight turns those into HTML lines with a <span> per coloured run.
var lines = highlight(src) # one HTML string per source line
The kinds, each a class hl--<kind> the stylesheet colours from its
tokens (so both themes have them):
| Kind | What |
|---|---|
kw |
a keyword: def, struct, var, comptime, if, return, ... |
str |
a string, "...", '...' or triple-quoted over several lines |
com |
a comment, # to the end of the line |
num |
a number: 42, 1_000, 0x1f, 3.5e-2 |
dec |
a decorator, @fieldwise_init |
fn |
the name a def, fn, struct or trait defines |
const |
True, False, None, self, Self |
Anything else is plain text. A string or comment never holds a span open across a line: each line's HTML is whole, so the hover can show any slice of them. It's a highlighter, not a parser: an unterminated string runs to the end of its line (or, triple-quoted, of the file).
Tokenstruct TokenA run of source of one kind: bytes start to end.
Implements Copyable, Movable
kind: StaticStringstart: Intend: Inttokensdef tokens(src: StringSpan) -> List[Token] src as runs of one kind each, in order, covering every byte.
highlightdef highlight(src: StringSpan) -> List[String] src as HTML, a string per line (split at \n, without it), each coloured run a <span class="hl hl--<kind>">, everything escaped.
comptime PLAIN = ""comptime KEYWORD = "kw"comptime STRING = "str"comptime COMMENT = "com"comptime NUMBER = "num"comptime DECORATOR = "dec"comptime NAME = "fn"comptime CONSTANT = "const"