Skip to main content

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.

Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited.

Why Tree-sitter?

Tree-sitter aims to provide a universal parsing solution that works across programming languages and use cases. Whether you’re building a text editor, a code analysis tool, or any application that needs to understand source code structure, Tree-sitter delivers.

General

Parse any programming language with a consistent API. Over 100 language grammars are available, from JavaScript and Python to Rust and Go.

Fast

Fast enough to parse on every keystroke in a text editor. Incremental parsing ensures updates happen in milliseconds, not seconds.

Robust

Provides useful results even in the presence of syntax errors. Error recovery keeps your tooling working while developers type.

Dependency-free

The runtime library is written in pure C and can be embedded in any application without external dependencies.

Core concepts

Tree-sitter works with four main types of objects:
1

Language

An opaque object that defines how to parse a particular programming language. Each language is generated by the Tree-sitter CLI and available as a separate package.
2

Parser

A stateful object that can be assigned a language and used to produce a syntax tree based on source code.
3

Syntax tree

Represents the complete syntactic structure of a source code file. Trees can be efficiently updated when the source code changes.
4

Syntax node

Represents a single node in the syntax tree, tracking its start and end positions and its relationship to other nodes (parent, siblings, children).

Key features

Incremental parsing

When source code changes, Tree-sitter can reparse only the affected portions of the file. This makes it ideal for real-time applications like text editors where every keystroke matters.

Concrete syntax trees

Tree-sitter produces concrete syntax trees that contain nodes for every token in the source code, including punctuation like commas and parentheses. This is essential for use cases like syntax highlighting and code formatting.

Named and anonymous nodes

While Tree-sitter generates concrete syntax trees, it distinguishes between named nodes (with explicit names in the grammar) and anonymous nodes (simple tokens). This lets you traverse trees as either concrete or abstract syntax trees depending on your needs.

Field names

Grammars can assign unique field names to child nodes, making it easy to access specific parts of syntax nodes without counting child indices.

Error recovery

Tree-sitter’s error recovery ensures you get a complete syntax tree even when the code contains syntax errors. This is crucial for providing code intelligence while developers are actively editing.

Use cases

Text editors

Power features like syntax highlighting, code folding, and navigation with fast, accurate parsing that keeps up with every keystroke.

Code analysis

Build static analysis tools, linters, and code quality checkers that understand the structure of code across multiple languages.

Code navigation

Extract tags and symbols from codebases to enable jump-to-definition, find references, and symbol search functionality.

Syntax highlighting

Implement precise, context-aware syntax highlighting using Tree-sitter’s query system and binding layers.

Getting started

Installation

Install Tree-sitter for your preferred language and platform

Quick start

Parse your first source code file in minutes

Using parsers

Learn how to work with syntax trees and nodes

Creating parsers

Write your own grammar to parse custom languages

Community and support

Discord

Join the community on Discord to ask questions and share projects

Matrix

Connect with the community on Matrix

GitHub

View the source code and contribute to the project

Documentation

Browse the complete documentation
Tree-sitter is used in production by major text editors including Neovim, Emacs, and Atom, as well as by GitHub for code navigation and search.