Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tree-sitter/tree-sitter/llms.txt
Use this file to discover all available pages before exploring further.
Introduction
This guide covers the fundamental concepts of using Tree-sitter, which is applicable across all programming languages. Although we’ll explore some C-specific details that are valuable for direct C API usage or creating new language bindings, the core concepts remain the same. Tree-sitter’s parsing functionality is implemented through its C API, with all functions documented in the tree_sitter/api.h header file. If you’re working in another language, you can use one of the official language bindings:Language Bindings
- Go - Idiomatic Go API
- Java - Java bindings with full API support
- JavaScript (Node.js) - Native Node.js addon
- Kotlin - Kotlin/JVM bindings
- Python - Python bindings with comprehensive API
- Rust - Safe Rust API with zero-cost abstractions
- Zig - Zig language bindings
The Basic Objects
There are four main types of objects involved when using Tree-sitter:TSLanguage
An opaque object that defines how to parse a particular programming language. The code for each language is generated by Tree-sitter.
TSParser
A stateful object that can be assigned a language and used to produce syntax trees based on source code.
TSTree
Represents the syntax tree of an entire source code file. It contains nodes that indicate the structure of the source code.
TSNode
Represents a single node in the syntax tree. It tracks its start and end positions in the source code, as well as its relation to other nodes.
Building the Library
To build the library on a POSIX system, just runmake in the Tree-sitter directory. This will create both static and dynamic libraries:
libtree-sitter.a- Static librarylibtree-sitter.so/libtree-sitter.dylib- Dynamic library
Embedding in Your Project
Alternatively, you can incorporate the library in a larger project’s build system by adding one source file: Source file:tree-sitter/lib/src/lib.c
tree-sitter/lib/srctree-sitter/lib/include
Getting Started
Here’s a minimal example of using Tree-sitter to parse JSON:What’s Next?
Basic Parsing
Learn how to parse source code and work with syntax nodes
Advanced Parsing
Explore incremental parsing, editing, and multi-language documents
Walking Trees
Use tree cursors for efficient tree traversal
Pattern Matching
Query syntax trees with powerful pattern matching
Many languages are already available in the Tree-sitter GitHub organization and the Tree-sitter grammars organization.