Skip to content

Commit

Permalink
Merge pull request #156 from micksmix/master
Browse files Browse the repository at this point in the history
Upgraded treesitter to latest version, v0.22.5
  • Loading branch information
smacker authored Apr 22, 2024
2 parents 99ab967 + 169cf1e commit 31bae7b
Show file tree
Hide file tree
Showing 20 changed files with 932 additions and 479 deletions.
2 changes: 1 addition & 1 deletion _automation/treesitter_updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

// Constants for the Tree Sitter version and download URL
const sitterVersion = "0.20.9"
const sitterVersion = "0.22.5"
const sitterURL = "https://github.com/tree-sitter/tree-sitter/archive/refs/tags/v" + sitterVersion + ".tar.gz"

func main() {
Expand Down
9 changes: 5 additions & 4 deletions alloc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "alloc.h"
#include "api.h"
#include <stdlib.h>

static void *ts_malloc_default(size_t size) {
Expand Down Expand Up @@ -29,10 +30,10 @@ static void *ts_realloc_default(void *buffer, size_t size) {
}

// Allow clients to override allocation functions dynamically
void *(*ts_current_malloc)(size_t) = ts_malloc_default;
void *(*ts_current_calloc)(size_t, size_t) = ts_calloc_default;
void *(*ts_current_realloc)(void *, size_t) = ts_realloc_default;
void (*ts_current_free)(void *) = free;
TS_PUBLIC void *(*ts_current_malloc)(size_t) = ts_malloc_default;
TS_PUBLIC void *(*ts_current_calloc)(size_t, size_t) = ts_calloc_default;
TS_PUBLIC void *(*ts_current_realloc)(void *, size_t) = ts_realloc_default;
TS_PUBLIC void (*ts_current_free)(void *) = free;

void ts_set_allocator(
void *(*new_malloc)(size_t size),
Expand Down
20 changes: 12 additions & 8 deletions alloc.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#ifndef TREE_SITTER_ALLOC_H_
#define TREE_SITTER_ALLOC_H_

#include "api.h"

#ifdef __cplusplus
extern "C" {
#endif

#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#if defined(TREE_SITTER_HIDDEN_SYMBOLS) || defined(_WIN32)
#define TS_PUBLIC
#else
#define TS_PUBLIC __attribute__((visibility("default")))
#endif

extern void *(*ts_current_malloc)(size_t);
extern void *(*ts_current_calloc)(size_t, size_t);
extern void *(*ts_current_realloc)(void *, size_t);
extern void (*ts_current_free)(void *);
TS_PUBLIC extern void *(*ts_current_malloc)(size_t);
TS_PUBLIC extern void *(*ts_current_calloc)(size_t, size_t);
TS_PUBLIC extern void *(*ts_current_realloc)(void *, size_t);
TS_PUBLIC extern void (*ts_current_free)(void *);

// Allow clients to override allocation functions
#ifndef ts_malloc
Expand All @@ -34,4 +38,4 @@ extern void (*ts_current_free)(void *);
}
#endif

#endif // TREE_SITTER_ALLOC_H_
#endif // TREE_SITTER_ALLOC_H_
56 changes: 38 additions & 18 deletions api.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef TREE_SITTER_API_H_
#define TREE_SITTER_API_H_

#ifndef TREE_SITTER_HIDE_SYMBOLS
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC visibility push(default)
#endif
#endif

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -46,46 +48,46 @@ typedef struct TSQuery TSQuery;
typedef struct TSQueryCursor TSQueryCursor;
typedef struct TSLookaheadIterator TSLookaheadIterator;

typedef enum {
typedef enum TSInputEncoding {
TSInputEncodingUTF8,
TSInputEncodingUTF16,
} TSInputEncoding;

typedef enum {
typedef enum TSSymbolType {
TSSymbolTypeRegular,
TSSymbolTypeAnonymous,
TSSymbolTypeAuxiliary,
} TSSymbolType;

typedef struct {
typedef struct TSPoint {
uint32_t row;
uint32_t column;
} TSPoint;

typedef struct {
typedef struct TSRange {
TSPoint start_point;
TSPoint end_point;
uint32_t start_byte;
uint32_t end_byte;
} TSRange;

typedef struct {
typedef struct TSInput {
void *payload;
const char *(*read)(void *payload, uint32_t byte_index, TSPoint position, uint32_t *bytes_read);
TSInputEncoding encoding;
} TSInput;

typedef enum {
typedef enum TSLogType {
TSLogTypeParse,
TSLogTypeLex,
} TSLogType;

typedef struct {
typedef struct TSLogger {
void *payload;
void (*log)(void *payload, TSLogType log_type, const char *buffer);
} TSLogger;

typedef struct {
typedef struct TSInputEdit {
uint32_t start_byte;
uint32_t old_end_byte;
uint32_t new_end_byte;
Expand All @@ -94,50 +96,50 @@ typedef struct {
TSPoint new_end_point;
} TSInputEdit;

typedef struct {
typedef struct TSNode {
uint32_t context[4];
const void *id;
const TSTree *tree;
} TSNode;

typedef struct {
typedef struct TSTreeCursor {
const void *tree;
const void *id;
uint32_t context[2];
uint32_t context[3];
} TSTreeCursor;

typedef struct {
typedef struct TSQueryCapture {
TSNode node;
uint32_t index;
} TSQueryCapture;

typedef enum {
typedef enum TSQuantifier {
TSQuantifierZero = 0, // must match the array initialization value
TSQuantifierZeroOrOne,
TSQuantifierZeroOrMore,
TSQuantifierOne,
TSQuantifierOneOrMore,
} TSQuantifier;

typedef struct {
typedef struct TSQueryMatch {
uint32_t id;
uint16_t pattern_index;
uint16_t capture_count;
const TSQueryCapture *captures;
} TSQueryMatch;

typedef enum {
typedef enum TSQueryPredicateStepType {
TSQueryPredicateStepTypeDone,
TSQueryPredicateStepTypeCapture,
TSQueryPredicateStepTypeString,
} TSQueryPredicateStepType;

typedef struct {
typedef struct TSQueryPredicateStep {
TSQueryPredicateStepType type;
uint32_t value_id;
} TSQueryPredicateStep;

typedef enum {
typedef enum TSQueryError {
TSQueryErrorNone = 0,
TSQueryErrorSyntax,
TSQueryErrorNodeType,
Expand Down Expand Up @@ -1013,6 +1015,17 @@ void ts_query_cursor_set_max_start_depth(TSQueryCursor *self, uint32_t max_start
/* Section - Language */
/**********************/

/**
* Get another reference to the given language.
*/
const TSLanguage *ts_language_copy(const TSLanguage *self);

/**
* Free any dynamically-allocated resources for this language, if
* this is the last reference.
*/
void ts_language_delete(const TSLanguage *self);

/**
* Get the number of distinct node types in the language.
*/
Expand Down Expand Up @@ -1190,9 +1203,14 @@ const TSLanguage *ts_wasm_store_load_language(
TSWasmError *error
);

/**
* Get the number of languages instantiated in the given wasm store.
*/
size_t ts_wasm_store_language_count(const TSWasmStore *);

/**
* Check if the language came from a Wasm module. If so, then in order to use
* this langauge with a Parser, that parser must have a Wasm store assigned.
* this language with a Parser, that parser must have a Wasm store assigned.
*/
bool ts_language_is_wasm(const TSLanguage *);

Expand Down Expand Up @@ -1239,8 +1257,10 @@ void ts_set_allocator(
}
#endif

#ifndef TREE_SITTER_HIDE_SYMBOLS
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC visibility pop
#endif
#endif

#endif // TREE_SITTER_API_H_
Loading

0 comments on commit 31bae7b

Please sign in to comment.