TheDocumentation 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.
init command is your starting point for creating a new grammar. It sets up a repository with all the essential files and structure needed for grammar development.
i
Generated Files
Required Files
These files are always created if missing:tree-sitter.json
The main configuration file that determines howtree-sitter interacts with the grammar. If missing, the command will prompt you for the required fields. See Structure of tree-sitter.json below.
package.json
The npm manifest for the parser. Required for some subcommands and if the grammar has dependencies (e.g., base grammars).grammar.js
An empty template for the main grammar file. See Creating Parsers.Language Bindings
Language bindings allow your parser to be used by projects in the respective language. The following bindings are created if enabled intree-sitter.json:
C/C++
Makefile- Build instructions formakeCMakeLists.txt- Build instructions forcmakebindings/c/tree_sitter/tree-sitter-language.h- C interfacebindings/c/tree-sitter-language.pc- pkg-config metadata
Go
go.mod- Go module manifestbindings/go/binding.go- Go module wrapperbindings/go/binding_test.go- Go package test
Node
binding.gyp- Node.js build instructionsbindings/node/binding.cc- JavaScript module wrapperbindings/node/index.js- Node.js entry pointbindings/node/index.d.ts- TypeScript type hintsbindings/node/binding_test.js- Node.js package test
Java
pom.xml- Maven package manifestbindings/java/main/namespace/language/TreeSitterLanguage.java- Java class wrapperbindings/java/test/TreeSitterLanguageTest.java- Java package test
Python
pyproject.toml- Python package manifestsetup.py- Python build instructionsbindings/python/tree_sitter_language/binding.c- Python module wrapperbindings/python/tree_sitter_language/__init__.py- Python loaderbindings/python/tree_sitter_language/__init__.pyi- Type hintsbindings/python/tree_sitter_language/py.typed- Type hints markerbindings/python/tests/test_binding.py- Python package test
Rust
Cargo.toml- Rust package manifestbindings/rust/build.rs- Rust build instructionsbindings/rust/lib.rs- Rust crate wrapper
Swift
Package.swift- Swift build instructionsbindings/swift/TreeSitterLanguage/language.h- Swift module wrapperbindings/swift/TreeSitterLanguageTests/TreeSitterLanguageTests.swift- Swift package test
Zig
build.zig- Zig build instructionsbuild.zig.zon- Zig package manifestbindings/zig/root.zig- Zig module wrapperbindings/zig/test.zig- Zig package test
Additional Files
These files improve the development experience:.editorconfig- Editor formatting configuration.gitattributes- Git line endings and language attribution.gitignore- Git ignore patterns
Structure of tree-sitter.json
grammars Field
An array of grammar objects. Typically only one object is needed unless your repo has multiple grammars (e.g., TypeScript and TSX).Basic Fields
A string like
"source.js" that identifies the language. Strive to match scope names used by popular TextMate grammars and the Linguist library.Relative path from
tree-sitter.json to the directory containing src/. Default is "." (same folder).List of relative paths to files that should be checked for modifications during recompilation. Useful for tracking changes to files like
scanner.c.Language Detection
Filename suffix strings (without the dot) that identify files for this language. Suffixes may match entire filenames.
Regex pattern tested against the first line of a file. Used when file type doesn’t match any grammar’s
file-types.Regex pattern tested against file contents to break ties when multiple grammars match. Grammars with matching content-regex are preferred.
Regex pattern tested against a language name for language injection sites. See Language Injection.
Query Paths
Relative paths fromtree-sitter.json to query files:
Path to highlight query file.
Path to local variable query file.
Path to injection query file.
Path to tag query file.
metadata Field
Information used to populate binding files and versions:Valid SPDX license identifier.
Brief description of your grammar.
Array of objects with
name (required), email, and url fields.Object with
repository field and optional funding field.Namespace for Java and Kotlin bindings.
bindings Field
Controls which bindings are generated:Generate C/C++ bindings.
Generate Go bindings.
Generate Java bindings.
Generate Node.js bindings.
Generate Python bindings.
Generate Rust bindings.
Generate Swift bindings.
Generate Zig bindings.
Options
Update outdated generated files, if possible. Existing files that may have been edited manually are not updated. To force an update, remove them and run
tree-sitter init -u again.The path to the directory containing the grammar.