r/java • u/Marcono1234 • Jul 14 '26
Type-safe Java bindings for Tree-sitter grammars
github.comI have just released version 0.1.0 of jtreesitter-type-gen, a library and CLI tool for generating type-safe Java bindings for Tree-sitter grammars. Tree-sitter is a popular parser generator and parsing library. The generated code is based on the official Java Tree-sitter (jtreesitter) bindings.
Here are two short examples for using the code generated by jtreesitter-type-gen (in this case for the JSON grammar):
-
type-safe parse tree traversal:
String source ; try -
typed query:
// Query which captures results in a List var q ; var query ; String source ; try
The README of the project includes more information on how to use it and how it works.
Hopefully this tool is useful for some of you. Any feedback is appreciated (either here or on the GitHub repository)!