tree-sitter-ssh-client-config 2024.2.29 → 2024.3.14

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/binding.gyp CHANGED
@@ -2,18 +2,20 @@
2
2
  "targets": [
3
3
  {
4
4
  "target_name": "tree_sitter_ssh_client_config_binding",
5
+ "dependencies": [
6
+ "<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
7
+ ],
5
8
  "include_dirs": [
6
- "<!(node -e \"require('nan')\")",
7
- "src"
9
+ "src",
8
10
  ],
9
11
  "sources": [
10
12
  "bindings/node/binding.cc",
11
13
  "src/parser.c",
12
- # If your language uses an external scanner, add it here.
14
+ # NOTE: if your language has an external scanner, add it here.
13
15
  ],
14
16
  "cflags_c": [
15
- "-std=c99",
16
- ]
17
+ "-std=c11",
18
+ ],
17
19
  }
18
20
  ]
19
21
  }
@@ -1,28 +1,20 @@
1
- #include "tree_sitter/parser.h"
2
- #include <node.h>
3
- #include "nan.h"
1
+ #include <napi.h>
4
2
 
5
- using namespace v8;
3
+ typedef struct TSLanguage TSLanguage;
6
4
 
7
- extern "C" TSLanguage * tree_sitter_ssh_client_config();
5
+ extern "C" TSLanguage *tree_sitter_ssh_client_config();
8
6
 
9
- namespace {
7
+ // "tree-sitter", "language" hashed with BLAKE2
8
+ const napi_type_tag LANGUAGE_TYPE_TAG = {
9
+ 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
10
+ };
10
11
 
11
- NAN_METHOD(New) {}
12
-
13
- void Init(Local<Object> exports, Local<Object> module) {
14
- Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
15
- tpl->SetClassName(Nan::New("Language").ToLocalChecked());
16
- tpl->InstanceTemplate()->SetInternalFieldCount(1);
17
-
18
- Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19
- Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
20
- Nan::SetInternalFieldPointer(instance, 0, tree_sitter_ssh_client_config());
21
-
22
- Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("ssh-client-config").ToLocalChecked());
23
- Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
12
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
13
+ exports["name"] = Napi::String::New(env, "ssh_client_config");
14
+ auto language = Napi::External<TSLanguage>::New(env, tree_sitter_ssh_client_config());
15
+ language.TypeTag(&LANGUAGE_TYPE_TAG);
16
+ exports["language"] = language;
17
+ return exports;
24
18
  }
25
19
 
26
- NODE_MODULE(tree_sitter_ssh_client_config_binding, Init)
27
-
28
- } // namespace
20
+ NODE_API_MODULE(tree_sitter_ssh_client_config_binding, Init)
@@ -0,0 +1,28 @@
1
+ type BaseNode = {
2
+ type: string;
3
+ named: boolean;
4
+ };
5
+
6
+ type ChildNode = {
7
+ multiple: boolean;
8
+ required: boolean;
9
+ types: BaseNode[];
10
+ };
11
+
12
+ type NodeInfo =
13
+ | (BaseNode & {
14
+ subtypes: BaseNode[];
15
+ })
16
+ | (BaseNode & {
17
+ fields: { [name: string]: ChildNode };
18
+ children: ChildNode[];
19
+ });
20
+
21
+ type Language = {
22
+ name: string;
23
+ language: unknown;
24
+ nodeTypeInfo: NodeInfo[];
25
+ };
26
+
27
+ declare const language: Language;
28
+ export = language;
@@ -1,18 +1,6 @@
1
- try {
2
- module.exports = require("../../build/Release/tree_sitter_ssh_client_config_binding");
3
- } catch (error1) {
4
- if (error1.code !== 'MODULE_NOT_FOUND') {
5
- throw error1;
6
- }
7
- try {
8
- module.exports = require("../../build/Debug/tree_sitter_ssh_client_config_binding");
9
- } catch (error2) {
10
- if (error2.code !== 'MODULE_NOT_FOUND') {
11
- throw error2;
12
- }
13
- throw error1
14
- }
15
- }
1
+ const root = require("path").join(__dirname, "..", "..");
2
+
3
+ module.exports = require("node-gyp-build")(root);
16
4
 
