The minor mode tree-sitter-mode
provides the high-level interface for working with an up-to-date buffer-local syntax tree. Writing a Dependent Minor Mode is recommended over directly using the low level parsing APIs below.
Parsing is done through stateful parser objects.
tsc-make-parser
tsc-set-language
parser language
tsc-parse-string
parser string
(let ((parser (tsc-make-parser)))
(tsc-set-language parser (tree-sitter-require 'rust))
(tsc-parse-string parser "fn foo() {}"))
tsc-parse-chunks
parser input-function old-tree
input-function
. The function should take 3 parameters: (bytepos line-number byte-column)
, and return a fragment of the source code, starting from the position identified by either bytepos
or (line-number . byte-column)
. It should return an empty string to signal the end of the source code.
Incremental parsing: If you have already parsed an earlier version of this document, and it has since been edited, pass the previously parsed old-tree
so that its unchanged parts can be reused. This will save time and memory. For this to work correctly, you must have already edited it using tsc-edit-tree
function in a way that exactly matches the source code changes.
tsc-edit-tree
tree ...
(line-number . byte-column)
coordinates.For more details, see Tree-sitter’s documentation: