Skip to content

Host-Native Language Passthrough

Tree-sitter-language-pack’s get_language() function returns the native tree-sitter Language type for your ecosystem—not a wrapper or opaque handle. This means you can pass the result directly to your parser without translation overhead or intermediate APIs.


These 9 bindings return the real Language type from the host ecosystem’s tree-sitter package:

Binding Returns Host Package Min Version
Python tree_sitter.Language (PyCapsule) tree-sitter ≥0.23
Node.js tree-sitter npm package Language tree-sitter latest
Go *tree_sitter.Language go-tree-sitter v0.24.0+
Java io.github.treesitter.jtreesitter.Language io.github.tree-sitter:jtreesitter 0.26.0+
C# TreeSitter.Language TreeSitter.DotNet 1.3.0+
Kotlin io.github.treesitter.ktreesitter.Language io.github.tree-sitter:ktreesitter 0.25.0+
Swift SwiftTreeSitter.Language SwiftTreeSitter (SwiftPM) 0.25.0+
Zig ?*const tree_sitter.Language zig-tree-sitter v0.26.0+
C FFI const TSLanguage * tree-sitter (libtree-sitter) ABI 14+

The C FFI surface is the canonical passthrough: ts_pack_get_language() returns the bare const TSLanguage * that every other C-ABI binding wraps in its host Language type. Pass it straight to ts_parser_set_language(). The returned pointer is borrowed — it points at a static, library-owned grammar, so do not free it (there is no ts_pack_language_free for it).

With a passthrough binding, you use the ecosystem’s native parser without any wrapper:

import tree_sitter
import tree_sitter_language_pack
# get_language returns tree_sitter.Language directly
python_lang = tree_sitter_language_pack.get_language("python")
# Use it with the native tree-sitter parser
parser = tree_sitter.Parser(python_lang)
tree = parser.parse(b"def foo(): pass")

These 5 bindings return an opaque handle specific to this package and do not expose a host-native Language. Use the package’s own Parser / process() API instead.

Binding Why no passthrough Recommendation
Ruby No maintained Ruby tree-sitter gem that constructs a Language from a raw pointer Use this package’s Parser wrapper
PHP No maintained PHP tree-sitter extension exposing a Language from a raw pointer Use this package’s extension API
Elixir No maintained Elixir tree-sitter library that ingests a raw TSLanguage * Use this package’s NIF wrapper
WASM The web-tree-sitter Language is loaded from .wasm bytes, not a native pointer Use this package’s JS wrapper
Dart Built with flutter_rust_bridge, which marshals Rust types as Arc-counted opaque proxies and never hands back the raw const TSLanguage * the capsule mechanism needs — and there is no maintained Dart tree-sitter package to construct from it Use the generated Parser wrapper

For opaque-handle bindings, use the high-level process() function or the package’s getParser() method instead:

require "tree_sitter_language_pack"
# Use getParser() to get a pre-configured parser
parser = TreeSitterLanguagePack.get_parser("python")
# Or use process() for structured analysis
result = TreeSitterLanguagePack.process(source, { language: "python" })

All passthrough bindings require you to handle the possibility that get_language() fails (e.g., unknown language name):

from tree_sitter_language_pack import LanguageNotFoundError
try:
lang = get_language("unknown_lang")
except LanguageNotFoundError as e:
print(f"Language not found: {e}")

A passthrough binding returns the ecosystem’s standard tree-sitter Language, so:

  1. The result works with the existing tree-sitter tooling in that ecosystem — query APIs, tree cursors, and editor integrations — with no wrapper in between.
  2. You choose when to upgrade your host tree-sitter package; the grammars are compiled at a backwards-compatible ABI (see below).
  3. You can use these 306 grammars alongside custom grammars or other tree-sitter packages in the same parser instance.

The language pack is compiled at tree-sitter ABI 14, which is stable across:

  • Tree-sitter runtime versions 0.21 through 0.26
  • All host package versions listed in the table above

This wide compatibility ensures you can use any reasonably recent version of your ecosystem’s tree-sitter package without pinning or rebuilding the language pack.