tree-sitter-beancount 2.3.3 → 2.4.1
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 +334 -4
- package/binding.gyp +17 -7
- package/bindings/node/binding.cc +14 -22
- package/bindings/node/index.d.ts +28 -0
- package/bindings/node/index.js +3 -15
- package/grammar.js +38 -125
- package/package.json +35 -5
- package/prebuilds/darwin-arm64/tree-sitter-beancount.node +0 -0
- package/prebuilds/darwin-x64/tree-sitter-beancount.node +0 -0
- package/prebuilds/linux-arm64/tree-sitter-beancount.node +0 -0
- package/prebuilds/linux-x64/tree-sitter-beancount.node +0 -0
- package/prebuilds/win32-arm64/tree-sitter-beancount.node +0 -0
- package/prebuilds/win32-x64/tree-sitter-beancount.node +0 -0
- package/src/grammar.json +149 -560
- package/src/node-types.json +10 -11
- package/src/parser.c +7615 -9089
- package/src/scanner.c +345 -67
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +291 -0
- package/src/tree_sitter/parser.h +68 -12
- package/.clang-format +0 -20
- package/.envrc +0 -1
- package/.gitattributes +0 -6
- package/.github/dependabot.yml +0 -26
- package/.github/workflows/cicd.yml +0 -30
- package/.github/workflows/release.yml +0 -72
- package/CHANGELOG.md +0 -80
- package/Cargo.lock +0 -71
- package/Cargo.toml +0 -26
- package/Package.swift +0 -20
- package/bindings/rust/build.rs +0 -39
- package/bindings/rust/lib.rs +0 -52
- package/flake.lock +0 -141
- package/flake.nix +0 -120
- package/test/corpus/arithmetic.txt +0 -373
- package/test/corpus/comment.txt +0 -992
- package/test/corpus/currencies.txt +0 -66
- package/test/corpus/entry_types.txt +0 -389
- package/test/corpus/markdown_orgmode.txt +0 -60
- package/test/corpus/metadata.txt +0 -414
- package/test/corpus/multi_line.txt +0 -27
- package/test/corpus/orgmode_sections.txt +0 -53
- package/test/corpus/parse_lots.txt +0 -417
- package/test/corpus/parser_include.txt +0 -23
- package/test/corpus/parser_links.txt +0 -32
- package/test/corpus/parser_options.txt +0 -39
- package/test/corpus/parser_plugin.txt +0 -35
- package/test/corpus/push_pop_meta.txt +0 -34
- package/test/corpus/push_pop_tag.txt +0 -23
- package/test/corpus/transaction.txt +0 -224
- package/test/corpus/ugly_bugs.txt +0 -91
|
@@ -0,0 +1,291 @@
|
|
|
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(push)
|
|
18
|
+
#pragma warning(disable : 4101)
|
|
19
|
+
#elif defined(__GNUC__) || defined(__clang__)
|
|
20
|
+
#pragma GCC diagnostic push
|
|
21
|
+
#pragma GCC diagnostic ignored "-Wunused-variable"
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#define Array(T) \
|
|
25
|
+
struct { \
|
|
26
|
+
T *contents; \
|
|
27
|
+
uint32_t size; \
|
|
28
|
+
uint32_t capacity; \
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// Initialize an array.
|
|
32
|
+
#define array_init(self) \
|
|
33
|
+
((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL)
|
|
34
|
+
|
|
35
|
+
/// Create an empty array.
|
|
36
|
+
#define array_new() \
|
|
37
|
+
{ NULL, 0, 0 }
|
|
38
|
+
|
|
39
|
+
/// Get a pointer to the element at a given `index` in the array.
|
|
40
|
+
#define array_get(self, _index) \
|
|
41
|
+
(assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index])
|
|
42
|
+
|
|
43
|
+
/// Get a pointer to the first element in the array.
|
|
44
|
+
#define array_front(self) array_get(self, 0)
|
|
45
|
+
|
|
46
|
+
/// Get a pointer to the last element in the array.
|
|
47
|
+
#define array_back(self) array_get(self, (self)->size - 1)
|
|
48
|
+
|
|
49
|
+
/// Clear the array, setting its size to zero. Note that this does not free any
|
|
50
|
+
/// memory allocated for the array's contents.
|
|
51
|
+
#define array_clear(self) ((self)->size = 0)
|
|
52
|
+
|
|
53
|
+
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
|
|
54
|
+
/// less than the array's current capacity, this function has no effect.
|
|
55
|
+
#define array_reserve(self, new_capacity) \
|
|
56
|
+
_array__reserve((Array *)(self), array_elem_size(self), new_capacity)
|
|
57
|
+
|
|
58
|
+
/// Free any memory allocated for this array. Note that this does not free any
|
|
59
|
+
/// memory allocated for the array's contents.
|
|
60
|
+
#define array_delete(self) _array__delete((Array *)(self))
|
|
61
|
+
|
|
62
|
+
/// Push a new `element` onto the end of the array.
|
|
63
|
+
#define array_push(self, element) \
|
|
64
|
+
(_array__grow((Array *)(self), 1, array_elem_size(self)), \
|
|
65
|
+
(self)->contents[(self)->size++] = (element))
|
|
66
|
+
|
|
67
|
+
/// Increase the array's size by `count` elements.
|
|
68
|
+
/// New elements are zero-initialized.
|
|
69
|
+
#define array_grow_by(self, count) \
|
|
70
|
+
do { \
|
|
71
|
+
if ((count) == 0) break; \
|
|
72
|
+
_array__grow((Array *)(self), count, array_elem_size(self)); \
|
|
73
|
+
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
|
|
74
|
+
(self)->size += (count); \
|
|
75
|
+
} while (0)
|
|
76
|
+
|
|
77
|
+
/// Append all elements from one array to the end of another.
|
|
78
|
+
#define array_push_all(self, other) \
|
|
79
|
+
array_extend((self), (other)->size, (other)->contents)
|
|
80
|
+
|
|
81
|
+
/// Append `count` elements to the end of the array, reading their values from the
|
|
82
|
+
/// `contents` pointer.
|
|
83
|
+
#define array_extend(self, count, contents) \
|
|
84
|
+
_array__splice( \
|
|
85
|
+
(Array *)(self), array_elem_size(self), (self)->size, \
|
|
86
|
+
0, count, contents \
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
/// Remove `old_count` elements from the array starting at the given `index`. At
|
|
90
|
+
/// the same index, insert `new_count` new elements, reading their values from the
|
|
91
|
+
/// `new_contents` pointer.
|
|
92
|
+
#define array_splice(self, _index, old_count, new_count, new_contents) \
|
|
93
|
+
_array__splice( \
|
|
94
|
+
(Array *)(self), array_elem_size(self), _index, \
|
|
95
|
+
old_count, new_count, new_contents \
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
/// Insert one `element` into the array at the given `index`.
|
|
99
|
+
#define array_insert(self, _index, element) \
|
|
100
|
+
_array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element))
|
|
101
|
+
|
|
102
|
+
/// Remove one element from the array at the given `index`.
|
|
103
|
+
#define array_erase(self, _index) \
|
|
104
|
+
_array__erase((Array *)(self), array_elem_size(self), _index)
|
|
105
|
+
|
|
106
|
+
/// Pop the last element off the array, returning the element by value.
|
|
107
|
+
#define array_pop(self) ((self)->contents[--(self)->size])
|
|
108
|
+
|
|
109
|
+
/// Assign the contents of one array to another, reallocating if necessary.
|
|
110
|
+
#define array_assign(self, other) \
|
|
111
|
+
_array__assign((Array *)(self), (const Array *)(other), array_elem_size(self))
|
|
112
|
+
|
|
113
|
+
/// Swap one array with another
|
|
114
|
+
#define array_swap(self, other) \
|
|
115
|
+
_array__swap((Array *)(self), (Array *)(other))
|
|
116
|
+
|
|
117
|
+
/// Get the size of the array contents
|
|
118
|
+
#define array_elem_size(self) (sizeof *(self)->contents)
|
|
119
|
+
|
|
120
|
+
/// Search a sorted array for a given `needle` value, using the given `compare`
|
|
121
|
+
/// callback to determine the order.
|
|
122
|
+
///
|
|
123
|
+
/// If an existing element is found to be equal to `needle`, then the `index`
|
|
124
|
+
/// out-parameter is set to the existing value's index, and the `exists`
|
|
125
|
+
/// out-parameter is set to true. Otherwise, `index` is set to an index where
|
|
126
|
+
/// `needle` should be inserted in order to preserve the sorting, and `exists`
|
|
127
|
+
/// is set to false.
|
|
128
|
+
#define array_search_sorted_with(self, compare, needle, _index, _exists) \
|
|
129
|
+
_array__search_sorted(self, 0, compare, , needle, _index, _exists)
|
|
130
|
+
|
|
131
|
+
/// Search a sorted array for a given `needle` value, using integer comparisons
|
|
132
|
+
/// of a given struct field (specified with a leading dot) to determine the order.
|
|
133
|
+
///
|
|
134
|
+
/// See also `array_search_sorted_with`.
|
|
135
|
+
#define array_search_sorted_by(self, field, needle, _index, _exists) \
|
|
136
|
+
_array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists)
|
|
137
|
+
|
|
138
|
+
/// Insert a given `value` into a sorted array, using the given `compare`
|
|
139
|
+
/// callback to determine the order.
|
|
140
|
+
#define array_insert_sorted_with(self, compare, value) \
|
|
141
|
+
do { \
|
|
142
|
+
unsigned _index, _exists; \
|
|
143
|
+
array_search_sorted_with(self, compare, &(value), &_index, &_exists); \
|
|
144
|
+
if (!_exists) array_insert(self, _index, value); \
|
|
145
|
+
} while (0)
|
|
146
|
+
|
|
147
|
+
/// Insert a given `value` into a sorted array, using integer comparisons of
|
|
148
|
+
/// a given struct field (specified with a leading dot) to determine the order.
|
|
149
|
+
///
|
|
150
|
+
/// See also `array_search_sorted_by`.
|
|
151
|
+
#define array_insert_sorted_by(self, field, value) \
|
|
152
|
+
do { \
|
|
153
|
+
unsigned _index, _exists; \
|
|
154
|
+
array_search_sorted_by(self, field, (value) field, &_index, &_exists); \
|
|
155
|
+
if (!_exists) array_insert(self, _index, value); \
|
|
156
|
+
} while (0)
|
|
157
|
+
|
|
158
|
+
// Private
|
|
159
|
+
|
|
160
|
+
typedef Array(void) Array;
|
|
161
|
+
|
|
162
|
+
/// This is not what you're looking for, see `array_delete`.
|
|
163
|
+
static inline void _array__delete(Array *self) {
|
|
164
|
+
if (self->contents) {
|
|
165
|
+
ts_free(self->contents);
|
|
166
|
+
self->contents = NULL;
|
|
167
|
+
self->size = 0;
|
|
168
|
+
self->capacity = 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/// This is not what you're looking for, see `array_erase`.
|
|
173
|
+
static inline void _array__erase(Array *self, size_t element_size,
|
|
174
|
+
uint32_t index) {
|
|
175
|
+
assert(index < self->size);
|
|
176
|
+
char *contents = (char *)self->contents;
|
|
177
|
+
memmove(contents + index * element_size, contents + (index + 1) * element_size,
|
|
178
|
+
(self->size - index - 1) * element_size);
|
|
179
|
+
self->size--;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/// This is not what you're looking for, see `array_reserve`.
|
|
183
|
+
static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) {
|
|
184
|
+
if (new_capacity > self->capacity) {
|
|
185
|
+
if (self->contents) {
|
|
186
|
+
self->contents = ts_realloc(self->contents, new_capacity * element_size);
|
|
187
|
+
} else {
|
|
188
|
+
self->contents = ts_malloc(new_capacity * element_size);
|
|
189
|
+
}
|
|
190
|
+
self->capacity = new_capacity;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/// This is not what you're looking for, see `array_assign`.
|
|
195
|
+
static inline void _array__assign(Array *self, const Array *other, size_t element_size) {
|
|
196
|
+
_array__reserve(self, element_size, other->size);
|
|
197
|
+
self->size = other->size;
|
|
198
|
+
memcpy(self->contents, other->contents, self->size * element_size);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/// This is not what you're looking for, see `array_swap`.
|
|
202
|
+
static inline void _array__swap(Array *self, Array *other) {
|
|
203
|
+
Array swap = *other;
|
|
204
|
+
*other = *self;
|
|
205
|
+
*self = swap;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
|
|
209
|
+
static inline void _array__grow(Array *self, uint32_t count, size_t element_size) {
|
|
210
|
+
uint32_t new_size = self->size + count;
|
|
211
|
+
if (new_size > self->capacity) {
|
|
212
|
+
uint32_t new_capacity = self->capacity * 2;
|
|
213
|
+
if (new_capacity < 8) new_capacity = 8;
|
|
214
|
+
if (new_capacity < new_size) new_capacity = new_size;
|
|
215
|
+
_array__reserve(self, element_size, new_capacity);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/// This is not what you're looking for, see `array_splice`.
|
|
220
|
+
static inline void _array__splice(Array *self, size_t element_size,
|
|
221
|
+
uint32_t index, uint32_t old_count,
|
|
222
|
+
uint32_t new_count, const void *elements) {
|
|
223
|
+
uint32_t new_size = self->size + new_count - old_count;
|
|
224
|
+
uint32_t old_end = index + old_count;
|
|
225
|
+
uint32_t new_end = index + new_count;
|
|
226
|
+
assert(old_end <= self->size);
|
|
227
|
+
|
|
228
|
+
_array__reserve(self, element_size, new_size);
|
|
229
|
+
|
|
230
|
+
char *contents = (char *)self->contents;
|
|
231
|
+
if (self->size > old_end) {
|
|
232
|
+
memmove(
|
|
233
|
+
contents + new_end * element_size,
|
|
234
|
+
contents + old_end * element_size,
|
|
235
|
+
(self->size - old_end) * element_size
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
if (new_count > 0) {
|
|
239
|
+
if (elements) {
|
|
240
|
+
memcpy(
|
|
241
|
+
(contents + index * element_size),
|
|
242
|
+
elements,
|
|
243
|
+
new_count * element_size
|
|
244
|
+
);
|
|
245
|
+
} else {
|
|
246
|
+
memset(
|
|
247
|
+
(contents + index * element_size),
|
|
248
|
+
0,
|
|
249
|
+
new_count * element_size
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
self->size += new_count - old_count;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/// A binary search routine, based on Rust's `std::slice::binary_search_by`.
|
|
257
|
+
/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`.
|
|
258
|
+
#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \
|
|
259
|
+
do { \
|
|
260
|
+
*(_index) = start; \
|
|
261
|
+
*(_exists) = false; \
|
|
262
|
+
uint32_t size = (self)->size - *(_index); \
|
|
263
|
+
if (size == 0) break; \
|
|
264
|
+
int comparison; \
|
|
265
|
+
while (size > 1) { \
|
|
266
|
+
uint32_t half_size = size / 2; \
|
|
267
|
+
uint32_t mid_index = *(_index) + half_size; \
|
|
268
|
+
comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \
|
|
269
|
+
if (comparison <= 0) *(_index) = mid_index; \
|
|
270
|
+
size -= half_size; \
|
|
271
|
+
} \
|
|
272
|
+
comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \
|
|
273
|
+
if (comparison == 0) *(_exists) = true; \
|
|
274
|
+
else if (comparison < 0) *(_index) += 1; \
|
|
275
|
+
} while (0)
|
|
276
|
+
|
|
277
|
+
/// Helper macro for the `_sorted_by` routines below. This takes the left (existing)
|
|
278
|
+
/// parameter by reference in order to work with the generic sorting function above.
|
|
279
|
+
#define _compare_int(a, b) ((int)*(a) - (int)(b))
|
|
280
|
+
|
|
281
|
+
#ifdef _MSC_VER
|
|
282
|
+
#pragma warning(pop)
|
|
283
|
+
#elif defined(__GNUC__) || defined(__clang__)
|
|
284
|
+
#pragma GCC diagnostic pop
|
|
285
|
+
#endif
|
|
286
|
+
|
|
287
|
+
#ifdef __cplusplus
|
|
288
|
+
}
|
|
289
|
+
#endif
|
|
290
|
+
|
|
291
|
+
#endif // TREE_SITTER_ARRAY_H_
|
package/src/tree_sitter/parser.h
CHANGED
|
@@ -18,6 +18,11 @@ typedef uint16_t TSStateId;
|
|
|
18
18
|
typedef uint16_t TSSymbol;
|
|
19
19
|
typedef uint16_t TSFieldId;
|
|
20
20
|
typedef struct TSLanguage TSLanguage;
|
|
21
|
+
typedef struct TSLanguageMetadata {
|
|
22
|
+
uint8_t major_version;
|
|
23
|
+
uint8_t minor_version;
|
|
24
|
+
uint8_t patch_version;
|
|
25
|
+
} TSLanguageMetadata;
|
|
21
26
|
#endif
|
|
22
27
|
|
|
23
28
|
typedef struct {
|
|
@@ -26,10 +31,11 @@ typedef struct {
|
|
|
26
31
|
bool inherited;
|
|
27
32
|
} TSFieldMapEntry;
|
|
28
33
|
|
|
34
|
+
// Used to index the field and supertype maps.
|
|
29
35
|
typedef struct {
|
|
30
36
|
uint16_t index;
|
|
31
37
|
uint16_t length;
|
|
32
|
-
}
|
|
38
|
+
} TSMapSlice;
|
|
33
39
|
|
|
34
40
|
typedef struct {
|
|
35
41
|
bool visible;
|
|
@@ -47,6 +53,7 @@ struct TSLexer {
|
|
|
47
53
|
uint32_t (*get_column)(TSLexer *);
|
|
48
54
|
bool (*is_at_included_range_start)(const TSLexer *);
|
|
49
55
|
bool (*eof)(const TSLexer *);
|
|
56
|
+
void (*log)(const TSLexer *, const char *, ...);
|
|
50
57
|
};
|
|
51
58
|
|
|
52
59
|
typedef enum {
|
|
@@ -78,6 +85,12 @@ typedef struct {
|
|
|
78
85
|
uint16_t external_lex_state;
|
|
79
86
|
} TSLexMode;
|
|
80
87
|
|
|
88
|
+
typedef struct {
|
|
89
|
+
uint16_t lex_state;
|
|
90
|
+
uint16_t external_lex_state;
|
|
91
|
+
uint16_t reserved_word_set_id;
|
|
92
|
+
} TSLexerMode;
|
|
93
|
+
|
|
81
94
|
typedef union {
|
|
82
95
|
TSParseAction action;
|
|
83
96
|
struct {
|
|
@@ -86,8 +99,13 @@ typedef union {
|
|
|
86
99
|
} entry;
|
|
87
100
|
} TSParseActionEntry;
|
|
88
101
|
|
|
102
|
+
typedef struct {
|
|
103
|
+
int32_t start;
|
|
104
|
+
int32_t end;
|
|
105
|
+
} TSCharacterRange;
|
|
106
|
+
|
|
89
107
|
struct TSLanguage {
|
|
90
|
-
uint32_t
|
|
108
|
+
uint32_t abi_version;
|
|
91
109
|
uint32_t symbol_count;
|
|
92
110
|
uint32_t alias_count;
|
|
93
111
|
uint32_t token_count;
|
|
@@ -103,13 +121,13 @@ struct TSLanguage {
|
|
|
103
121
|
const TSParseActionEntry *parse_actions;
|
|
104
122
|
const char * const *symbol_names;
|
|
105
123
|
const char * const *field_names;
|
|
106
|
-
const
|
|
124
|
+
const TSMapSlice *field_map_slices;
|
|
107
125
|
const TSFieldMapEntry *field_map_entries;
|
|
108
126
|
const TSSymbolMetadata *symbol_metadata;
|
|
109
127
|
const TSSymbol *public_symbol_map;
|
|
110
128
|
const uint16_t *alias_map;
|
|
111
129
|
const TSSymbol *alias_sequences;
|
|
112
|
-
const
|
|
130
|
+
const TSLexerMode *lex_modes;
|
|
113
131
|
bool (*lex_fn)(TSLexer *, TSStateId);
|
|
114
132
|
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
|
115
133
|
TSSymbol keyword_capture_token;
|
|
@@ -123,8 +141,34 @@ struct TSLanguage {
|
|
|
123
141
|
void (*deserialize)(void *, const char *, unsigned);
|
|
124
142
|
} external_scanner;
|
|
125
143
|
const TSStateId *primary_state_ids;
|
|
144
|
+
const char *name;
|
|
145
|
+
const TSSymbol *reserved_words;
|
|
146
|
+
uint16_t max_reserved_word_set_size;
|
|
147
|
+
uint32_t supertype_count;
|
|
148
|
+
const TSSymbol *supertype_symbols;
|
|
149
|
+
const TSMapSlice *supertype_map_slices;
|
|
150
|
+
const TSSymbol *supertype_map_entries;
|
|
151
|
+
TSLanguageMetadata metadata;
|
|
126
152
|
};
|
|
127
153
|
|
|
154
|
+
static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
|
|
155
|
+
uint32_t index = 0;
|
|
156
|
+
uint32_t size = len - index;
|
|
157
|
+
while (size > 1) {
|
|
158
|
+
uint32_t half_size = size / 2;
|
|
159
|
+
uint32_t mid_index = index + half_size;
|
|
160
|
+
const TSCharacterRange *range = &ranges[mid_index];
|
|
161
|
+
if (lookahead >= range->start && lookahead <= range->end) {
|
|
162
|
+
return true;
|
|
163
|
+
} else if (lookahead > range->end) {
|
|
164
|
+
index = mid_index;
|
|
165
|
+
}
|
|
166
|
+
size -= half_size;
|
|
167
|
+
}
|
|
168
|
+
const TSCharacterRange *range = &ranges[index];
|
|
169
|
+
return (lookahead >= range->start && lookahead <= range->end);
|
|
170
|
+
}
|
|
171
|
+
|
|
128
172
|
/*
|
|
129
173
|
* Lexer Macros
|
|
130
174
|
*/
|
|
@@ -154,6 +198,17 @@ struct TSLanguage {
|
|
|
154
198
|
goto next_state; \
|
|
155
199
|
}
|
|
156
200
|
|
|
201
|
+
#define ADVANCE_MAP(...) \
|
|
202
|
+
{ \
|
|
203
|
+
static const uint16_t map[] = { __VA_ARGS__ }; \
|
|
204
|
+
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
|
|
205
|
+
if (map[i] == lookahead) { \
|
|
206
|
+
state = map[i + 1]; \
|
|
207
|
+
goto next_state; \
|
|
208
|
+
} \
|
|
209
|
+
} \
|
|
210
|
+
}
|
|
211
|
+
|
|
157
212
|
#define SKIP(state_value) \
|
|
158
213
|
{ \
|
|
159
214
|
skip = true; \
|
|
@@ -203,14 +258,15 @@ struct TSLanguage {
|
|
|
203
258
|
} \
|
|
204
259
|
}}
|
|
205
260
|
|
|
206
|
-
#define REDUCE(
|
|
207
|
-
{{
|
|
208
|
-
.reduce = {
|
|
209
|
-
.type = TSParseActionTypeReduce,
|
|
210
|
-
.symbol =
|
|
211
|
-
.child_count =
|
|
212
|
-
|
|
213
|
-
|
|
261
|
+
#define REDUCE(symbol_name, children, precedence, prod_id) \
|
|
262
|
+
{{ \
|
|
263
|
+
.reduce = { \
|
|
264
|
+
.type = TSParseActionTypeReduce, \
|
|
265
|
+
.symbol = symbol_name, \
|
|
266
|
+
.child_count = children, \
|
|
267
|
+
.dynamic_precedence = precedence, \
|
|
268
|
+
.production_id = prod_id \
|
|
269
|
+
}, \
|
|
214
270
|
}}
|
|
215
271
|
|
|
216
272
|
#define RECOVER() \
|
package/.clang-format
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
BasedOnStyle: LLVM
|
|
3
|
-
IndentWidth: 4
|
|
4
|
-
---
|
|
5
|
-
Language: Cpp
|
|
6
|
-
# Force pointers to the type for C.
|
|
7
|
-
DerivePointerAlignment: false
|
|
8
|
-
PointerAlignment: Right
|
|
9
|
-
|
|
10
|
-
# Short functions should not be on a single line, unless empty
|
|
11
|
-
AllowShortFunctionsOnASingleLine: Empty
|
|
12
|
-
|
|
13
|
-
# It makes more sense this way
|
|
14
|
-
BreakBeforeBinaryOperators: All
|
|
15
|
-
BreakBeforeTernaryOperators: true
|
|
16
|
-
|
|
17
|
-
# Aesthetic
|
|
18
|
-
AlignOperands: AlignAfterOperator
|
|
19
|
-
BinPackParameters: false
|
|
20
|
-
---
|
package/.envrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
use flake
|
package/.gitattributes
DELETED
package/.github/dependabot.yml
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
version: 2
|
|
2
|
-
updates:
|
|
3
|
-
- package-ecosystem: "cargo"
|
|
4
|
-
directory: "/"
|
|
5
|
-
schedule:
|
|
6
|
-
interval: "weekly"
|
|
7
|
-
commit-message:
|
|
8
|
-
prefix: "chore(deps):"
|
|
9
|
-
labels:
|
|
10
|
-
- "dependencies"
|
|
11
|
-
- "cargo"
|
|
12
|
-
groups:
|
|
13
|
-
cargo:
|
|
14
|
-
patterns: ["*"]
|
|
15
|
-
- package-ecosystem: "github-actions"
|
|
16
|
-
directory: "/"
|
|
17
|
-
schedule:
|
|
18
|
-
interval: "weekly"
|
|
19
|
-
commit-message:
|
|
20
|
-
prefix: "ci:"
|
|
21
|
-
labels:
|
|
22
|
-
- "dependencies"
|
|
23
|
-
- "github-actions"
|
|
24
|
-
groups:
|
|
25
|
-
actions:
|
|
26
|
-
patterns: ["*"]
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
name: cicd
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
pull_request:
|
|
6
|
-
branches:
|
|
7
|
-
- '**:**'
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
build:
|
|
11
|
-
name: build
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
steps:
|
|
14
|
-
- name: Checkout code
|
|
15
|
-
uses: actions/checkout@v4
|
|
16
|
-
|
|
17
|
-
- name: Setup Node
|
|
18
|
-
uses: actions/setup-node@v4.0.3
|
|
19
|
-
with:
|
|
20
|
-
node-version: '18'
|
|
21
|
-
|
|
22
|
-
- name: Display Node versions
|
|
23
|
-
run: |
|
|
24
|
-
node --version
|
|
25
|
-
npm --version
|
|
26
|
-
- name: Install dependencies
|
|
27
|
-
run: npm install
|
|
28
|
-
|
|
29
|
-
- name: Test corpus & parse examples
|
|
30
|
-
run: npm test
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
name: release
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches: [master]
|
|
5
|
-
|
|
6
|
-
jobs:
|
|
7
|
-
release-please:
|
|
8
|
-
runs-on: ubuntu-latest
|
|
9
|
-
outputs:
|
|
10
|
-
release_created: ${{ steps.release.outputs.release_created }}
|
|
11
|
-
steps:
|
|
12
|
-
- uses: google-github-actions/release-please-action@v4
|
|
13
|
-
id: release
|
|
14
|
-
with:
|
|
15
|
-
release-type: node
|
|
16
|
-
package-name: tree-sitter-beancount
|
|
17
|
-
bump-minor-pre-major: true
|
|
18
|
-
bump-patch-for-minor-pre-major: true
|
|
19
|
-
extra-files: |
|
|
20
|
-
Cargo.toml
|
|
21
|
-
|
|
22
|
-
publish_cargo:
|
|
23
|
-
name: Publish Crate
|
|
24
|
-
runs-on: ubuntu-latest
|
|
25
|
-
needs: [release-please]
|
|
26
|
-
if: needs.release-please.outputs.release_created
|
|
27
|
-
steps:
|
|
28
|
-
- name: Installing Rust toolchain
|
|
29
|
-
uses: actions-rs/toolchain@v1
|
|
30
|
-
with:
|
|
31
|
-
toolchain: stable
|
|
32
|
-
profile: minimal
|
|
33
|
-
override: true
|
|
34
|
-
- name: Checking out sources
|
|
35
|
-
uses: actions/checkout@v4
|
|
36
|
-
- name: Cache Cargo
|
|
37
|
-
uses: actions/cache@v4
|
|
38
|
-
with:
|
|
39
|
-
path: |
|
|
40
|
-
~/.cargo/registry
|
|
41
|
-
~/.cargo/git
|
|
42
|
-
target
|
|
43
|
-
key: ${{ runner.os }}-cargo-publish-${{ hashFiles('**/Cargo.lock') }}
|
|
44
|
-
- name: Installing dependencies
|
|
45
|
-
run: |
|
|
46
|
-
sudo apt-get update
|
|
47
|
-
sudo apt-get install -y -qq pkg-config libssl-dev
|
|
48
|
-
- uses: actions-rs/cargo@v1
|
|
49
|
-
with:
|
|
50
|
-
command: publish
|
|
51
|
-
args: --token ${{ secrets.CARGO_API_KEY }} --allow-dirty
|
|
52
|
-
|
|
53
|
-
publish_npm:
|
|
54
|
-
name: Publish npm
|
|
55
|
-
runs-on: ubuntu-latest
|
|
56
|
-
needs: [release-please]
|
|
57
|
-
if: needs.release-please.outputs.release_created
|
|
58
|
-
steps:
|
|
59
|
-
- name: Checking out sources
|
|
60
|
-
uses: actions/checkout@v4
|
|
61
|
-
- name: Set up Node
|
|
62
|
-
uses: actions/setup-node@v4.0.3
|
|
63
|
-
with:
|
|
64
|
-
node-version: '16'
|
|
65
|
-
registry-url: 'https://registry.npmjs.org'
|
|
66
|
-
cache: 'npm'
|
|
67
|
-
- name: Install dependencies
|
|
68
|
-
run: npm install
|
|
69
|
-
- name: Publish to npm
|
|
70
|
-
run: npm publish
|
|
71
|
-
env:
|
|
72
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/CHANGELOG.md
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## [2.3.3](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.3.2...v2.3.3) (2024-07-20)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
### Bug Fixes
|
|
7
|
-
|
|
8
|
-
* support comments as part of key value lists ([c25f803](https://github.com/polarmutex/tree-sitter-beancount/commit/c25f8034c977681653a8acd541c8b4877a58f474))
|
|
9
|
-
* support embedded escaped quotes in strings ([9f6eb73](https://github.com/polarmutex/tree-sitter-beancount/commit/9f6eb73b2cc06325f6c31f9c58f84ba802a88fd0))
|
|
10
|
-
|
|
11
|
-
## [2.3.2](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.3.1...v2.3.2) (2024-03-09)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
### Bug Fixes
|
|
15
|
-
|
|
16
|
-
* binding and lock files for rust ([0727d62](https://github.com/polarmutex/tree-sitter-beancount/commit/0727d62af0dea0a78bbf132f53876888fc656c19))
|
|
17
|
-
* fix other scanner.cc references ([1f19abf](https://github.com/polarmutex/tree-sitter-beancount/commit/1f19abf1e162e1828013cb5434c6cf30f4054e80))
|
|
18
|
-
|
|
19
|
-
## [2.3.1](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.3.0...v2.3.1) (2024-02-29)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
### Bug Fixes
|
|
23
|
-
|
|
24
|
-
* cargo version ([01cc2ca](https://github.com/polarmutex/tree-sitter-beancount/commit/01cc2ca9073b1dab75e6d7996f48331b0c3f9057))
|
|
25
|
-
|
|
26
|
-
## [2.3.0](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.2.0...v2.3.0) (2024-02-29)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
### Features
|
|
30
|
-
|
|
31
|
-
* Add swift bindings ([0e08ee4](https://github.com/polarmutex/tree-sitter-beancount/commit/0e08ee4212edef5088bb3dd93ab0ba01f94792b0))
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
### Bug Fixes
|
|
35
|
-
|
|
36
|
-
* remove unneeded excludes ([cd08aef](https://github.com/polarmutex/tree-sitter-beancount/commit/cd08aefa20dc0f3d5984b08b5d468f75bf4fd096))
|
|
37
|
-
|
|
38
|
-
## [2.2.0](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.1.3...v2.2.0) (2023-10-10)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Features
|
|
42
|
-
|
|
43
|
-
* add named field for narration and payee ([0631b99](https://github.com/polarmutex/tree-sitter-beancount/commit/0631b99d9096e10f4e289efe618e518debe918b4))
|
|
44
|
-
|
|
45
|
-
## [2.1.3](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.1.2...v2.1.3) (2023-07-02)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
### Bug Fixes
|
|
49
|
-
|
|
50
|
-
* detect in error recovery and exit scan ([f3c05c6](https://github.com/polarmutex/tree-sitter-beancount/commit/f3c05c68aa03631fb4b9f0f7592bfec48376e65a))
|
|
51
|
-
|
|
52
|
-
## [2.1.2](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.1.1...v2.1.2) (2023-01-28)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
### Bug Fixes
|
|
56
|
-
|
|
57
|
-
* cleanup grammar upon feedback ([015e228](https://github.com/polarmutex/tree-sitter-beancount/commit/015e228ca684bbba5ee3e457020cf9c5d1d20afc))
|
|
58
|
-
* npm publish ([4cbd1f0](https://github.com/polarmutex/tree-sitter-beancount/commit/4cbd1f09cd07c1f1fabf867c2cf354f9da53cc4c))
|
|
59
|
-
|
|
60
|
-
## [2.1.1](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.1.0...v2.1.1) (2022-07-02)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### Bug Fixes
|
|
64
|
-
|
|
65
|
-
* changelog for prior versions ([8197699](https://github.com/polarmutex/tree-sitter-beancount/commit/8197699421b9787a3940b097ced363b9a4ba2f13))
|
|
66
|
-
* npm publish ([a105058](https://github.com/polarmutex/tree-sitter-beancount/commit/a1050584340a2375b6b480ba9e9691aebb9d33d5))
|
|
67
|
-
* rust binding build error ([bfbfa12](https://github.com/polarmutex/tree-sitter-beancount/commit/bfbfa12da0e1c7e598768c0f46f90bbe179d4be5))
|
|
68
|
-
|
|
69
|
-
## [2.1.0](https://github.com/polarmutex/tree-sitter-beancount/compare/v2.0.0...v2.1.0) (2022-06-28)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
### Features
|
|
73
|
-
|
|
74
|
-
* support org sections ([1b06224](https://github.com/polarmutex/tree-sitter-beancount/commit/1b06224c446f49586b0952de795e1562c6d76e3b))
|
|
75
|
-
|
|
76
|
-
## [2.0.0] (2021-11-11)
|
|
77
|
-
|
|
78
|
-
### Features
|
|
79
|
-
|
|
80
|
-
* Initial version of grammar
|