isabella232 / jsitter

tree-sitter API for JVM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rational

tree-sitter is a nice piece of parser technology.

  • Automatic error recovery
  • Incremental reparse
  • Immutable persistent trees, with structural sharing

This features makes it perfect for use in IDEs and editors. However it is not obvious how we could take advantage over it on JVM platform.

Here we have options:

  • Port it to Java. It requires too much work and probably some loss of performance.
  • Wrap tree nodes with Java objects. Leads to significant memory pressure and redundancy.
  • Navigate throught trees in native memory using Zippers.

API with Zippers is the solution taken. Zipper gives us a nice abstraction over the place-in-tree (with ability to ascend) without compromising immutability of the tree itself. Zippers are implemented by accessing internal TreeSitter data structures directly using sun.misc.Unsafe instrinsics and don't do any JNI calls and don't consume any additional off-heap memory.

Here is some discussion regarding the TreeSitter API: tree-sitter/tree-sitter#360 (comment)

Build Instructions

$ git submodule update --init --recursive
$ ./make.sh 
$ mvn install

About

tree-sitter API for JVM

License:Other


Languages

Language:Kotlin 60.3%Language:C 21.8%Language:Java 12.9%Language:Clojure 3.4%Language:CMake 1.1%Language:Shell 0.5%