tree-sitter-java-orchard 0.5.7 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -2
- package/bindings/node/binding_test.js +7 -5
- package/bindings/node/index.d.ts +36 -3
- package/bindings/node/index.js +34 -8
- package/grammar.js +2 -2
- package/package.json +8 -4
- package/src/grammar.json +11 -2
- package/src/parser.c +30471 -30229
- package/src/tree_sitter/array.h +118 -73
- package/tree-sitter-java_orchard.wasm +0 -0
- package/tree-sitter.json +3 -2
package/src/tree_sitter/array.h
CHANGED
|
@@ -50,69 +50,104 @@ extern "C" {
|
|
|
50
50
|
/// memory allocated for the array's contents.
|
|
51
51
|
#define array_clear(self) ((self)->size = 0)
|
|
52
52
|
|
|
53
|
+
#ifdef __cplusplus
|
|
54
|
+
#define _array__cast(self, expr) (decltype((self)->contents))(expr)
|
|
55
|
+
#else
|
|
56
|
+
#define _array__cast(self, expr) (expr)
|
|
57
|
+
#endif
|
|
58
|
+
|
|
53
59
|
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
|
|
54
60
|
/// less than the array's current capacity, this function has no effect.
|
|
55
|
-
#define array_reserve(self, new_capacity)
|
|
56
|
-
|
|
61
|
+
#define array_reserve(self, new_capacity) \
|
|
62
|
+
((self)->contents = _array__cast(self, _array__reserve( \
|
|
63
|
+
(void *)(self)->contents, &(self)->capacity, \
|
|
64
|
+
array_elem_size(self), new_capacity)) \
|
|
65
|
+
)
|
|
57
66
|
|
|
58
67
|
/// Free any memory allocated for this array. Note that this does not free any
|
|
59
68
|
/// memory allocated for the array's contents.
|
|
60
|
-
#define array_delete(self)
|
|
69
|
+
#define array_delete(self) \
|
|
70
|
+
do { \
|
|
71
|
+
if ((self)->contents) ts_free((self)->contents); \
|
|
72
|
+
(self)->contents = NULL; \
|
|
73
|
+
(self)->size = 0; \
|
|
74
|
+
(self)->capacity = 0; \
|
|
75
|
+
} while (0)
|
|
61
76
|
|
|
62
77
|
/// Push a new `element` onto the end of the array.
|
|
63
|
-
#define array_push(self, element)
|
|
64
|
-
|
|
65
|
-
|
|
78
|
+
#define array_push(self, element) \
|
|
79
|
+
do { \
|
|
80
|
+
(self)->contents = _array__cast(self, _array__grow( \
|
|
81
|
+
(void *)(self)->contents, (self)->size, &(self)->capacity, \
|
|
82
|
+
1, array_elem_size(self) \
|
|
83
|
+
)); \
|
|
84
|
+
(self)->contents[(self)->size++] = (element); \
|
|
85
|
+
} while(0)
|
|
66
86
|
|
|
67
87
|
/// Increase the array's size by `count` elements.
|
|
68
88
|
/// New elements are zero-initialized.
|
|
69
|
-
#define array_grow_by(self, count)
|
|
70
|
-
do {
|
|
71
|
-
if ((count) == 0) break;
|
|
72
|
-
|
|
89
|
+
#define array_grow_by(self, count) \
|
|
90
|
+
do { \
|
|
91
|
+
if ((count) == 0) break; \
|
|
92
|
+
(self)->contents = _array__cast(self, _array__grow( \
|
|
93
|
+
(self)->contents, (self)->size, &(self)->capacity, \
|
|
94
|
+
count, array_elem_size(self) \
|
|
95
|
+
)); \
|
|
73
96
|
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
|
|
74
|
-
(self)->size += (count);
|
|
97
|
+
(self)->size += (count); \
|
|
75
98
|
} while (0)
|
|
76
99
|
|
|
77
100
|
/// Append all elements from one array to the end of another.
|
|
78
|
-
#define array_push_all(self, other)
|
|
101
|
+
#define array_push_all(self, other) \
|
|
79
102
|
array_extend((self), (other)->size, (other)->contents)
|
|
80
103
|
|
|
81
104
|
/// Append `count` elements to the end of the array, reading their values from the
|
|
82
105
|
/// `contents` pointer.
|
|
83
|
-
#define array_extend(self, count,
|
|
84
|
-
_array__splice(
|
|
85
|
-
(
|
|
86
|
-
0, count,
|
|
87
|
-
)
|
|
106
|
+
#define array_extend(self, count, other_contents) \
|
|
107
|
+
((self)->contents = _array__cast(self, _array__splice( \
|
|
108
|
+
(void*)(self)->contents, &(self)->size, &(self)->capacity, \
|
|
109
|
+
array_elem_size(self), (self)->size, 0, count, other_contents \
|
|
110
|
+
)))
|
|
88
111
|
|
|
89
112
|
/// Remove `old_count` elements from the array starting at the given `index`. At
|
|
90
113
|
/// the same index, insert `new_count` new elements, reading their values from the
|
|
91
114
|
/// `new_contents` pointer.
|
|
92
|
-
#define array_splice(self, _index, old_count, new_count, new_contents)
|
|
93
|
-
_array__splice(
|
|
94
|
-
(
|
|
95
|
-
old_count, new_count, new_contents
|
|
96
|
-
)
|
|
115
|
+
#define array_splice(self, _index, old_count, new_count, new_contents) \
|
|
116
|
+
((self)->contents = _array__cast(self, _array__splice( \
|
|
117
|
+
(void *)(self)->contents, &(self)->size, &(self)->capacity, \
|
|
118
|
+
array_elem_size(self), _index, old_count, new_count, new_contents \
|
|
119
|
+
)))
|
|
97
120
|
|
|
98
121
|
/// Insert one `element` into the array at the given `index`.
|
|
99
|
-
#define array_insert(self, _index, element)
|
|
100
|
-
|
|
122
|
+
#define array_insert(self, _index, element) \
|
|
123
|
+
((self)->contents = _array__cast(self, _array__splice( \
|
|
124
|
+
(void *)(self)->contents, &(self)->size, &(self)->capacity, \
|
|
125
|
+
array_elem_size(self), _index, 0, 1, &(element) \
|
|
126
|
+
)))
|
|
101
127
|
|
|
102
128
|
/// Remove one element from the array at the given `index`.
|
|
103
129
|
#define array_erase(self, _index) \
|
|
104
|
-
_array__erase((
|
|
130
|
+
_array__erase((void *)(self)->contents, &(self)->size, array_elem_size(self), _index)
|
|
105
131
|
|
|
106
132
|
/// Pop the last element off the array, returning the element by value.
|
|
107
133
|
#define array_pop(self) ((self)->contents[--(self)->size])
|
|
108
134
|
|
|
109
135
|
/// Assign the contents of one array to another, reallocating if necessary.
|
|
110
|
-
#define array_assign(self, other)
|
|
111
|
-
|
|
136
|
+
#define array_assign(self, other) \
|
|
137
|
+
((self)->contents = _array__cast(self, _array__assign( \
|
|
138
|
+
(void *)(self)->contents, &(self)->size, &(self)->capacity, \
|
|
139
|
+
(const void *)(other)->contents, (other)->size, array_elem_size(self) \
|
|
140
|
+
)))
|
|
112
141
|
|
|
113
142
|
/// Swap one array with another
|
|
114
|
-
#define array_swap(self, other)
|
|
115
|
-
|
|
143
|
+
#define array_swap(self, other) \
|
|
144
|
+
do { \
|
|
145
|
+
void *_array_swap_tmp = (void *)(self)->contents; \
|
|
146
|
+
(self)->contents = (other)->contents; \
|
|
147
|
+
(other)->contents = _array__cast(other, _array_swap_tmp); \
|
|
148
|
+
_array__swap(&(self)->size, &(self)->capacity, \
|
|
149
|
+
&(other)->size, &(other)->capacity); \
|
|
150
|
+
} while (0)
|
|
116
151
|
|
|
117
152
|
/// Get the size of the array contents
|
|
118
153
|
#define array_elem_size(self) (sizeof *(self)->contents)
|
|
@@ -157,82 +192,90 @@ extern "C" {
|
|
|
157
192
|
|
|
158
193
|
// Private
|
|
159
194
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
self->contents = NULL;
|
|
167
|
-
self->size = 0;
|
|
168
|
-
self->capacity = 0;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
195
|
+
// Pointers to individual `Array` fields (rather than the entire `Array` itself)
|
|
196
|
+
// are passed to the various `_array__*` functions below to address strict aliasing
|
|
197
|
+
// violations that arises when the _entire_ `Array` struct is passed as `Array(void)*`.
|
|
198
|
+
//
|
|
199
|
+
// The `Array` type itself was not altered as a solution in order to avoid breakage
|
|
200
|
+
// with existing consumers (in particular, parsers with external scanners).
|
|
171
201
|
|
|
172
202
|
/// This is not what you're looking for, see `array_erase`.
|
|
173
|
-
static inline void _array__erase(
|
|
174
|
-
uint32_t index) {
|
|
175
|
-
assert(index <
|
|
176
|
-
char *contents = (char *)
|
|
203
|
+
static inline void _array__erase(void* self_contents, uint32_t *size,
|
|
204
|
+
size_t element_size, uint32_t index) {
|
|
205
|
+
assert(index < *size);
|
|
206
|
+
char *contents = (char *)self_contents;
|
|
177
207
|
memmove(contents + index * element_size, contents + (index + 1) * element_size,
|
|
178
|
-
(
|
|
179
|
-
|
|
208
|
+
(*size - index - 1) * element_size);
|
|
209
|
+
(*size)--;
|
|
180
210
|
}
|
|
181
211
|
|
|
182
212
|
/// This is not what you're looking for, see `array_reserve`.
|
|
183
|
-
static inline void _array__reserve(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
213
|
+
static inline void *_array__reserve(void *contents, uint32_t *capacity,
|
|
214
|
+
size_t element_size, uint32_t new_capacity) {
|
|
215
|
+
void *new_contents = contents;
|
|
216
|
+
if (new_capacity > *capacity) {
|
|
217
|
+
if (contents) {
|
|
218
|
+
new_contents = ts_realloc(contents, new_capacity * element_size);
|
|
187
219
|
} else {
|
|
188
|
-
|
|
220
|
+
new_contents = ts_malloc(new_capacity * element_size);
|
|
189
221
|
}
|
|
190
|
-
|
|
222
|
+
*capacity = new_capacity;
|
|
191
223
|
}
|
|
224
|
+
return new_contents;
|
|
192
225
|
}
|
|
193
226
|
|
|
194
227
|
/// This is not what you're looking for, see `array_assign`.
|
|
195
|
-
static inline void _array__assign(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
228
|
+
static inline void *_array__assign(void* self_contents, uint32_t *self_size, uint32_t *self_capacity,
|
|
229
|
+
const void *other_contents, uint32_t other_size, size_t element_size) {
|
|
230
|
+
void *new_contents = _array__reserve(self_contents, self_capacity, element_size, other_size);
|
|
231
|
+
*self_size = other_size;
|
|
232
|
+
memcpy(new_contents, other_contents, *self_size * element_size);
|
|
233
|
+
return new_contents;
|
|
199
234
|
}
|
|
200
235
|
|
|
201
236
|
/// This is not what you're looking for, see `array_swap`.
|
|
202
|
-
static inline void _array__swap(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
237
|
+
static inline void _array__swap(uint32_t *self_size, uint32_t *self_capacity,
|
|
238
|
+
uint32_t *other_size, uint32_t *other_capacity) {
|
|
239
|
+
uint32_t tmp_size = *self_size;
|
|
240
|
+
uint32_t tmp_capacity = *self_capacity;
|
|
241
|
+
*self_size = *other_size;
|
|
242
|
+
*self_capacity = *other_capacity;
|
|
243
|
+
*other_size = tmp_size;
|
|
244
|
+
*other_capacity = tmp_capacity;
|
|
206
245
|
}
|
|
207
246
|
|
|
208
247
|
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
|
|
209
|
-
static inline void _array__grow(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
248
|
+
static inline void *_array__grow(void *contents, uint32_t size, uint32_t *capacity,
|
|
249
|
+
uint32_t count, size_t element_size) {
|
|
250
|
+
void *new_contents = contents;
|
|
251
|
+
uint32_t new_size = size + count;
|
|
252
|
+
if (new_size > *capacity) {
|
|
253
|
+
uint32_t new_capacity = *capacity * 2;
|
|
213
254
|
if (new_capacity < 8) new_capacity = 8;
|
|
214
255
|
if (new_capacity < new_size) new_capacity = new_size;
|
|
215
|
-
_array__reserve(
|
|
256
|
+
new_contents = _array__reserve(contents, capacity, element_size, new_capacity);
|
|
216
257
|
}
|
|
258
|
+
return new_contents;
|
|
217
259
|
}
|
|
218
260
|
|
|
219
261
|
/// This is not what you're looking for, see `array_splice`.
|
|
220
|
-
static inline void _array__splice(
|
|
262
|
+
static inline void *_array__splice(void *self_contents, uint32_t *size, uint32_t *capacity,
|
|
263
|
+
size_t element_size,
|
|
221
264
|
uint32_t index, uint32_t old_count,
|
|
222
265
|
uint32_t new_count, const void *elements) {
|
|
223
|
-
uint32_t new_size =
|
|
266
|
+
uint32_t new_size = *size + new_count - old_count;
|
|
224
267
|
uint32_t old_end = index + old_count;
|
|
225
268
|
uint32_t new_end = index + new_count;
|
|
226
|
-
assert(old_end <=
|
|
269
|
+
assert(old_end <= *size);
|
|
227
270
|
|
|
228
|
-
_array__reserve(
|
|
271
|
+
void *new_contents = _array__reserve(self_contents, capacity, element_size, new_size);
|
|
229
272
|
|
|
230
|
-
char *contents = (char *)
|
|
231
|
-
if (
|
|
273
|
+
char *contents = (char *)new_contents;
|
|
274
|
+
if (*size > old_end) {
|
|
232
275
|
memmove(
|
|
233
276
|
contents + new_end * element_size,
|
|
234
277
|
contents + old_end * element_size,
|
|
235
|
-
(
|
|
278
|
+
(*size - old_end) * element_size
|
|
236
279
|
);
|
|
237
280
|
}
|
|
238
281
|
if (new_count > 0) {
|
|
@@ -250,7 +293,9 @@ static inline void _array__splice(Array *self, size_t element_size,
|
|
|
250
293
|
);
|
|
251
294
|
}
|
|
252
295
|
}
|
|
253
|
-
|
|
296
|
+
*size += new_count - old_count;
|
|
297
|
+
|
|
298
|
+
return new_contents;
|
|
254
299
|
}
|
|
255
300
|
|
|
256
301
|
/// A binary search routine, based on Rust's `std::slice::binary_search_by`.
|
|
Binary file
|
package/tree-sitter.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
16
|
"metadata": {
|
|
17
|
-
"version": "0.5.
|
|
17
|
+
"version": "0.5.9",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"description": "Java grammar for tree-sitter",
|
|
20
20
|
"authors": [
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
}
|
|
33
33
|
],
|
|
34
34
|
"links": {
|
|
35
|
-
"repository": "https://codeberg.org/grammar-orchard/tree-sitter-java-orchard"
|
|
35
|
+
"repository": "https://codeberg.org/grammar-orchard/tree-sitter-java-orchard",
|
|
36
|
+
"upstream": "https://github.com/tree-sitter/tree-sitter-java"
|
|
36
37
|
}
|
|
37
38
|
},
|
|
38
39
|
"bindings": {
|