Skip to content

Bzero/Qt-TreeSitterHighlighter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qt-TreeSitterHighlighter

Qt-TreeSitterHighlighter is a syntax-highlighter for Qt that can be used on QTextEdit, QPlainTextEdit or any other QTextDocument and rehighlights it on every change of the document. It makes use of tree-sitter, an incremental parsing library to build a syntax tree of the document source code for accurate and fast highlighting.

Usage

To use Qt-TreeSitterHighlighter, three configuration elements have to be provided:

  • A tree-sitter language to parse the source and construct a syntax tree. Most often one of the readily available parsers can be used.
  • A tree-sitter highlighting query string to extract the relevant captures from the syntax tree. Most available parsers also come with a highlight query.
  • A highlighting format map to map capture names to their desired QTextCharFormat format.

An example on how to use Qt-TreeSitterHighlighter can be found in ./examples/main.cpp.

Requirements

To build the example the tree-sitter-cpp parser is needed as well.

tree-sitter and tree-sitter-cpp are automatically included if the repository is cloned with the --recurse-submodules flag.

Building

cd Qt-TreeSitterHighlighter
cmake . -B build
cmake --build build

Run the example to see see Qt-TreeSitterHighlighter in action:

./build/tree-sitter-highlighter-example

Contributing

Contributions are very welcome!

License

Qt-TreeSitterHighlighter is licensed under the MIT License.

About

A tree-sitter based syntax highlighter for Qt.

Resources

License

Stars

Watchers

Forks

Releases

No releases published