TSLexia is a Scintilla lexer that makes use of Tree-sitter parsers.
TSLexia requires only a C compiler and a C++ compiler that supports C++17.
make deps
make # or 'make win' for Windows dlls
make parsers
There are now libtslexia.so and libtree-sitter-[name].so (or TSLexia.dll and tree-sitter-[name].dll) libraries you can use with your Scintilla application.
- In your application,
#include "TSLexia.h"
. - Dynamically load the libtslexia.so or TSLexia.dll library if needed.
- Call
CreateLexer()
with the path to a Tree-sitter parser, e.g.CreateLexer("/path/to/libtree-sitter-c.so")
. For multi-language files or for parsers that depend on others, use a ';'-separated list of paths, e.g.CreateLexer("libtree-sitter-c.so;libtree-sitter-cpp.so")
. Make sure the order is from generic to specific or parent to child. - Use the returned lexer with Scintilla's
SCI_SETILEXER
message to set it. - Use Scintilla's
SCI_SETKEYWORDS
message to pass in a Tree-sitter query file that matches nodes and uses named captures for assigning styles to those nodes, e.g.SendScintilla(sci, SCI_SETKEYWORDS, 0, (sptr_t)"/path/to/tslexia/queries/c.scm")
. When using multiple parsers, use the index of the parser passed toCreateLexer()
. - Define style settings for TSLexia's
TSLEXIA_*
styles (see TSLexia.h). - That's it!