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