pub fn lex_json(source: &str) -> StringExpand description
Lexes source and answers a colour for every part of it.
{"ok":bool,"spans":[{"at":int,"len":int,"kind":string}]}The spans tile: the first begins at zero, each begins where the last
ended, and together they cover the source, so a page renders the whole
editor by walking the list and slicing its own text. at and len count
UTF-16 code units, which is what a JavaScript string is indexed in.
kind is one of keyword, type, string, number, comment and
plain. highlight::Kind says what falls into each and which two are
not decided by the lexer. Its seventh, slot, is a disassembly’s and
never appears here.
ok is whether the source lexed without complaint. It is false whenever
the reader is part-way through typing a string literal, which is most of
the time one is being typed, and the spans are still a tiling of what was
sent: highlight says what a broken source is coloured as and why the
answer is not “nothing”.
This is the front end’s first stage and none of the rest, so it costs a
pass over the text and nothing else. That is what makes it the thing to
call on every keystroke, where compile_json is not.