changelog shortlog graph tags branches files raw help

Mercurial > core / changeset: add back tree-sitter wrappers

changeset 412: 0aabe04c7625
parent 411: 7e3c88fff062
child 413: 600e4fc73cb3
author: Richard Westhaver <ellis@rwest.io>
date: Wed, 05 Jun 2024 22:06:05 -0400
files: lisp/ffi/tree-sitter/alien.c lisp/ffi/tree-sitter/ts-api.h
description: add back tree-sitter wrappers
     1.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2+++ b/lisp/ffi/tree-sitter/alien.c	Wed Jun 05 22:06:05 2024 -0400
     1.3@@ -0,0 +1,65 @@
     1.4+//! tree-sitter/alien.c --- Tree-sitter C wrapper
     1.5+
     1.6+// based on https://github.com/death/cl-tree-sitter
     1.7+
     1.8+// it's annoying that we need this, I thought we could get away
     1.9+// without it. Alas, SB-ALIEN is also unable to fully interoperate
    1.10+// with the types defined in api.h, so we need to manually create
    1.11+// pointer type definitions for them.
    1.12+
    1.13+// build with:
    1.14+/*
    1.15+  sudo clang -g -O2 -Wall -Wno-unused-value -ltree-sitter -shared alien.c -o /usr/local/lib/libtree-sitter-alien.so
    1.16+*/
    1.17+
    1.18+/// Code:
    1.19+#include <stdlib.h>
    1.20+
    1.21+#include "ts-api.h"
    1.22+
    1.23+TSNode *ts_tree_root_node_pointer(const TSTree *self) {
    1.24+    TSNode *node = malloc(sizeof(TSNode));
    1.25+
    1.26+    if (node) {
    1.27+        *node = ts_tree_root_node(self);
    1.28+    }
    1.29+
    1.30+    return node;
    1.31+}
    1.32+
    1.33+TSTreeCursor *ts_tree_cursor_new_pointer(TSNode *node) {
    1.34+    TSTreeCursor *cursor = malloc(sizeof(TSTreeCursor));
    1.35+
    1.36+    if (cursor) {
    1.37+        *cursor = ts_tree_cursor_new(*node);
    1.38+    }
    1.39+
    1.40+    return cursor;
    1.41+}
    1.42+
    1.43+TSNode *ts_tree_cursor_current_node_pointer(const TSTreeCursor *cursor) {
    1.44+    TSNode *return_node = malloc(sizeof(TSNode));
    1.45+
    1.46+    if (return_node) {
    1.47+        *return_node = ts_tree_cursor_current_node(cursor);
    1.48+    }
    1.49+
    1.50+    return return_node;
    1.51+}
    1.52+
    1.53+int ts_node_is_named_pointer(TSNode *node) {
    1.54+    return ts_node_is_named(*node);
    1.55+}
    1.56+
    1.57+TSPoint ts_node_start_point_pointer(TSNode *node) {
    1.58+    return ts_node_start_point(*node);
    1.59+}
    1.60+
    1.61+
    1.62+TSPoint ts_node_end_point_pointer(TSNode *node) {
    1.63+    return ts_node_end_point(*node);
    1.64+}
    1.65+
    1.66+const char *ts_node_type_pointer(TSNode *node) {
    1.67+    return ts_node_type(*node);
    1.68+}
     2.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2+++ b/lisp/ffi/tree-sitter/ts-api.h	Wed Jun 05 22:06:05 2024 -0400
     2.3@@ -0,0 +1,1180 @@
     2.4+#ifndef TREE_SITTER_API_H_
     2.5+#define TREE_SITTER_API_H_
     2.6+
     2.7+#if defined(__GNUC__) || defined(__clang__)
     2.8+#pragma GCC visibility push(default)
     2.9+#endif
    2.10+
    2.11+#ifdef __cplusplus
    2.12+extern "C" {
    2.13+#endif
    2.14+
    2.15+#include <stdlib.h>
    2.16+#include <stdint.h>
    2.17+#include <stdbool.h>
    2.18+
    2.19+/****************************/
    2.20+/* Section - ABI Versioning */
    2.21+/****************************/
    2.22+
    2.23+/**
    2.24+ * The latest ABI version that is supported by the current version of the
    2.25+ * library. When Languages are generated by the Tree-sitter CLI, they are
    2.26+ * assigned an ABI version number that corresponds to the current CLI version.
    2.27+ * The Tree-sitter library is generally backwards-compatible with languages
    2.28+ * generated using older CLI versions, but is not forwards-compatible.
    2.29+ */
    2.30+#define TREE_SITTER_LANGUAGE_VERSION 14
    2.31+
    2.32+/**
    2.33+ * The earliest ABI version that is supported by the current version of the
    2.34+ * library.
    2.35+ */
    2.36+#define TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION 13
    2.37+
    2.38+/*******************/
    2.39+/* Section - Types */
    2.40+/*******************/
    2.41+
    2.42+typedef uint16_t TSStateId;
    2.43+typedef uint16_t TSSymbol;
    2.44+typedef uint16_t TSFieldId;
    2.45+typedef struct TSLanguage TSLanguage;
    2.46+typedef struct TSParser TSParser;
    2.47+typedef struct TSTree TSTree;
    2.48+typedef struct TSQuery TSQuery;
    2.49+typedef struct TSQueryCursor TSQueryCursor;
    2.50+typedef struct TSLookaheadIterator TSLookaheadIterator;
    2.51+
    2.52+typedef enum {
    2.53+  TSInputEncodingUTF8,
    2.54+  TSInputEncodingUTF16,
    2.55+} TSInputEncoding;
    2.56+
    2.57+typedef enum {
    2.58+  TSSymbolTypeRegular,
    2.59+  TSSymbolTypeAnonymous,
    2.60+  TSSymbolTypeAuxiliary,
    2.61+} TSSymbolType;
    2.62+
    2.63+typedef struct {
    2.64+  uint32_t row;
    2.65+  uint32_t column;
    2.66+} TSPoint;
    2.67+
    2.68+typedef struct {
    2.69+  TSPoint start_point;
    2.70+  TSPoint end_point;
    2.71+  uint32_t start_byte;
    2.72+  uint32_t end_byte;
    2.73+} TSRange;
    2.74+
    2.75+typedef struct {
    2.76+  void *payload;
    2.77+  const char *(*read)(void *payload, uint32_t byte_index, TSPoint position, uint32_t *bytes_read);
    2.78+  TSInputEncoding encoding;
    2.79+} TSInput;
    2.80+
    2.81+typedef enum {
    2.82+  TSLogTypeParse,
    2.83+  TSLogTypeLex,
    2.84+} TSLogType;
    2.85+
    2.86+typedef struct {
    2.87+  void *payload;
    2.88+  void (*log)(void *payload, TSLogType log_type, const char *buffer);
    2.89+} TSLogger;
    2.90+
    2.91+typedef struct {
    2.92+  uint32_t start_byte;
    2.93+  uint32_t old_end_byte;
    2.94+  uint32_t new_end_byte;
    2.95+  TSPoint start_point;
    2.96+  TSPoint old_end_point;
    2.97+  TSPoint new_end_point;
    2.98+} TSInputEdit;
    2.99+
   2.100+typedef struct {
   2.101+  uint32_t context[4];
   2.102+  const void *id;
   2.103+  const TSTree *tree;
   2.104+} TSNode;
   2.105+
   2.106+typedef struct {
   2.107+  const void *tree;
   2.108+  const void *id;
   2.109+  uint32_t context[2];
   2.110+} TSTreeCursor;
   2.111+
   2.112+typedef struct {
   2.113+  TSNode node;
   2.114+  uint32_t index;
   2.115+} TSQueryCapture;
   2.116+
   2.117+typedef enum {
   2.118+  TSQuantifierZero = 0, // must match the array initialization value
   2.119+  TSQuantifierZeroOrOne,
   2.120+  TSQuantifierZeroOrMore,
   2.121+  TSQuantifierOne,
   2.122+  TSQuantifierOneOrMore,
   2.123+} TSQuantifier;
   2.124+
   2.125+typedef struct {
   2.126+  uint32_t id;
   2.127+  uint16_t pattern_index;
   2.128+  uint16_t capture_count;
   2.129+  const TSQueryCapture *captures;
   2.130+} TSQueryMatch;
   2.131+
   2.132+typedef enum {
   2.133+  TSQueryPredicateStepTypeDone,
   2.134+  TSQueryPredicateStepTypeCapture,
   2.135+  TSQueryPredicateStepTypeString,
   2.136+} TSQueryPredicateStepType;
   2.137+
   2.138+typedef struct {
   2.139+  TSQueryPredicateStepType type;
   2.140+  uint32_t value_id;
   2.141+} TSQueryPredicateStep;
   2.142+
   2.143+typedef enum {
   2.144+  TSQueryErrorNone = 0,
   2.145+  TSQueryErrorSyntax,
   2.146+  TSQueryErrorNodeType,
   2.147+  TSQueryErrorField,
   2.148+  TSQueryErrorCapture,
   2.149+  TSQueryErrorStructure,
   2.150+  TSQueryErrorLanguage,
   2.151+} TSQueryError;
   2.152+
   2.153+/********************/
   2.154+/* Section - Parser */
   2.155+/********************/
   2.156+
   2.157+/**
   2.158+ * Create a new parser.
   2.159+ */
   2.160+TSParser *ts_parser_new(void);
   2.161+
   2.162+/**
   2.163+ * Delete the parser, freeing all of the memory that it used.
   2.164+ */
   2.165+void ts_parser_delete(TSParser *self);
   2.166+
   2.167+/**
   2.168+ * Get the parser's current language.
   2.169+ */
   2.170+const TSLanguage *ts_parser_language(const TSParser *self);
   2.171+
   2.172+/**
   2.173+ * Set the language that the parser should use for parsing.
   2.174+ *
   2.175+ * Returns a boolean indicating whether or not the language was successfully
   2.176+ * assigned. True means assignment succeeded. False means there was a version
   2.177+ * mismatch: the language was generated with an incompatible version of the
   2.178+ * Tree-sitter CLI. Check the language's version using [`ts_language_version`]
   2.179+ * and compare it to this library's [`TREE_SITTER_LANGUAGE_VERSION`] and
   2.180+ * [`TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION`] constants.
   2.181+ */
   2.182+bool ts_parser_set_language(TSParser *self, const TSLanguage *language);
   2.183+
   2.184+/**
   2.185+ * Set the ranges of text that the parser should include when parsing.
   2.186+ *
   2.187+ * By default, the parser will always include entire documents. This function
   2.188+ * allows you to parse only a *portion* of a document but still return a syntax
   2.189+ * tree whose ranges match up with the document as a whole. You can also pass
   2.190+ * multiple disjoint ranges.
   2.191+ *
   2.192+ * The second and third parameters specify the location and length of an array
   2.193+ * of ranges. The parser does *not* take ownership of these ranges; it copies
   2.194+ * the data, so it doesn't matter how these ranges are allocated.
   2.195+ *
   2.196+ * If `count` is zero, then the entire document will be parsed. Otherwise,
   2.197+ * the given ranges must be ordered from earliest to latest in the document,
   2.198+ * and they must not overlap. That is, the following must hold for all:
   2.199+ *
   2.200+ * `i < count - 1`: `ranges[i].end_byte <= ranges[i + 1].start_byte`
   2.201+ *
   2.202+ * If this requirement is not satisfied, the operation will fail, the ranges
   2.203+ * will not be assigned, and this function will return `false`. On success,
   2.204+ * this function returns `true`
   2.205+ */
   2.206+bool ts_parser_set_included_ranges(
   2.207+  TSParser *self,
   2.208+  const TSRange *ranges,
   2.209+  uint32_t count
   2.210+);
   2.211+
   2.212+/**
   2.213+ * Get the ranges of text that the parser will include when parsing.
   2.214+ *
   2.215+ * The returned pointer is owned by the parser. The caller should not free it
   2.216+ * or write to it. The length of the array will be written to the given
   2.217+ * `count` pointer.
   2.218+ */
   2.219+const TSRange *ts_parser_included_ranges(
   2.220+  const TSParser *self,
   2.221+  uint32_t *count
   2.222+);
   2.223+
   2.224+/**
   2.225+ * Use the parser to parse some source code and create a syntax tree.
   2.226+ *
   2.227+ * If you are parsing this document for the first time, pass `NULL` for the
   2.228+ * `old_tree` parameter. Otherwise, if you have already parsed an earlier
   2.229+ * version of this document and the document has since been edited, pass the
   2.230+ * previous syntax tree so that the unchanged parts of it can be reused.
   2.231+ * This will save time and memory. For this to work correctly, you must have
   2.232+ * already edited the old syntax tree using the [`ts_tree_edit`] function in a
   2.233+ * way that exactly matches the source code changes.
   2.234+ *
   2.235+ * The [`TSInput`] parameter lets you specify how to read the text. It has the
   2.236+ * following three fields:
   2.237+ * 1. [`read`]: A function to retrieve a chunk of text at a given byte offset
   2.238+ *    and (row, column) position. The function should return a pointer to the
   2.239+ *    text and write its length to the [`bytes_read`] pointer. The parser does
   2.240+ *    not take ownership of this buffer; it just borrows it until it has
   2.241+ *    finished reading it. The function should write a zero value to the
   2.242+ *    [`bytes_read`] pointer to indicate the end of the document.
   2.243+ * 2. [`payload`]: An arbitrary pointer that will be passed to each invocation
   2.244+ *    of the [`read`] function.
   2.245+ * 3. [`encoding`]: An indication of how the text is encoded. Either
   2.246+ *    `TSInputEncodingUTF8` or `TSInputEncodingUTF16`.
   2.247+ *
   2.248+ * This function returns a syntax tree on success, and `NULL` on failure. There
   2.249+ * are three possible reasons for failure:
   2.250+ * 1. The parser does not have a language assigned. Check for this using the
   2.251+      [`ts_parser_language`] function.
   2.252+ * 2. Parsing was cancelled due to a timeout that was set by an earlier call to
   2.253+ *    the [`ts_parser_set_timeout_micros`] function. You can resume parsing from
   2.254+ *    where the parser left out by calling [`ts_parser_parse`] again with the
   2.255+ *    same arguments. Or you can start parsing from scratch by first calling
   2.256+ *    [`ts_parser_reset`].
   2.257+ * 3. Parsing was cancelled using a cancellation flag that was set by an
   2.258+ *    earlier call to [`ts_parser_set_cancellation_flag`]. You can resume parsing
   2.259+ *    from where the parser left out by calling [`ts_parser_parse`] again with
   2.260+ *    the same arguments.
   2.261+ *
   2.262+ * [`read`]: TSInput::read
   2.263+ * [`payload`]: TSInput::payload
   2.264+ * [`encoding`]: TSInput::encoding
   2.265+ * [`bytes_read`]: TSInput::read
   2.266+ */
   2.267+TSTree *ts_parser_parse(
   2.268+  TSParser *self,
   2.269+  const TSTree *old_tree,
   2.270+  TSInput input
   2.271+);
   2.272+
   2.273+/**
   2.274+ * Use the parser to parse some source code stored in one contiguous buffer.
   2.275+ * The first two parameters are the same as in the [`ts_parser_parse`] function
   2.276+ * above. The second two parameters indicate the location of the buffer and its
   2.277+ * length in bytes.
   2.278+ */
   2.279+TSTree *ts_parser_parse_string(
   2.280+  TSParser *self,
   2.281+  const TSTree *old_tree,
   2.282+  const char *string,
   2.283+  uint32_t length
   2.284+);
   2.285+
   2.286+/**
   2.287+ * Use the parser to parse some source code stored in one contiguous buffer with
   2.288+ * a given encoding. The first four parameters work the same as in the
   2.289+ * [`ts_parser_parse_string`] method above. The final parameter indicates whether
   2.290+ * the text is encoded as UTF8 or UTF16.
   2.291+ */
   2.292+TSTree *ts_parser_parse_string_encoding(
   2.293+  TSParser *self,
   2.294+  const TSTree *old_tree,
   2.295+  const char *string,
   2.296+  uint32_t length,
   2.297+  TSInputEncoding encoding
   2.298+);
   2.299+
   2.300+/**
   2.301+ * Instruct the parser to start the next parse from the beginning.
   2.302+ *
   2.303+ * If the parser previously failed because of a timeout or a cancellation, then
   2.304+ * by default, it will resume where it left off on the next call to
   2.305+ * [`ts_parser_parse`] or other parsing functions. If you don't want to resume,
   2.306+ * and instead intend to use this parser to parse some other document, you must
   2.307+ * call [`ts_parser_reset`] first.
   2.308+ */
   2.309+void ts_parser_reset(TSParser *self);
   2.310+
   2.311+/**
   2.312+ * Set the maximum duration in microseconds that parsing should be allowed to
   2.313+ * take before halting.
   2.314+ *
   2.315+ * If parsing takes longer than this, it will halt early, returning NULL.
   2.316+ * See [`ts_parser_parse`] for more information.
   2.317+ */
   2.318+void ts_parser_set_timeout_micros(TSParser *self, uint64_t timeout_micros);
   2.319+
   2.320+/**
   2.321+ * Get the duration in microseconds that parsing is allowed to take.
   2.322+ */
   2.323+uint64_t ts_parser_timeout_micros(const TSParser *self);
   2.324+
   2.325+/**
   2.326+ * Set the parser's current cancellation flag pointer.
   2.327+ *
   2.328+ * If a non-null pointer is assigned, then the parser will periodically read
   2.329+ * from this pointer during parsing. If it reads a non-zero value, it will
   2.330+ * halt early, returning NULL. See [`ts_parser_parse`] for more information.
   2.331+ */
   2.332+void ts_parser_set_cancellation_flag(TSParser *self, const size_t *flag);
   2.333+
   2.334+/**
   2.335+ * Get the parser's current cancellation flag pointer.
   2.336+ */
   2.337+const size_t *ts_parser_cancellation_flag(const TSParser *self);
   2.338+
   2.339+/**
   2.340+ * Set the logger that a parser should use during parsing.
   2.341+ *
   2.342+ * The parser does not take ownership over the logger payload. If a logger was
   2.343+ * previously assigned, the caller is responsible for releasing any memory
   2.344+ * owned by the previous logger.
   2.345+ */
   2.346+void ts_parser_set_logger(TSParser *self, TSLogger logger);
   2.347+
   2.348+/**
   2.349+ * Get the parser's current logger.
   2.350+ */
   2.351+TSLogger ts_parser_logger(const TSParser *self);
   2.352+
   2.353+/**
   2.354+ * Set the file descriptor to which the parser should write debugging graphs
   2.355+ * during parsing. The graphs are formatted in the DOT language. You may want
   2.356+ * to pipe these graphs directly to a `dot(1)` process in order to generate
   2.357+ * SVG output. You can turn off this logging by passing a negative number.
   2.358+ */
   2.359+void ts_parser_print_dot_graphs(TSParser *self, int fd);
   2.360+
   2.361+/******************/
   2.362+/* Section - Tree */
   2.363+/******************/
   2.364+
   2.365+/**
   2.366+ * Create a shallow copy of the syntax tree. This is very fast.
   2.367+ *
   2.368+ * You need to copy a syntax tree in order to use it on more than one thread at
   2.369+ * a time, as syntax trees are not thread safe.
   2.370+ */
   2.371+TSTree *ts_tree_copy(const TSTree *self);
   2.372+
   2.373+/**
   2.374+ * Delete the syntax tree, freeing all of the memory that it used.
   2.375+ */
   2.376+void ts_tree_delete(TSTree *self);
   2.377+
   2.378+/**
   2.379+ * Get the root node of the syntax tree.
   2.380+ */
   2.381+TSNode ts_tree_root_node(const TSTree *self);
   2.382+
   2.383+/**
   2.384+ * Get the root node of the syntax tree, but with its position
   2.385+ * shifted forward by the given offset.
   2.386+ */
   2.387+TSNode ts_tree_root_node_with_offset(
   2.388+  const TSTree *self,
   2.389+  uint32_t offset_bytes,
   2.390+  TSPoint offset_extent
   2.391+);
   2.392+
   2.393+/**
   2.394+ * Get the language that was used to parse the syntax tree.
   2.395+ */
   2.396+const TSLanguage *ts_tree_language(const TSTree *self);
   2.397+
   2.398+/**
   2.399+ * Get the array of included ranges that was used to parse the syntax tree.
   2.400+ *
   2.401+ * The returned pointer must be freed by the caller.
   2.402+ */
   2.403+TSRange *ts_tree_included_ranges(const TSTree *self, uint32_t *length);
   2.404+
   2.405+/**
   2.406+ * Edit the syntax tree to keep it in sync with source code that has been
   2.407+ * edited.
   2.408+ *
   2.409+ * You must describe the edit both in terms of byte offsets and in terms of
   2.410+ * (row, column) coordinates.
   2.411+ */
   2.412+void ts_tree_edit(TSTree *self, const TSInputEdit *edit);
   2.413+
   2.414+/**
   2.415+ * Compare an old edited syntax tree to a new syntax tree representing the same
   2.416+ * document, returning an array of ranges whose syntactic structure has changed.
   2.417+ *
   2.418+ * For this to work correctly, the old syntax tree must have been edited such
   2.419+ * that its ranges match up to the new tree. Generally, you'll want to call
   2.420+ * this function right after calling one of the [`ts_parser_parse`] functions.
   2.421+ * You need to pass the old tree that was passed to parse, as well as the new
   2.422+ * tree that was returned from that function.
   2.423+ *
   2.424+ * The returned array is allocated using `malloc` and the caller is responsible
   2.425+ * for freeing it using `free`. The length of the array will be written to the
   2.426+ * given `length` pointer.
   2.427+ */
   2.428+TSRange *ts_tree_get_changed_ranges(
   2.429+  const TSTree *old_tree,
   2.430+  const TSTree *new_tree,
   2.431+  uint32_t *length
   2.432+);
   2.433+
   2.434+/**
   2.435+ * Write a DOT graph describing the syntax tree to the given file.
   2.436+ */
   2.437+void ts_tree_print_dot_graph(const TSTree *self, int file_descriptor);
   2.438+
   2.439+/******************/
   2.440+/* Section - Node */
   2.441+/******************/
   2.442+
   2.443+/**
   2.444+ * Get the node's type as a null-terminated string.
   2.445+ */
   2.446+const char *ts_node_type(TSNode self);
   2.447+
   2.448+/**
   2.449+ * Get the node's type as a numerical id.
   2.450+ */
   2.451+TSSymbol ts_node_symbol(TSNode self);
   2.452+
   2.453+/**
   2.454+ * Get the node's language.
   2.455+ */
   2.456+const TSLanguage *ts_node_language(TSNode self);
   2.457+
   2.458+/**
   2.459+ * Get the node's type as it appears in the grammar ignoring aliases as a
   2.460+ * null-terminated string.
   2.461+ */
   2.462+const char *ts_node_grammar_type(TSNode self);
   2.463+
   2.464+/**
   2.465+ * Get the node's type as a numerical id as it appears in the grammar ignoring
   2.466+ * aliases. This should be used in [`ts_language_next_state`] instead of
   2.467+ * [`ts_node_symbol`].
   2.468+ */
   2.469+TSSymbol ts_node_grammar_symbol(TSNode self);
   2.470+
   2.471+/**
   2.472+ * Get the node's start byte.
   2.473+ */
   2.474+uint32_t ts_node_start_byte(TSNode self);
   2.475+
   2.476+/**
   2.477+ * Get the node's start position in terms of rows and columns.
   2.478+ */
   2.479+TSPoint ts_node_start_point(TSNode self);
   2.480+
   2.481+/**
   2.482+ * Get the node's end byte.
   2.483+ */
   2.484+uint32_t ts_node_end_byte(TSNode self);
   2.485+
   2.486+/**
   2.487+ * Get the node's end position in terms of rows and columns.
   2.488+ */
   2.489+TSPoint ts_node_end_point(TSNode self);
   2.490+
   2.491+/**
   2.492+ * Get an S-expression representing the node as a string.
   2.493+ *
   2.494+ * This string is allocated with `malloc` and the caller is responsible for
   2.495+ * freeing it using `free`.
   2.496+ */
   2.497+char *ts_node_string(TSNode self);
   2.498+
   2.499+/**
   2.500+ * Check if the node is null. Functions like [`ts_node_child`] and
   2.501+ * [`ts_node_next_sibling`] will return a null node to indicate that no such node
   2.502+ * was found.
   2.503+ */
   2.504+bool ts_node_is_null(TSNode self);
   2.505+
   2.506+/**
   2.507+ * Check if the node is *named*. Named nodes correspond to named rules in the
   2.508+ * grammar, whereas *anonymous* nodes correspond to string literals in the
   2.509+ * grammar.
   2.510+ */
   2.511+bool ts_node_is_named(TSNode self);
   2.512+
   2.513+/**
   2.514+ * Check if the node is *missing*. Missing nodes are inserted by the parser in
   2.515+ * order to recover from certain kinds of syntax errors.
   2.516+ */
   2.517+bool ts_node_is_missing(TSNode self);
   2.518+
   2.519+/**
   2.520+ * Check if the node is *extra*. Extra nodes represent things like comments,
   2.521+ * which are not required the grammar, but can appear anywhere.
   2.522+ */
   2.523+bool ts_node_is_extra(TSNode self);
   2.524+
   2.525+/**
   2.526+ * Check if a syntax node has been edited.
   2.527+ */
   2.528+bool ts_node_has_changes(TSNode self);
   2.529+
   2.530+/**
   2.531+ * Check if the node is a syntax error or contains any syntax errors.
   2.532+ */
   2.533+bool ts_node_has_error(TSNode self);
   2.534+
   2.535+/**
   2.536+ * Check if the node is a syntax error.
   2.537+*/
   2.538+bool ts_node_is_error(TSNode self);
   2.539+
   2.540+/**
   2.541+ * Get this node's parse state.
   2.542+*/
   2.543+TSStateId ts_node_parse_state(TSNode self);
   2.544+
   2.545+/**
   2.546+ * Get the parse state after this node.
   2.547+*/
   2.548+TSStateId ts_node_next_parse_state(TSNode self);
   2.549+
   2.550+/**
   2.551+ * Get the node's immediate parent.
   2.552+ */
   2.553+TSNode ts_node_parent(TSNode self);
   2.554+
   2.555+/**
   2.556+ * Get the node's child at the given index, where zero represents the first
   2.557+ * child.
   2.558+ */
   2.559+TSNode ts_node_child(TSNode self, uint32_t child_index);
   2.560+
   2.561+/**
   2.562+ * Get the field name for node's child at the given index, where zero represents
   2.563+ * the first child. Returns NULL, if no field is found.
   2.564+ */
   2.565+const char *ts_node_field_name_for_child(TSNode self, uint32_t child_index);
   2.566+
   2.567+/**
   2.568+ * Get the node's number of children.
   2.569+ */
   2.570+uint32_t ts_node_child_count(TSNode self);
   2.571+
   2.572+/**
   2.573+ * Get the node's *named* child at the given index.
   2.574+ *
   2.575+ * See also [`ts_node_is_named`].
   2.576+ */
   2.577+TSNode ts_node_named_child(TSNode self, uint32_t child_index);
   2.578+
   2.579+/**
   2.580+ * Get the node's number of *named* children.
   2.581+ *
   2.582+ * See also [`ts_node_is_named`].
   2.583+ */
   2.584+uint32_t ts_node_named_child_count(TSNode self);
   2.585+
   2.586+/**
   2.587+ * Get the node's child with the given field name.
   2.588+ */
   2.589+TSNode ts_node_child_by_field_name(
   2.590+  TSNode self,
   2.591+  const char *name,
   2.592+  uint32_t name_length
   2.593+);
   2.594+
   2.595+/**
   2.596+ * Get the node's child with the given numerical field id.
   2.597+ *
   2.598+ * You can convert a field name to an id using the
   2.599+ * [`ts_language_field_id_for_name`] function.
   2.600+ */
   2.601+TSNode ts_node_child_by_field_id(TSNode self, TSFieldId field_id);
   2.602+
   2.603+/**
   2.604+ * Get the node's next / previous sibling.
   2.605+ */
   2.606+TSNode ts_node_next_sibling(TSNode self);
   2.607+TSNode ts_node_prev_sibling(TSNode self);
   2.608+
   2.609+/**
   2.610+ * Get the node's next / previous *named* sibling.
   2.611+ */
   2.612+TSNode ts_node_next_named_sibling(TSNode self);
   2.613+TSNode ts_node_prev_named_sibling(TSNode self);
   2.614+
   2.615+/**
   2.616+ * Get the node's first child that extends beyond the given byte offset.
   2.617+ */
   2.618+TSNode ts_node_first_child_for_byte(TSNode self, uint32_t byte);
   2.619+
   2.620+/**
   2.621+ * Get the node's first named child that extends beyond the given byte offset.
   2.622+ */
   2.623+TSNode ts_node_first_named_child_for_byte(TSNode self, uint32_t byte);
   2.624+
   2.625+/**
   2.626+ * Get the node's number of descendants, including one for the node itself.
   2.627+ */
   2.628+uint32_t ts_node_descendant_count(TSNode self);
   2.629+
   2.630+/**
   2.631+ * Get the smallest node within this node that spans the given range of bytes
   2.632+ * or (row, column) positions.
   2.633+ */
   2.634+TSNode ts_node_descendant_for_byte_range(TSNode self, uint32_t start, uint32_t end);
   2.635+TSNode ts_node_descendant_for_point_range(TSNode self, TSPoint start, TSPoint end);
   2.636+
   2.637+/**
   2.638+ * Get the smallest named node within this node that spans the given range of
   2.639+ * bytes or (row, column) positions.
   2.640+ */
   2.641+TSNode ts_node_named_descendant_for_byte_range(TSNode self, uint32_t start, uint32_t end);
   2.642+TSNode ts_node_named_descendant_for_point_range(TSNode self, TSPoint start, TSPoint end);
   2.643+
   2.644+/**
   2.645+ * Edit the node to keep it in-sync with source code that has been edited.
   2.646+ *
   2.647+ * This function is only rarely needed. When you edit a syntax tree with the
   2.648+ * [`ts_tree_edit`] function, all of the nodes that you retrieve from the tree
   2.649+ * afterward will already reflect the edit. You only need to use [`ts_node_edit`]
   2.650+ * when you have a [`TSNode`] instance that you want to keep and continue to use
   2.651+ * after an edit.
   2.652+ */
   2.653+void ts_node_edit(TSNode *self, const TSInputEdit *edit);
   2.654+
   2.655+/**
   2.656+ * Check if two nodes are identical.
   2.657+ */
   2.658+bool ts_node_eq(TSNode self, TSNode other);
   2.659+
   2.660+/************************/
   2.661+/* Section - TreeCursor */
   2.662+/************************/
   2.663+
   2.664+/**
   2.665+ * Create a new tree cursor starting from the given node.
   2.666+ *
   2.667+ * A tree cursor allows you to walk a syntax tree more efficiently than is
   2.668+ * possible using the [`TSNode`] functions. It is a mutable object that is always
   2.669+ * on a certain syntax node, and can be moved imperatively to different nodes.
   2.670+ */
   2.671+TSTreeCursor ts_tree_cursor_new(TSNode node);
   2.672+
   2.673+/**
   2.674+ * Delete a tree cursor, freeing all of the memory that it used.
   2.675+ */
   2.676+void ts_tree_cursor_delete(TSTreeCursor *self);
   2.677+
   2.678+/**
   2.679+ * Re-initialize a tree cursor to start at a different node.
   2.680+ */
   2.681+void ts_tree_cursor_reset(TSTreeCursor *self, TSNode node);
   2.682+
   2.683+/**
   2.684+ * Re-initialize a tree cursor to the same position as another cursor.
   2.685+ *
   2.686+ * Unlike [`ts_tree_cursor_reset`], this will not lose parent information and
   2.687+ * allows reusing already created cursors.
   2.688+*/
   2.689+void ts_tree_cursor_reset_to(TSTreeCursor *dst, const TSTreeCursor *src);
   2.690+
   2.691+/**
   2.692+ * Get the tree cursor's current node.
   2.693+ */
   2.694+TSNode ts_tree_cursor_current_node(const TSTreeCursor *self);
   2.695+
   2.696+/**
   2.697+ * Get the field name of the tree cursor's current node.
   2.698+ *
   2.699+ * This returns `NULL` if the current node doesn't have a field.
   2.700+ * See also [`ts_node_child_by_field_name`].
   2.701+ */
   2.702+const char *ts_tree_cursor_current_field_name(const TSTreeCursor *self);
   2.703+
   2.704+/**
   2.705+ * Get the field id of the tree cursor's current node.
   2.706+ *
   2.707+ * This returns zero if the current node doesn't have a field.
   2.708+ * See also [`ts_node_child_by_field_id`], [`ts_language_field_id_for_name`].
   2.709+ */
   2.710+TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *self);
   2.711+
   2.712+/**
   2.713+ * Move the cursor to the parent of its current node.
   2.714+ *
   2.715+ * This returns `true` if the cursor successfully moved, and returns `false`
   2.716+ * if there was no parent node (the cursor was already on the root node).
   2.717+ */
   2.718+bool ts_tree_cursor_goto_parent(TSTreeCursor *self);
   2.719+
   2.720+/**
   2.721+ * Move the cursor to the next sibling of its current node.
   2.722+ *
   2.723+ * This returns `true` if the cursor successfully moved, and returns `false`
   2.724+ * if there was no next sibling node.
   2.725+ */
   2.726+bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *self);
   2.727+
   2.728+/**
   2.729+ * Move the cursor to the previous sibling of its current node.
   2.730+ *
   2.731+ * This returns `true` if the cursor successfully moved, and returns `false` if
   2.732+ * there was no previous sibling node.
   2.733+ *
   2.734+ * Note, that this function may be slower than
   2.735+ * [`ts_tree_cursor_goto_next_sibling`] due to how node positions are stored. In
   2.736+ * the worst case, this will need to iterate through all the children upto the
   2.737+ * previous sibling node to recalculate its position.
   2.738+ */
   2.739+bool ts_tree_cursor_goto_previous_sibling(TSTreeCursor *self);
   2.740+
   2.741+/**
   2.742+ * Move the cursor to the first child of its current node.
   2.743+ *
   2.744+ * This returns `true` if the cursor successfully moved, and returns `false`
   2.745+ * if there were no children.
   2.746+ */
   2.747+bool ts_tree_cursor_goto_first_child(TSTreeCursor *self);
   2.748+
   2.749+/**
   2.750+ * Move the cursor to the last child of its current node.
   2.751+ *
   2.752+ * This returns `true` if the cursor successfully moved, and returns `false` if
   2.753+ * there were no children.
   2.754+ *
   2.755+ * Note that this function may be slower than [`ts_tree_cursor_goto_first_child`]
   2.756+ * because it needs to iterate through all the children to compute the child's
   2.757+ * position.
   2.758+ */
   2.759+bool ts_tree_cursor_goto_last_child(TSTreeCursor *self);
   2.760+
   2.761+/**
   2.762+ * Move the cursor to the node that is the nth descendant of
   2.763+ * the original node that the cursor was constructed with, where
   2.764+ * zero represents the original node itself.
   2.765+ */
   2.766+void ts_tree_cursor_goto_descendant(TSTreeCursor *self, uint32_t goal_descendant_index);
   2.767+
   2.768+/**
   2.769+ * Get the index of the cursor's current node out of all of the
   2.770+ * descendants of the original node that the cursor was constructed with.
   2.771+ */
   2.772+uint32_t ts_tree_cursor_current_descendant_index(const TSTreeCursor *self);
   2.773+
   2.774+/**
   2.775+ * Get the depth of the cursor's current node relative to the original
   2.776+ * node that the cursor was constructed with.
   2.777+ */
   2.778+uint32_t ts_tree_cursor_current_depth(const TSTreeCursor *self);
   2.779+
   2.780+/**
   2.781+ * Move the cursor to the first child of its current node that extends beyond
   2.782+ * the given byte offset or point.
   2.783+ *
   2.784+ * This returns the index of the child node if one was found, and returns -1
   2.785+ * if no such child was found.
   2.786+ */
   2.787+int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *self, uint32_t goal_byte);
   2.788+int64_t ts_tree_cursor_goto_first_child_for_point(TSTreeCursor *self, TSPoint goal_point);
   2.789+
   2.790+TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *cursor);
   2.791+
   2.792+/*******************/
   2.793+/* Section - Query */
   2.794+/*******************/
   2.795+
   2.796+/**
   2.797+ * Create a new query from a string containing one or more S-expression
   2.798+ * patterns. The query is associated with a particular language, and can
   2.799+ * only be run on syntax nodes parsed with that language.
   2.800+ *
   2.801+ * If all of the given patterns are valid, this returns a [`TSQuery`].
   2.802+ * If a pattern is invalid, this returns `NULL`, and provides two pieces
   2.803+ * of information about the problem:
   2.804+ * 1. The byte offset of the error is written to the `error_offset` parameter.
   2.805+ * 2. The type of error is written to the `error_type` parameter.
   2.806+ */
   2.807+TSQuery *ts_query_new(
   2.808+  const TSLanguage *language,
   2.809+  const char *source,
   2.810+  uint32_t source_len,
   2.811+  uint32_t *error_offset,
   2.812+  TSQueryError *error_type
   2.813+);
   2.814+
   2.815+/**
   2.816+ * Delete a query, freeing all of the memory that it used.
   2.817+ */
   2.818+void ts_query_delete(TSQuery *self);
   2.819+
   2.820+/**
   2.821+ * Get the number of patterns, captures, or string literals in the query.
   2.822+ */
   2.823+uint32_t ts_query_pattern_count(const TSQuery *self);
   2.824+uint32_t ts_query_capture_count(const TSQuery *self);
   2.825+uint32_t ts_query_string_count(const TSQuery *self);
   2.826+
   2.827+/**
   2.828+ * Get the byte offset where the given pattern starts in the query's source.
   2.829+ *
   2.830+ * This can be useful when combining queries by concatenating their source
   2.831+ * code strings.
   2.832+ */
   2.833+uint32_t ts_query_start_byte_for_pattern(const TSQuery *self, uint32_t pattern_index);
   2.834+
   2.835+/**
   2.836+ * Get all of the predicates for the given pattern in the query.
   2.837+ *
   2.838+ * The predicates are represented as a single array of steps. There are three
   2.839+ * types of steps in this array, which correspond to the three legal values for
   2.840+ * the `type` field:
   2.841+ * - `TSQueryPredicateStepTypeCapture` - Steps with this type represent names
   2.842+ *    of captures. Their `value_id` can be used with the
   2.843+ *   [`ts_query_capture_name_for_id`] function to obtain the name of the capture.
   2.844+ * - `TSQueryPredicateStepTypeString` - Steps with this type represent literal
   2.845+ *    strings. Their `value_id` can be used with the
   2.846+ *    [`ts_query_string_value_for_id`] function to obtain their string value.
   2.847+ * - `TSQueryPredicateStepTypeDone` - Steps with this type are *sentinels*
   2.848+ *    that represent the end of an individual predicate. If a pattern has two
   2.849+ *    predicates, then there will be two steps with this `type` in the array.
   2.850+ */
   2.851+const TSQueryPredicateStep *ts_query_predicates_for_pattern(
   2.852+  const TSQuery *self,
   2.853+  uint32_t pattern_index,
   2.854+  uint32_t *step_count
   2.855+);
   2.856+
   2.857+/*
   2.858+ * Check if the given pattern in the query has a single root node.
   2.859+ */
   2.860+bool ts_query_is_pattern_rooted(const TSQuery *self, uint32_t pattern_index);
   2.861+
   2.862+/*
   2.863+ * Check if the given pattern in the query is 'non local'.
   2.864+ *
   2.865+ * A non-local pattern has multiple root nodes and can match within a
   2.866+ * repeating sequence of nodes, as specified by the grammar. Non-local
   2.867+ * patterns disable certain optimizations that would otherwise be possible
   2.868+ * when executing a query on a specific range of a syntax tree.
   2.869+ */
   2.870+bool ts_query_is_pattern_non_local(const TSQuery *self, uint32_t pattern_index);
   2.871+
   2.872+/*
   2.873+ * Check if a given pattern is guaranteed to match once a given step is reached.
   2.874+ * The step is specified by its byte offset in the query's source code.
   2.875+ */
   2.876+bool ts_query_is_pattern_guaranteed_at_step(const TSQuery *self, uint32_t byte_offset);
   2.877+
   2.878+/**
   2.879+ * Get the name and length of one of the query's captures, or one of the
   2.880+ * query's string literals. Each capture and string is associated with a
   2.881+ * numeric id based on the order that it appeared in the query's source.
   2.882+ */
   2.883+const char *ts_query_capture_name_for_id(
   2.884+  const TSQuery *self,
   2.885+  uint32_t index,
   2.886+  uint32_t *length
   2.887+);
   2.888+
   2.889+/**
   2.890+ * Get the quantifier of the query's captures. Each capture is * associated
   2.891+ * with a numeric id based on the order that it appeared in the query's source.
   2.892+ */
   2.893+TSQuantifier ts_query_capture_quantifier_for_id(
   2.894+  const TSQuery *self,
   2.895+  uint32_t pattern_index,
   2.896+  uint32_t capture_index
   2.897+);
   2.898+
   2.899+const char *ts_query_string_value_for_id(
   2.900+  const TSQuery *self,
   2.901+  uint32_t index,
   2.902+  uint32_t *length
   2.903+);
   2.904+
   2.905+/**
   2.906+ * Disable a certain capture within a query.
   2.907+ *
   2.908+ * This prevents the capture from being returned in matches, and also avoids
   2.909+ * any resource usage associated with recording the capture. Currently, there
   2.910+ * is no way to undo this.
   2.911+ */
   2.912+void ts_query_disable_capture(TSQuery *self, const char *name, uint32_t length);
   2.913+
   2.914+/**
   2.915+ * Disable a certain pattern within a query.
   2.916+ *
   2.917+ * This prevents the pattern from matching and removes most of the overhead
   2.918+ * associated with the pattern. Currently, there is no way to undo this.
   2.919+ */
   2.920+void ts_query_disable_pattern(TSQuery *self, uint32_t pattern_index);
   2.921+
   2.922+/**
   2.923+ * Create a new cursor for executing a given query.
   2.924+ *
   2.925+ * The cursor stores the state that is needed to iteratively search
   2.926+ * for matches. To use the query cursor, first call [`ts_query_cursor_exec`]
   2.927+ * to start running a given query on a given syntax node. Then, there are
   2.928+ * two options for consuming the results of the query:
   2.929+ * 1. Repeatedly call [`ts_query_cursor_next_match`] to iterate over all of the
   2.930+ *    *matches* in the order that they were found. Each match contains the
   2.931+ *    index of the pattern that matched, and an array of captures. Because
   2.932+ *    multiple patterns can match the same set of nodes, one match may contain
   2.933+ *    captures that appear *before* some of the captures from a previous match.
   2.934+ * 2. Repeatedly call [`ts_query_cursor_next_capture`] to iterate over all of the
   2.935+ *    individual *captures* in the order that they appear. This is useful if
   2.936+ *    don't care about which pattern matched, and just want a single ordered
   2.937+ *    sequence of captures.
   2.938+ *
   2.939+ * If you don't care about consuming all of the results, you can stop calling
   2.940+ * [`ts_query_cursor_next_match`] or [`ts_query_cursor_next_capture`] at any point.
   2.941+ *  You can then start executing another query on another node by calling
   2.942+ *  [`ts_query_cursor_exec`] again.
   2.943+ */
   2.944+TSQueryCursor *ts_query_cursor_new(void);
   2.945+
   2.946+/**
   2.947+ * Delete a query cursor, freeing all of the memory that it used.
   2.948+ */
   2.949+void ts_query_cursor_delete(TSQueryCursor *self);
   2.950+
   2.951+/**
   2.952+ * Start running a given query on a given node.
   2.953+ */
   2.954+void ts_query_cursor_exec(TSQueryCursor *self, const TSQuery *query, TSNode node);
   2.955+
   2.956+/**
   2.957+ * Manage the maximum number of in-progress matches allowed by this query
   2.958+ * cursor.
   2.959+ *
   2.960+ * Query cursors have an optional maximum capacity for storing lists of
   2.961+ * in-progress captures. If this capacity is exceeded, then the
   2.962+ * earliest-starting match will silently be dropped to make room for further
   2.963+ * matches. This maximum capacity is optional — by default, query cursors allow
   2.964+ * any number of pending matches, dynamically allocating new space for them as
   2.965+ * needed as the query is executed.
   2.966+ */
   2.967+bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *self);
   2.968+uint32_t ts_query_cursor_match_limit(const TSQueryCursor *self);
   2.969+void ts_query_cursor_set_match_limit(TSQueryCursor *self, uint32_t limit);
   2.970+
   2.971+/**
   2.972+ * Set the range of bytes or (row, column) positions in which the query
   2.973+ * will be executed.
   2.974+ */
   2.975+void ts_query_cursor_set_byte_range(TSQueryCursor *self, uint32_t start_byte, uint32_t end_byte);
   2.976+void ts_query_cursor_set_point_range(TSQueryCursor *self, TSPoint start_point, TSPoint end_point);
   2.977+
   2.978+/**
   2.979+ * Advance to the next match of the currently running query.
   2.980+ *
   2.981+ * If there is a match, write it to `*match` and return `true`.
   2.982+ * Otherwise, return `false`.
   2.983+ */
   2.984+bool ts_query_cursor_next_match(TSQueryCursor *self, TSQueryMatch *match);
   2.985+void ts_query_cursor_remove_match(TSQueryCursor *self, uint32_t match_id);
   2.986+
   2.987+/**
   2.988+ * Advance to the next capture of the currently running query.
   2.989+ *
   2.990+ * If there is a capture, write its match to `*match` and its index within
   2.991+ * the matche's capture list to `*capture_index`. Otherwise, return `false`.
   2.992+ */
   2.993+bool ts_query_cursor_next_capture(
   2.994+  TSQueryCursor *self,
   2.995+  TSQueryMatch *match,
   2.996+  uint32_t *capture_index
   2.997+);
   2.998+
   2.999+/**
  2.1000+ * Set the maximum start depth for a query cursor.
  2.1001+ *
  2.1002+ * This prevents cursors from exploring children nodes at a certain depth.
  2.1003+ * Note if a pattern includes many children, then they will still be checked.
  2.1004+ *
  2.1005+ * The zero max start depth value can be used as a special behavior and
  2.1006+ * it helps to destructure a subtree by staying on a node and using captures
  2.1007+ * for interested parts. Note that the zero max start depth only limit a search
  2.1008+ * depth for a pattern's root node but other nodes that are parts of the pattern
  2.1009+ * may be searched at any depth what defined by the pattern structure.
  2.1010+ *
  2.1011+ * Set to `UINT32_MAX` to remove the maximum start depth.
  2.1012+ */
  2.1013+void ts_query_cursor_set_max_start_depth(TSQueryCursor *self, uint32_t max_start_depth);
  2.1014+
  2.1015+/**********************/
  2.1016+/* Section - Language */
  2.1017+/**********************/
  2.1018+
  2.1019+/**
  2.1020+ * Get the number of distinct node types in the language.
  2.1021+ */
  2.1022+uint32_t ts_language_symbol_count(const TSLanguage *self);
  2.1023+
  2.1024+/**
  2.1025+ * Get the number of valid states in this language.
  2.1026+*/
  2.1027+uint32_t ts_language_state_count(const TSLanguage *self);
  2.1028+
  2.1029+/**
  2.1030+ * Get a node type string for the given numerical id.
  2.1031+ */
  2.1032+const char *ts_language_symbol_name(const TSLanguage *self, TSSymbol symbol);
  2.1033+
  2.1034+/**
  2.1035+ * Get the numerical id for the given node type string.
  2.1036+ */
  2.1037+TSSymbol ts_language_symbol_for_name(
  2.1038+  const TSLanguage *self,
  2.1039+  const char *string,
  2.1040+  uint32_t length,
  2.1041+  bool is_named
  2.1042+);
  2.1043+
  2.1044+/**
  2.1045+ * Get the number of distinct field names in the language.
  2.1046+ */
  2.1047+uint32_t ts_language_field_count(const TSLanguage *self);
  2.1048+
  2.1049+/**
  2.1050+ * Get the field name string for the given numerical id.
  2.1051+ */
  2.1052+const char *ts_language_field_name_for_id(const TSLanguage *self, TSFieldId id);
  2.1053+
  2.1054+/**
  2.1055+ * Get the numerical id for the given field name string.
  2.1056+ */
  2.1057+TSFieldId ts_language_field_id_for_name(const TSLanguage *self, const char *name, uint32_t name_length);
  2.1058+
  2.1059+/**
  2.1060+ * Check whether the given node type id belongs to named nodes, anonymous nodes,
  2.1061+ * or a hidden nodes.
  2.1062+ *
  2.1063+ * See also [`ts_node_is_named`]. Hidden nodes are never returned from the API.
  2.1064+ */
  2.1065+TSSymbolType ts_language_symbol_type(const TSLanguage *self, TSSymbol symbol);
  2.1066+
  2.1067+/**
  2.1068+ * Get the ABI version number for this language. This version number is used
  2.1069+ * to ensure that languages were generated by a compatible version of
  2.1070+ * Tree-sitter.
  2.1071+ *
  2.1072+ * See also [`ts_parser_set_language`].
  2.1073+ */
  2.1074+uint32_t ts_language_version(const TSLanguage *self);
  2.1075+
  2.1076+/**
  2.1077+ * Get the next parse state. Combine this with lookahead iterators to generate
  2.1078+ * completion suggestions or valid symbols in error nodes. Use
  2.1079+ * [`ts_node_grammar_symbol`] for valid symbols.
  2.1080+*/
  2.1081+TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state, TSSymbol symbol);
  2.1082+
  2.1083+/********************************/
  2.1084+/* Section - Lookahead Iterator */
  2.1085+/********************************/
  2.1086+
  2.1087+/**
  2.1088+ * Create a new lookahead iterator for the given language and parse state.
  2.1089+ *
  2.1090+ * This returns `NULL` if state is invalid for the language.
  2.1091+ *
  2.1092+ * Repeatedly using [`ts_lookahead_iterator_next`] and
  2.1093+ * [`ts_lookahead_iterator_current_symbol`] will generate valid symbols in the
  2.1094+ * given parse state. Newly created lookahead iterators will contain the `ERROR`
  2.1095+ * symbol.
  2.1096+ *
  2.1097+ * Lookahead iterators can be useful to generate suggestions and improve syntax
  2.1098+ * error diagnostics. To get symbols valid in an ERROR node, use the lookahead
  2.1099+ * iterator on its first leaf node state. For `MISSING` nodes, a lookahead
  2.1100+ * iterator created on the previous non-extra leaf node may be appropriate.
  2.1101+*/
  2.1102+TSLookaheadIterator *ts_lookahead_iterator_new(const TSLanguage *self, TSStateId state);
  2.1103+
  2.1104+/**
  2.1105+ * Delete a lookahead iterator freeing all the memory used.
  2.1106+*/
  2.1107+void ts_lookahead_iterator_delete(TSLookaheadIterator *self);
  2.1108+
  2.1109+/**
  2.1110+ * Reset the lookahead iterator to another state.
  2.1111+ *
  2.1112+ * This returns `true` if the iterator was reset to the given state and `false`
  2.1113+ * otherwise.
  2.1114+*/
  2.1115+bool ts_lookahead_iterator_reset_state(TSLookaheadIterator *self, TSStateId state);
  2.1116+
  2.1117+/**
  2.1118+ * Reset the lookahead iterator.
  2.1119+ *
  2.1120+ * This returns `true` if the language was set successfully and `false`
  2.1121+ * otherwise.
  2.1122+*/
  2.1123+bool ts_lookahead_iterator_reset(TSLookaheadIterator *self, const TSLanguage *language, TSStateId state);
  2.1124+
  2.1125+/**
  2.1126+ * Get the current language of the lookahead iterator.
  2.1127+*/
  2.1128+const TSLanguage *ts_lookahead_iterator_language(const TSLookaheadIterator *self);
  2.1129+
  2.1130+/**
  2.1131+ * Advance the lookahead iterator to the next symbol.
  2.1132+ *
  2.1133+ * This returns `true` if there is a new symbol and `false` otherwise.
  2.1134+*/
  2.1135+bool ts_lookahead_iterator_next(TSLookaheadIterator *self);
  2.1136+
  2.1137+/**
  2.1138+ * Get the current symbol of the lookahead iterator;
  2.1139+*/
  2.1140+TSSymbol ts_lookahead_iterator_current_symbol(const TSLookaheadIterator *self);
  2.1141+
  2.1142+/**
  2.1143+ * Get the current symbol type of the lookahead iterator as a null terminated
  2.1144+ * string.
  2.1145+*/
  2.1146+const char *ts_lookahead_iterator_current_symbol_name(const TSLookaheadIterator *self);
  2.1147+
  2.1148+/**********************************/
  2.1149+/* Section - Global Configuration */
  2.1150+/**********************************/
  2.1151+
  2.1152+/**
  2.1153+ * Set the allocation functions used by the library.
  2.1154+ *
  2.1155+ * By default, Tree-sitter uses the standard libc allocation functions,
  2.1156+ * but aborts the process when an allocation fails. This function lets
  2.1157+ * you supply alternative allocation functions at runtime.
  2.1158+ *
  2.1159+ * If you pass `NULL` for any parameter, Tree-sitter will switch back to
  2.1160+ * its default implementation of that function.
  2.1161+ *
  2.1162+ * If you call this function after the library has already been used, then
  2.1163+ * you must ensure that either:
  2.1164+ *  1. All the existing objects have been freed.
  2.1165+ *  2. The new allocator shares its state with the old one, so it is capable
  2.1166+ *     of freeing memory that was allocated by the old allocator.
  2.1167+ */
  2.1168+void ts_set_allocator(
  2.1169+  void *(*new_malloc)(size_t),
  2.1170+	void *(*new_calloc)(size_t, size_t),
  2.1171+	void *(*new_realloc)(void *, size_t),
  2.1172+	void (*new_free)(void *)
  2.1173+);
  2.1174+
  2.1175+#ifdef __cplusplus
  2.1176+}
  2.1177+#endif
  2.1178+
  2.1179+#if defined(__GNUC__) || defined(__clang__)
  2.1180+#pragma GCC visibility pop
  2.1181+#endif
  2.1182+
  2.1183+#endif  // TREE_SITTER_API_H_