17
5
  try {
18
6
  module.exports.nodeTypeInfo = require("../../src/node-types.json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-ssh-client-config",
3
- "version": "2024.2.29",
3
+ "version": "2024.3.14",
4
4
  "description": "tree-sitter grammar for SSH client configuration files",
5
5
  "keywords": [
6
6
  "parser",
@@ -10,12 +10,15 @@
10
10
  "config"
11
11
  ],
12
12
  "main": "bindings/node",
13
+ "types": "bindings/node",
13
14
  "scripts": {
14
15
  "init": "tree-sitter init-config",
15
16
  "generate": "tree-sitter generate",
16
17
  "test": "tree-sitter test",
17
18
  "parse": "tree-sitter parse",
18
- "examples": "tree-sitter parse 'examples/*' --quiet --stat"
19
+ "examples": "tree-sitter parse 'examples/*' --quiet --stat",
20
+ "install": "node-gyp-build",
21
+ "prebuildify": "prebuildify --napi --strip"
19
22
  },
20
23
  "homepage": "https://github.com/metio/tree-sitter-ssh-client-config",
21
24
  "repository": {
@@ -30,10 +33,20 @@
30
33
  "contributors": [],
31
34
  "license": "CC0-1.0",
32
35
  "dependencies": {
33
- "nan": "2.18.0"
36
+ "node-addon-api": "^7.1.0",
37
+ "node-gyp-build": "^4.8.0"
38
+ },
39
+ "peerDependencies": {
40
+ "tree-sitter": "^0.21.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "tree_sitter": {
44
+ "optional": true
45
+ }
34
46
  },
35
47
  "devDependencies": {
36
- "tree-sitter-cli": "0.21.0"
48
+ "tree-sitter-cli": "0.22.1",
49
+ "prebuildify": "^6.0.0"
37
50
  },
38
51
  "tree-sitter": [
39
52
  {
package/src/parser.c CHANGED
@@ -1,7 +1,6 @@
1
1
  #include "tree_sitter/parser.h"
2
2
 
3
3
  #if defined(__GNUC__) || defined(__clang__)
4
- #pragma GCC diagnostic push
5
4
  #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
6
5
  #endif
7
6
 
@@ -118435,10 +118434,12 @@ static const TSParseActionEntry ts_parse_actions[] = {
118435
118434
  extern "C" {
118436
118435
  #endif
118437
118436
  #ifdef _WIN32
118438
- #define extern __declspec(dllexport)
118437
+ #define TS_PUBLIC __declspec(dllexport)
118438
+ #else
118439
+ #define TS_PUBLIC __attribute__((visibility("default")))
118439
118440
  #endif
118440
118441
 
118441
- extern const TSLanguage *tree_sitter_ssh_client_config(void) {
118442
+ TS_PUBLIC const TSLanguage *tree_sitter_ssh_client_config() {
118442
118443
  static const TSLanguage language = {
118443
118444
  .version = LANGUAGE_VERSION,
118444
118445
  .symbol_count = SYMBOL_COUNT,
@@ -0,0 +1,54 @@
1
+ #ifndef TREE_SITTER_ALLOC_H_
2
+ #define TREE_SITTER_ALLOC_H_
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include <stdbool.h>
9
+ #include <stdio.h>
10
+ #include <stdlib.h>
11
+
12
+ // Allow clients to override allocation functions
13
+ #ifdef TREE_SITTER_REUSE_ALLOCATOR
14
+
15
+ extern void *(*ts_current_malloc)(size_t);
16
+ extern void *(*ts_current_calloc)(size_t, size_t);
17
+ extern void *(*ts_current_realloc)(void *, size_t);
18
+ extern void (*ts_current_free)(void *);
19
+
20
+ #ifndef ts_malloc
21
+ #define ts_malloc ts_current_malloc
22
+ #endif
23
+ #ifndef ts_calloc
24
+ #define ts_calloc ts_current_calloc
25
+ #endif
26
+ #ifndef ts_realloc
27
+ #define ts_realloc ts_current_realloc
28
+ #endif
29
+ #ifndef ts_free
30
+ #define ts_free ts_current_free
31
+ #endif
32
+
33
+ #else
34
+
35
+ #ifndef ts_malloc
36
+ #define ts_malloc malloc
37
+ #endif
38
+ #ifndef ts_calloc
39
+ #define ts_calloc calloc
40
+ #endif
41
+ #ifndef ts_realloc
42
+ #define ts_realloc realloc
43
+ #endif
44
+ #ifndef ts_free
45
+ #define ts_free free
46
+ #endif
47
+
48
+ #endif
49
+
50
+ #ifdef __cplusplus
51
+ }
52
+ #endif
53
+
54
+ #endif // TREE_SITTER_ALLOC_H_
@@ -0,0 +1,287 @@
1
+ #ifndef TREE_SITTER_ARRAY_H_
2
+ #define TREE_SITTER_ARRAY_H_
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include "./alloc.h"
9
+
10
+ #include <assert.h>
11
+ #include <stdbool.h>
12
+ #include <stdint.h>
13
+ #include <stdlib.h>
14
+ #include <string.h>
15
+
16
+ #ifdef _MSC_VER
17
+ #pragma warning(disable : 4101)
18
+ #elif defined(__GNUC__) || defined(__clang__)
19
+ #pragma GCC diagnostic push
20
+ #pragma GCC diagnostic ignored "-Wunused-variable"
21
+ #endif
22
+
23
+ #define Array(T) \
24
+ struct { \
25
+ T *contents; \
26
+ uint32_t size; \
27
+ uint32_t capacity; \
28
+ }
29
+
30
+ /// Initialize an array.
31
+ #define array_init(self) \
32
+ ((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL)
33
+
34
+ /// Create an empty array.
35
+ #define array_new() \
36
+ { NULL, 0, 0 }
37
+
38
+ /// Get a pointer to the element at a given `index` in the array.
39
+ #define array_get(self, _index) \
40
+ (assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index])
41
+
42
+ /// Get a pointer to the first element in the array.
43
+ #define array_front(self) array_get(self, 0)
44
+
45
+ /// Get a pointer to the last element in the array.
46
+ #define array_back(self) array_get(self, (self)->size - 1)
47
+
48
+ /// Clear the array, setting its size to zero. Note that this does not free any
49
+ /// memory allocated for the array's contents.
50
+ #define array_clear(self) ((self)->size = 0)
51
+
52
+ /// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
53
+ /// less than the array's current capacity, this function has no effect.
54
+ #define array_reserve(self, new_capacity) \
55
+ _array__reserve((Array *)(self), array_elem_size(self), new_capacity)
56
+
57
+ /// Free any memory allocated for this array. Note that this does not free any
58
+ /// memory allocated for the array's contents.
59
+ #define array_delete(self) _array__delete((Array *)(self))
60
+
61
+ /// Push a new `element` onto the end of the array.
62
+ #define array_push(self, element) \
63
+ (_array__grow((Array *)(self), 1, array_elem_size(self)), \
64
+ (self)->contents[(self)->size++] = (element))
65
+
66
+ /// Increase the array's size by `count` elements.
67
+ /// New elements are zero-initialized.
68
+ #define array_grow_by(self, count) \
69
+ (_array__grow((Array *)(self), count, array_elem_size(self)), \
70
+ memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)), \
71
+ (self)->size += (count))
72
+
73
+ /// Append all elements from one array to the end of another.
74
+ #define array_push_all(self, other) \
75
+ array_extend((self), (other)->size, (other)->contents)
76
+
77
+ /// Append `count` elements to the end of the array, reading their values from the
78
+ /// `contents` pointer.
79
+ #define array_extend(self, count, contents) \
80
+ _array__splice( \
81
+ (Array *)(self), array_elem_size(self), (self)->size, \
82
+ 0, count, contents \
83
+ )
84
+
85
+ /// Remove `old_count` elements from the array starting at the given `index`. At
86
+ /// the same index, insert `new_count` new elements, reading their values from the
87
+ /// `new_contents` pointer.
88
+ #define array_splice(self, _index, old_count, new_count, new_contents) \
89
+ _array__splice( \
90
+ (Array *)(self), array_elem_size(self), _index, \
91
+ old_count, new_count, new_contents \
92
+ )
93
+
94
+ /// Insert one `element` into the array at the given `index`.
95
+ #define array_insert(self, _index, element) \
96
+ _array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element))
97
+
98
+ /// Remove one element from the array at the given `index`.
99
+ #define array_erase(self, _index) \
100
+ _array__erase((Array *)(self), array_elem_size(self), _index)
101
+
102
+ /// Pop the last element off the array, returning the element by value.
103
+ #define array_pop(self) ((self)->contents[--(self)->size])
104
+
105
+ /// Assign the contents of one array to another, reallocating if necessary.
106
+ #define array_assign(self, other) \
107
+ _array__assign((Array *)(self), (const Array *)(other), array_elem_size(self))
108
+
109
+ /// Swap one array with another
110
+ #define array_swap(self, other) \
111
+ _array__swap((Array *)(self), (Array *)(other))
112
+
113
+ /// Get the size of the array contents
114
+ #define array_elem_size(self) (sizeof *(self)->contents)
115
+
116
+ /// Search a sorted array for a given `needle` value, using the given `compare`
117
+ /// callback to determine the order.
118
+ ///
119
+ /// If an existing element is found to be equal to `needle`, then the `index`
120
+ /// out-parameter is set to the existing value's index, and the `exists`
121
+ /// out-parameter is set to true. Otherwise, `index` is set to an index where
122
+ /// `needle` should be inserted in order to preserve the sorting, and `exists`
123
+ /// is set to false.
124
+ #define array_search_sorted_with(self, compare, needle, _index, _exists) \
125
+ _array__search_sorted(self, 0, compare, , needle, _index, _exists)
126
+
127
+ /// Search a sorted array for a given `needle` value, using integer comparisons
128
+ /// of a given struct field (specified with a leading dot) to determine the order.
129
+ ///
130
+ /// See also `array_search_sorted_with`.
131
+ #define array_search_sorted_by(self, field, needle, _index, _exists) \
132
+ _array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists)
133
+
134
+ /// Insert a given `value` into a sorted array, using the given `compare`
135
+ /// callback to determine the order.
136
+ #define array_insert_sorted_with(self, compare, value) \
137
+ do { \
138
+ unsigned _index, _exists; \
139
+ array_search_sorted_with(self, compare, &(value), &_index, &_exists); \
140
+ if (!_exists) array_insert(self, _index, value); \
141
+ } while (0)
142
+
143
+ /// Insert a given `value` into a sorted array, using integer comparisons of
144
+ /// a given struct field (specified with a leading dot) to determine the order.
145
+ ///
146
+ /// See also `array_search_sorted_by`.
147
+ #define array_insert_sorted_by(self, field, value) \
148
+ do { \
149
+ unsigned _index, _exists; \
150
+ array_search_sorted_by(self, field, (value) field, &_index, &_exists); \
151
+ if (!_exists) array_insert(self, _index, value); \
152
+ } while (0)
153
+
154
+ // Private
155
+
156
+ typedef Array(void) Array;
157
+
158
+ /// This is not what you're looking for, see `array_delete`.
159
+ static inline void _array__delete(Array *self) {
160
+ if (self->contents) {
161
+ ts_free(self->contents);
162
+ self->contents = NULL;
163
+ self->size = 0;
164
+ self->capacity = 0;
165
+ }
166
+ }
167
+
168
+ /// This is not what you're looking for, see `array_erase`.
169
+ static inline void _array__erase(Array *self, size_t element_size,
170
+ uint32_t index) {
171
+ assert(index < self->size);
172
+ char *contents = (char *)self->contents;
173
+ memmove(contents + index * element_size, contents + (index + 1) * element_size,
174
+ (self->size - index - 1) * element_size);
175
+ self->size--;
176
+ }
177
+
178
+ /// This is not what you're looking for, see `array_reserve`.
179
+ static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) {
180
+ if (new_capacity > self->capacity) {
181
+ if (self->contents) {
182
+ self->contents = ts_realloc(self->contents, new_capacity * element_size);
183
+ } else {
184
+ self->contents = ts_malloc(new_capacity * element_size);
185
+ }
186
+ self->capacity = new_capacity;
187
+ }
188
+ }
189
+
190
+ /// This is not what you're looking for, see `array_assign`.
191
+ static inline void _array__assign(Array *self, const Array *other, size_t element_size) {
192
+ _array__reserve(self, element_size, other->size);
193
+ self->size = other->size;
194
+ memcpy(self->contents, other->contents, self->size * element_size);
195
+ }
196
+
197
+ /// This is not what you're looking for, see `array_swap`.
198
+ static inline void _array__swap(Array *self, Array *other) {
199
+ Array swap = *other;
200
+ *other = *self;
201
+ *self = swap;
202
+ }
203
+
204
+ /// This is not what you're looking for, see `array_push` or `array_grow_by`.
205
+ static inline void _array__grow(Array *self, uint32_t count, size_t element_size) {
206
+ uint32_t new_size = self->size + count;
207
+ if (new_size > self->capacity) {
208
+ uint32_t new_capacity = self->capacity * 2;
209
+ if (new_capacity < 8) new_capacity = 8;
210
+ if (new_capacity < new_size) new_capacity = new_size;
211
+ _array__reserve(self, element_size, new_capacity);
212
+ }
213
+ }
214
+
215
+ /// This is not what you're looking for, see `array_splice`.
216
+ static inline void _array__splice(Array *self, size_t element_size,
217
+ uint32_t index, uint32_t old_count,
218
+ uint32_t new_count, const void *elements) {
219
+ uint32_t new_size = self->size + new_count - old_count;
220
+ uint32_t old_end = index + old_count;
221
+ uint32_t new_end = index + new_count;
222
+ assert(old_end <= self->size);
223
+
224
+ _array__reserve(self, element_size, new_size);
225
+
226
+ char *contents = (char *)self->contents;
227
+ if (self->size > old_end) {
228
+ memmove(
229
+ contents + new_end * element_size,
230
+ contents + old_end * element_size,
231
+ (self->size - old_end) * element_size
232
+ );
233
+ }
234
+ if (new_count > 0) {
235
+ if (elements) {
236
+ memcpy(
237
+ (contents + index * element_size),
238
+ elements,
239
+ new_count * element_size
240
+ );
241
+ } else {
242
+ memset(
243
+ (contents + index * element_size),
244
+ 0,
245
+ new_count * element_size
246
+ );
247
+ }
248
+ }
249
+ self->size += new_count - old_count;
250
+ }
251
+
252
+ /// A binary search routine, based on Rust's `std::slice::binary_search_by`.
253
+ /// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`.
254
+ #define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \
255
+ do { \
256
+ *(_index) = start; \
257
+ *(_exists) = false; \
258
+ uint32_t size = (self)->size - *(_index); \
259
+ if (size == 0) break; \
260
+ int comparison; \
261
+ while (size > 1) { \
262
+ uint32_t half_size = size / 2; \
263
+ uint32_t mid_index = *(_index) + half_size; \
264
+ comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \
265
+ if (comparison <= 0) *(_index) = mid_index; \
266
+ size -= half_size; \
267
+ } \
268
+ comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \
269
+ if (comparison == 0) *(_exists) = true; \
270
+ else if (comparison < 0) *(_index) += 1; \
271
+ } while (0)
272
+
273
+ /// Helper macro for the `_sorted_by` routines below. This takes the left (existing)
274
+ /// parameter by reference in order to work with the generic sorting function above.
275
+ #define _compare_int(a, b) ((int)*(a) - (int)(b))
276
+
277
+ #ifdef _MSC_VER
278
+ #pragma warning(default : 4101)
279
+ #elif defined(__GNUC__) || defined(__clang__)
280
+ #pragma GCC diagnostic pop
281
+ #endif
282
+
283
+ #ifdef __cplusplus
284
+ }
285
+ #endif
286
+
287
+ #endif // TREE_SITTER_ARRAY_H_