1.1--- a/emacs/default.el Fri Oct 04 16:14:44 2024 -0400
1.2+++ b/emacs/default.el Fri Oct 04 21:11:52 2024 -0400
1.3@@ -225,6 +225,12 @@
1.4 ;;; Lisp
1.5 (use-package company :ensure t)
1.6
1.7+(setq inferior-lisp-program "sbcl --dynamic-space-size=8G --control-stack-size 8"
1.8+ scheme-program-name "gsi"
1.9+ guile-program "guile"
1.10+ cmulisp-program "lisp"
1.11+ scsh-program "scsh")
1.12+
1.13 (defvar slime-toggle nil)
1.14 (defun slime-toggle ()
1.15 "toggle between lisp file and slime-repl"
1.16@@ -327,16 +333,6 @@
1.17 ;; (add-hook 'slime-repl-mode-hook 'slime-cape-maybe-enable)
1.18 )
1.19
1.20-(use-package lisp-mode
1.21- :ensure nil
1.22- :after slime
1.23- :custom
1.24- inferior-lisp-program "sbcl --dynamic-space-size=8G"
1.25- scheme-program-name "gsi"
1.26- guile-program "guile"
1.27- cmulisp-program "lisp"
1.28- scsh-program "scsh")
1.29-
1.30 ;;; Eglot
1.31 ;; (with-eval-after-load 'eglot
1.32 ;; (unless (package-installed-p 'eglot-x)
2.1--- a/lisp/bench/tpc-h.lisp Fri Oct 04 16:14:44 2024 -0400
2.2+++ b/lisp/bench/tpc-h.lisp Fri Oct 04 21:11:52 2024 -0400
2.3@@ -203,7 +203,7 @@
2.4 (defun dbgen-thread ()
2.5 (lambda (x y)
2.6 (gen-table x y)
2.7- (print-top-level (format nil "finished: ~A~%" x))))
2.8+ (std/thread:print-top-level (format nil "finished: ~A~%" x))))
2.9
2.10 (defun dbgen (&optional (scale-factor 1)) ;; ~= 2.4G, 200s
2.11 "Generate the TPC-H database in standardized format (|-delim ASCII). Files are
3.1--- a/lisp/bin/skel.lisp Fri Oct 04 16:14:44 2024 -0400
3.2+++ b/lisp/bin/skel.lisp Fri Oct 04 21:11:52 2024 -0400
3.3@@ -181,7 +181,7 @@
3.4
3.5 (defcmd skc-make
3.6 (let ((sk (find-skelfile #P"." :load t)))
3.7- ;; (sb-ext:enable-debugger)
3.8+ (sb-ext:enable-debugger)
3.9 (log:debug! "cli args" *args*)
3.10 ;; (setq *no-exit* t)
3.11 (if *args*
4.1--- a/lisp/ffi/sndfile/pkg.lisp Fri Oct 04 16:14:44 2024 -0400
4.2+++ b/lisp/ffi/sndfile/pkg.lisp Fri Oct 04 21:11:52 2024 -0400
4.3@@ -13,9 +13,9 @@
4.4
4.5 (define-alien-loader "sndfile" t "/usr/lib/")
4.6
4.7-(define-opaque sndfile t)
4.8-
4.9-(define-opaque sf-chunk-iterator)
4.10+(eval-always
4.11+ (define-opaque sndfile t)
4.12+ (define-opaque sf-chunk-iterator t))
4.13
4.14 (define-alien-type sf-count long)
4.15
5.1--- a/lisp/ffi/tree-sitter/alien.c Fri Oct 04 16:14:44 2024 -0400
5.2+++ b/lisp/ffi/tree-sitter/alien.c Fri Oct 04 21:11:52 2024 -0400
5.3@@ -9,13 +9,13 @@
5.4
5.5 // build with:
5.6 /*
5.7- sudo cc -g -O2 -Wall -Wno-unused-value -ltree-sitter -shared alien.c -o /usr/local/lib/libtree-sitter-alien.so
5.8+ cc -g -O2 -Wall -Wno-unused-value -ltree-sitter -shared alien.c -o /usr/local/lib/libtree-sitter-alien.so
5.9 */
5.10
5.11 /// Code:
5.12 #include <stdlib.h>
5.13
5.14-#include "ts-api.h"
5.15+#include "alien.h"
5.16
5.17 TSNode *ts_tree_root_node_pointer(const TSTree *self) {
5.18 TSNode *node = malloc(sizeof(TSNode));
6.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2+++ b/lisp/ffi/tree-sitter/alien.h Fri Oct 04 21:11:52 2024 -0400
6.3@@ -0,0 +1,1282 @@
6.4+#ifndef TREE_SITTER_API_H_
6.5+#define TREE_SITTER_API_H_
6.6+
6.7+#ifndef TREE_SITTER_HIDE_SYMBOLS
6.8+#if defined(__GNUC__) || defined(__clang__)
6.9+#pragma GCC visibility push(default)
6.10+#endif
6.11+#endif
6.12+
6.13+#include <stdlib.h>
6.14+#include <stdint.h>
6.15+#include <stdbool.h>
6.16+
6.17+#ifdef __cplusplus
6.18+extern "C" {
6.19+#endif
6.20+
6.21+/****************************/
6.22+/* Section - ABI Versioning */
6.23+/****************************/
6.24+
6.25+/**
6.26+ * The latest ABI version that is supported by the current version of the
6.27+ * library. When Languages are generated by the Tree-sitter CLI, they are
6.28+ * assigned an ABI version number that corresponds to the current CLI version.
6.29+ * The Tree-sitter library is generally backwards-compatible with languages
6.30+ * generated using older CLI versions, but is not forwards-compatible.
6.31+ */
6.32+#define TREE_SITTER_LANGUAGE_VERSION 14
6.33+
6.34+/**
6.35+ * The earliest ABI version that is supported by the current version of the
6.36+ * library.
6.37+ */
6.38+#define TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION 13
6.39+
6.40+/*******************/
6.41+/* Section - Types */
6.42+/*******************/
6.43+
6.44+typedef uint16_t TSStateId;
6.45+typedef uint16_t TSSymbol;
6.46+typedef uint16_t TSFieldId;
6.47+typedef struct TSLanguage TSLanguage;
6.48+typedef struct TSParser TSParser;
6.49+typedef struct TSTree TSTree;
6.50+typedef struct TSQuery TSQuery;
6.51+typedef struct TSQueryCursor TSQueryCursor;
6.52+typedef struct TSLookaheadIterator TSLookaheadIterator;
6.53+
6.54+typedef enum TSInputEncoding {
6.55+ TSInputEncodingUTF8,
6.56+ TSInputEncodingUTF16,
6.57+} TSInputEncoding;
6.58+
6.59+typedef enum TSSymbolType {
6.60+ TSSymbolTypeRegular,
6.61+ TSSymbolTypeAnonymous,
6.62+ TSSymbolTypeAuxiliary,
6.63+} TSSymbolType;
6.64+
6.65+typedef struct TSPoint {
6.66+ uint32_t row;
6.67+ uint32_t column;
6.68+} TSPoint;
6.69+
6.70+typedef struct TSRange {
6.71+ TSPoint start_point;
6.72+ TSPoint end_point;
6.73+ uint32_t start_byte;
6.74+ uint32_t end_byte;
6.75+} TSRange;
6.76+
6.77+typedef struct TSInput {
6.78+ void *payload;
6.79+ const char *(*read)(void *payload, uint32_t byte_index, TSPoint position, uint32_t *bytes_read);
6.80+ TSInputEncoding encoding;
6.81+} TSInput;
6.82+
6.83+typedef enum TSLogType {
6.84+ TSLogTypeParse,
6.85+ TSLogTypeLex,
6.86+} TSLogType;
6.87+
6.88+typedef struct TSLogger {
6.89+ void *payload;
6.90+ void (*log)(void *payload, TSLogType log_type, const char *buffer);
6.91+} TSLogger;
6.92+
6.93+typedef struct TSInputEdit {
6.94+ uint32_t start_byte;
6.95+ uint32_t old_end_byte;
6.96+ uint32_t new_end_byte;
6.97+ TSPoint start_point;
6.98+ TSPoint old_end_point;
6.99+ TSPoint new_end_point;
6.100+} TSInputEdit;
6.101+
6.102+typedef struct TSNode {
6.103+ uint32_t context[4];
6.104+ const void *id;
6.105+ const TSTree *tree;
6.106+} TSNode;
6.107+
6.108+typedef struct TSTreeCursor {
6.109+ const void *tree;
6.110+ const void *id;
6.111+ uint32_t context[3];
6.112+} TSTreeCursor;
6.113+
6.114+typedef struct TSQueryCapture {
6.115+ TSNode node;
6.116+ uint32_t index;
6.117+} TSQueryCapture;
6.118+
6.119+typedef enum TSQuantifier {
6.120+ TSQuantifierZero = 0, // must match the array initialization value
6.121+ TSQuantifierZeroOrOne,
6.122+ TSQuantifierZeroOrMore,
6.123+ TSQuantifierOne,
6.124+ TSQuantifierOneOrMore,
6.125+} TSQuantifier;
6.126+
6.127+typedef struct TSQueryMatch {
6.128+ uint32_t id;
6.129+ uint16_t pattern_index;
6.130+ uint16_t capture_count;
6.131+ const TSQueryCapture *captures;
6.132+} TSQueryMatch;
6.133+
6.134+typedef enum TSQueryPredicateStepType {
6.135+ TSQueryPredicateStepTypeDone,
6.136+ TSQueryPredicateStepTypeCapture,
6.137+ TSQueryPredicateStepTypeString,
6.138+} TSQueryPredicateStepType;
6.139+
6.140+typedef struct TSQueryPredicateStep {
6.141+ TSQueryPredicateStepType type;
6.142+ uint32_t value_id;
6.143+} TSQueryPredicateStep;
6.144+
6.145+typedef enum TSQueryError {
6.146+ TSQueryErrorNone = 0,
6.147+ TSQueryErrorSyntax,
6.148+ TSQueryErrorNodeType,
6.149+ TSQueryErrorField,
6.150+ TSQueryErrorCapture,
6.151+ TSQueryErrorStructure,
6.152+ TSQueryErrorLanguage,
6.153+} TSQueryError;
6.154+
6.155+/********************/
6.156+/* Section - Parser */
6.157+/********************/
6.158+
6.159+/**
6.160+ * Create a new parser.
6.161+ */
6.162+TSParser *ts_parser_new(void);
6.163+
6.164+/**
6.165+ * Delete the parser, freeing all of the memory that it used.
6.166+ */
6.167+void ts_parser_delete(TSParser *self);
6.168+
6.169+/**
6.170+ * Get the parser's current language.
6.171+ */
6.172+const TSLanguage *ts_parser_language(const TSParser *self);
6.173+
6.174+/**
6.175+ * Set the language that the parser should use for parsing.
6.176+ *
6.177+ * Returns a boolean indicating whether or not the language was successfully
6.178+ * assigned. True means assignment succeeded. False means there was a version
6.179+ * mismatch: the language was generated with an incompatible version of the
6.180+ * Tree-sitter CLI. Check the language's version using [`ts_language_version`]
6.181+ * and compare it to this library's [`TREE_SITTER_LANGUAGE_VERSION`] and
6.182+ * [`TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION`] constants.
6.183+ */
6.184+bool ts_parser_set_language(TSParser *self, const TSLanguage *language);
6.185+
6.186+/**
6.187+ * Set the ranges of text that the parser should include when parsing.
6.188+ *
6.189+ * By default, the parser will always include entire documents. This function
6.190+ * allows you to parse only a *portion* of a document but still return a syntax
6.191+ * tree whose ranges match up with the document as a whole. You can also pass
6.192+ * multiple disjoint ranges.
6.193+ *
6.194+ * The second and third parameters specify the location and length of an array
6.195+ * of ranges. The parser does *not* take ownership of these ranges; it copies
6.196+ * the data, so it doesn't matter how these ranges are allocated.
6.197+ *
6.198+ * If `count` is zero, then the entire document will be parsed. Otherwise,
6.199+ * the given ranges must be ordered from earliest to latest in the document,
6.200+ * and they must not overlap. That is, the following must hold for all:
6.201+ *
6.202+ * `i < count - 1`: `ranges[i].end_byte <= ranges[i + 1].start_byte`
6.203+ *
6.204+ * If this requirement is not satisfied, the operation will fail, the ranges
6.205+ * will not be assigned, and this function will return `false`. On success,
6.206+ * this function returns `true`
6.207+ */
6.208+bool ts_parser_set_included_ranges(
6.209+ TSParser *self,
6.210+ const TSRange *ranges,
6.211+ uint32_t count
6.212+);
6.213+
6.214+/**
6.215+ * Get the ranges of text that the parser will include when parsing.
6.216+ *
6.217+ * The returned pointer is owned by the parser. The caller should not free it
6.218+ * or write to it. The length of the array will be written to the given
6.219+ * `count` pointer.
6.220+ */
6.221+const TSRange *ts_parser_included_ranges(
6.222+ const TSParser *self,
6.223+ uint32_t *count
6.224+);
6.225+
6.226+/**
6.227+ * Use the parser to parse some source code and create a syntax tree.
6.228+ *
6.229+ * If you are parsing this document for the first time, pass `NULL` for the
6.230+ * `old_tree` parameter. Otherwise, if you have already parsed an earlier
6.231+ * version of this document and the document has since been edited, pass the
6.232+ * previous syntax tree so that the unchanged parts of it can be reused.
6.233+ * This will save time and memory. For this to work correctly, you must have
6.234+ * already edited the old syntax tree using the [`ts_tree_edit`] function in a
6.235+ * way that exactly matches the source code changes.
6.236+ *
6.237+ * The [`TSInput`] parameter lets you specify how to read the text. It has the
6.238+ * following three fields:
6.239+ * 1. [`read`]: A function to retrieve a chunk of text at a given byte offset
6.240+ * and (row, column) position. The function should return a pointer to the
6.241+ * text and write its length to the [`bytes_read`] pointer. The parser does
6.242+ * not take ownership of this buffer; it just borrows it until it has
6.243+ * finished reading it. The function should write a zero value to the
6.244+ * [`bytes_read`] pointer to indicate the end of the document.
6.245+ * 2. [`payload`]: An arbitrary pointer that will be passed to each invocation
6.246+ * of the [`read`] function.
6.247+ * 3. [`encoding`]: An indication of how the text is encoded. Either
6.248+ * `TSInputEncodingUTF8` or `TSInputEncodingUTF16`.
6.249+ *
6.250+ * This function returns a syntax tree on success, and `NULL` on failure. There
6.251+ * are three possible reasons for failure:
6.252+ * 1. The parser does not have a language assigned. Check for this using the
6.253+ [`ts_parser_language`] function.
6.254+ * 2. Parsing was cancelled due to a timeout that was set by an earlier call to
6.255+ * the [`ts_parser_set_timeout_micros`] function. You can resume parsing from
6.256+ * where the parser left out by calling [`ts_parser_parse`] again with the
6.257+ * same arguments. Or you can start parsing from scratch by first calling
6.258+ * [`ts_parser_reset`].
6.259+ * 3. Parsing was cancelled using a cancellation flag that was set by an
6.260+ * earlier call to [`ts_parser_set_cancellation_flag`]. You can resume parsing
6.261+ * from where the parser left out by calling [`ts_parser_parse`] again with
6.262+ * the same arguments.
6.263+ *
6.264+ * [`read`]: TSInput::read
6.265+ * [`payload`]: TSInput::payload
6.266+ * [`encoding`]: TSInput::encoding
6.267+ * [`bytes_read`]: TSInput::read
6.268+ */
6.269+TSTree *ts_parser_parse(
6.270+ TSParser *self,
6.271+ const TSTree *old_tree,
6.272+ TSInput input
6.273+);
6.274+
6.275+/**
6.276+ * Use the parser to parse some source code stored in one contiguous buffer.
6.277+ * The first two parameters are the same as in the [`ts_parser_parse`] function
6.278+ * above. The second two parameters indicate the location of the buffer and its
6.279+ * length in bytes.
6.280+ */
6.281+TSTree *ts_parser_parse_string(
6.282+ TSParser *self,
6.283+ const TSTree *old_tree,
6.284+ const char *string,
6.285+ uint32_t length
6.286+);
6.287+
6.288+/**
6.289+ * Use the parser to parse some source code stored in one contiguous buffer with
6.290+ * a given encoding. The first four parameters work the same as in the
6.291+ * [`ts_parser_parse_string`] method above. The final parameter indicates whether
6.292+ * the text is encoded as UTF8 or UTF16.
6.293+ */
6.294+TSTree *ts_parser_parse_string_encoding(
6.295+ TSParser *self,
6.296+ const TSTree *old_tree,
6.297+ const char *string,
6.298+ uint32_t length,
6.299+ TSInputEncoding encoding
6.300+);
6.301+
6.302+/**
6.303+ * Instruct the parser to start the next parse from the beginning.
6.304+ *
6.305+ * If the parser previously failed because of a timeout or a cancellation, then
6.306+ * by default, it will resume where it left off on the next call to
6.307+ * [`ts_parser_parse`] or other parsing functions. If you don't want to resume,
6.308+ * and instead intend to use this parser to parse some other document, you must
6.309+ * call [`ts_parser_reset`] first.
6.310+ */
6.311+void ts_parser_reset(TSParser *self);
6.312+
6.313+/**
6.314+ * Set the maximum duration in microseconds that parsing should be allowed to
6.315+ * take before halting.
6.316+ *
6.317+ * If parsing takes longer than this, it will halt early, returning NULL.
6.318+ * See [`ts_parser_parse`] for more information.
6.319+ */
6.320+void ts_parser_set_timeout_micros(TSParser *self, uint64_t timeout_micros);
6.321+
6.322+/**
6.323+ * Get the duration in microseconds that parsing is allowed to take.
6.324+ */
6.325+uint64_t ts_parser_timeout_micros(const TSParser *self);
6.326+
6.327+/**
6.328+ * Set the parser's current cancellation flag pointer.
6.329+ *
6.330+ * If a non-null pointer is assigned, then the parser will periodically read
6.331+ * from this pointer during parsing. If it reads a non-zero value, it will
6.332+ * halt early, returning NULL. See [`ts_parser_parse`] for more information.
6.333+ */
6.334+void ts_parser_set_cancellation_flag(TSParser *self, const size_t *flag);
6.335+
6.336+/**
6.337+ * Get the parser's current cancellation flag pointer.
6.338+ */
6.339+const size_t *ts_parser_cancellation_flag(const TSParser *self);
6.340+
6.341+/**
6.342+ * Set the logger that a parser should use during parsing.
6.343+ *
6.344+ * The parser does not take ownership over the logger payload. If a logger was
6.345+ * previously assigned, the caller is responsible for releasing any memory
6.346+ * owned by the previous logger.
6.347+ */
6.348+void ts_parser_set_logger(TSParser *self, TSLogger logger);
6.349+
6.350+/**
6.351+ * Get the parser's current logger.
6.352+ */
6.353+TSLogger ts_parser_logger(const TSParser *self);
6.354+
6.355+/**
6.356+ * Set the file descriptor to which the parser should write debugging graphs
6.357+ * during parsing. The graphs are formatted in the DOT language. You may want
6.358+ * to pipe these graphs directly to a `dot(1)` process in order to generate
6.359+ * SVG output. You can turn off this logging by passing a negative number.
6.360+ */
6.361+void ts_parser_print_dot_graphs(TSParser *self, int fd);
6.362+
6.363+/******************/
6.364+/* Section - Tree */
6.365+/******************/
6.366+
6.367+/**
6.368+ * Create a shallow copy of the syntax tree. This is very fast.
6.369+ *
6.370+ * You need to copy a syntax tree in order to use it on more than one thread at
6.371+ * a time, as syntax trees are not thread safe.
6.372+ */
6.373+TSTree *ts_tree_copy(const TSTree *self);
6.374+
6.375+/**
6.376+ * Delete the syntax tree, freeing all of the memory that it used.
6.377+ */
6.378+void ts_tree_delete(TSTree *self);
6.379+
6.380+/**
6.381+ * Get the root node of the syntax tree.
6.382+ */
6.383+TSNode ts_tree_root_node(const TSTree *self);
6.384+
6.385+/**
6.386+ * Get the root node of the syntax tree, but with its position
6.387+ * shifted forward by the given offset.
6.388+ */
6.389+TSNode ts_tree_root_node_with_offset(
6.390+ const TSTree *self,
6.391+ uint32_t offset_bytes,
6.392+ TSPoint offset_extent
6.393+);
6.394+
6.395+/**
6.396+ * Get the language that was used to parse the syntax tree.
6.397+ */
6.398+const TSLanguage *ts_tree_language(const TSTree *self);
6.399+
6.400+/**
6.401+ * Get the array of included ranges that was used to parse the syntax tree.
6.402+ *
6.403+ * The returned pointer must be freed by the caller.
6.404+ */
6.405+TSRange *ts_tree_included_ranges(const TSTree *self, uint32_t *length);
6.406+
6.407+/**
6.408+ * Edit the syntax tree to keep it in sync with source code that has been
6.409+ * edited.
6.410+ *
6.411+ * You must describe the edit both in terms of byte offsets and in terms of
6.412+ * (row, column) coordinates.
6.413+ */
6.414+void ts_tree_edit(TSTree *self, const TSInputEdit *edit);
6.415+
6.416+/**
6.417+ * Compare an old edited syntax tree to a new syntax tree representing the same
6.418+ * document, returning an array of ranges whose syntactic structure has changed.
6.419+ *
6.420+ * For this to work correctly, the old syntax tree must have been edited such
6.421+ * that its ranges match up to the new tree. Generally, you'll want to call
6.422+ * this function right after calling one of the [`ts_parser_parse`] functions.
6.423+ * You need to pass the old tree that was passed to parse, as well as the new
6.424+ * tree that was returned from that function.
6.425+ *
6.426+ * The returned array is allocated using `malloc` and the caller is responsible
6.427+ * for freeing it using `free`. The length of the array will be written to the
6.428+ * given `length` pointer.
6.429+ */
6.430+TSRange *ts_tree_get_changed_ranges(
6.431+ const TSTree *old_tree,
6.432+ const TSTree *new_tree,
6.433+ uint32_t *length
6.434+);
6.435+
6.436+/**
6.437+ * Write a DOT graph describing the syntax tree to the given file.
6.438+ */
6.439+void ts_tree_print_dot_graph(const TSTree *self, int file_descriptor);
6.440+
6.441+/******************/
6.442+/* Section - Node */
6.443+/******************/
6.444+
6.445+/**
6.446+ * Get the node's type as a null-terminated string.
6.447+ */
6.448+const char *ts_node_type(TSNode self);
6.449+
6.450+/**
6.451+ * Get the node's type as a numerical id.
6.452+ */
6.453+TSSymbol ts_node_symbol(TSNode self);
6.454+
6.455+/**
6.456+ * Get the node's language.
6.457+ */
6.458+const TSLanguage *ts_node_language(TSNode self);
6.459+
6.460+/**
6.461+ * Get the node's type as it appears in the grammar ignoring aliases as a
6.462+ * null-terminated string.
6.463+ */
6.464+const char *ts_node_grammar_type(TSNode self);
6.465+
6.466+/**
6.467+ * Get the node's type as a numerical id as it appears in the grammar ignoring
6.468+ * aliases. This should be used in [`ts_language_next_state`] instead of
6.469+ * [`ts_node_symbol`].
6.470+ */
6.471+TSSymbol ts_node_grammar_symbol(TSNode self);
6.472+
6.473+/**
6.474+ * Get the node's start byte.
6.475+ */
6.476+uint32_t ts_node_start_byte(TSNode self);
6.477+
6.478+/**
6.479+ * Get the node's start position in terms of rows and columns.
6.480+ */
6.481+TSPoint ts_node_start_point(TSNode self);
6.482+
6.483+/**
6.484+ * Get the node's end byte.
6.485+ */
6.486+uint32_t ts_node_end_byte(TSNode self);
6.487+
6.488+/**
6.489+ * Get the node's end position in terms of rows and columns.
6.490+ */
6.491+TSPoint ts_node_end_point(TSNode self);
6.492+
6.493+/**
6.494+ * Get an S-expression representing the node as a string.
6.495+ *
6.496+ * This string is allocated with `malloc` and the caller is responsible for
6.497+ * freeing it using `free`.
6.498+ */
6.499+char *ts_node_string(TSNode self);
6.500+
6.501+/**
6.502+ * Check if the node is null. Functions like [`ts_node_child`] and
6.503+ * [`ts_node_next_sibling`] will return a null node to indicate that no such node
6.504+ * was found.
6.505+ */
6.506+bool ts_node_is_null(TSNode self);
6.507+
6.508+/**
6.509+ * Check if the node is *named*. Named nodes correspond to named rules in the
6.510+ * grammar, whereas *anonymous* nodes correspond to string literals in the
6.511+ * grammar.
6.512+ */
6.513+bool ts_node_is_named(TSNode self);
6.514+
6.515+/**
6.516+ * Check if the node is *missing*. Missing nodes are inserted by the parser in
6.517+ * order to recover from certain kinds of syntax errors.
6.518+ */
6.519+bool ts_node_is_missing(TSNode self);
6.520+
6.521+/**
6.522+ * Check if the node is *extra*. Extra nodes represent things like comments,
6.523+ * which are not required the grammar, but can appear anywhere.
6.524+ */
6.525+bool ts_node_is_extra(TSNode self);
6.526+
6.527+/**
6.528+ * Check if a syntax node has been edited.
6.529+ */
6.530+bool ts_node_has_changes(TSNode self);
6.531+
6.532+/**
6.533+ * Check if the node is a syntax error or contains any syntax errors.
6.534+ */
6.535+bool ts_node_has_error(TSNode self);
6.536+
6.537+/**
6.538+ * Check if the node is a syntax error.
6.539+*/
6.540+bool ts_node_is_error(TSNode self);
6.541+
6.542+/**
6.543+ * Get this node's parse state.
6.544+*/
6.545+TSStateId ts_node_parse_state(TSNode self);
6.546+
6.547+/**
6.548+ * Get the parse state after this node.
6.549+*/
6.550+TSStateId ts_node_next_parse_state(TSNode self);
6.551+
6.552+/**
6.553+ * Get the node's immediate parent.
6.554+ * Prefer [`ts_node_child_containing_descendant`] for
6.555+ * iterating over the node's ancestors.
6.556+ */
6.557+TSNode ts_node_parent(TSNode self);
6.558+
6.559+/**
6.560+ * Get the node's child that contains `descendant`.
6.561+ */
6.562+TSNode ts_node_child_containing_descendant(TSNode self, TSNode descendant);
6.563+
6.564+/**
6.565+ * Get the node's child at the given index, where zero represents the first
6.566+ * child.
6.567+ */
6.568+TSNode ts_node_child(TSNode self, uint32_t child_index);
6.569+
6.570+/**
6.571+ * Get the field name for node's child at the given index, where zero represents
6.572+ * the first child. Returns NULL, if no field is found.
6.573+ */
6.574+const char *ts_node_field_name_for_child(TSNode self, uint32_t child_index);
6.575+
6.576+/**
6.577+ * Get the node's number of children.
6.578+ */
6.579+uint32_t ts_node_child_count(TSNode self);
6.580+
6.581+/**
6.582+ * Get the node's *named* child at the given index.
6.583+ *
6.584+ * See also [`ts_node_is_named`].
6.585+ */
6.586+TSNode ts_node_named_child(TSNode self, uint32_t child_index);
6.587+
6.588+/**
6.589+ * Get the node's number of *named* children.
6.590+ *
6.591+ * See also [`ts_node_is_named`].
6.592+ */
6.593+uint32_t ts_node_named_child_count(TSNode self);
6.594+
6.595+/**
6.596+ * Get the node's child with the given field name.
6.597+ */
6.598+TSNode ts_node_child_by_field_name(
6.599+ TSNode self,
6.600+ const char *name,
6.601+ uint32_t name_length
6.602+);
6.603+
6.604+/**
6.605+ * Get the node's child with the given numerical field id.
6.606+ *
6.607+ * You can convert a field name to an id using the
6.608+ * [`ts_language_field_id_for_name`] function.
6.609+ */
6.610+TSNode ts_node_child_by_field_id(TSNode self, TSFieldId field_id);
6.611+
6.612+/**
6.613+ * Get the node's next / previous sibling.
6.614+ */
6.615+TSNode ts_node_next_sibling(TSNode self);
6.616+TSNode ts_node_prev_sibling(TSNode self);
6.617+
6.618+/**
6.619+ * Get the node's next / previous *named* sibling.
6.620+ */
6.621+TSNode ts_node_next_named_sibling(TSNode self);
6.622+TSNode ts_node_prev_named_sibling(TSNode self);
6.623+
6.624+/**
6.625+ * Get the node's first child that extends beyond the given byte offset.
6.626+ */
6.627+TSNode ts_node_first_child_for_byte(TSNode self, uint32_t byte);
6.628+
6.629+/**
6.630+ * Get the node's first named child that extends beyond the given byte offset.
6.631+ */
6.632+TSNode ts_node_first_named_child_for_byte(TSNode self, uint32_t byte);
6.633+
6.634+/**
6.635+ * Get the node's number of descendants, including one for the node itself.
6.636+ */
6.637+uint32_t ts_node_descendant_count(TSNode self);
6.638+
6.639+/**
6.640+ * Get the smallest node within this node that spans the given range of bytes
6.641+ * or (row, column) positions.
6.642+ */
6.643+TSNode ts_node_descendant_for_byte_range(TSNode self, uint32_t start, uint32_t end);
6.644+TSNode ts_node_descendant_for_point_range(TSNode self, TSPoint start, TSPoint end);
6.645+
6.646+/**
6.647+ * Get the smallest named node within this node that spans the given range of
6.648+ * bytes or (row, column) positions.
6.649+ */
6.650+TSNode ts_node_named_descendant_for_byte_range(TSNode self, uint32_t start, uint32_t end);
6.651+TSNode ts_node_named_descendant_for_point_range(TSNode self, TSPoint start, TSPoint end);
6.652+
6.653+/**
6.654+ * Edit the node to keep it in-sync with source code that has been edited.
6.655+ *
6.656+ * This function is only rarely needed. When you edit a syntax tree with the
6.657+ * [`ts_tree_edit`] function, all of the nodes that you retrieve from the tree
6.658+ * afterward will already reflect the edit. You only need to use [`ts_node_edit`]
6.659+ * when you have a [`TSNode`] instance that you want to keep and continue to use
6.660+ * after an edit.
6.661+ */
6.662+void ts_node_edit(TSNode *self, const TSInputEdit *edit);
6.663+
6.664+/**
6.665+ * Check if two nodes are identical.
6.666+ */
6.667+bool ts_node_eq(TSNode self, TSNode other);
6.668+
6.669+/************************/
6.670+/* Section - TreeCursor */
6.671+/************************/
6.672+
6.673+/**
6.674+ * Create a new tree cursor starting from the given node.
6.675+ *
6.676+ * A tree cursor allows you to walk a syntax tree more efficiently than is
6.677+ * possible using the [`TSNode`] functions. It is a mutable object that is always
6.678+ * on a certain syntax node, and can be moved imperatively to different nodes.
6.679+ */
6.680+TSTreeCursor ts_tree_cursor_new(TSNode node);
6.681+
6.682+/**
6.683+ * Delete a tree cursor, freeing all of the memory that it used.
6.684+ */
6.685+void ts_tree_cursor_delete(TSTreeCursor *self);
6.686+
6.687+/**
6.688+ * Re-initialize a tree cursor to start at the original node that the cursor was
6.689+ * constructed with.
6.690+ */
6.691+void ts_tree_cursor_reset(TSTreeCursor *self, TSNode node);
6.692+
6.693+/**
6.694+ * Re-initialize a tree cursor to the same position as another cursor.
6.695+ *
6.696+ * Unlike [`ts_tree_cursor_reset`], this will not lose parent information and
6.697+ * allows reusing already created cursors.
6.698+*/
6.699+void ts_tree_cursor_reset_to(TSTreeCursor *dst, const TSTreeCursor *src);
6.700+
6.701+/**
6.702+ * Get the tree cursor's current node.
6.703+ */
6.704+TSNode ts_tree_cursor_current_node(const TSTreeCursor *self);
6.705+
6.706+/**
6.707+ * Get the field name of the tree cursor's current node.
6.708+ *
6.709+ * This returns `NULL` if the current node doesn't have a field.
6.710+ * See also [`ts_node_child_by_field_name`].
6.711+ */
6.712+const char *ts_tree_cursor_current_field_name(const TSTreeCursor *self);
6.713+
6.714+/**
6.715+ * Get the field id of the tree cursor's current node.
6.716+ *
6.717+ * This returns zero if the current node doesn't have a field.
6.718+ * See also [`ts_node_child_by_field_id`], [`ts_language_field_id_for_name`].
6.719+ */
6.720+TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *self);
6.721+
6.722+/**
6.723+ * Move the cursor to the parent of its current node.
6.724+ *
6.725+ * This returns `true` if the cursor successfully moved, and returns `false`
6.726+ * if there was no parent node (the cursor was already on the root node).
6.727+ */
6.728+bool ts_tree_cursor_goto_parent(TSTreeCursor *self);
6.729+
6.730+/**
6.731+ * Move the cursor to the next sibling of its current node.
6.732+ *
6.733+ * This returns `true` if the cursor successfully moved, and returns `false`
6.734+ * if there was no next sibling node.
6.735+ */
6.736+bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *self);
6.737+
6.738+/**
6.739+ * Move the cursor to the previous sibling of its current node.
6.740+ *
6.741+ * This returns `true` if the cursor successfully moved, and returns `false` if
6.742+ * there was no previous sibling node.
6.743+ *
6.744+ * Note, that this function may be slower than
6.745+ * [`ts_tree_cursor_goto_next_sibling`] due to how node positions are stored. In
6.746+ * the worst case, this will need to iterate through all the children upto the
6.747+ * previous sibling node to recalculate its position.
6.748+ */
6.749+bool ts_tree_cursor_goto_previous_sibling(TSTreeCursor *self);
6.750+
6.751+/**
6.752+ * Move the cursor to the first child of its current node.
6.753+ *
6.754+ * This returns `true` if the cursor successfully moved, and returns `false`
6.755+ * if there were no children.
6.756+ */
6.757+bool ts_tree_cursor_goto_first_child(TSTreeCursor *self);
6.758+
6.759+/**
6.760+ * Move the cursor to the last child of its current node.
6.761+ *
6.762+ * This returns `true` if the cursor successfully moved, and returns `false` if
6.763+ * there were no children.
6.764+ *
6.765+ * Note that this function may be slower than [`ts_tree_cursor_goto_first_child`]
6.766+ * because it needs to iterate through all the children to compute the child's
6.767+ * position.
6.768+ */
6.769+bool ts_tree_cursor_goto_last_child(TSTreeCursor *self);
6.770+
6.771+/**
6.772+ * Move the cursor to the node that is the nth descendant of
6.773+ * the original node that the cursor was constructed with, where
6.774+ * zero represents the original node itself.
6.775+ */
6.776+void ts_tree_cursor_goto_descendant(TSTreeCursor *self, uint32_t goal_descendant_index);
6.777+
6.778+/**
6.779+ * Get the index of the cursor's current node out of all of the
6.780+ * descendants of the original node that the cursor was constructed with.
6.781+ */
6.782+uint32_t ts_tree_cursor_current_descendant_index(const TSTreeCursor *self);
6.783+
6.784+/**
6.785+ * Get the depth of the cursor's current node relative to the original
6.786+ * node that the cursor was constructed with.
6.787+ */
6.788+uint32_t ts_tree_cursor_current_depth(const TSTreeCursor *self);
6.789+
6.790+/**
6.791+ * Move the cursor to the first child of its current node that extends beyond
6.792+ * the given byte offset or point.
6.793+ *
6.794+ * This returns the index of the child node if one was found, and returns -1
6.795+ * if no such child was found.
6.796+ */
6.797+int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *self, uint32_t goal_byte);
6.798+int64_t ts_tree_cursor_goto_first_child_for_point(TSTreeCursor *self, TSPoint goal_point);
6.799+
6.800+TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *cursor);
6.801+
6.802+/*******************/
6.803+/* Section - Query */
6.804+/*******************/
6.805+
6.806+/**
6.807+ * Create a new query from a string containing one or more S-expression
6.808+ * patterns. The query is associated with a particular language, and can
6.809+ * only be run on syntax nodes parsed with that language.
6.810+ *
6.811+ * If all of the given patterns are valid, this returns a [`TSQuery`].
6.812+ * If a pattern is invalid, this returns `NULL`, and provides two pieces
6.813+ * of information about the problem:
6.814+ * 1. The byte offset of the error is written to the `error_offset` parameter.
6.815+ * 2. The type of error is written to the `error_type` parameter.
6.816+ */
6.817+TSQuery *ts_query_new(
6.818+ const TSLanguage *language,
6.819+ const char *source,
6.820+ uint32_t source_len,
6.821+ uint32_t *error_offset,
6.822+ TSQueryError *error_type
6.823+);
6.824+
6.825+/**
6.826+ * Delete a query, freeing all of the memory that it used.
6.827+ */
6.828+void ts_query_delete(TSQuery *self);
6.829+
6.830+/**
6.831+ * Get the number of patterns, captures, or string literals in the query.
6.832+ */
6.833+uint32_t ts_query_pattern_count(const TSQuery *self);
6.834+uint32_t ts_query_capture_count(const TSQuery *self);
6.835+uint32_t ts_query_string_count(const TSQuery *self);
6.836+
6.837+/**
6.838+ * Get the byte offset where the given pattern starts in the query's source.
6.839+ *
6.840+ * This can be useful when combining queries by concatenating their source
6.841+ * code strings.
6.842+ */
6.843+uint32_t ts_query_start_byte_for_pattern(const TSQuery *self, uint32_t pattern_index);
6.844+
6.845+/**
6.846+ * Get the byte offset where the given pattern ends in the query's source.
6.847+ *
6.848+ * This can be useful when combining queries by concatenating their source
6.849+ * code strings.
6.850+ */
6.851+uint32_t ts_query_end_byte_for_pattern(const TSQuery *self, uint32_t pattern_index);
6.852+
6.853+/**
6.854+ * Get all of the predicates for the given pattern in the query.
6.855+ *
6.856+ * The predicates are represented as a single array of steps. There are three
6.857+ * types of steps in this array, which correspond to the three legal values for
6.858+ * the `type` field:
6.859+ * - `TSQueryPredicateStepTypeCapture` - Steps with this type represent names
6.860+ * of captures. Their `value_id` can be used with the
6.861+ * [`ts_query_capture_name_for_id`] function to obtain the name of the capture.
6.862+ * - `TSQueryPredicateStepTypeString` - Steps with this type represent literal
6.863+ * strings. Their `value_id` can be used with the
6.864+ * [`ts_query_string_value_for_id`] function to obtain their string value.
6.865+ * - `TSQueryPredicateStepTypeDone` - Steps with this type are *sentinels*
6.866+ * that represent the end of an individual predicate. If a pattern has two
6.867+ * predicates, then there will be two steps with this `type` in the array.
6.868+ */
6.869+const TSQueryPredicateStep *ts_query_predicates_for_pattern(
6.870+ const TSQuery *self,
6.871+ uint32_t pattern_index,
6.872+ uint32_t *step_count
6.873+);
6.874+
6.875+/*
6.876+ * Check if the given pattern in the query has a single root node.
6.877+ */
6.878+bool ts_query_is_pattern_rooted(const TSQuery *self, uint32_t pattern_index);
6.879+
6.880+/*
6.881+ * Check if the given pattern in the query is 'non local'.
6.882+ *
6.883+ * A non-local pattern has multiple root nodes and can match within a
6.884+ * repeating sequence of nodes, as specified by the grammar. Non-local
6.885+ * patterns disable certain optimizations that would otherwise be possible
6.886+ * when executing a query on a specific range of a syntax tree.
6.887+ */
6.888+bool ts_query_is_pattern_non_local(const TSQuery *self, uint32_t pattern_index);
6.889+
6.890+/*
6.891+ * Check if a given pattern is guaranteed to match once a given step is reached.
6.892+ * The step is specified by its byte offset in the query's source code.
6.893+ */
6.894+bool ts_query_is_pattern_guaranteed_at_step(const TSQuery *self, uint32_t byte_offset);
6.895+
6.896+/**
6.897+ * Get the name and length of one of the query's captures, or one of the
6.898+ * query's string literals. Each capture and string is associated with a
6.899+ * numeric id based on the order that it appeared in the query's source.
6.900+ */
6.901+const char *ts_query_capture_name_for_id(
6.902+ const TSQuery *self,
6.903+ uint32_t index,
6.904+ uint32_t *length
6.905+);
6.906+
6.907+/**
6.908+ * Get the quantifier of the query's captures. Each capture is * associated
6.909+ * with a numeric id based on the order that it appeared in the query's source.
6.910+ */
6.911+TSQuantifier ts_query_capture_quantifier_for_id(
6.912+ const TSQuery *self,
6.913+ uint32_t pattern_index,
6.914+ uint32_t capture_index
6.915+);
6.916+
6.917+const char *ts_query_string_value_for_id(
6.918+ const TSQuery *self,
6.919+ uint32_t index,
6.920+ uint32_t *length
6.921+);
6.922+
6.923+/**
6.924+ * Disable a certain capture within a query.
6.925+ *
6.926+ * This prevents the capture from being returned in matches, and also avoids
6.927+ * any resource usage associated with recording the capture. Currently, there
6.928+ * is no way to undo this.
6.929+ */
6.930+void ts_query_disable_capture(TSQuery *self, const char *name, uint32_t length);
6.931+
6.932+/**
6.933+ * Disable a certain pattern within a query.
6.934+ *
6.935+ * This prevents the pattern from matching and removes most of the overhead
6.936+ * associated with the pattern. Currently, there is no way to undo this.
6.937+ */
6.938+void ts_query_disable_pattern(TSQuery *self, uint32_t pattern_index);
6.939+
6.940+/**
6.941+ * Create a new cursor for executing a given query.
6.942+ *
6.943+ * The cursor stores the state that is needed to iteratively search
6.944+ * for matches. To use the query cursor, first call [`ts_query_cursor_exec`]
6.945+ * to start running a given query on a given syntax node. Then, there are
6.946+ * two options for consuming the results of the query:
6.947+ * 1. Repeatedly call [`ts_query_cursor_next_match`] to iterate over all of the
6.948+ * *matches* in the order that they were found. Each match contains the
6.949+ * index of the pattern that matched, and an array of captures. Because
6.950+ * multiple patterns can match the same set of nodes, one match may contain
6.951+ * captures that appear *before* some of the captures from a previous match.
6.952+ * 2. Repeatedly call [`ts_query_cursor_next_capture`] to iterate over all of the
6.953+ * individual *captures* in the order that they appear. This is useful if
6.954+ * don't care about which pattern matched, and just want a single ordered
6.955+ * sequence of captures.
6.956+ *
6.957+ * If you don't care about consuming all of the results, you can stop calling
6.958+ * [`ts_query_cursor_next_match`] or [`ts_query_cursor_next_capture`] at any point.
6.959+ * You can then start executing another query on another node by calling
6.960+ * [`ts_query_cursor_exec`] again.
6.961+ */
6.962+TSQueryCursor *ts_query_cursor_new(void);
6.963+
6.964+/**
6.965+ * Delete a query cursor, freeing all of the memory that it used.
6.966+ */
6.967+void ts_query_cursor_delete(TSQueryCursor *self);
6.968+
6.969+/**
6.970+ * Start running a given query on a given node.
6.971+ */
6.972+void ts_query_cursor_exec(TSQueryCursor *self, const TSQuery *query, TSNode node);
6.973+
6.974+/**
6.975+ * Manage the maximum number of in-progress matches allowed by this query
6.976+ * cursor.
6.977+ *
6.978+ * Query cursors have an optional maximum capacity for storing lists of
6.979+ * in-progress captures. If this capacity is exceeded, then the
6.980+ * earliest-starting match will silently be dropped to make room for further
6.981+ * matches. This maximum capacity is optional — by default, query cursors allow
6.982+ * any number of pending matches, dynamically allocating new space for them as
6.983+ * needed as the query is executed.
6.984+ */
6.985+bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *self);
6.986+uint32_t ts_query_cursor_match_limit(const TSQueryCursor *self);
6.987+void ts_query_cursor_set_match_limit(TSQueryCursor *self, uint32_t limit);
6.988+
6.989+/**
6.990+ * Set the range of bytes or (row, column) positions in which the query
6.991+ * will be executed.
6.992+ */
6.993+void ts_query_cursor_set_byte_range(TSQueryCursor *self, uint32_t start_byte, uint32_t end_byte);
6.994+void ts_query_cursor_set_point_range(TSQueryCursor *self, TSPoint start_point, TSPoint end_point);
6.995+
6.996+/**
6.997+ * Advance to the next match of the currently running query.
6.998+ *
6.999+ * If there is a match, write it to `*match` and return `true`.
6.1000+ * Otherwise, return `false`.
6.1001+ */
6.1002+bool ts_query_cursor_next_match(TSQueryCursor *self, TSQueryMatch *match);
6.1003+void ts_query_cursor_remove_match(TSQueryCursor *self, uint32_t match_id);
6.1004+
6.1005+/**
6.1006+ * Advance to the next capture of the currently running query.
6.1007+ *
6.1008+ * If there is a capture, write its match to `*match` and its index within
6.1009+ * the matche's capture list to `*capture_index`. Otherwise, return `false`.
6.1010+ */
6.1011+bool ts_query_cursor_next_capture(
6.1012+ TSQueryCursor *self,
6.1013+ TSQueryMatch *match,
6.1014+ uint32_t *capture_index
6.1015+);
6.1016+
6.1017+/**
6.1018+ * Set the maximum start depth for a query cursor.
6.1019+ *
6.1020+ * This prevents cursors from exploring children nodes at a certain depth.
6.1021+ * Note if a pattern includes many children, then they will still be checked.
6.1022+ *
6.1023+ * The zero max start depth value can be used as a special behavior and
6.1024+ * it helps to destructure a subtree by staying on a node and using captures
6.1025+ * for interested parts. Note that the zero max start depth only limit a search
6.1026+ * depth for a pattern's root node but other nodes that are parts of the pattern
6.1027+ * may be searched at any depth what defined by the pattern structure.
6.1028+ *
6.1029+ * Set to `UINT32_MAX` to remove the maximum start depth.
6.1030+ */
6.1031+void ts_query_cursor_set_max_start_depth(TSQueryCursor *self, uint32_t max_start_depth);
6.1032+
6.1033+/**********************/
6.1034+/* Section - Language */
6.1035+/**********************/
6.1036+
6.1037+/**
6.1038+ * Get another reference to the given language.
6.1039+ */
6.1040+const TSLanguage *ts_language_copy(const TSLanguage *self);
6.1041+
6.1042+/**
6.1043+ * Free any dynamically-allocated resources for this language, if
6.1044+ * this is the last reference.
6.1045+ */
6.1046+void ts_language_delete(const TSLanguage *self);
6.1047+
6.1048+/**
6.1049+ * Get the number of distinct node types in the language.
6.1050+ */
6.1051+uint32_t ts_language_symbol_count(const TSLanguage *self);
6.1052+
6.1053+/**
6.1054+ * Get the number of valid states in this language.
6.1055+*/
6.1056+uint32_t ts_language_state_count(const TSLanguage *self);
6.1057+
6.1058+/**
6.1059+ * Get a node type string for the given numerical id.
6.1060+ */
6.1061+const char *ts_language_symbol_name(const TSLanguage *self, TSSymbol symbol);
6.1062+
6.1063+/**
6.1064+ * Get the numerical id for the given node type string.
6.1065+ */
6.1066+TSSymbol ts_language_symbol_for_name(
6.1067+ const TSLanguage *self,
6.1068+ const char *string,
6.1069+ uint32_t length,
6.1070+ bool is_named
6.1071+);
6.1072+
6.1073+/**
6.1074+ * Get the number of distinct field names in the language.
6.1075+ */
6.1076+uint32_t ts_language_field_count(const TSLanguage *self);
6.1077+
6.1078+/**
6.1079+ * Get the field name string for the given numerical id.
6.1080+ */
6.1081+const char *ts_language_field_name_for_id(const TSLanguage *self, TSFieldId id);
6.1082+
6.1083+/**
6.1084+ * Get the numerical id for the given field name string.
6.1085+ */
6.1086+TSFieldId ts_language_field_id_for_name(const TSLanguage *self, const char *name, uint32_t name_length);
6.1087+
6.1088+/**
6.1089+ * Check whether the given node type id belongs to named nodes, anonymous nodes,
6.1090+ * or a hidden nodes.
6.1091+ *
6.1092+ * See also [`ts_node_is_named`]. Hidden nodes are never returned from the API.
6.1093+ */
6.1094+TSSymbolType ts_language_symbol_type(const TSLanguage *self, TSSymbol symbol);
6.1095+
6.1096+/**
6.1097+ * Get the ABI version number for this language. This version number is used
6.1098+ * to ensure that languages were generated by a compatible version of
6.1099+ * Tree-sitter.
6.1100+ *
6.1101+ * See also [`ts_parser_set_language`].
6.1102+ */
6.1103+uint32_t ts_language_version(const TSLanguage *self);
6.1104+
6.1105+/**
6.1106+ * Get the next parse state. Combine this with lookahead iterators to generate
6.1107+ * completion suggestions or valid symbols in error nodes. Use
6.1108+ * [`ts_node_grammar_symbol`] for valid symbols.
6.1109+*/
6.1110+TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state, TSSymbol symbol);
6.1111+
6.1112+/********************************/
6.1113+/* Section - Lookahead Iterator */
6.1114+/********************************/
6.1115+
6.1116+/**
6.1117+ * Create a new lookahead iterator for the given language and parse state.
6.1118+ *
6.1119+ * This returns `NULL` if state is invalid for the language.
6.1120+ *
6.1121+ * Repeatedly using [`ts_lookahead_iterator_next`] and
6.1122+ * [`ts_lookahead_iterator_current_symbol`] will generate valid symbols in the
6.1123+ * given parse state. Newly created lookahead iterators will contain the `ERROR`
6.1124+ * symbol.
6.1125+ *
6.1126+ * Lookahead iterators can be useful to generate suggestions and improve syntax
6.1127+ * error diagnostics. To get symbols valid in an ERROR node, use the lookahead
6.1128+ * iterator on its first leaf node state. For `MISSING` nodes, a lookahead
6.1129+ * iterator created on the previous non-extra leaf node may be appropriate.
6.1130+*/
6.1131+TSLookaheadIterator *ts_lookahead_iterator_new(const TSLanguage *self, TSStateId state);
6.1132+
6.1133+/**
6.1134+ * Delete a lookahead iterator freeing all the memory used.
6.1135+*/
6.1136+void ts_lookahead_iterator_delete(TSLookaheadIterator *self);
6.1137+
6.1138+/**
6.1139+ * Reset the lookahead iterator to another state.
6.1140+ *
6.1141+ * This returns `true` if the iterator was reset to the given state and `false`
6.1142+ * otherwise.
6.1143+*/
6.1144+bool ts_lookahead_iterator_reset_state(TSLookaheadIterator *self, TSStateId state);
6.1145+
6.1146+/**
6.1147+ * Reset the lookahead iterator.
6.1148+ *
6.1149+ * This returns `true` if the language was set successfully and `false`
6.1150+ * otherwise.
6.1151+*/
6.1152+bool ts_lookahead_iterator_reset(TSLookaheadIterator *self, const TSLanguage *language, TSStateId state);
6.1153+
6.1154+/**
6.1155+ * Get the current language of the lookahead iterator.
6.1156+*/
6.1157+const TSLanguage *ts_lookahead_iterator_language(const TSLookaheadIterator *self);
6.1158+
6.1159+/**
6.1160+ * Advance the lookahead iterator to the next symbol.
6.1161+ *
6.1162+ * This returns `true` if there is a new symbol and `false` otherwise.
6.1163+*/
6.1164+bool ts_lookahead_iterator_next(TSLookaheadIterator *self);
6.1165+
6.1166+/**
6.1167+ * Get the current symbol of the lookahead iterator;
6.1168+*/
6.1169+TSSymbol ts_lookahead_iterator_current_symbol(const TSLookaheadIterator *self);
6.1170+
6.1171+/**
6.1172+ * Get the current symbol type of the lookahead iterator as a null terminated
6.1173+ * string.
6.1174+*/
6.1175+const char *ts_lookahead_iterator_current_symbol_name(const TSLookaheadIterator *self);
6.1176+
6.1177+/*************************************/
6.1178+/* Section - WebAssembly Integration */
6.1179+/************************************/
6.1180+
6.1181+typedef struct wasm_engine_t TSWasmEngine;
6.1182+typedef struct TSWasmStore TSWasmStore;
6.1183+
6.1184+typedef enum {
6.1185+ TSWasmErrorKindNone = 0,
6.1186+ TSWasmErrorKindParse,
6.1187+ TSWasmErrorKindCompile,
6.1188+ TSWasmErrorKindInstantiate,
6.1189+ TSWasmErrorKindAllocate,
6.1190+} TSWasmErrorKind;
6.1191+
6.1192+typedef struct {
6.1193+ TSWasmErrorKind kind;
6.1194+ char *message;
6.1195+} TSWasmError;
6.1196+
6.1197+/**
6.1198+ * Create a Wasm store.
6.1199+ */
6.1200+TSWasmStore *ts_wasm_store_new(
6.1201+ TSWasmEngine *engine,
6.1202+ TSWasmError *error
6.1203+);
6.1204+
6.1205+/**
6.1206+ * Free the memory associated with the given Wasm store.
6.1207+ */
6.1208+void ts_wasm_store_delete(TSWasmStore *);
6.1209+
6.1210+/**
6.1211+ * Create a language from a buffer of Wasm. The resulting language behaves
6.1212+ * like any other Tree-sitter language, except that in order to use it with
6.1213+ * a parser, that parser must have a Wasm store. Note that the language
6.1214+ * can be used with any Wasm store, it doesn't need to be the same store that
6.1215+ * was used to originally load it.
6.1216+ */
6.1217+const TSLanguage *ts_wasm_store_load_language(
6.1218+ TSWasmStore *,
6.1219+ const char *name,
6.1220+ const char *wasm,
6.1221+ uint32_t wasm_len,
6.1222+ TSWasmError *error
6.1223+);
6.1224+
6.1225+/**
6.1226+ * Get the number of languages instantiated in the given wasm store.
6.1227+ */
6.1228+size_t ts_wasm_store_language_count(const TSWasmStore *);
6.1229+
6.1230+/**
6.1231+ * Check if the language came from a Wasm module. If so, then in order to use
6.1232+ * this language with a Parser, that parser must have a Wasm store assigned.
6.1233+ */
6.1234+bool ts_language_is_wasm(const TSLanguage *);
6.1235+
6.1236+/**
6.1237+ * Assign the given Wasm store to the parser. A parser must have a Wasm store
6.1238+ * in order to use Wasm languages.
6.1239+ */
6.1240+void ts_parser_set_wasm_store(TSParser *, TSWasmStore *);
6.1241+
6.1242+/**
6.1243+ * Remove the parser's current Wasm store and return it. This returns NULL if
6.1244+ * the parser doesn't have a Wasm store.
6.1245+ */
6.1246+TSWasmStore *ts_parser_take_wasm_store(TSParser *);
6.1247+
6.1248+/**********************************/
6.1249+/* Section - Global Configuration */
6.1250+/**********************************/
6.1251+
6.1252+/**
6.1253+ * Set the allocation functions used by the library.
6.1254+ *
6.1255+ * By default, Tree-sitter uses the standard libc allocation functions,
6.1256+ * but aborts the process when an allocation fails. This function lets
6.1257+ * you supply alternative allocation functions at runtime.
6.1258+ *
6.1259+ * If you pass `NULL` for any parameter, Tree-sitter will switch back to
6.1260+ * its default implementation of that function.
6.1261+ *
6.1262+ * If you call this function after the library has already been used, then
6.1263+ * you must ensure that either:
6.1264+ * 1. All the existing objects have been freed.
6.1265+ * 2. The new allocator shares its state with the old one, so it is capable
6.1266+ * of freeing memory that was allocated by the old allocator.
6.1267+ */
6.1268+void ts_set_allocator(
6.1269+ void *(*new_malloc)(size_t),
6.1270+ void *(*new_calloc)(size_t, size_t),
6.1271+ void *(*new_realloc)(void *, size_t),
6.1272+ void (*new_free)(void *)
6.1273+);
6.1274+
6.1275+#ifdef __cplusplus
6.1276+}
6.1277+#endif
6.1278+
6.1279+#ifndef TREE_SITTER_HIDE_SYMBOLS
6.1280+#if defined(__GNUC__) || defined(__clang__)
6.1281+#pragma GCC visibility pop
6.1282+#endif
6.1283+#endif
6.1284+
6.1285+#endif // TREE_SITTER_API_H_
7.1--- a/lisp/ffi/tree-sitter/ts-api.h Fri Oct 04 16:14:44 2024 -0400
7.2+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3@@ -1,1180 +0,0 @@
7.4-#ifndef TREE_SITTER_API_H_
7.5-#define TREE_SITTER_API_H_
7.6-
7.7-#if defined(__GNUC__) || defined(__clang__)
7.8-#pragma GCC visibility push(default)
7.9-#endif
7.10-
7.11-#ifdef __cplusplus
7.12-extern "C" {
7.13-#endif
7.14-
7.15-#include <stdlib.h>
7.16-#include <stdint.h>
7.17-#include <stdbool.h>
7.18-
7.19-/****************************/
7.20-/* Section - ABI Versioning */
7.21-/****************************/
7.22-
7.23-/**
7.24- * The latest ABI version that is supported by the current version of the
7.25- * library. When Languages are generated by the Tree-sitter CLI, they are
7.26- * assigned an ABI version number that corresponds to the current CLI version.
7.27- * The Tree-sitter library is generally backwards-compatible with languages
7.28- * generated using older CLI versions, but is not forwards-compatible.
7.29- */
7.30-#define TREE_SITTER_LANGUAGE_VERSION 14
7.31-
7.32-/**
7.33- * The earliest ABI version that is supported by the current version of the
7.34- * library.
7.35- */
7.36-#define TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION 13
7.37-
7.38-/*******************/
7.39-/* Section - Types */
7.40-/*******************/
7.41-
7.42-typedef uint16_t TSStateId;
7.43-typedef uint16_t TSSymbol;
7.44-typedef uint16_t TSFieldId;
7.45-typedef struct TSLanguage TSLanguage;
7.46-typedef struct TSParser TSParser;
7.47-typedef struct TSTree TSTree;
7.48-typedef struct TSQuery TSQuery;
7.49-typedef struct TSQueryCursor TSQueryCursor;
7.50-typedef struct TSLookaheadIterator TSLookaheadIterator;
7.51-
7.52-typedef enum {
7.53- TSInputEncodingUTF8,
7.54- TSInputEncodingUTF16,
7.55-} TSInputEncoding;
7.56-
7.57-typedef enum {
7.58- TSSymbolTypeRegular,
7.59- TSSymbolTypeAnonymous,
7.60- TSSymbolTypeAuxiliary,
7.61-} TSSymbolType;
7.62-
7.63-typedef struct {
7.64- uint32_t row;
7.65- uint32_t column;
7.66-} TSPoint;
7.67-
7.68-typedef struct {
7.69- TSPoint start_point;
7.70- TSPoint end_point;
7.71- uint32_t start_byte;
7.72- uint32_t end_byte;
7.73-} TSRange;
7.74-
7.75-typedef struct {
7.76- void *payload;
7.77- const char *(*read)(void *payload, uint32_t byte_index, TSPoint position, uint32_t *bytes_read);
7.78- TSInputEncoding encoding;
7.79-} TSInput;
7.80-
7.81-typedef enum {
7.82- TSLogTypeParse,
7.83- TSLogTypeLex,
7.84-} TSLogType;
7.85-
7.86-typedef struct {
7.87- void *payload;
7.88- void (*log)(void *payload, TSLogType log_type, const char *buffer);
7.89-} TSLogger;
7.90-
7.91-typedef struct {
7.92- uint32_t start_byte;
7.93- uint32_t old_end_byte;
7.94- uint32_t new_end_byte;
7.95- TSPoint start_point;
7.96- TSPoint old_end_point;
7.97- TSPoint new_end_point;
7.98-} TSInputEdit;
7.99-
7.100-typedef struct {
7.101- uint32_t context[4];
7.102- const void *id;
7.103- const TSTree *tree;
7.104-} TSNode;
7.105-
7.106-typedef struct {
7.107- const void *tree;
7.108- const void *id;
7.109- uint32_t context[2];
7.110-} TSTreeCursor;
7.111-
7.112-typedef struct {
7.113- TSNode node;
7.114- uint32_t index;
7.115-} TSQueryCapture;
7.116-
7.117-typedef enum {
7.118- TSQuantifierZero = 0, // must match the array initialization value
7.119- TSQuantifierZeroOrOne,
7.120- TSQuantifierZeroOrMore,
7.121- TSQuantifierOne,
7.122- TSQuantifierOneOrMore,
7.123-} TSQuantifier;
7.124-
7.125-typedef struct {
7.126- uint32_t id;
7.127- uint16_t pattern_index;
7.128- uint16_t capture_count;
7.129- const TSQueryCapture *captures;
7.130-} TSQueryMatch;
7.131-
7.132-typedef enum {
7.133- TSQueryPredicateStepTypeDone,
7.134- TSQueryPredicateStepTypeCapture,
7.135- TSQueryPredicateStepTypeString,
7.136-} TSQueryPredicateStepType;
7.137-
7.138-typedef struct {
7.139- TSQueryPredicateStepType type;
7.140- uint32_t value_id;
7.141-} TSQueryPredicateStep;
7.142-
7.143-typedef enum {
7.144- TSQueryErrorNone = 0,
7.145- TSQueryErrorSyntax,
7.146- TSQueryErrorNodeType,
7.147- TSQueryErrorField,
7.148- TSQueryErrorCapture,
7.149- TSQueryErrorStructure,
7.150- TSQueryErrorLanguage,
7.151-} TSQueryError;
7.152-
7.153-/********************/
7.154-/* Section - Parser */
7.155-/********************/
7.156-
7.157-/**
7.158- * Create a new parser.
7.159- */
7.160-TSParser *ts_parser_new(void);
7.161-
7.162-/**
7.163- * Delete the parser, freeing all of the memory that it used.
7.164- */
7.165-void ts_parser_delete(TSParser *self);
7.166-
7.167-/**
7.168- * Get the parser's current language.
7.169- */
7.170-const TSLanguage *ts_parser_language(const TSParser *self);
7.171-
7.172-/**
7.173- * Set the language that the parser should use for parsing.
7.174- *
7.175- * Returns a boolean indicating whether or not the language was successfully
7.176- * assigned. True means assignment succeeded. False means there was a version
7.177- * mismatch: the language was generated with an incompatible version of the
7.178- * Tree-sitter CLI. Check the language's version using [`ts_language_version`]
7.179- * and compare it to this library's [`TREE_SITTER_LANGUAGE_VERSION`] and
7.180- * [`TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION`] constants.
7.181- */
7.182-bool ts_parser_set_language(TSParser *self, const TSLanguage *language);
7.183-
7.184-/**
7.185- * Set the ranges of text that the parser should include when parsing.
7.186- *
7.187- * By default, the parser will always include entire documents. This function
7.188- * allows you to parse only a *portion* of a document but still return a syntax
7.189- * tree whose ranges match up with the document as a whole. You can also pass
7.190- * multiple disjoint ranges.
7.191- *
7.192- * The second and third parameters specify the location and length of an array
7.193- * of ranges. The parser does *not* take ownership of these ranges; it copies
7.194- * the data, so it doesn't matter how these ranges are allocated.
7.195- *
7.196- * If `count` is zero, then the entire document will be parsed. Otherwise,
7.197- * the given ranges must be ordered from earliest to latest in the document,
7.198- * and they must not overlap. That is, the following must hold for all:
7.199- *
7.200- * `i < count - 1`: `ranges[i].end_byte <= ranges[i + 1].start_byte`
7.201- *
7.202- * If this requirement is not satisfied, the operation will fail, the ranges
7.203- * will not be assigned, and this function will return `false`. On success,
7.204- * this function returns `true`
7.205- */
7.206-bool ts_parser_set_included_ranges(
7.207- TSParser *self,
7.208- const TSRange *ranges,
7.209- uint32_t count
7.210-);
7.211-
7.212-/**
7.213- * Get the ranges of text that the parser will include when parsing.
7.214- *
7.215- * The returned pointer is owned by the parser. The caller should not free it
7.216- * or write to it. The length of the array will be written to the given
7.217- * `count` pointer.
7.218- */
7.219-const TSRange *ts_parser_included_ranges(
7.220- const TSParser *self,
7.221- uint32_t *count
7.222-);
7.223-
7.224-/**
7.225- * Use the parser to parse some source code and create a syntax tree.
7.226- *
7.227- * If you are parsing this document for the first time, pass `NULL` for the
7.228- * `old_tree` parameter. Otherwise, if you have already parsed an earlier
7.229- * version of this document and the document has since been edited, pass the
7.230- * previous syntax tree so that the unchanged parts of it can be reused.
7.231- * This will save time and memory. For this to work correctly, you must have
7.232- * already edited the old syntax tree using the [`ts_tree_edit`] function in a
7.233- * way that exactly matches the source code changes.
7.234- *
7.235- * The [`TSInput`] parameter lets you specify how to read the text. It has the
7.236- * following three fields:
7.237- * 1. [`read`]: A function to retrieve a chunk of text at a given byte offset
7.238- * and (row, column) position. The function should return a pointer to the
7.239- * text and write its length to the [`bytes_read`] pointer. The parser does
7.240- * not take ownership of this buffer; it just borrows it until it has
7.241- * finished reading it. The function should write a zero value to the
7.242- * [`bytes_read`] pointer to indicate the end of the document.
7.243- * 2. [`payload`]: An arbitrary pointer that will be passed to each invocation
7.244- * of the [`read`] function.
7.245- * 3. [`encoding`]: An indication of how the text is encoded. Either
7.246- * `TSInputEncodingUTF8` or `TSInputEncodingUTF16`.
7.247- *
7.248- * This function returns a syntax tree on success, and `NULL` on failure. There
7.249- * are three possible reasons for failure:
7.250- * 1. The parser does not have a language assigned. Check for this using the
7.251- [`ts_parser_language`] function.
7.252- * 2. Parsing was cancelled due to a timeout that was set by an earlier call to
7.253- * the [`ts_parser_set_timeout_micros`] function. You can resume parsing from
7.254- * where the parser left out by calling [`ts_parser_parse`] again with the
7.255- * same arguments. Or you can start parsing from scratch by first calling
7.256- * [`ts_parser_reset`].
7.257- * 3. Parsing was cancelled using a cancellation flag that was set by an
7.258- * earlier call to [`ts_parser_set_cancellation_flag`]. You can resume parsing
7.259- * from where the parser left out by calling [`ts_parser_parse`] again with
7.260- * the same arguments.
7.261- *
7.262- * [`read`]: TSInput::read
7.263- * [`payload`]: TSInput::payload
7.264- * [`encoding`]: TSInput::encoding
7.265- * [`bytes_read`]: TSInput::read
7.266- */
7.267-TSTree *ts_parser_parse(
7.268- TSParser *self,
7.269- const TSTree *old_tree,
7.270- TSInput input
7.271-);
7.272-
7.273-/**
7.274- * Use the parser to parse some source code stored in one contiguous buffer.
7.275- * The first two parameters are the same as in the [`ts_parser_parse`] function
7.276- * above. The second two parameters indicate the location of the buffer and its
7.277- * length in bytes.
7.278- */
7.279-TSTree *ts_parser_parse_string(
7.280- TSParser *self,
7.281- const TSTree *old_tree,
7.282- const char *string,
7.283- uint32_t length
7.284-);
7.285-
7.286-/**
7.287- * Use the parser to parse some source code stored in one contiguous buffer with
7.288- * a given encoding. The first four parameters work the same as in the
7.289- * [`ts_parser_parse_string`] method above. The final parameter indicates whether
7.290- * the text is encoded as UTF8 or UTF16.
7.291- */
7.292-TSTree *ts_parser_parse_string_encoding(
7.293- TSParser *self,
7.294- const TSTree *old_tree,
7.295- const char *string,
7.296- uint32_t length,
7.297- TSInputEncoding encoding
7.298-);
7.299-
7.300-/**
7.301- * Instruct the parser to start the next parse from the beginning.
7.302- *
7.303- * If the parser previously failed because of a timeout or a cancellation, then
7.304- * by default, it will resume where it left off on the next call to
7.305- * [`ts_parser_parse`] or other parsing functions. If you don't want to resume,
7.306- * and instead intend to use this parser to parse some other document, you must
7.307- * call [`ts_parser_reset`] first.
7.308- */
7.309-void ts_parser_reset(TSParser *self);
7.310-
7.311-/**
7.312- * Set the maximum duration in microseconds that parsing should be allowed to
7.313- * take before halting.
7.314- *
7.315- * If parsing takes longer than this, it will halt early, returning NULL.
7.316- * See [`ts_parser_parse`] for more information.
7.317- */
7.318-void ts_parser_set_timeout_micros(TSParser *self, uint64_t timeout_micros);
7.319-
7.320-/**
7.321- * Get the duration in microseconds that parsing is allowed to take.
7.322- */
7.323-uint64_t ts_parser_timeout_micros(const TSParser *self);
7.324-
7.325-/**
7.326- * Set the parser's current cancellation flag pointer.
7.327- *
7.328- * If a non-null pointer is assigned, then the parser will periodically read
7.329- * from this pointer during parsing. If it reads a non-zero value, it will
7.330- * halt early, returning NULL. See [`ts_parser_parse`] for more information.
7.331- */
7.332-void ts_parser_set_cancellation_flag(TSParser *self, const size_t *flag);
7.333-
7.334-/**
7.335- * Get the parser's current cancellation flag pointer.
7.336- */
7.337-const size_t *ts_parser_cancellation_flag(const TSParser *self);
7.338-
7.339-/**
7.340- * Set the logger that a parser should use during parsing.
7.341- *
7.342- * The parser does not take ownership over the logger payload. If a logger was
7.343- * previously assigned, the caller is responsible for releasing any memory
7.344- * owned by the previous logger.
7.345- */
7.346-void ts_parser_set_logger(TSParser *self, TSLogger logger);
7.347-
7.348-/**
7.349- * Get the parser's current logger.
7.350- */
7.351-TSLogger ts_parser_logger(const TSParser *self);
7.352-
7.353-/**
7.354- * Set the file descriptor to which the parser should write debugging graphs
7.355- * during parsing. The graphs are formatted in the DOT language. You may want
7.356- * to pipe these graphs directly to a `dot(1)` process in order to generate
7.357- * SVG output. You can turn off this logging by passing a negative number.
7.358- */
7.359-void ts_parser_print_dot_graphs(TSParser *self, int fd);
7.360-
7.361-/******************/
7.362-/* Section - Tree */
7.363-/******************/
7.364-
7.365-/**
7.366- * Create a shallow copy of the syntax tree. This is very fast.
7.367- *
7.368- * You need to copy a syntax tree in order to use it on more than one thread at
7.369- * a time, as syntax trees are not thread safe.
7.370- */
7.371-TSTree *ts_tree_copy(const TSTree *self);
7.372-
7.373-/**
7.374- * Delete the syntax tree, freeing all of the memory that it used.
7.375- */
7.376-void ts_tree_delete(TSTree *self);
7.377-
7.378-/**
7.379- * Get the root node of the syntax tree.
7.380- */
7.381-TSNode ts_tree_root_node(const TSTree *self);
7.382-
7.383-/**
7.384- * Get the root node of the syntax tree, but with its position
7.385- * shifted forward by the given offset.
7.386- */
7.387-TSNode ts_tree_root_node_with_offset(
7.388- const TSTree *self,
7.389- uint32_t offset_bytes,
7.390- TSPoint offset_extent
7.391-);
7.392-
7.393-/**
7.394- * Get the language that was used to parse the syntax tree.
7.395- */
7.396-const TSLanguage *ts_tree_language(const TSTree *self);
7.397-
7.398-/**
7.399- * Get the array of included ranges that was used to parse the syntax tree.
7.400- *
7.401- * The returned pointer must be freed by the caller.
7.402- */
7.403-TSRange *ts_tree_included_ranges(const TSTree *self, uint32_t *length);
7.404-
7.405-/**
7.406- * Edit the syntax tree to keep it in sync with source code that has been
7.407- * edited.
7.408- *
7.409- * You must describe the edit both in terms of byte offsets and in terms of
7.410- * (row, column) coordinates.
7.411- */
7.412-void ts_tree_edit(TSTree *self, const TSInputEdit *edit);
7.413-
7.414-/**
7.415- * Compare an old edited syntax tree to a new syntax tree representing the same
7.416- * document, returning an array of ranges whose syntactic structure has changed.
7.417- *
7.418- * For this to work correctly, the old syntax tree must have been edited such
7.419- * that its ranges match up to the new tree. Generally, you'll want to call
7.420- * this function right after calling one of the [`ts_parser_parse`] functions.
7.421- * You need to pass the old tree that was passed to parse, as well as the new
7.422- * tree that was returned from that function.
7.423- *
7.424- * The returned array is allocated using `malloc` and the caller is responsible
7.425- * for freeing it using `free`. The length of the array will be written to the
7.426- * given `length` pointer.
7.427- */
7.428-TSRange *ts_tree_get_changed_ranges(
7.429- const TSTree *old_tree,
7.430- const TSTree *new_tree,
7.431- uint32_t *length
7.432-);
7.433-
7.434-/**
7.435- * Write a DOT graph describing the syntax tree to the given file.
7.436- */
7.437-void ts_tree_print_dot_graph(const TSTree *self, int file_descriptor);
7.438-
7.439-/******************/
7.440-/* Section - Node */
7.441-/******************/
7.442-
7.443-/**
7.444- * Get the node's type as a null-terminated string.
7.445- */
7.446-const char *ts_node_type(TSNode self);
7.447-
7.448-/**
7.449- * Get the node's type as a numerical id.
7.450- */
7.451-TSSymbol ts_node_symbol(TSNode self);
7.452-
7.453-/**
7.454- * Get the node's language.
7.455- */
7.456-const TSLanguage *ts_node_language(TSNode self);
7.457-
7.458-/**
7.459- * Get the node's type as it appears in the grammar ignoring aliases as a
7.460- * null-terminated string.
7.461- */
7.462-const char *ts_node_grammar_type(TSNode self);
7.463-
7.464-/**
7.465- * Get the node's type as a numerical id as it appears in the grammar ignoring
7.466- * aliases. This should be used in [`ts_language_next_state`] instead of
7.467- * [`ts_node_symbol`].
7.468- */
7.469-TSSymbol ts_node_grammar_symbol(TSNode self);
7.470-
7.471-/**
7.472- * Get the node's start byte.
7.473- */
7.474-uint32_t ts_node_start_byte(TSNode self);
7.475-
7.476-/**
7.477- * Get the node's start position in terms of rows and columns.
7.478- */
7.479-TSPoint ts_node_start_point(TSNode self);
7.480-
7.481-/**
7.482- * Get the node's end byte.
7.483- */
7.484-uint32_t ts_node_end_byte(TSNode self);
7.485-
7.486-/**
7.487- * Get the node's end position in terms of rows and columns.
7.488- */
7.489-TSPoint ts_node_end_point(TSNode self);
7.490-
7.491-/**
7.492- * Get an S-expression representing the node as a string.
7.493- *
7.494- * This string is allocated with `malloc` and the caller is responsible for
7.495- * freeing it using `free`.
7.496- */
7.497-char *ts_node_string(TSNode self);
7.498-
7.499-/**
7.500- * Check if the node is null. Functions like [`ts_node_child`] and
7.501- * [`ts_node_next_sibling`] will return a null node to indicate that no such node
7.502- * was found.
7.503- */
7.504-bool ts_node_is_null(TSNode self);
7.505-
7.506-/**
7.507- * Check if the node is *named*. Named nodes correspond to named rules in the
7.508- * grammar, whereas *anonymous* nodes correspond to string literals in the
7.509- * grammar.
7.510- */
7.511-bool ts_node_is_named(TSNode self);
7.512-
7.513-/**
7.514- * Check if the node is *missing*. Missing nodes are inserted by the parser in
7.515- * order to recover from certain kinds of syntax errors.
7.516- */
7.517-bool ts_node_is_missing(TSNode self);
7.518-
7.519-/**
7.520- * Check if the node is *extra*. Extra nodes represent things like comments,
7.521- * which are not required the grammar, but can appear anywhere.
7.522- */
7.523-bool ts_node_is_extra(TSNode self);
7.524-
7.525-/**
7.526- * Check if a syntax node has been edited.
7.527- */
7.528-bool ts_node_has_changes(TSNode self);
7.529-
7.530-/**
7.531- * Check if the node is a syntax error or contains any syntax errors.
7.532- */
7.533-bool ts_node_has_error(TSNode self);
7.534-
7.535-/**
7.536- * Check if the node is a syntax error.
7.537-*/
7.538-bool ts_node_is_error(TSNode self);
7.539-
7.540-/**
7.541- * Get this node's parse state.
7.542-*/
7.543-TSStateId ts_node_parse_state(TSNode self);
7.544-
7.545-/**
7.546- * Get the parse state after this node.
7.547-*/
7.548-TSStateId ts_node_next_parse_state(TSNode self);
7.549-
7.550-/**
7.551- * Get the node's immediate parent.
7.552- */
7.553-TSNode ts_node_parent(TSNode self);
7.554-
7.555-/**
7.556- * Get the node's child at the given index, where zero represents the first
7.557- * child.
7.558- */
7.559-TSNode ts_node_child(TSNode self, uint32_t child_index);
7.560-
7.561-/**
7.562- * Get the field name for node's child at the given index, where zero represents
7.563- * the first child. Returns NULL, if no field is found.
7.564- */
7.565-const char *ts_node_field_name_for_child(TSNode self, uint32_t child_index);
7.566-
7.567-/**
7.568- * Get the node's number of children.
7.569- */
7.570-uint32_t ts_node_child_count(TSNode self);
7.571-
7.572-/**
7.573- * Get the node's *named* child at the given index.
7.574- *
7.575- * See also [`ts_node_is_named`].
7.576- */
7.577-TSNode ts_node_named_child(TSNode self, uint32_t child_index);
7.578-
7.579-/**
7.580- * Get the node's number of *named* children.
7.581- *
7.582- * See also [`ts_node_is_named`].
7.583- */
7.584-uint32_t ts_node_named_child_count(TSNode self);
7.585-
7.586-/**
7.587- * Get the node's child with the given field name.
7.588- */
7.589-TSNode ts_node_child_by_field_name(
7.590- TSNode self,
7.591- const char *name,
7.592- uint32_t name_length
7.593-);
7.594-
7.595-/**
7.596- * Get the node's child with the given numerical field id.
7.597- *
7.598- * You can convert a field name to an id using the
7.599- * [`ts_language_field_id_for_name`] function.
7.600- */
7.601-TSNode ts_node_child_by_field_id(TSNode self, TSFieldId field_id);
7.602-
7.603-/**
7.604- * Get the node's next / previous sibling.
7.605- */
7.606-TSNode ts_node_next_sibling(TSNode self);
7.607-TSNode ts_node_prev_sibling(TSNode self);
7.608-
7.609-/**
7.610- * Get the node's next / previous *named* sibling.
7.611- */
7.612-TSNode ts_node_next_named_sibling(TSNode self);
7.613-TSNode ts_node_prev_named_sibling(TSNode self);
7.614-
7.615-/**
7.616- * Get the node's first child that extends beyond the given byte offset.
7.617- */
7.618-TSNode ts_node_first_child_for_byte(TSNode self, uint32_t byte);
7.619-
7.620-/**
7.621- * Get the node's first named child that extends beyond the given byte offset.
7.622- */
7.623-TSNode ts_node_first_named_child_for_byte(TSNode self, uint32_t byte);
7.624-
7.625-/**
7.626- * Get the node's number of descendants, including one for the node itself.
7.627- */
7.628-uint32_t ts_node_descendant_count(TSNode self);
7.629-
7.630-/**
7.631- * Get the smallest node within this node that spans the given range of bytes
7.632- * or (row, column) positions.
7.633- */
7.634-TSNode ts_node_descendant_for_byte_range(TSNode self, uint32_t start, uint32_t end);
7.635-TSNode ts_node_descendant_for_point_range(TSNode self, TSPoint start, TSPoint end);
7.636-
7.637-/**
7.638- * Get the smallest named node within this node that spans the given range of
7.639- * bytes or (row, column) positions.
7.640- */
7.641-TSNode ts_node_named_descendant_for_byte_range(TSNode self, uint32_t start, uint32_t end);
7.642-TSNode ts_node_named_descendant_for_point_range(TSNode self, TSPoint start, TSPoint end);
7.643-
7.644-/**
7.645- * Edit the node to keep it in-sync with source code that has been edited.
7.646- *
7.647- * This function is only rarely needed. When you edit a syntax tree with the
7.648- * [`ts_tree_edit`] function, all of the nodes that you retrieve from the tree
7.649- * afterward will already reflect the edit. You only need to use [`ts_node_edit`]
7.650- * when you have a [`TSNode`] instance that you want to keep and continue to use
7.651- * after an edit.
7.652- */
7.653-void ts_node_edit(TSNode *self, const TSInputEdit *edit);
7.654-
7.655-/**
7.656- * Check if two nodes are identical.
7.657- */
7.658-bool ts_node_eq(TSNode self, TSNode other);
7.659-
7.660-/************************/
7.661-/* Section - TreeCursor */
7.662-/************************/
7.663-
7.664-/**
7.665- * Create a new tree cursor starting from the given node.
7.666- *
7.667- * A tree cursor allows you to walk a syntax tree more efficiently than is
7.668- * possible using the [`TSNode`] functions. It is a mutable object that is always
7.669- * on a certain syntax node, and can be moved imperatively to different nodes.
7.670- */
7.671-TSTreeCursor ts_tree_cursor_new(TSNode node);
7.672-
7.673-/**
7.674- * Delete a tree cursor, freeing all of the memory that it used.
7.675- */
7.676-void ts_tree_cursor_delete(TSTreeCursor *self);
7.677-
7.678-/**
7.679- * Re-initialize a tree cursor to start at a different node.
7.680- */
7.681-void ts_tree_cursor_reset(TSTreeCursor *self, TSNode node);
7.682-
7.683-/**
7.684- * Re-initialize a tree cursor to the same position as another cursor.
7.685- *
7.686- * Unlike [`ts_tree_cursor_reset`], this will not lose parent information and
7.687- * allows reusing already created cursors.
7.688-*/
7.689-void ts_tree_cursor_reset_to(TSTreeCursor *dst, const TSTreeCursor *src);
7.690-
7.691-/**
7.692- * Get the tree cursor's current node.
7.693- */
7.694-TSNode ts_tree_cursor_current_node(const TSTreeCursor *self);
7.695-
7.696-/**
7.697- * Get the field name of the tree cursor's current node.
7.698- *
7.699- * This returns `NULL` if the current node doesn't have a field.
7.700- * See also [`ts_node_child_by_field_name`].
7.701- */
7.702-const char *ts_tree_cursor_current_field_name(const TSTreeCursor *self);
7.703-
7.704-/**
7.705- * Get the field id of the tree cursor's current node.
7.706- *
7.707- * This returns zero if the current node doesn't have a field.
7.708- * See also [`ts_node_child_by_field_id`], [`ts_language_field_id_for_name`].
7.709- */
7.710-TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *self);
7.711-
7.712-/**
7.713- * Move the cursor to the parent of its current node.
7.714- *
7.715- * This returns `true` if the cursor successfully moved, and returns `false`
7.716- * if there was no parent node (the cursor was already on the root node).
7.717- */
7.718-bool ts_tree_cursor_goto_parent(TSTreeCursor *self);
7.719-
7.720-/**
7.721- * Move the cursor to the next sibling of its current node.
7.722- *
7.723- * This returns `true` if the cursor successfully moved, and returns `false`
7.724- * if there was no next sibling node.
7.725- */
7.726-bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *self);
7.727-
7.728-/**
7.729- * Move the cursor to the previous sibling of its current node.
7.730- *
7.731- * This returns `true` if the cursor successfully moved, and returns `false` if
7.732- * there was no previous sibling node.
7.733- *
7.734- * Note, that this function may be slower than
7.735- * [`ts_tree_cursor_goto_next_sibling`] due to how node positions are stored. In
7.736- * the worst case, this will need to iterate through all the children upto the
7.737- * previous sibling node to recalculate its position.
7.738- */
7.739-bool ts_tree_cursor_goto_previous_sibling(TSTreeCursor *self);
7.740-
7.741-/**
7.742- * Move the cursor to the first child of its current node.
7.743- *
7.744- * This returns `true` if the cursor successfully moved, and returns `false`
7.745- * if there were no children.
7.746- */
7.747-bool ts_tree_cursor_goto_first_child(TSTreeCursor *self);
7.748-
7.749-/**
7.750- * Move the cursor to the last child of its current node.
7.751- *
7.752- * This returns `true` if the cursor successfully moved, and returns `false` if
7.753- * there were no children.
7.754- *
7.755- * Note that this function may be slower than [`ts_tree_cursor_goto_first_child`]
7.756- * because it needs to iterate through all the children to compute the child's
7.757- * position.
7.758- */
7.759-bool ts_tree_cursor_goto_last_child(TSTreeCursor *self);
7.760-
7.761-/**
7.762- * Move the cursor to the node that is the nth descendant of
7.763- * the original node that the cursor was constructed with, where
7.764- * zero represents the original node itself.
7.765- */
7.766-void ts_tree_cursor_goto_descendant(TSTreeCursor *self, uint32_t goal_descendant_index);
7.767-
7.768-/**
7.769- * Get the index of the cursor's current node out of all of the
7.770- * descendants of the original node that the cursor was constructed with.
7.771- */
7.772-uint32_t ts_tree_cursor_current_descendant_index(const TSTreeCursor *self);
7.773-
7.774-/**
7.775- * Get the depth of the cursor's current node relative to the original
7.776- * node that the cursor was constructed with.
7.777- */
7.778-uint32_t ts_tree_cursor_current_depth(const TSTreeCursor *self);
7.779-
7.780-/**
7.781- * Move the cursor to the first child of its current node that extends beyond
7.782- * the given byte offset or point.
7.783- *
7.784- * This returns the index of the child node if one was found, and returns -1
7.785- * if no such child was found.
7.786- */
7.787-int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *self, uint32_t goal_byte);
7.788-int64_t ts_tree_cursor_goto_first_child_for_point(TSTreeCursor *self, TSPoint goal_point);
7.789-
7.790-TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *cursor);
7.791-
7.792-/*******************/
7.793-/* Section - Query */
7.794-/*******************/
7.795-
7.796-/**
7.797- * Create a new query from a string containing one or more S-expression
7.798- * patterns. The query is associated with a particular language, and can
7.799- * only be run on syntax nodes parsed with that language.
7.800- *
7.801- * If all of the given patterns are valid, this returns a [`TSQuery`].
7.802- * If a pattern is invalid, this returns `NULL`, and provides two pieces
7.803- * of information about the problem:
7.804- * 1. The byte offset of the error is written to the `error_offset` parameter.
7.805- * 2. The type of error is written to the `error_type` parameter.
7.806- */
7.807-TSQuery *ts_query_new(
7.808- const TSLanguage *language,
7.809- const char *source,
7.810- uint32_t source_len,
7.811- uint32_t *error_offset,
7.812- TSQueryError *error_type
7.813-);
7.814-
7.815-/**
7.816- * Delete a query, freeing all of the memory that it used.
7.817- */
7.818-void ts_query_delete(TSQuery *self);
7.819-
7.820-/**
7.821- * Get the number of patterns, captures, or string literals in the query.
7.822- */
7.823-uint32_t ts_query_pattern_count(const TSQuery *self);
7.824-uint32_t ts_query_capture_count(const TSQuery *self);
7.825-uint32_t ts_query_string_count(const TSQuery *self);
7.826-
7.827-/**
7.828- * Get the byte offset where the given pattern starts in the query's source.
7.829- *
7.830- * This can be useful when combining queries by concatenating their source
7.831- * code strings.
7.832- */
7.833-uint32_t ts_query_start_byte_for_pattern(const TSQuery *self, uint32_t pattern_index);
7.834-
7.835-/**
7.836- * Get all of the predicates for the given pattern in the query.
7.837- *
7.838- * The predicates are represented as a single array of steps. There are three
7.839- * types of steps in this array, which correspond to the three legal values for
7.840- * the `type` field:
7.841- * - `TSQueryPredicateStepTypeCapture` - Steps with this type represent names
7.842- * of captures. Their `value_id` can be used with the
7.843- * [`ts_query_capture_name_for_id`] function to obtain the name of the capture.
7.844- * - `TSQueryPredicateStepTypeString` - Steps with this type represent literal
7.845- * strings. Their `value_id` can be used with the
7.846- * [`ts_query_string_value_for_id`] function to obtain their string value.
7.847- * - `TSQueryPredicateStepTypeDone` - Steps with this type are *sentinels*
7.848- * that represent the end of an individual predicate. If a pattern has two
7.849- * predicates, then there will be two steps with this `type` in the array.
7.850- */
7.851-const TSQueryPredicateStep *ts_query_predicates_for_pattern(
7.852- const TSQuery *self,
7.853- uint32_t pattern_index,
7.854- uint32_t *step_count
7.855-);
7.856-
7.857-/*
7.858- * Check if the given pattern in the query has a single root node.
7.859- */
7.860-bool ts_query_is_pattern_rooted(const TSQuery *self, uint32_t pattern_index);
7.861-
7.862-/*
7.863- * Check if the given pattern in the query is 'non local'.
7.864- *
7.865- * A non-local pattern has multiple root nodes and can match within a
7.866- * repeating sequence of nodes, as specified by the grammar. Non-local
7.867- * patterns disable certain optimizations that would otherwise be possible
7.868- * when executing a query on a specific range of a syntax tree.
7.869- */
7.870-bool ts_query_is_pattern_non_local(const TSQuery *self, uint32_t pattern_index);
7.871-
7.872-/*
7.873- * Check if a given pattern is guaranteed to match once a given step is reached.
7.874- * The step is specified by its byte offset in the query's source code.
7.875- */
7.876-bool ts_query_is_pattern_guaranteed_at_step(const TSQuery *self, uint32_t byte_offset);
7.877-
7.878-/**
7.879- * Get the name and length of one of the query's captures, or one of the
7.880- * query's string literals. Each capture and string is associated with a
7.881- * numeric id based on the order that it appeared in the query's source.
7.882- */
7.883-const char *ts_query_capture_name_for_id(
7.884- const TSQuery *self,
7.885- uint32_t index,
7.886- uint32_t *length
7.887-);
7.888-
7.889-/**
7.890- * Get the quantifier of the query's captures. Each capture is * associated
7.891- * with a numeric id based on the order that it appeared in the query's source.
7.892- */
7.893-TSQuantifier ts_query_capture_quantifier_for_id(
7.894- const TSQuery *self,
7.895- uint32_t pattern_index,
7.896- uint32_t capture_index
7.897-);
7.898-
7.899-const char *ts_query_string_value_for_id(
7.900- const TSQuery *self,
7.901- uint32_t index,
7.902- uint32_t *length
7.903-);
7.904-
7.905-/**
7.906- * Disable a certain capture within a query.
7.907- *
7.908- * This prevents the capture from being returned in matches, and also avoids
7.909- * any resource usage associated with recording the capture. Currently, there
7.910- * is no way to undo this.
7.911- */
7.912-void ts_query_disable_capture(TSQuery *self, const char *name, uint32_t length);
7.913-
7.914-/**
7.915- * Disable a certain pattern within a query.
7.916- *
7.917- * This prevents the pattern from matching and removes most of the overhead
7.918- * associated with the pattern. Currently, there is no way to undo this.
7.919- */
7.920-void ts_query_disable_pattern(TSQuery *self, uint32_t pattern_index);
7.921-
7.922-/**
7.923- * Create a new cursor for executing a given query.
7.924- *
7.925- * The cursor stores the state that is needed to iteratively search
7.926- * for matches. To use the query cursor, first call [`ts_query_cursor_exec`]
7.927- * to start running a given query on a given syntax node. Then, there are
7.928- * two options for consuming the results of the query:
7.929- * 1. Repeatedly call [`ts_query_cursor_next_match`] to iterate over all of the
7.930- * *matches* in the order that they were found. Each match contains the
7.931- * index of the pattern that matched, and an array of captures. Because
7.932- * multiple patterns can match the same set of nodes, one match may contain
7.933- * captures that appear *before* some of the captures from a previous match.
7.934- * 2. Repeatedly call [`ts_query_cursor_next_capture`] to iterate over all of the
7.935- * individual *captures* in the order that they appear. This is useful if
7.936- * don't care about which pattern matched, and just want a single ordered
7.937- * sequence of captures.
7.938- *
7.939- * If you don't care about consuming all of the results, you can stop calling
7.940- * [`ts_query_cursor_next_match`] or [`ts_query_cursor_next_capture`] at any point.
7.941- * You can then start executing another query on another node by calling
7.942- * [`ts_query_cursor_exec`] again.
7.943- */
7.944-TSQueryCursor *ts_query_cursor_new(void);
7.945-
7.946-/**
7.947- * Delete a query cursor, freeing all of the memory that it used.
7.948- */
7.949-void ts_query_cursor_delete(TSQueryCursor *self);
7.950-
7.951-/**
7.952- * Start running a given query on a given node.
7.953- */
7.954-void ts_query_cursor_exec(TSQueryCursor *self, const TSQuery *query, TSNode node);
7.955-
7.956-/**
7.957- * Manage the maximum number of in-progress matches allowed by this query
7.958- * cursor.
7.959- *
7.960- * Query cursors have an optional maximum capacity for storing lists of
7.961- * in-progress captures. If this capacity is exceeded, then the
7.962- * earliest-starting match will silently be dropped to make room for further
7.963- * matches. This maximum capacity is optional — by default, query cursors allow
7.964- * any number of pending matches, dynamically allocating new space for them as
7.965- * needed as the query is executed.
7.966- */
7.967-bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *self);
7.968-uint32_t ts_query_cursor_match_limit(const TSQueryCursor *self);
7.969-void ts_query_cursor_set_match_limit(TSQueryCursor *self, uint32_t limit);
7.970-
7.971-/**
7.972- * Set the range of bytes or (row, column) positions in which the query
7.973- * will be executed.
7.974- */
7.975-void ts_query_cursor_set_byte_range(TSQueryCursor *self, uint32_t start_byte, uint32_t end_byte);
7.976-void ts_query_cursor_set_point_range(TSQueryCursor *self, TSPoint start_point, TSPoint end_point);
7.977-
7.978-/**
7.979- * Advance to the next match of the currently running query.
7.980- *
7.981- * If there is a match, write it to `*match` and return `true`.
7.982- * Otherwise, return `false`.
7.983- */
7.984-bool ts_query_cursor_next_match(TSQueryCursor *self, TSQueryMatch *match);
7.985-void ts_query_cursor_remove_match(TSQueryCursor *self, uint32_t match_id);
7.986-
7.987-/**
7.988- * Advance to the next capture of the currently running query.
7.989- *
7.990- * If there is a capture, write its match to `*match` and its index within
7.991- * the matche's capture list to `*capture_index`. Otherwise, return `false`.
7.992- */
7.993-bool ts_query_cursor_next_capture(
7.994- TSQueryCursor *self,
7.995- TSQueryMatch *match,
7.996- uint32_t *capture_index
7.997-);
7.998-
7.999-/**
7.1000- * Set the maximum start depth for a query cursor.
7.1001- *
7.1002- * This prevents cursors from exploring children nodes at a certain depth.
7.1003- * Note if a pattern includes many children, then they will still be checked.
7.1004- *
7.1005- * The zero max start depth value can be used as a special behavior and
7.1006- * it helps to destructure a subtree by staying on a node and using captures
7.1007- * for interested parts. Note that the zero max start depth only limit a search
7.1008- * depth for a pattern's root node but other nodes that are parts of the pattern
7.1009- * may be searched at any depth what defined by the pattern structure.
7.1010- *
7.1011- * Set to `UINT32_MAX` to remove the maximum start depth.
7.1012- */
7.1013-void ts_query_cursor_set_max_start_depth(TSQueryCursor *self, uint32_t max_start_depth);
7.1014-
7.1015-/**********************/
7.1016-/* Section - Language */
7.1017-/**********************/
7.1018-
7.1019-/**
7.1020- * Get the number of distinct node types in the language.
7.1021- */
7.1022-uint32_t ts_language_symbol_count(const TSLanguage *self);
7.1023-
7.1024-/**
7.1025- * Get the number of valid states in this language.
7.1026-*/
7.1027-uint32_t ts_language_state_count(const TSLanguage *self);
7.1028-
7.1029-/**
7.1030- * Get a node type string for the given numerical id.
7.1031- */
7.1032-const char *ts_language_symbol_name(const TSLanguage *self, TSSymbol symbol);
7.1033-
7.1034-/**
7.1035- * Get the numerical id for the given node type string.
7.1036- */
7.1037-TSSymbol ts_language_symbol_for_name(
7.1038- const TSLanguage *self,
7.1039- const char *string,
7.1040- uint32_t length,
7.1041- bool is_named
7.1042-);
7.1043-
7.1044-/**
7.1045- * Get the number of distinct field names in the language.
7.1046- */
7.1047-uint32_t ts_language_field_count(const TSLanguage *self);
7.1048-
7.1049-/**
7.1050- * Get the field name string for the given numerical id.
7.1051- */
7.1052-const char *ts_language_field_name_for_id(const TSLanguage *self, TSFieldId id);
7.1053-
7.1054-/**
7.1055- * Get the numerical id for the given field name string.
7.1056- */
7.1057-TSFieldId ts_language_field_id_for_name(const TSLanguage *self, const char *name, uint32_t name_length);
7.1058-
7.1059-/**
7.1060- * Check whether the given node type id belongs to named nodes, anonymous nodes,
7.1061- * or a hidden nodes.
7.1062- *
7.1063- * See also [`ts_node_is_named`]. Hidden nodes are never returned from the API.
7.1064- */
7.1065-TSSymbolType ts_language_symbol_type(const TSLanguage *self, TSSymbol symbol);
7.1066-
7.1067-/**
7.1068- * Get the ABI version number for this language. This version number is used
7.1069- * to ensure that languages were generated by a compatible version of
7.1070- * Tree-sitter.
7.1071- *
7.1072- * See also [`ts_parser_set_language`].
7.1073- */
7.1074-uint32_t ts_language_version(const TSLanguage *self);
7.1075-
7.1076-/**
7.1077- * Get the next parse state. Combine this with lookahead iterators to generate
7.1078- * completion suggestions or valid symbols in error nodes. Use
7.1079- * [`ts_node_grammar_symbol`] for valid symbols.
7.1080-*/
7.1081-TSStateId ts_language_next_state(const TSLanguage *self, TSStateId state, TSSymbol symbol);
7.1082-
7.1083-/********************************/
7.1084-/* Section - Lookahead Iterator */
7.1085-/********************************/
7.1086-
7.1087-/**
7.1088- * Create a new lookahead iterator for the given language and parse state.
7.1089- *
7.1090- * This returns `NULL` if state is invalid for the language.
7.1091- *
7.1092- * Repeatedly using [`ts_lookahead_iterator_next`] and
7.1093- * [`ts_lookahead_iterator_current_symbol`] will generate valid symbols in the
7.1094- * given parse state. Newly created lookahead iterators will contain the `ERROR`
7.1095- * symbol.
7.1096- *
7.1097- * Lookahead iterators can be useful to generate suggestions and improve syntax
7.1098- * error diagnostics. To get symbols valid in an ERROR node, use the lookahead
7.1099- * iterator on its first leaf node state. For `MISSING` nodes, a lookahead
7.1100- * iterator created on the previous non-extra leaf node may be appropriate.
7.1101-*/
7.1102-TSLookaheadIterator *ts_lookahead_iterator_new(const TSLanguage *self, TSStateId state);
7.1103-
7.1104-/**
7.1105- * Delete a lookahead iterator freeing all the memory used.
7.1106-*/
7.1107-void ts_lookahead_iterator_delete(TSLookaheadIterator *self);
7.1108-
7.1109-/**
7.1110- * Reset the lookahead iterator to another state.
7.1111- *
7.1112- * This returns `true` if the iterator was reset to the given state and `false`
7.1113- * otherwise.
7.1114-*/
7.1115-bool ts_lookahead_iterator_reset_state(TSLookaheadIterator *self, TSStateId state);
7.1116-
7.1117-/**
7.1118- * Reset the lookahead iterator.
7.1119- *
7.1120- * This returns `true` if the language was set successfully and `false`
7.1121- * otherwise.
7.1122-*/
7.1123-bool ts_lookahead_iterator_reset(TSLookaheadIterator *self, const TSLanguage *language, TSStateId state);
7.1124-
7.1125-/**
7.1126- * Get the current language of the lookahead iterator.
7.1127-*/
7.1128-const TSLanguage *ts_lookahead_iterator_language(const TSLookaheadIterator *self);
7.1129-
7.1130-/**
7.1131- * Advance the lookahead iterator to the next symbol.
7.1132- *
7.1133- * This returns `true` if there is a new symbol and `false` otherwise.
7.1134-*/
7.1135-bool ts_lookahead_iterator_next(TSLookaheadIterator *self);
7.1136-
7.1137-/**
7.1138- * Get the current symbol of the lookahead iterator;
7.1139-*/
7.1140-TSSymbol ts_lookahead_iterator_current_symbol(const TSLookaheadIterator *self);
7.1141-
7.1142-/**
7.1143- * Get the current symbol type of the lookahead iterator as a null terminated
7.1144- * string.
7.1145-*/
7.1146-const char *ts_lookahead_iterator_current_symbol_name(const TSLookaheadIterator *self);
7.1147-
7.1148-/**********************************/
7.1149-/* Section - Global Configuration */
7.1150-/**********************************/
7.1151-
7.1152-/**
7.1153- * Set the allocation functions used by the library.
7.1154- *
7.1155- * By default, Tree-sitter uses the standard libc allocation functions,
7.1156- * but aborts the process when an allocation fails. This function lets
7.1157- * you supply alternative allocation functions at runtime.
7.1158- *
7.1159- * If you pass `NULL` for any parameter, Tree-sitter will switch back to
7.1160- * its default implementation of that function.
7.1161- *
7.1162- * If you call this function after the library has already been used, then
7.1163- * you must ensure that either:
7.1164- * 1. All the existing objects have been freed.
7.1165- * 2. The new allocator shares its state with the old one, so it is capable
7.1166- * of freeing memory that was allocated by the old allocator.
7.1167- */
7.1168-void ts_set_allocator(
7.1169- void *(*new_malloc)(size_t),
7.1170- void *(*new_calloc)(size_t, size_t),
7.1171- void *(*new_realloc)(void *, size_t),
7.1172- void (*new_free)(void *)
7.1173-);
7.1174-
7.1175-#ifdef __cplusplus
7.1176-}
7.1177-#endif
7.1178-
7.1179-#if defined(__GNUC__) || defined(__clang__)
7.1180-#pragma GCC visibility pop
7.1181-#endif
7.1182-
7.1183-#endif // TREE_SITTER_API_H_
8.1--- a/lisp/ffi/ublk/srv.lisp Fri Oct 04 16:14:44 2024 -0400
8.2+++ b/lisp/ffi/ublk/srv.lisp Fri Oct 04 21:11:52 2024 -0400
8.3@@ -6,22 +6,7 @@
8.4 (in-package :ublk)
8.5
8.6 (define-alien-type ublksrv-ctrl-dev (struct ublksrv-ctrl-dev))
8.7-
8.8-(define-alien-type ublksrv-queue
8.9- (struct ublksrv-queue
8.10- (q-id int)
8.11- (q-depth int)
8.12- (ring-ptr (* io-uring))
8.13- (dev (* ublksrv-dev))
8.14- (private-data (* t))))
8.15-
8.16-(define-alien-type ublk-io-data
8.17- (struct ublk-io-data
8.18- (tag int)
8.19- (pad unsigned-int)
8.20- (iod (* ublksrv-io-desc))
8.21- (private-data (* t))))
8.22-
8.23+(define-alien-type ublksrv-tgt-type (struct ublksrv-tgt-type))
8.24 ;; TODO 2024-09-29: add all of these as callbacks :C
8.25 ;; (define-alien-type ublksrv-tgt-type
8.26 ;; (struct ublksrv-tgt-type
8.27@@ -76,6 +61,21 @@
8.28 (struct ublksrv-dev
8.29 (tgt ublksrv-tgt-info)))
8.30
8.31+(define-alien-type ublksrv-queue
8.32+ (struct ublksrv-queue
8.33+ (q-id int)
8.34+ (q-depth int)
8.35+ (ring-ptr (* io-uring))
8.36+ (dev (* ublksrv-dev))
8.37+ (private-data (* t))))
8.38+
8.39+(define-alien-type ublk-io-data
8.40+ (struct ublk-io-data
8.41+ (tag int)
8.42+ (pad unsigned-int)
8.43+ (iod (* ublksrv-io-desc))
8.44+ (private-data (* t))))
8.45+
8.46 (define-alien-routine build-user-data (unsigned 64)
8.47 (tag unsigned)
8.48 (op unsigned)
9.1--- a/lisp/ffi/xkb/tests.lisp Fri Oct 04 16:14:44 2024 -0400
9.2+++ b/lisp/ffi/xkb/tests.lisp Fri Oct 04 21:11:52 2024 -0400
9.3@@ -7,7 +7,7 @@
9.4 (load-xkbcommon)
9.5
9.6 (deftest xkb-basic ()
9.7- (is (= xkb:xkb-keysym-max 536870911))
9.8+ (is (= xkb::+xkb-keysym-max+ 536870911))
9.9 (let* ((ctx (xkb:xkb-context-new (xkb-context-flags :no-flags)))
9.10 (map (xkb::xkb-keymap-new-from-names ctx nil (xkb::xkb-keymap-compile-flags :no-flags)))
9.11 (state (xkb::xkb-state-new map)))
10.1--- a/lisp/ffi/zstd/dict.lisp Fri Oct 04 16:14:44 2024 -0400
10.2+++ b/lisp/ffi/zstd/dict.lisp Fri Oct 04 21:11:52 2024 -0400
10.3@@ -315,3 +315,38 @@
10.4 (shrink-dict unsigned)
10.5 (shrink-dict-max-regression unsigned)
10.6 (zparams zdict-params)))
10.7+
10.8+(define-alien-routine ("ZDICT_trainFromBuffer" zdict-train-from-buffer) size-t
10.9+ (dict-buffer (* t))
10.10+ (dict-buffer-capacity size-t)
10.11+ (samples-buffer (* t))
10.12+ (samples-sizes (* size-t))
10.13+ (nb-samples unsigned))
10.14+
10.15+(define-alien-type zdict-params
10.16+ (struct zdict-params-t
10.17+ (compression-level int)
10.18+ (notification-level unsigned)
10.19+ (dict-id unsigned)))
10.20+
10.21+;; Requires returning struct by value
10.22+;; (define-alien-routine ("ZDICT_finalizeDictionary" zdict-finalize-dictionary) size-t
10.23+;; (dst-dict-buffer (* t))
10.24+;; (max-dict-size size-t)
10.25+;; (dict-content (* t))
10.26+;; (dict-content-size size-t)
10.27+;; (samples-buffer (* t))
10.28+;; (samples-sizes (* size-t))
10.29+;; (nb-samples unsigned)
10.30+;; (parameters zdict-params))
10.31+
10.32+(define-alien-routine ("ZDICT_getDictID" zdict-get-dict-id) unsigned
10.33+ (dict-buffer (* t))
10.34+ (dict-size size-t))
10.35+
10.36+(define-alien-routine ("ZDICT_getDictHeaderSize" zdict-get-dict-header-size) size-t
10.37+ (dict-buffer (* t))
10.38+ (dict-size size-t))
10.39+
10.40+(define-alien-routine ("ZDICT_isError" zdict-is-error) unsigned
10.41+ (error-code size-t))
11.1--- a/lisp/lib/cli/tests/shell.lisp Fri Oct 04 16:14:44 2024 -0400
11.2+++ b/lisp/lib/cli/tests/shell.lisp Fri Oct 04 21:11:52 2024 -0400
11.3@@ -5,9 +5,8 @@
11.4 ;;; Code:
11.5 (in-package :cli/tests)
11.6 (in-suite :cli)
11.7-
11.8-(defparameter *shell-test-fn* #$ls #,*default-pathname-defaults* $#)
11.9-
11.10+(in-readtable :shell)
11.11 (deftest shell-reader ()
11.12- (in-readtable :shell)
11.13- (is (functionp *shell-test-fn*)))
11.14+ ;; can't dump functions
11.15+ ;; (is #$ls #,*default-pathname-defaults* $#)
11.16+)
12.1--- a/lisp/lib/rdb/err.lisp Fri Oct 04 16:14:44 2024 -0400
12.2+++ b/lisp/lib/rdb/err.lisp Fri Oct 04 21:11:52 2024 -0400
12.3@@ -5,15 +5,15 @@
12.4 ;;; Code:
12.5 (in-package :rdb)
12.6
12.7-(deferror rdb-error ()
12.8- ((message :initarg :message
12.9- :reader rdb-error-message))
12.10- (:auto t)
12.11- (:documentation "Error signaled by the RDB system."))
12.12-
12.13-(define-condition rocksdb-alien-error (rdb-error)
12.14- ((db :initarg :db :reader rdb-error-db))
12.15- (:documentation "Error signaled by RocksDB subsystem."))
12.16+(eval-always
12.17+ (deferror rdb-error ()
12.18+ ((message :initarg :message
12.19+ :reader rdb-error-message))
12.20+ (:auto t)
12.21+ (:documentation "Error signaled by the RDB system."))
12.22+ (define-condition rocksdb-alien-error (rdb-error)
12.23+ ((db :initarg :db :reader rdb-error-db))
12.24+ (:documentation "Error signaled by RocksDB subsystem.")))
12.25
12.26 (defmethod print-object ((obj rdb-error) stream)
12.27 (print-unreadable-object (obj stream :type t :identity t)
13.1--- a/lisp/lib/skel/core/obj.lisp Fri Oct 04 16:14:44 2024 -0400
13.2+++ b/lisp/lib/skel/core/obj.lisp Fri Oct 04 21:11:52 2024 -0400
13.3@@ -315,7 +315,7 @@
13.4 (sk-run rule))))))
13.5
13.6 (defun sk-run-with-sources (obj rule)
13.7- (when-let ((sources (sk-rule-source rule)))
13.8+ (when-let ((sources (and rule (sk-rule-source rule))))
13.9 (mapcar
13.10 (lambda (src)
13.11 (if-let* ((sr (sk-find-rule src obj)))
14.1--- a/lisp/std/condition.lisp Fri Oct 04 16:14:44 2024 -0400
14.2+++ b/lisp/std/condition.lisp Fri Oct 04 21:11:52 2024 -0400
14.3@@ -39,12 +39,12 @@
14.4 "Define an error condition."
14.5 (let ((fun (member :auto options :test #'car-eql)))
14.6 (when fun (setq options (remove (car fun) options)))
14.7- `(eval-when (:compile-toplevel :load-toplevel :execute) (prog1
14.8- (define-condition ,name ,(or parent-types '(std-error)) ,slot-specs ,@options)
14.9- (when ',fun
14.10- (if (member 'simple-error ',parent-types)
14.11- (def-simple-error-reporter ,name)
14.12- (def-error-reporter ,name)))))))
14.13+ `(prog1
14.14+ (define-condition ,name ,(or parent-types '(std-error)) ,slot-specs ,@options)
14.15+ (when ',fun
14.16+ (if (member 'simple-error ',parent-types)
14.17+ (def-simple-error-reporter ,name)
14.18+ (def-error-reporter ,name))))))
14.19
14.20 (defmacro def-error-reporter (err)
14.21 `(defun ,err (&rest args)
15.1--- a/lisp/std/pkg.lisp Fri Oct 04 16:14:44 2024 -0400
15.2+++ b/lisp/std/pkg.lisp Fri Oct 04 21:11:52 2024 -0400
15.3@@ -359,7 +359,7 @@
15.4 (defpkg :std/task
15.5 (:use :cl :std/thread :sb-concurrency)
15.6 (:import-from :std/thread :%make-thread)
15.7- (:import-from :std/macs :if-let)
15.8+ (:import-from :std/macs :if-let :eval-always)
15.9 (:import-from :std/list :deletef)
15.10 (:export
15.11 :spawn-workers
15.12@@ -368,7 +368,7 @@
15.13 :oracle-id :find-thread
15.14 :push-job :push-task
15.15 :push-worker :push-task-result
15.16- :run :run-object
15.17+ :run-object
15.18 :work
15.19 :pop-job :pop-task
15.20 :workers
16.1--- a/lisp/std/task.lisp Fri Oct 04 16:14:44 2024 -0400
16.2+++ b/lisp/std/task.lisp Fri Oct 04 21:11:52 2024 -0400
16.3@@ -15,7 +15,7 @@
16.4 (sb-ext:defglobal *oracle-threads* nil)
16.5 (sb-ext:defglobal *supervisor-threads* nil)
16.6
16.7-(eval-when (:compile-toplevel)
16.8+(eval-always
16.9 (defvar *task*)
16.10 (defvar *task-result* nil))
16.11
16.12@@ -73,7 +73,6 @@
16.13
16.14 (defgeneric tasks (self))
16.15 (defgeneric results (self))
16.16-(defgeneric run (self object &rest initargs &key &allow-other-keys))
16.17 (defgeneric run-object (self))
16.18 (defgeneric work (self &key &allow-other-keys))
16.19 (defgeneric workers (self))
16.20@@ -128,8 +127,8 @@
16.21 (defmethod run-object ((self worker))
16.22 (run-worker self))
16.23
16.24-(defmethod run ((self worker) (object t) &key wait &allow-other-keys)
16.25- (run-worker self :input object :wait wait))
16.26+(defun run-with-worker (worker object &key wait)
16.27+ (run-worker worker :input object :wait wait))
16.28
16.29 (defun kill-worker (worker)
16.30 (declare (worker worker))
17.1--- a/skelfile Fri Oct 04 16:14:44 2024 -0400
17.2+++ b/skelfile Fri Oct 04 21:11:52 2024 -0400
17.3@@ -47,12 +47,14 @@
17.4 (download "https://publicsuffix.org/list/public_suffix_list.dat"
17.5 :output (merge-pathnames
17.6 ".stash/psl.dat"
17.7- *skel-path*)))
17.8+ *skel-path*)
17.9+ :if-exists :supersede))
17.10 (rgb.txt (%stash)
17.11 (download "https://packy.compiler.company/data/rgb.txt"
17.12 :output (merge-pathnames
17.13 ".stash/rgb.txt"
17.14- *skel-path*)))
17.15+ *skel-path*)
17.16+ :if-exists :supersede))
17.17 (x11.lisp (rgb.txt)
17.18 (color::parse-x11-color-definitions
17.19 :input ".stash/rgb.txt"
17.20@@ -60,16 +62,19 @@
17.21 (parquet.thrift (%stash)
17.22 (download
17.23 "https://raw.githubusercontent.com/apache/parquet-format/master/src/main/thrift/parquet.thrift"
17.24- :output (merge-pathnames ".stash/parquet.thrift" *skel-path*))
17.25+ :output (merge-pathnames ".stash/parquet.thrift" *skel-path*)
17.26+ :if-exists :supersede)
17.27 #$thrift --gen json -out .stash .stash/parquet.thrift$#)
17.28 (parquet.json (%stash)
17.29 (download "https://packy.compiler.company/data/parquet.json"
17.30- :output (merge-pathnames ".stash/parquet.json" *skel-path*)))
17.31+ :output (merge-pathnames ".stash/parquet.json" *skel-path*)
17.32+ :if-exists :supersede))
17.33 (freedesktop.org.xml (%stash)
17.34 (download "https://packy.compiler.company/data/freedesktop.org.xml"
17.35 :output (merge-pathnames ".stash/freedesktop.org.xml" *skel-path*)))
17.36 (parquet-test-data (%stash) (download "https://packy.compiler.company/data/test/alltypes_plain.parquet"
17.37- :output (merge-pathnames ".stash/alltypes_plain.parquet" *skel-path*)))
17.38+ :output (merge-pathnames ".stash/alltypes_plain.parquet" *skel-path*)
17.39+ :if-exists :supersede))
17.40 ;; lisp
17.41 (%stash () #$mkdir -pv .stash$#)
17.42 (rdb (%stash)