Skip to content

Commit c890dce

Browse files
committed
updated tree-sitter to v0.21.0
1 parent 99ab967 commit c890dce

File tree

13 files changed

+249
-116
lines changed

13 files changed

+249
-116
lines changed

_automation/treesitter_updater/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

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

2222
func main() {

api.h

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,46 +46,46 @@ typedef struct TSQuery TSQuery;
4646
typedef struct TSQueryCursor TSQueryCursor;
4747
typedef struct TSLookaheadIterator TSLookaheadIterator;
4848

49-
typedef enum {
49+
typedef enum TSInputEncoding {
5050
TSInputEncodingUTF8,
5151
TSInputEncodingUTF16,
5252
} TSInputEncoding;
5353

54-
typedef enum {
54+
typedef enum TSSymbolType {
5555
TSSymbolTypeRegular,
5656
TSSymbolTypeAnonymous,
5757
TSSymbolTypeAuxiliary,
5858
} TSSymbolType;
5959

60-
typedef struct {
60+
typedef struct TSPoint {
6161
uint32_t row;
6262
uint32_t column;
6363
} TSPoint;
6464

65-
typedef struct {
65+
typedef struct TSRange {
6666
TSPoint start_point;
6767
TSPoint end_point;
6868
uint32_t start_byte;
6969
uint32_t end_byte;
7070
} TSRange;
7171

72-
typedef struct {
72+
typedef struct TSInput {
7373
void *payload;
7474
const char *(*read)(void *payload, uint32_t byte_index, TSPoint position, uint32_t *bytes_read);
7575
TSInputEncoding encoding;
7676
} TSInput;
7777

78-
typedef enum {
78+
typedef enum TSLogType {
7979
TSLogTypeParse,
8080
TSLogTypeLex,
8181
} TSLogType;
8282

83-
typedef struct {
83+
typedef struct TSLogger {
8484
void *payload;
8585
void (*log)(void *payload, TSLogType log_type, const char *buffer);
8686
} TSLogger;
8787

88-
typedef struct {
88+
typedef struct TSInputEdit {
8989
uint32_t start_byte;
9090
uint32_t old_end_byte;
9191
uint32_t new_end_byte;
@@ -94,50 +94,50 @@ typedef struct {
9494
TSPoint new_end_point;
9595
} TSInputEdit;
9696

97-
typedef struct {
97+
typedef struct TSNode {
9898
uint32_t context[4];
9999
const void *id;
100100
const TSTree *tree;
101101
} TSNode;
102102

103-
typedef struct {
103+
typedef struct TSTreeCursor {
104104
const void *tree;
105105
const void *id;
106106
uint32_t context[2];
107107
} TSTreeCursor;
108108

109-
typedef struct {
109+
typedef struct TSQueryCapture {
110110
TSNode node;
111111
uint32_t index;
112112
} TSQueryCapture;
113113

114-
typedef enum {
114+
typedef enum TSQuantifier {
115115
TSQuantifierZero = 0, // must match the array initialization value
116116
TSQuantifierZeroOrOne,
117117
TSQuantifierZeroOrMore,
118118
TSQuantifierOne,
119119
TSQuantifierOneOrMore,
120120
} TSQuantifier;
121121

122-
typedef struct {
122+
typedef struct TSQueryMatch {
123123
uint32_t id;
124124
uint16_t pattern_index;
125125
uint16_t capture_count;
126126
const TSQueryCapture *captures;
127127
} TSQueryMatch;
128128

129-
typedef enum {
129+
typedef enum TSQueryPredicateStepType {
130130
TSQueryPredicateStepTypeDone,
131131
TSQueryPredicateStepTypeCapture,
132132
TSQueryPredicateStepTypeString,
133133
} TSQueryPredicateStepType;
134134

135-
typedef struct {
135+
typedef struct TSQueryPredicateStep {
136136
TSQueryPredicateStepType type;
137137
uint32_t value_id;
138138
} TSQueryPredicateStep;
139139

140-
typedef enum {
140+
typedef enum TSQueryError {
141141
TSQueryErrorNone = 0,
142142
TSQueryErrorSyntax,
143143
TSQueryErrorNodeType,
@@ -1013,6 +1013,17 @@ void ts_query_cursor_set_max_start_depth(TSQueryCursor *self, uint32_t max_start
10131013
/* Section - Language */
10141014
/**********************/
10151015

1016+
/**
1017+
* Get another reference to the given language.
1018+
*/
1019+
const TSLanguage *ts_language_copy(const TSLanguage *self);
1020+
1021+
/**
1022+
* Free any dynamically-allocated resources for this language, if
1023+
* this is the last reference.
1024+
*/
1025+
void ts_language_delete(const TSLanguage *self);
1026+
10161027
/**
10171028
* Get the number of distinct node types in the language.
10181029
*/
@@ -1190,9 +1201,14 @@ const TSLanguage *ts_wasm_store_load_language(
11901201
TSWasmError *error
11911202
);
11921203

1204+
/**
1205+
* Get the number of languages instantiated in the given wasm store.
1206+
*/
1207+
size_t ts_wasm_store_language_count(const TSWasmStore *);
1208+
11931209
/**
11941210
* Check if the language came from a Wasm module. If so, then in order to use
1195-
* this langauge with a Parser, that parser must have a Wasm store assigned.
1211+
* this language with a Parser, that parser must have a Wasm store assigned.
11961212
*/
11971213
bool ts_language_is_wasm(const TSLanguage *);
11981214

language.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
#include "./language.h"
2+
#include "./wasm.h"
3+
#include "api.h"
24
#include <string.h>
35

6+
const TSLanguage *ts_language_copy(const TSLanguage *self) {
7+
if (self && ts_language_is_wasm(self)) {
8+
ts_wasm_language_retain(self);
9+
}
10+
return self;
11+
}
12+
13+
void ts_language_delete(const TSLanguage *self) {
14+
if (self && ts_language_is_wasm(self)) {
15+
ts_wasm_language_release(self);
16+
}
17+
}
18+
419
uint32_t ts_language_symbol_count(const TSLanguage *self) {
520
return self->symbol_count + self->alias_count;
621
}

language.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern "C" {
66
#endif
77

88
#include "./subtree.h"
9-
#include "parser.h"
9+
#include "./parser.h"
1010

1111
#define ts_builtin_sym_error_repeat (ts_builtin_sym_error - 1)
1212

lexer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern "C" {
88
#include "./length.h"
99
#include "./subtree.h"
1010
#include "api.h"
11-
#include "parser.h"
11+
#include "./parser.h"
1212

1313
typedef struct {
1414
TSLexer data;

parser.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <stdio.h>
44
#include <limits.h>
55
#include <stdbool.h>
6+
#include <inttypes.h>
67
#include "api.h"
78
#include "./alloc.h"
89
#include "./array.h"
@@ -818,14 +819,14 @@ static bool ts_parser__select_tree(TSParser *self, Subtree left, Subtree right)
818819
}
819820

820821
if (ts_subtree_dynamic_precedence(right) > ts_subtree_dynamic_precedence(left)) {
821-
LOG("select_higher_precedence symbol:%s, prec:%u, over_symbol:%s, other_prec:%u",
822+
LOG("select_higher_precedence symbol:%s, prec:%" PRId32 ", over_symbol:%s, other_prec:%u",
822823
TREE_NAME(right), ts_subtree_dynamic_precedence(right), TREE_NAME(left),
823824
ts_subtree_dynamic_precedence(left));
824825
return true;
825826
}
826827

827828
if (ts_subtree_dynamic_precedence(left) > ts_subtree_dynamic_precedence(right)) {
828-
LOG("select_higher_precedence symbol:%s, prec:%u, over_symbol:%s, other_prec:%u",
829+
LOG("select_higher_precedence symbol:%s, prec:%" PRId32 ", over_symbol:%s, other_prec:%u",
829830
TREE_NAME(left), ts_subtree_dynamic_precedence(left), TREE_NAME(right),
830831
ts_subtree_dynamic_precedence(right));
831832
return false;
@@ -1768,7 +1769,7 @@ static unsigned ts_parser__condense_stack(TSParser *self) {
17681769
}
17691770
}
17701771

1771-
// Enfore a hard upper bound on the number of stack versions by
1772+
// Enforce a hard upper bound on the number of stack versions by
17721773
// discarding the least promising versions.
17731774
while (ts_stack_version_count(self->stack) > MAX_VERSION_COUNT) {
17741775
ts_stack_remove_version(self->stack, MAX_VERSION_COUNT);
@@ -1869,6 +1870,7 @@ const TSLanguage *ts_parser_language(const TSParser *self) {
18691870

18701871
bool ts_parser_set_language(TSParser *self, const TSLanguage *language) {
18711872
ts_parser__external_scanner_destroy(self);
1873+
ts_language_delete(self->language);
18721874
self->language = NULL;
18731875

18741876
if (language) {
@@ -1885,7 +1887,7 @@ bool ts_parser_set_language(TSParser *self, const TSLanguage *language) {
18851887
}
18861888
}
18871889

1888-
self->language = language;
1890+
self->language = ts_language_copy(language);
18891891
ts_parser__external_scanner_create(self);
18901892
ts_parser_reset(self);
18911893
return true;
@@ -2024,7 +2026,7 @@ TSTree *ts_parser_parse(
20242026
bool allow_node_reuse = version_count == 1;
20252027
while (ts_stack_is_active(self->stack, version)) {
20262028
LOG(
2027-
"process version:%d, version_count:%u, state:%d, row:%u, col:%u",
2029+
"process version:%u, version_count:%u, state:%d, row:%u, col:%u",
20282030
version,
20292031
ts_stack_version_count(self->stack),
20302032
ts_stack_state(self->stack, version),

query.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ typedef struct {
4242
* - `depth` - The depth where this node occurs in the pattern. The root node
4343
* of the pattern has depth zero.
4444
* - `negated_field_list_id` - An id representing a set of fields that must
45-
* that must not be present on a node matching this step.
45+
* not be present on a node matching this step.
4646
*
4747
* Steps have some additional fields in order to handle the `.` (or "anchor") operator,
4848
* which forbids additional child nodes:
@@ -1030,7 +1030,7 @@ static inline void analysis_state_set__delete(AnalysisStateSet *self) {
10301030
* QueryAnalyzer
10311031
****************/
10321032

1033-
static inline QueryAnalysis query_analysis__new() {
1033+
static inline QueryAnalysis query_analysis__new(void) {
10341034
return (QueryAnalysis) {
10351035
.states = array_new(),
10361036
.next_states = array_new(),
@@ -2312,15 +2312,8 @@ static TSQueryError ts_query__parse_pattern(
23122312
stream_scan_identifier(stream);
23132313
uint32_t length = (uint32_t)(stream->input - node_name);
23142314

2315-
// TODO - remove.
2316-
// For temporary backward compatibility, handle predicates without the leading '#' sign.
2317-
if (length > 0 && (node_name[length - 1] == '!' || node_name[length - 1] == '?')) {
2318-
stream_reset(stream, node_name);
2319-
return ts_query__parse_predicate(self, stream);
2320-
}
2321-
23222315
// Parse the wildcard symbol
2323-
else if (length == 1 && node_name[0] == '_') {
2316+
if (length == 1 && node_name[0] == '_') {
23242317
symbol = WILDCARD_SYMBOL;
23252318
}
23262319

@@ -2698,7 +2691,7 @@ TSQuery *ts_query_new(
26982691
.negated_fields = array_new(),
26992692
.repeat_symbols_with_rootless_patterns = array_new(),
27002693
.wildcard_root_pattern_count = 0,
2701-
.language = language,
2694+
.language = ts_language_copy(language),
27022695
};
27032696

27042697
array_push(&self->negated_fields, 0);
@@ -2812,6 +2805,7 @@ void ts_query_delete(TSQuery *self) {
28122805
array_delete(&self->string_buffer);
28132806
array_delete(&self->negated_fields);
28142807
array_delete(&self->repeat_symbols_with_rootless_patterns);
2808+
ts_language_delete(self->language);
28152809
symbol_table_delete(&self->captures);
28162810
symbol_table_delete(&self->predicate_values);
28172811
for (uint32_t index = 0; index < self->capture_quantifiers.size; index++) {
@@ -3848,7 +3842,7 @@ static inline bool ts_query_cursor__advance(
38483842
continue;
38493843
}
38503844

3851-
// Enfore the longest-match criteria. When a query pattern contains optional or
3845+
// Enforce the longest-match criteria. When a query pattern contains optional or
38523846
// repeated nodes, this is necessary to avoid multiple redundant states, where
38533847
// one state has a strict subset of another state's captures.
38543848
bool did_remove = false;

stack.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
#include "./stack.h"
66
#include "./length.h"
77
#include <assert.h>
8+
#include <inttypes.h>
89
#include <stdio.h>
910

1011
#define MAX_LINK_COUNT 8
1112
#define MAX_NODE_POOL_SIZE 50
1213
#define MAX_ITERATOR_COUNT 64
1314

1415
#if defined _WIN32 && !defined __GNUC__
15-
#define inline __forceinline
16+
#define forceinline __forceinline
1617
#else
17-
#define inline static inline __attribute__((always_inline))
18+
#define forceinline static inline __attribute__((always_inline))
1819
#endif
1920

2021
typedef struct StackNode StackNode;
@@ -509,7 +510,7 @@ void ts_stack_push(
509510
head->node = new_node;
510511
}
511512

512-
inline StackAction pop_count_callback(void *payload, const StackIterator *iterator) {
513+
forceinline StackAction pop_count_callback(void *payload, const StackIterator *iterator) {
513514
unsigned *goal_subtree_count = payload;
514515
if (iterator->subtree_count == *goal_subtree_count) {
515516
return StackActionPop | StackActionStop;
@@ -522,7 +523,7 @@ StackSliceArray ts_stack_pop_count(Stack *self, StackVersion version, uint32_t c
522523
return stack__iter(self, version, pop_count_callback, &count, (int)count);
523524
}
524525

525-
inline StackAction pop_pending_callback(void *payload, const StackIterator *iterator) {
526+
forceinline StackAction pop_pending_callback(void *payload, const StackIterator *iterator) {
526527
(void)payload;
527528
if (iterator->subtree_count >= 1) {
528529
if (iterator->is_pending) {
@@ -544,7 +545,7 @@ StackSliceArray ts_stack_pop_pending(Stack *self, StackVersion version) {
544545
return pop;
545546
}
546547

547-
inline StackAction pop_error_callback(void *payload, const StackIterator *iterator) {
548+
forceinline StackAction pop_error_callback(void *payload, const StackIterator *iterator) {
548549
if (iterator->subtrees.size > 0) {
549550
bool *found_error = payload;
550551
if (!*found_error && ts_subtree_is_error(iterator->subtrees.contents[0])) {
@@ -575,7 +576,7 @@ SubtreeArray ts_stack_pop_error(Stack *self, StackVersion version) {
575576
return (SubtreeArray) {.size = 0};
576577
}
577578

578-
inline StackAction pop_all_callback(void *payload, const StackIterator *iterator) {
579+
forceinline StackAction pop_all_callback(void *payload, const StackIterator *iterator) {
579580
(void)payload;
580581
return iterator->node->link_count == 0 ? StackActionPop : StackActionNone;
581582
}
@@ -589,7 +590,7 @@ typedef struct {
589590
unsigned max_depth;
590591
} SummarizeStackSession;
591592

592-
inline StackAction summarize_stack_callback(void *payload, const StackIterator *iterator) {
593+
forceinline StackAction summarize_stack_callback(void *payload, const StackIterator *iterator) {
593594
SummarizeStackSession *session = payload;
594595
TSStateId state = iterator->node->state;
595596
unsigned depth = iterator->subtree_count;
@@ -866,7 +867,7 @@ bool ts_stack_print_dot_graph(Stack *self, const TSLanguage *language, FILE *f)
866867
fprintf(f, "\"");
867868
fprintf(
868869
f,
869-
"labeltooltip=\"error_cost: %u\ndynamic_precedence: %u\"",
870+
"labeltooltip=\"error_cost: %u\ndynamic_precedence: %" PRId32 "\"",
870871
ts_subtree_error_cost(link.subtree),
871872
ts_subtree_dynamic_precedence(link.subtree)
872873
);
@@ -894,4 +895,4 @@ bool ts_stack_print_dot_graph(Stack *self, const TSLanguage *language, FILE *f)
894895
return true;
895896
}
896897

897-
#undef inline
898+
#undef forceinline

0 commit comments

Comments
 (0)