Package io.github.treesitter.jtreesitter
package io.github.treesitter.jtreesitter
Java bindings to the tree-sitter parsing library.
Requirements
- JDK 22 (for the Foreign Function and Memory API )
- Tree-sitter shared library
- Generated bindings for languages
- Shared libraries for languages
java.library.path
Basic Usage
Language language = new Language(TreeSitterJava.language());
try (Parser parser = new Parser(language)) {
try (Tree tree = parser.parse("void main() {}", InputEncoding.UTF_8).orElseThrow()) {
Node rootNode = tree.getRootNode();
assert rootNode.getType().equals("program");
assert rootNode.getStartPoint().column() == 0;
assert rootNode.getEndPoint().column() == 14;
}
}
- See Also:
-
ClassDescriptionAn edit to a text document.The encoding of source code.A class that defines how to parse a particular language.A function that logs parsing results.The type of a log message.A class that is used to look up valid symbols in a specific parse state.A class that pairs a symbol ID with its name.A single node within a syntax tree.A function that retrieves a chunk of text at a given byte offset and point.A class that is used to produce a syntax tree from source code.A class representing a cancellation flag.A position in a text document in terms of rows and columns.A class that represents a set of patterns which match nodes in a syntax tree.A
Node
that was captured with a certain capture name.Any error that occurred while instantiating aQuery
.A capture name error.A field name error.A node type error.A query predicate error.A pattern structure error.A query syntax error.A match that corresponds to a certain pattern in the query.A query predicate that associates conditions (or arbitrary metadata) with a pattern.Handles the following predicates:
#any-of?
,#not-any-of?
Handles the following predicates:
#eq?
,#not-eq?
,#any-eq?
,#any-not-eq?
Handles the following predicates:
#match?
,#not-match?
,#any-match?
,#any-not-match?
An argument to aQueryPredicate
.A capture argument (@value
).A literal string argument ("value"
).A range of positions in a text document, both in terms of bytes and of row-column points.A class that represents a syntax tree.A class that can be used to efficiently walk a syntax tree.Specifies that the value is of an unsigned data type.