Generate OCaml parsers based on tree-sitter grammars.
ocaml-tree-sitter is under initial development and is not ready to be installed or used by a wide audience.
Development setup:
- Install opam.
- Install ocaml dev tools for your favorite
editor:
typically
opam install merlin+ some plugin for your editor. - Install
pre-commitwithpip3 install pre-commitand runpre-commit installto set up the pre-commit hook. This will re-indent code in a consistent fashion each time you callgit commit.
For building or rebuilding everything after big changes, use this script:
./scripts/rebuild-everything
For working with the OCaml source code for the ocaml-tree-sitter code generator, the normal development commands are:
makemake install- necessary for generating parser code in the steps below.make test
For updating a tree-sitter grammar, the typical process is:
- Edit the
tree-sitter-Xproject on GitHub corresponding to the target language X. - Go to
lang/semgrep-grammars/src/tree-sitter-Xand pull the git commit you want to test. - Run
npm installfrom the project root to install the updatedtree-sitter-X. - Optionally update the semgrep syntax extensions in
lang/semgrep-grammars/src/semgrep-X. - Run
make -C langandmake -C lang testto build and test the extended grammar for language X. - Publish the generated code with
(cd lang && ./release X). - In the semgrep repo, update the submodule for language X:
git -C semgrep-core/tree-sitter-lang/semgrep-X pull origin mainand commit.
- Note that you must have Xcode and CLT installed for Mac to run make setup.
- If you are having trouble with node setup, reference node page.
- You must also have bash version 4.0 or higher. To make this your default bash:
- Run
brew install bashorbrew upgrade bash - Go to
/etc/shellsand addusr/local/bin/bash - Run
chsh -s /usr/local/bin/bash - Close your shell and reopen. To check your bash version, run
bash --version.
- Run
- Go to
ocaml-tree-sitter/lang/semgrep-grammars/src. - Build with
make. - Go to
ocaml-tree-sitter/lang/<language name>. - Build with
make.
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 r2c.
- OCaml code developed specifically for this project is distributed under the terms of the GNU GPL v3.
- The OCaml bindings to tree-sitter's C API were created by Bryan Phelps as part of the reason-tree-sitter project.
- The tree-sitter grammars for major programming languages were imported from their respective projects, and we try to keep them in sync. Each comes with its own license.