@prosdevlab/dev-agent 0.8.5

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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +138 -0
  3. package/dist/cli.js +74721 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/mcp.js +61445 -0
  6. package/dist/mcp.js.map +1 -0
  7. package/dist/vendor/web-tree-sitter/lib/alloc.c +48 -0
  8. package/dist/vendor/web-tree-sitter/lib/alloc.h +41 -0
  9. package/dist/vendor/web-tree-sitter/lib/array.h +291 -0
  10. package/dist/vendor/web-tree-sitter/lib/atomic.h +68 -0
  11. package/dist/vendor/web-tree-sitter/lib/clock.h +146 -0
  12. package/dist/vendor/web-tree-sitter/lib/error_costs.h +11 -0
  13. package/dist/vendor/web-tree-sitter/lib/get_changed_ranges.c +523 -0
  14. package/dist/vendor/web-tree-sitter/lib/get_changed_ranges.h +36 -0
  15. package/dist/vendor/web-tree-sitter/lib/host.h +21 -0
  16. package/dist/vendor/web-tree-sitter/lib/language.c +293 -0
  17. package/dist/vendor/web-tree-sitter/lib/language.h +293 -0
  18. package/dist/vendor/web-tree-sitter/lib/length.h +52 -0
  19. package/dist/vendor/web-tree-sitter/lib/lexer.c +483 -0
  20. package/dist/vendor/web-tree-sitter/lib/lexer.h +54 -0
  21. package/dist/vendor/web-tree-sitter/lib/lib.c +12 -0
  22. package/dist/vendor/web-tree-sitter/lib/node.c +875 -0
  23. package/dist/vendor/web-tree-sitter/lib/parser.c +2297 -0
  24. package/dist/vendor/web-tree-sitter/lib/parser.h +286 -0
  25. package/dist/vendor/web-tree-sitter/lib/point.h +48 -0
  26. package/dist/vendor/web-tree-sitter/lib/query.c +4347 -0
  27. package/dist/vendor/web-tree-sitter/lib/reduce_action.h +34 -0
  28. package/dist/vendor/web-tree-sitter/lib/reusable_node.h +95 -0
  29. package/dist/vendor/web-tree-sitter/lib/stack.c +912 -0
  30. package/dist/vendor/web-tree-sitter/lib/stack.h +133 -0
  31. package/dist/vendor/web-tree-sitter/lib/subtree.c +1034 -0
  32. package/dist/vendor/web-tree-sitter/lib/subtree.h +399 -0
  33. package/dist/vendor/web-tree-sitter/lib/tree-sitter.c +987 -0
  34. package/dist/vendor/web-tree-sitter/lib/tree-sitter.cjs +2988 -0
  35. package/dist/vendor/web-tree-sitter/lib/tree-sitter.wasm +0 -0
  36. package/dist/vendor/web-tree-sitter/lib/tree-sitter.wasm.map +1 -0
  37. package/dist/vendor/web-tree-sitter/lib/tree.c +170 -0
  38. package/dist/vendor/web-tree-sitter/lib/tree.h +31 -0
  39. package/dist/vendor/web-tree-sitter/lib/tree_cursor.c +716 -0
  40. package/dist/vendor/web-tree-sitter/lib/tree_cursor.h +48 -0
  41. package/dist/vendor/web-tree-sitter/lib/ts_assert.h +11 -0
  42. package/dist/vendor/web-tree-sitter/lib/unicode.h +75 -0
  43. package/dist/vendor/web-tree-sitter/lib/wasm_store.c +1937 -0
  44. package/dist/vendor/web-tree-sitter/lib/wasm_store.h +31 -0
  45. package/dist/vendor/web-tree-sitter/package.json +98 -0
  46. package/dist/vendor/web-tree-sitter/tree-sitter.cjs +4031 -0
  47. package/dist/vendor/web-tree-sitter/tree-sitter.wasm +0 -0
  48. package/dist/wasm/tree-sitter-go.wasm +0 -0
  49. package/dist/wasm/tree-sitter.wasm +0 -0
  50. package/package.json +65 -0
