Syntax Highlighting โ
Problem โ
Highlighters must classify every token correctly even while the user is mid-keystroke and the code does not parse cleanly.
Why tree-sitter.zig helps โ
Error recovery keeps a full tree available at all times, and changed ranges say exactly which spans need repainting.
API โ
Parser.parse โ Tree โ TreeCursor walk โ getChangedRanges per edit.
Architecture โ
text
Keystroke โ InputEdit โ incremental parse โ changed ranges
โ re-walk dirty spans โ classify by nodeType โ repaintExample โ
Walk dirty nodes with tree.cursor(); map identifier โ variable face, number โ constant face, anonymous operators โ punctuation face, ERROR nodes โ error face.
Output โ
Only the edited expression re-tokenizes; the rest of the buffer keeps its faces.
