package tree-sitter

  1. Overview
  2. Docs

Module Tree_sitter_ocamlSource

Tree-sitter OCaml grammars with built-in highlighting.

This module provides grammars for three OCaml dialects — implementation files (.ml), interface files (.mli), and standalone type expressions — together with convenience highlighting functions.

  let ranges = Tree_sitter_ocaml.highlight_ocaml "let x = 1"
  (* ranges : (int * int * string) list *)

Languages

Sourceval ocaml : unit -> Tree_sitter.Language.t

ocaml () is the grammar for OCaml implementation files (.ml).

Sourceval interface : unit -> Tree_sitter.Language.t

interface () is the grammar for OCaml interface files (.mli).

Sourceval type_ : unit -> Tree_sitter.Language.t

type_ () is the grammar for standalone OCaml type expressions.

Highlighting

Sourceval ocaml_highlights_query : string

ocaml_highlights_query is the highlight query source for OCaml implementation files. Targets comments, strings, types, keywords, variables, and numbers.

Sourceval interface_highlights_query : string

interface_highlights_query is the highlight query source for OCaml interface files. Currently identical to ocaml_highlights_query.

Sourceval highlight_ocaml : string -> (int * int * string) list

highlight_ocaml content parses content as OCaml and returns (start_byte, end_byte, capture_group) triples. Equivalent to parsing with ocaml and running Tree_sitter.highlight with ocaml_highlights_query.

Sourceval highlight_interface : string -> (int * int * string) list

highlight_interface content parses content as an OCaml interface and returns (start_byte, end_byte, capture_group) triples. Equivalent to parsing with interface and running Tree_sitter.highlight with interface_highlights_query.