OCaml code generator and runtime library for handling typed tree-sitter CSTs
60
stars
533
commits
OCaml
primary language
Jul 30, 2026
updated
Generate OCaml parsers based on tree-sitter grammars. This project was originally intended for semgrep. This repository contains the code for generating code for tree-sitter grammars but does not contain grammars for specific languages other than tests.
The ocaml-tree-sitter repositories are:
Installing ocaml-tree-sitter alone isn't of great use at the
moment. It is useful as part of the flow for generating OCaml parsers
from tree-sitter grammars, which is done from the lang/ folder
in ocaml-tree-sitter-semgrep.
See the Contributing instructions below.
Before you get started, make sure you're ok with signing the CLA which will be needed before we accept your pull request. The goal is only to allow future relicensing without having to track down any past contributor, if such need were to arise. Note that the current license is LGPL and any contribution made today will remain available under that license no matter what.
opam install merlin + some plugin for your editor.pre-commit with pip3 install pre-commit and run
pre-commit install to set up the pre-commit hook.
This will re-indent code in a consistent fashion each time you call
git commit.For building or rebuilding everything after big changes:
# Install OCaml dependencies (if not already installed)
$ opam install --deps-only .
# Build and test (automatically sets up tree-sitter on first build)
$ dune build
$ dune runtest
The default tree-sitter version to use is in the
tree-sitter-version file.
Under the default configuration used for local development purposes,
the version being actually used is stored in the file
tree-sitter-version. To use a different version, edit that file;
dune will download and build the corresponding tree-sitter sources on
the next build.
IMPORTANT Note that the selection in tree-sitter-version affects
the tree-sitter runtime that the ocaml-tree-sitter code generator
and its OCaml bindings are compiled against, as well as the CLI used to
generate parsers.
It does not determine which tree-sitter version grammars are built with.
In ocaml-tree-sitter-semgrep, every grammar is built by the tree-sitter version
specified by the lang/languages-<version> lists.
See the "tree-sitter versions (per language)" section of the
ocaml-tree-sitter-semgrep README.
Because the C API surface we rely on is stable across these versions, a
single build of the ocaml-tree-sitter generator works with grammars
generated for any of the supported versions.
We have limited documentation which is mostly targeted at early contributors. It's growing organically based on demand, so don't hesitate to file an issue explaining what you're trying to do.
ocaml-tree-sitter is free software with contributors from multiple organizations. The project is driven by Semgrep.
OCaml
77.2%
Shell
8.1%
C
4.6%
JavaScript
3.4%
Standard ML
2.1%
Reason
2.1%
Python
1.8%
OCaml code generator and runtime library for handling typed tree-sitter CSTs
60
stars
533
commits
OCaml
primary language
Jul 30, 2026
updated
Generate OCaml parsers based on tree-sitter grammars. This project was originally intended for semgrep. This repository contains the code for generating code for tree-sitter grammars but does not contain grammars for specific languages other than tests.
The ocaml-tree-sitter repositories are:
Installing ocaml-tree-sitter alone isn't of great use at the
moment. It is useful as part of the flow for generating OCaml parsers
from tree-sitter grammars, which is done from the lang/ folder
in ocaml-tree-sitter-semgrep.
See the Contributing instructions below.
Before you get started, make sure you're ok with signing the CLA which will be needed before we accept your pull request. The goal is only to allow future relicensing without having to track down any past contributor, if such need were to arise. Note that the current license is LGPL and any contribution made today will remain available under that license no matter what.
opam install merlin + some plugin for your editor.pre-commit with pip3 install pre-commit and run
pre-commit install to set up the pre-commit hook.
This will re-indent code in a consistent fashion each time you call
git commit.For building or rebuilding everything after big changes:
# Install OCaml dependencies (if not already installed)
$ opam install --deps-only .
# Build and test (automatically sets up tree-sitter on first build)
$ dune build
$ dune runtest
The default tree-sitter version to use is in the
tree-sitter-version file.
Under the default configuration used for local development purposes,
the version being actually used is stored in the file
tree-sitter-version. To use a different version, edit that file;
dune will download and build the corresponding tree-sitter sources on
the next build.
IMPORTANT Note that the selection in tree-sitter-version affects
the tree-sitter runtime that the ocaml-tree-sitter code generator
and its OCaml bindings are compiled against, as well as the CLI used to
generate parsers.
It does not determine which tree-sitter version grammars are built with.
In ocaml-tree-sitter-semgrep, every grammar is built by the tree-sitter version
specified by the lang/languages-<version> lists.
See the "tree-sitter versions (per language)" section of the
ocaml-tree-sitter-semgrep README.
Because the C API surface we rely on is stable across these versions, a
single build of the ocaml-tree-sitter generator works with grammars
generated for any of the supported versions.
We have limited documentation which is mostly targeted at early contributors. It's growing organically based on demand, so don't hesitate to file an issue explaining what you're trying to do.
ocaml-tree-sitter is free software with contributors from multiple organizations. The project is driven by Semgrep.
OCaml
77.2%
Shell
8.1%
C
4.6%
JavaScript
3.4%
Standard ML
2.1%
Reason
2.1%
Python
1.8%