package tree-sitter

  1. Overview
  2. Docs

Module Tree_sitter.LanguageSource

Language grammars.

A Language.t describes the grammar rules, symbols, and fields for a particular programming language. Obtain one from a grammar package (e.g. Tree_sitter_json.language ()) rather than calling of_address directly.

Sourcetype t

The type for Tree-sitter language grammars.

Constructors

Sourceval of_address : nativeint -> t

of_address addr is a language from a native pointer addr.

Warning. addr must point to a valid TSLanguage returned by a tree_sitter_<lang>() C function. Prefer grammar-package helpers (e.g. Tree_sitter_json.language ()) instead.

Properties

Sourceval name : t -> string

name lang is the language name (e.g. "json", "ocaml").

Sourceval version : t -> int

version lang is the ABI version of the grammar.

Sourceval symbol_count : t -> int

symbol_count lang is the total number of symbols in the grammar.

Sourceval field_count : t -> int

field_count lang is the number of named fields in the grammar.

Symbol lookups

Sourceval symbol_name : t -> int -> string

symbol_name lang id is the name of symbol id.

Sourceval symbol_type : t -> int -> symbol_type

symbol_type lang id is the symbol_type of symbol id.

Sourceval symbol_for_name : t -> string -> named:bool -> int option

symbol_for_name lang name ~named is the symbol ID for name, if any. When ~named is true, only named (non-anonymous) symbols are searched.

Field lookups

Sourceval field_name_for_id : t -> int -> string option

field_name_for_id lang id is the field name for id, if any.

Sourceval field_id_for_name : t -> string -> int option

field_id_for_name lang name is the field ID for name, if any.