tree-sitter-ocaml
![pypi](https://img.shields.io/pypi/v/tree-sitter-ocaml?logo=pypi&logoColor=white&label=PyPI)
This module provides OCaml grammars for the tree-sitter parsing library.
There are separate grammars for implementations (.ml
), interfaces (.mli
)
and types.
Installation
pip install tree-sitter-ocaml
You will probably also need the tree-sitter binding.
pip install tree-sitter
Usage
Load the grammar as a Language
object:
import tree_sitter_ocaml
from tree_sitter import Language, Parser
language_ocaml = Language(tree_sitter_ocaml.language_ocaml())
Create a Parser
and configure it to use the language:
parser = Parser(language_ocaml)
Parse some source code:
tree = parser.parse(
b"""
module M : sig
val x : int
end
"""
)
Use language_ocaml_interface()
to parse interface files (with .mli
extension)
and language_ocaml_type()
to parse type signatures.