Package io.github.treesitter.jtreesitter


package io.github.treesitter.jtreesitter
Java bindings to the tree-sitter parsing library.

Requirements

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;
     }
 }

Library Loading

There are three ways to load the shared libraries:
  1. The libraries can be installed in the OS-specific library search path or in java.library.path. The search path can be amended using the LD_LIBRARY_PATH environment variable on Linux, DYLD_LIBRARY_PATH on macOS, or PATH on Windows. The libraries will be loaded automatically by SymbolLookup.libraryLookup(String, Arena)RESTRICTED.
  2. The libraries can be loaded manually by calling System.loadLibrary(String), if the library is installed in java.library.path, or System.load(String).
  3. The libraries can be loaded manually by registering a custom implementation of NativeLibraryLookup. This can be used, for example, to load libraries from inside a JAR file.