@@ -0,0 +1,293 @@
1
+ #include "./language.h"
2
+ #include "./wasm_store.h"
3
+ #include "tree_sitter/api.h"
4
+ #include <string.h>
5
+
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
+
19
+ uint32_t ts_language_symbol_count(const TSLanguage *self) {
20
+ return self->symbol_count + self->alias_count;
21
+ }
22
+
23
+ uint32_t ts_language_state_count(const TSLanguage *self) {
24
+ return self->state_count;
25
+ }
26
+
27
+ const TSSymbol *ts_language_supertypes(const TSLanguage *self, uint32_t *length) {
28
+ if (self->abi_version >= LANGUAGE_VERSION_WITH_RESERVED_WORDS) {
29
+ *length = self->supertype_count;
30
+ return self->supertype_symbols;
31
+ } else {
32
+ *length = 0;
33
+ return NULL;
34
+ }
35
+ }
36
+
37
+ const TSSymbol *ts_language_subtypes(
38
+ const TSLanguage *self,
39
+ TSSymbol supertype,
40
+ uint32_t *length
41
+ ) {
42
+ if (self->abi_version < LANGUAGE_VERSION_WITH_RESERVED_WORDS || !ts_language_symbol_metadata(self, supertype).supertype) {
43
+ *length = 0;
44
+ return NULL;
45
+ }
46
+
47
+ TSMapSlice slice = self->supertype_map_slices[supertype];
48
+ *length = slice.length;
49
+ return &self->supertype_map_entries[slice.index];
50
+ }
51
+
52
+ uint32_t ts_language_version(const TSLanguage *self) {
53
+ return self->abi_version;
54
+ }
55
+
56
+ uint32_t ts_language_abi_version(const TSLanguage *self) {
57
+ return self->abi_version;
58
+ }
59
+
60
+ const TSLanguageMetadata *ts_language_metadata(const TSLanguage *self) {
61
+ return self->abi_version >= LANGUAGE_VERSION_WITH_RESERVED_WORDS ? &self->metadata : NULL;
62
+ }
63
+
64
+ const char *ts_language_name(const TSLanguage *self) {
65
+ return self->abi_version >= LANGUAGE_VERSION_WITH_RESERVED_WORDS ? self->name : NULL;
66
+ }
67
+
68
+ uint32_t ts_language_field_count(const TSLanguage *self) {
69
+ return self->field_count;
70
+ }
71
+
72
+ void ts_language_table_entry(
73
+ const TSLanguage *self,
74
+ TSStateId state,
75
+ TSSymbol symbol,
76
+ TableEntry *result
77
+ ) {
78
+ if (symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat) {
79
+ result->action_count = 0;
80
+ result->is_reusable = false;
81
+ result->actions = NULL;
82
+ } else {
83
+ ts_assert(symbol < self->token_count);
84
+ uint32_t action_index = ts_language_lookup(self, state, symbol);
85
+ const TSParseActionEntry *entry = &self->parse_actions[action_index];
86
+ result->action_count = entry->entry.count;
87
+ result->is_reusable = entry->entry.reusable;
88
+ result->actions = (const TSParseAction *)(entry + 1);
89
+ }
90
+ }
91
+
92
+ TSLexerMode ts_language_lex_mode_for_state(
93
+ const TSLanguage *self,
94
+ TSStateId state
95
+ ) {
96
+ if (self->abi_version < 15) {
97
+ TSLexMode mode = ((const TSLexMode *)self->lex_modes)[state];
98
+ return (TSLexerMode) {
99
+ .lex_state = mode.lex_state,
100
+ .external_lex_state = mode.external_lex_state,
101
+ .reserved_word_set_id = 0,
102
+ };
103
+ } else {
104
+ return self->lex_modes[state];
105
+ }
106
+ }
107
+
108
+ bool ts_language_is_reserved_word(
109
+ const TSLanguage *self,
110
+ TSStateId state,
111
+ TSSymbol symbol
112
+ ) {
113
+ TSLexerMode lex_mode = ts_language_lex_mode_for_state(self, state);
114
+ if (lex_mode.reserved_word_set_id > 0) {
115
+ unsigned start = lex_mode.reserved_word_set_id * self->max_reserved_word_set_size;
116
+ unsigned end = start + self->max_reserved_word_set_size;
117
+ for (unsigned i = start; i < end; i++) {
118
+ if (self->reserved_words[i] == symbol) return true;
119
+ if (self->reserved_words[i] == 0) break;
120
+ }
121
+ }
122
+ return false;
123
+ }
124
+
125
+ TSSymbolMetadata ts_language_symbol_metadata(
126
+ const TSLanguage *self,
127
+ TSSymbol symbol
128
+ ) {
129
+ if (symbol == ts_builtin_sym_error) {
130
+ return (TSSymbolMetadata) {.visible = true, .named = true};
131
+ } else if (symbol == ts_builtin_sym_error_repeat) {
132
+ return (TSSymbolMetadata) {.visible = false, .named = false};
133
+ } else {
134
+ return self->symbol_metadata[symbol];
135
+ }
136
+ }
137
+
138
+ TSSymbol ts_language_public_symbol(
139
+ const TSLanguage *self,
140
+ TSSymbol symbol
141
+ ) {
142
+ if (symbol == ts_builtin_sym_error) return symbol;
143
+ return self->public_symbol_map[symbol];
144
+ }
145
+
146
+ TSStateId ts_language_next_state(
147
+ const TSLanguage *self,
148
+ TSStateId state,
149
+ TSSymbol symbol
150
+ ) {
151
+ if (symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat) {
152
+ return 0;
153
+ } else if (symbol < self->token_count) {
154
+ uint32_t count;
155
+ const TSParseAction *actions = ts_language_actions(self, state, symbol, &count);
156
+ if (count > 0) {
157
+ TSParseAction action = actions[count - 1];
158
+ if (action.type == TSParseActionTypeShift) {
159
+ return action.shift.extra ? state : action.shift.state;
160
+ }
161
+ }
162
+ return 0;
163
+ } else {
164
+ return ts_language_lookup(self, state, symbol);
165
+ }
166
+ }
167
+
168
+ const char *ts_language_symbol_name(
169
+ const TSLanguage *self,
170
+ TSSymbol symbol
171
+ ) {
172
+ if (symbol == ts_builtin_sym_error) {
173
+ return "ERROR";
174
+ } else if (symbol == ts_builtin_sym_error_repeat) {
175
+ return "_ERROR";
176
+ } else if (symbol < ts_language_symbol_count(self)) {
177
+ return self->symbol_names[symbol];
178
+ } else {
179
+ return NULL;
180
+ }
181
+ }
182
+
183
+ TSSymbol ts_language_symbol_for_name(
184
+ const TSLanguage *self,
185
+ const char *string,
186
+ uint32_t length,
187
+ bool is_named
188
+ ) {
189
+ if (is_named && !strncmp(string, "ERROR", length)) return ts_builtin_sym_error;
190
+ uint16_t count = (uint16_t)ts_language_symbol_count(self);
191
+ for (TSSymbol i = 0; i < count; i++) {
192
+ TSSymbolMetadata metadata = ts_language_symbol_metadata(self, i);
193
+ if ((!metadata.visible && !metadata.supertype) || metadata.named != is_named) continue;
194
+ const char *symbol_name = self->symbol_names[i];
195
+ if (!strncmp(symbol_name, string, length) && !symbol_name[length]) {
196
+ return self->public_symbol_map[i];
197
+ }
198
+ }
199
+ return 0;
200
+ }
201
+
202
+ TSSymbolType ts_language_symbol_type(
203
+ const TSLanguage *self,
204
+ TSSymbol symbol
205
+ ) {
206
+ TSSymbolMetadata metadata = ts_language_symbol_metadata(self, symbol);
207
+ if (metadata.named && metadata.visible) {
208
+ return TSSymbolTypeRegular;
209
+ } else if (metadata.visible) {
210
+ return TSSymbolTypeAnonymous;
211
+ } else if (metadata.supertype) {
212
+ return TSSymbolTypeSupertype;
213
+ } else {
214
+ return TSSymbolTypeAuxiliary;
215
+ }
216
+ }
217
+
218
+ const char *ts_language_field_name_for_id(
219
+ const TSLanguage *self,
220
+ TSFieldId id
221
+ ) {
222
+ uint32_t count = ts_language_field_count(self);
223
+ if (count && id <= count) {
224
+ return self->field_names[id];
225
+ } else {
226
+ return NULL;
227
+ }
228
+ }
229
+
230
+ TSFieldId ts_language_field_id_for_name(
231
+ const TSLanguage *self,
232
+ const char *name,
233
+ uint32_t name_length
234
+ ) {
235
+ uint16_t count = (uint16_t)ts_language_field_count(self);
236
+ for (TSSymbol i = 1; i < count + 1; i++) {
237
+ switch (strncmp(name, self->field_names[i], name_length)) {
238
+ case 0:
239
+ if (self->field_names[i][name_length] == 0) return i;
240
+ break;
241
+ case -1:
242
+ return 0;
243
+ default:
244
+ break;
245
+ }
246
+ }
247
+ return 0;
248
+ }
249
+
250
+ TSLookaheadIterator *ts_lookahead_iterator_new(const TSLanguage *self, TSStateId state) {
251
+ if (state >= self->state_count) return NULL;
252
+ LookaheadIterator *iterator = ts_malloc(sizeof(LookaheadIterator));
253
+ *iterator = ts_language_lookaheads(self, state);
254
+ return (TSLookaheadIterator *)iterator;
255
+ }
256
+
257
+ void ts_lookahead_iterator_delete(TSLookaheadIterator *self) {
258
+ ts_free(self);
259
+ }
260
+
261
+ bool ts_lookahead_iterator_reset_state(TSLookaheadIterator * self, TSStateId state) {
262
+ LookaheadIterator *iterator = (LookaheadIterator *)self;
263
+ if (state >= iterator->language->state_count) return false;
264
+ *iterator = ts_language_lookaheads(iterator->language, state);
265
+ return true;
266
+ }
267
+
268
+ const TSLanguage *ts_lookahead_iterator_language(const TSLookaheadIterator *self) {
269
+ const LookaheadIterator *iterator = (const LookaheadIterator *)self;
270
+ return iterator->language;
271
+ }
272
+
273
+ bool ts_lookahead_iterator_reset(TSLookaheadIterator *self, const TSLanguage *language, TSStateId state) {
274
+ if (state >= language->state_count) return false;
275
+ LookaheadIterator *iterator = (LookaheadIterator *)self;
276
+ *iterator = ts_language_lookaheads(language, state);
277
+ return true;
278
+ }
279
+
280
+ bool ts_lookahead_iterator_next(TSLookaheadIterator *self) {
281
+ LookaheadIterator *iterator = (LookaheadIterator *)self;
282
+ return ts_lookahead_iterator__next(iterator);
283
+ }
284
+
285
+ TSSymbol ts_lookahead_iterator_current_symbol(const TSLookaheadIterator *self) {
286
+ const LookaheadIterator *iterator = (const LookaheadIterator *)self;
287
+ return iterator->symbol;
288
+ }
289
+
290
+ const char *ts_lookahead_iterator_current_symbol_name(const TSLookaheadIterator *self) {
291
+ const LookaheadIterator *iterator = (const LookaheadIterator *)self;
292
+ return ts_language_symbol_name(iterator->language, iterator->symbol);
293
+ }
@@ -0,0 +1,293 @@
1
+ #ifndef TREE_SITTER_LANGUAGE_H_
2
+ #define TREE_SITTER_LANGUAGE_H_
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include "./subtree.h"
9
+ #include "./parser.h"
10
+
11
+ #define ts_builtin_sym_error_repeat (ts_builtin_sym_error - 1)
12
+
13
+ #define LANGUAGE_VERSION_WITH_RESERVED_WORDS 15
14
+ #define LANGUAGE_VERSION_WITH_PRIMARY_STATES 14
15
+
16
+ typedef struct {
17
+ const TSParseAction *actions;
18
+ uint32_t action_count;
19
+ bool is_reusable;
20
+ } TableEntry;
21
+
22
+ typedef struct {
23
+ const TSLanguage *language;
24
+ const uint16_t *data;
25
+ const uint16_t *group_end;
26
+ TSStateId state;
27
+ uint16_t table_value;
28
+ uint16_t section_index;
29
+ uint16_t group_count;
30
+ bool is_small_state;
31
+
32
+ const TSParseAction *actions;
33
+ TSSymbol symbol;
34
+ TSStateId next_state;
35
+ uint16_t action_count;
36
+ } LookaheadIterator;
37
+
38
+ void ts_language_table_entry(const TSLanguage *self, TSStateId state, TSSymbol symbol, TableEntry *result);
39
+ TSLexerMode ts_language_lex_mode_for_state(const TSLanguage *self, TSStateId state);
40
+ bool ts_language_is_reserved_word(const TSLanguage *self, TSStateId state, TSSymbol symbol);
41
+ TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *self, TSSymbol symbol);
42
+ TSSymbol ts_language_public_symbol(const TSLanguage *self, TSSymbol symbol);
43
+
44
+ static inline const TSParseAction *ts_language_actions(
45
+ const TSLanguage *self,
46
+ TSStateId state,
47
+ TSSymbol symbol,
48
+ uint32_t *count
49
+ ) {
50
+ TableEntry entry;
51
+ ts_language_table_entry(self, state, symbol, &entry);
52
+ *count = entry.action_count;
53
+ return entry.actions;
54
+ }
55
+
56
+ static inline bool ts_language_has_reduce_action(
57
+ const TSLanguage *self,
58
+ TSStateId state,
59
+ TSSymbol symbol
60
+ ) {
61
+ TableEntry entry;
62
+ ts_language_table_entry(self, state, symbol, &entry);
63
+ return entry.action_count > 0 && entry.actions[0].type == TSParseActionTypeReduce;
64
+ }
65
+
66
+ // Lookup the table value for a given symbol and state.
67
+ //
68
+ // For non-terminal symbols, the table value represents a successor state.
69
+ // For terminal symbols, it represents an index in the actions table.
70
+ // For 'large' parse states, this is a direct lookup. For 'small' parse
71
+ // states, this requires searching through the symbol groups to find
72
+ // the given symbol.
73
+ static inline uint16_t ts_language_lookup(
74
+ const TSLanguage *self,
75
+ TSStateId state,
76
+ TSSymbol symbol
77
+ ) {
78
+ if (state >= self->large_state_count) {
79
+ uint32_t index = self->small_parse_table_map[state - self->large_state_count];
80
+ const uint16_t *data = &self->small_parse_table[index];
81
+ uint16_t group_count = *(data++);
82
+ for (unsigned i = 0; i < group_count; i++) {
83
+ uint16_t section_value = *(data++);
84
+ uint16_t symbol_count = *(data++);
85
+ for (unsigned j = 0; j < symbol_count; j++) {
86
+ if (*(data++) == symbol) return section_value;
87
+ }
88
+ }
89
+ return 0;
90
+ } else {
91
+ return self->parse_table[state * self->symbol_count + symbol];
92
+ }
93
+ }
94
+
95
+ static inline bool ts_language_has_actions(
96
+ const TSLanguage *self,
97
+ TSStateId state,
98
+ TSSymbol symbol
99
+ ) {
100
+ return ts_language_lookup(self, state, symbol) != 0;
101
+ }
102
+
103
+ // Iterate over all of the symbols that are valid in the given state.
104
+ //
105
+ // For 'large' parse states, this just requires iterating through
106
+ // all possible symbols and checking the parse table for each one.
107
+ // For 'small' parse states, this exploits the structure of the
108
+ // table to only visit the valid symbols.
109
+ static inline LookaheadIterator ts_language_lookaheads(
110
+ const TSLanguage *self,
111
+ TSStateId state
112
+ ) {
113
+ bool is_small_state = state >= self->large_state_count;
114
+ const uint16_t *data;
115
+ const uint16_t *group_end = NULL;
116
+ uint16_t group_count = 0;
117
+ if (is_small_state) {
118
+ uint32_t index = self->small_parse_table_map[state - self->large_state_count];
119
+ data = &self->small_parse_table[index];
120
+ group_end = data + 1;
121
+ group_count = *data;
122
+ } else {
123
+ data = &self->parse_table[state * self->symbol_count] - 1;
124
+ }
125
+ return (LookaheadIterator) {
126
+ .language = self,
127
+ .data = data,
128
+ .group_end = group_end,
129
+ .group_count = group_count,
130
+ .is_small_state = is_small_state,
131
+ .symbol = UINT16_MAX,
132
+ .next_state = 0,
133
+ };
134
+ }
135
+
136
+ static inline bool ts_lookahead_iterator__next(LookaheadIterator *self) {
137
+ // For small parse states, valid symbols are listed explicitly,
138
+ // grouped by their value. There's no need to look up the actions
139
+ // again until moving to the next group.
140
+ if (self->is_small_state) {
141
+ self->data++;
142
+ if (self->data == self->group_end) {
143
+ if (self->group_count == 0) return false;
144
+ self->group_count--;
145
+ self->table_value = *(self->data++);
146
+ unsigned symbol_count = *(self->data++);
147
+ self->group_end = self->data + symbol_count;
148
+ self->symbol = *self->data;
149
+ } else {
150
+ self->symbol = *self->data;
151
+ return true;
152
+ }
153
+ }
154
+
155
+ // For large parse states, iterate through every symbol until one
156
+ // is found that has valid actions.
157
+ else {
158
+ do {
159
+ self->data++;
160
+ self->symbol++;
161
+ if (self->symbol >= self->language->symbol_count) return false;
162
+ self->table_value = *self->data;
163
+ } while (!self->table_value);
164
+ }
165
+
166
+ // Depending on if the symbols is terminal or non-terminal, the table value either
167
+ // represents a list of actions or a successor state.
168
+ if (self->symbol < self->language->token_count) {
169
+ const TSParseActionEntry *entry = &self->language->parse_actions[self->table_value];
170
+ self->action_count = entry->entry.count;
171
+ self->actions = (const TSParseAction *)(entry + 1);
172
+ self->next_state = 0;
173
+ } else {
174
+ self->action_count = 0;
175
+ self->next_state = self->table_value;
176
+ }
177
+ return true;
178
+ }
179
+
180
+ // Whether the state is a "primary state". If this returns false, it indicates that there exists
181
+ // another state that behaves identically to this one with respect to query analysis.
182
+ static inline bool ts_language_state_is_primary(
183
+ const TSLanguage *self,
184
+ TSStateId state
185
+ ) {
186
+ if (self->abi_version >= LANGUAGE_VERSION_WITH_PRIMARY_STATES) {
187
+ return state == self->primary_state_ids[state];
188
+ } else {
189
+ return true;
190
+ }
191
+ }
192
+
193
+ static inline const bool *ts_language_enabled_external_tokens(
194
+ const TSLanguage *self,
195
+ unsigned external_scanner_state
196
+ ) {
197
+ if (external_scanner_state == 0) {
198
+ return NULL;
199
+ } else {
200
+ return self->external_scanner.states + self->external_token_count * external_scanner_state;
201
+ }
202
+ }
203
+
204
+ static inline const TSSymbol *ts_language_alias_sequence(
205
+ const TSLanguage *self,
206
+ uint32_t production_id
207
+ ) {
208
+ return production_id ?
209
+ &self->alias_sequences[production_id * self->max_alias_sequence_length] :
210
+ NULL;
211
+ }
212
+
213
+ static inline TSSymbol ts_language_alias_at(
214
+ const TSLanguage *self,
215
+ uint32_t production_id,
216
+ uint32_t child_index
217
+ ) {
218
+ return production_id ?
219
+ self->alias_sequences[production_id * self->max_alias_sequence_length + child_index] :
220
+ 0;
221
+ }
222
+
223
+ static inline void ts_language_field_map(
224
+ const TSLanguage *self,
225
+ uint32_t production_id,
226
+ const TSFieldMapEntry **start,
227
+ const TSFieldMapEntry **end
228
+ ) {
229
+ if (self->field_count == 0) {
230
+ *start = NULL;
231
+ *end = NULL;
232
+ return;
233
+ }
234
+
235
+ TSMapSlice slice = self->field_map_slices[production_id];
236
+ *start = &self->field_map_entries[slice.index];
237
+ *end = &self->field_map_entries[slice.index] + slice.length;
238
+ }
239
+
240
+ static inline void ts_language_aliases_for_symbol(
241
+ const TSLanguage *self,
242
+ TSSymbol original_symbol,
243
+ const TSSymbol **start,
244
+ const TSSymbol **end
245
+ ) {
246
+ *start = &self->public_symbol_map[original_symbol];
247
+ *end = *start + 1;
248
+
249
+ unsigned idx = 0;
250
+ for (;;) {
251
+ TSSymbol symbol = self->alias_map[idx++];
252
+ if (symbol == 0 || symbol > original_symbol) break;
253
+ uint16_t count = self->alias_map[idx++];
254
+ if (symbol == original_symbol) {
255
+ *start = &self->alias_map[idx];
256
+ *end = &self->alias_map[idx + count];
257
+ break;
258
+ }
259
+ idx += count;
260
+ }
261
+ }
262
+
263
+ static inline void ts_language_write_symbol_as_dot_string(
264
+ const TSLanguage *self,
265
+ FILE *f,
266
+ TSSymbol symbol
267
+ ) {
268
+ const char *name = ts_language_symbol_name(self, symbol);
269
+ for (const char *chr = name; *chr; chr++) {
270
+ switch (*chr) {
271
+ case '"':
272
+ case '\\':
273
+ fputc('\\', f);
274
+ fputc(*chr, f);
275
+ break;
276
+ case '\n':
277
+ fputs("\\n", f);
278
+ break;
279
+ case '\t':
280
+ fputs("\\t", f);
281
+ break;
282
+ default:
283
+ fputc(*chr, f);
284
+ break;
285
+ }
286
+ }
287
+ }
288
+
289
+ #ifdef __cplusplus
290
+ }
291
+ #endif
292
+
293
+ #endif // TREE_SITTER_LANGUAGE_H_
@@ -0,0 +1,52 @@
1
+ #ifndef TREE_SITTER_LENGTH_H_
2
+ #define TREE_SITTER_LENGTH_H_
3
+
4
+ #include <stdlib.h>
5
+ #include <stdbool.h>
6
+ #include "./point.h"
7
+ #include "tree_sitter/api.h"
8
+
9
+ typedef struct {
10
+ uint32_t bytes;
11
+ TSPoint extent;
12
+ } Length;
13
+
14
+ static const Length LENGTH_UNDEFINED = {0, {0, 1}};
15
+ static const Length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}};
16
+
17
+ static inline bool length_is_undefined(Length length) {
18
+ return length.bytes == 0 && length.extent.column != 0;
19
+ }
20
+
21
+ static inline Length length_min(Length len1, Length len2) {
22
+ return (len1.bytes < len2.bytes) ? len1 : len2;
23
+ }
24
+
25
+ static inline Length length_add(Length len1, Length len2) {
26
+ Length result;
27
+ result.bytes = len1.bytes + len2.bytes;
28
+ result.extent = point_add(len1.extent, len2.extent);
29
+ return result;
30
+ }
31
+
32
+ static inline Length length_sub(Length len1, Length len2) {
33
+ Length result;
34
+ result.bytes = (len1.bytes >= len2.bytes) ? len1.bytes - len2.bytes : 0;
35
+ result.extent = point_sub(len1.extent, len2.extent);
36
+ return result;
37
+ }
38
+
39
+ static inline Length length_zero(void) {
40
+ Length result = {0, {0, 0}};
41
+ return result;
42
+ }
43
+
44
+ static inline Length length_saturating_sub(Length len1, Length len2) {
45
+ if (len1.bytes > len2.bytes) {
46
+ return length_sub(len1, len2);
47
+ } else {
48
+ return length_zero();
49
+ }
50
+ }
51
+
52
+ #endif