13 #define MAX_STEP_CAPTURE_COUNT 3
14 #define MAX_NEGATED_FIELD_COUNT 8
15 #define MAX_STATE_PREDECESSOR_COUNT 256
16 #define MAX_ANALYSIS_STATE_DEPTH 8
17 #define MAX_ANALYSIS_ITERATION_COUNT 256
119 Array(
char) characters;
203 CaptureList empty_list;
272 Array(CaptureQuantifiers) capture_quantifiers;
280 Array(
char) string_buffer;
282 uint16_t wildcard_root_pattern_count;
302 bool did_exceed_match_limit;
316 self->input +=
self->next_size;
317 if (self->input < self->end) {
320 self->end - self->input,
324 self->next_size =
size;
355 if (iswspace(self->next)) {
357 }
else if (self->next ==
';') {
360 while (self->next && self->next !=
'\n') {
370 return iswalnum(self->next) ||
self->next ==
'_' ||
self->next ==
'-';
387 return self->input -
self->start;
399 .free_capture_list_count = 0,
408 self->free_capture_list_count =
self->list.size;
419 if (
id >= self->list.size)
return &
self->empty_list;
420 return &
self->list.contents[
id];
425 return &
self->list.contents[
id];
431 return self->free_capture_list_count == 0 &&
self->list.size >=
self->max_capture_list_count;
436 if (self->free_capture_list_count > 0) {
440 self->free_capture_list_count--;
449 if (
i >= self->max_capture_list_count) {
459 if (
id >= self->list.size)
return;
461 self->free_capture_list_count++;
634 CaptureQuantifiers *
self
641 CaptureQuantifiers *
self
648 CaptureQuantifiers *
self,
649 CaptureQuantifiers *quantifiers
657 const CaptureQuantifiers *
self,
665 CaptureQuantifiers *
self,
669 if (self->size <=
id) {
678 CaptureQuantifiers *
self,
679 CaptureQuantifiers *quantifiers
681 if (self->size < quantifiers->size) {
684 for (
uint16_t id = 0;
id < quantifiers->size;
id++) {
693 CaptureQuantifiers *
self,
696 for (
uint16_t id = 0;
id <
self->size;
id++) {
704 CaptureQuantifiers *
self,
705 CaptureQuantifiers *quantifiers
707 if (self->size < quantifiers->size) {
710 for (
uint32_t id = 0;
id < quantifiers->size;
id++) {
715 for (
uint32_t id = quantifiers->size; id < self->
size;
id++) {
742 for (
unsigned i = 0;
i <
self->slices.size;
i++) {
743 Slice slice =
self->slices.contents[
i];
757 Slice slice =
self->slices.contents[
id];
759 return &
self->characters.contents[slice.
offset];
770 .
offset =
self->characters.size,
775 self->characters.contents[
self->characters.size - 1] = 0;
777 return self->slices.size - 1;
794 .alternative_index =
NONE,
795 .negated_field_list_id = 0,
796 .contains_captures =
false,
797 .is_last_child =
false,
799 .is_pass_through =
false,
800 .is_dead_end =
false,
801 .root_pattern_guaranteed =
false,
803 .alternative_is_immediate =
false,
809 if (self->capture_ids[
i] ==
NONE) {
810 self->capture_ids[
i] = capture_id;
818 if (self->capture_ids[
i] == capture_id) {
819 self->capture_ids[
i] =
NONE;
821 if (self->capture_ids[
i + 1] ==
NONE)
break;
822 self->capture_ids[
i] =
self->capture_ids[
i + 1];
823 self->capture_ids[
i + 1] =
NONE;
859 (*count < MAX_STATE_PREDECESSOR_COUNT && self->contents[index + *
count] != predecessor)
862 self->contents[index + *
count] = predecessor;
872 *
count =
self->contents[index];
873 return &
self->contents[index + 1];
882 for (
unsigned i = 0;
i <
self->depth;
i++) {
883 TSSymbol symbol =
self->stack[
i].parent_symbol;
884 for (
unsigned j = 0; j <
i; j++) {
885 if (self->stack[j].parent_symbol == symbol) {
898 for (
unsigned i = 0;
i < (*self)->depth;
i++) {
899 if (
i >= (*other)->depth)
return -1;
900 if ((*self)->stack[
i].child_index < (*other)->stack[
i].child_index)
return -1;
901 if ((*self)->stack[
i].child_index > (*other)->stack[
i].child_index)
return 1;
903 if ((*self)->depth < (*other)->depth)
return 1;
904 if ((*self)->step_index < (*other)->step_index)
return -1;
905 if ((*self)->step_index > (*other)->step_index)
return 1;
914 if (result != 0)
return result;
915 for (
unsigned i = 0;
i < (*self)->depth;
i++) {
916 if ((*self)->stack[
i].parent_symbol < (*other)->stack[
i].parent_symbol)
return -1;
917 if ((*self)->stack[
i].parent_symbol > (*other)->stack[
i].parent_symbol)
return 1;
918 if ((*self)->stack[
i].parse_state < (*other)->stack[
i].parse_state)
return -1;
919 if ((*self)->stack[
i].parse_state > (*other)->stack[
i].parse_state)
return 1;
920 if ((*self)->stack[
i].field_id < (*other)->stack[
i].field_id)
return -1;
921 if ((*self)->stack[
i].field_id > (*other)->stack[
i].field_id)
return 1;
927 return &
self->stack[
self->depth - 1];
931 for (
unsigned i = 0;
i <
self->depth;
i++) {
932 if (self->stack[
i].parent_symbol == symbol)
return true;
950 AnalysisStatePool *
self,
956 *new_item = *borrowed_item;
971 AnalysisStateSet *
self,
972 AnalysisStatePool *pool,
975 unsigned index, exists;
992 AnalysisStateSet *
self,
993 AnalysisStatePool *pool,
1009 for (
unsigned i = 0;
i <
self->size;
i++) {
1020 if (self->state < other->state)
return -1;
1021 if (self->state > other->state)
return 1;
1022 if (self->child_index < other->child_index)
return -1;
1023 if (self->child_index > other->child_index)
return 1;
1024 if (self->done < other->done)
return -1;
1025 if (self->done > other->done)
return 1;
1026 if (self->production_id < other->production_id)
return -1;
1027 if (self->production_id > other->production_id)
return 1;
1054 uint32_t base_index =
self->wildcard_root_pattern_count;
1057 *result = base_index;
1062 uint32_t mid_index = base_index + half_size;
1063 TSSymbol mid_symbol =
self->steps.contents[
1064 self->pattern_map.contents[mid_index].step_index
1066 if (needle > mid_symbol) base_index = mid_index;
1070 TSSymbol symbol =
self->steps.contents[
1071 self->pattern_map.contents[base_index].step_index
1074 if (needle > symbol) {
1076 if (base_index < self->pattern_map.size) {
1077 symbol =
self->steps.contents[
1078 self->pattern_map.contents[base_index].step_index
1083 *result = base_index;
1084 return needle == symbol;
1101 while (index < self->pattern_map.size) {
1104 self->steps.contents[
entry->step_index].symbol == symbol &&
1105 entry->pattern_index < new_entry.pattern_index
1121 for (
unsigned i = 0;
i <
self->steps.size;
i++) {
1124 step->parent_pattern_guaranteed =
true;
1125 step->root_pattern_guaranteed =
true;
1129 bool has_children =
false;
1131 step->contains_captures =
step->capture_ids[0] !=
NONE;
1132 for (
unsigned j =
i + 1; j <
self->steps.size; j++) {
1133 QueryStep *next_step = &
self->steps.contents[j];
1139 step->contains_captures =
true;
1145 has_children =
true;
1148 if (has_children && !is_wildcard) {
1162 for (
unsigned i = 0;
i < parent_step_indices.size;
i++) {
1163 uint32_t parent_step_index = parent_step_indices.contents[
i];
1164 TSSymbol parent_symbol =
self->steps.contents[parent_step_index].symbol;
1168 for (
TSSymbol sym = self->language->token_count; sym < self->language->symbol_count; sym++) {
1183 unsigned subgraph_index, exists;
1190 const TSSymbol *aliases, *aliases_end;
1197 for (
const TSSymbol *symbol = aliases; symbol < aliases_end; symbol++) {
1207 if (subgraph->nodes.size == 0 ||
array_back(&subgraph->nodes)->state !=
state) {
1210 .production_id = action->reduce.production_id,
1211 .child_index = action->reduce.child_count,
1222 }
else if (lookahead_iterator.
next_state != 0) {
1227 const TSSymbol *aliases, *aliases_end;
1230 lookahead_iterator.
symbol,
1234 for (
const TSSymbol *symbol = aliases; symbol < aliases_end; symbol++) {
1245 subgraph->start_states.size == 0 ||
1259 for (
unsigned i = 0;
i < subgraphs.size;
i++) {
1261 if (subgraph->nodes.size == 0) {
1268 while (next_nodes.size > 0) {
1270 if (node.child_index > 1) {
1271 unsigned predecessor_count;
1277 for (
unsigned j = 0; j < predecessor_count; j++) {
1279 .state = predecessors[j],
1280 .child_index = node.child_index - 1,
1281 .production_id = node.production_id,
1284 unsigned index, exists;
1290 array_insert(&subgraph->nodes, index, predecessor_node);
1298 #ifdef DEBUG_ANALYZE_QUERY
1299 printf(
"\nSubgraphs:\n");
1300 for (
unsigned i = 0;
i < subgraphs.size;
i++) {
1303 for (
unsigned j = 0; j < subgraph->start_states.size; j++) {
1306 subgraph->start_states.contents[j]
1309 for (
unsigned j = 0; j < subgraph->nodes.size; j++) {
1312 " {state: %u, child_index: %u, production_id: %u, done: %d}\n",
1313 node->state, node->child_index, node->production_id, node->done
1322 bool all_patterns_are_valid =
true;
1324 AnalysisStateSet next_states =
array_new();
1325 AnalysisStateSet deeper_states =
array_new();
1326 AnalysisStatePool state_pool =
array_new();
1328 for (
unsigned i = 0;
i < parent_step_indices.size;
i++) {
1329 uint16_t parent_step_index = parent_step_indices.contents[
i];
1330 uint16_t parent_depth =
self->steps.contents[parent_step_index].depth;
1331 TSSymbol parent_symbol =
self->steps.contents[parent_step_index].symbol;
1336 unsigned subgraph_index, exists;
1339 unsigned first_child_step_index = parent_step_index + 1;
1343 *error_offset =
self->step_offsets.contents[
i].byte_offset;
1344 all_patterns_are_valid =
false;
1353 for (
unsigned j = 0; j < subgraph->start_states.size; j++) {
1354 TSStateId parse_state = subgraph->start_states.contents[j];
1356 .step_index = parent_step_index + 1,
1359 .parse_state = parse_state,
1360 .parent_symbol = parent_symbol,
1372 bool can_finish_pattern =
false;
1373 bool did_abort_analysis =
false;
1374 unsigned recursion_depth_limit = 0;
1375 unsigned prev_final_step_count = 0;
1377 for (
unsigned iteration = 0;; iteration++) {
1379 did_abort_analysis =
true;
1383 #ifdef DEBUG_ANALYZE_QUERY
1384 printf(
"Iteration: %u. Final step indices:", iteration);
1385 for (
unsigned j = 0; j < final_step_indices.size; j++) {
1386 printf(
" %4u", final_step_indices.contents[j]);
1389 for (
unsigned j = 0; j <
states.size; j++) {
1391 printf(
" %3u: step: %u, stack: [", j,
state->step_index);
1392 for (
unsigned k = 0;
k <
state->depth;
k++) {
1394 " {%s, child: %u, state: %4u",
1395 self->language->symbol_names[
state->stack[
k].parent_symbol],
1396 state->stack[
k].child_index,
1397 state->stack[
k].parse_state
1399 if (
state->stack[
k].field_id)
printf(
", field: %s", self->language->field_names[
state->stack[
k].field_id]);
1413 deeper_states.size > 0
1414 && final_step_indices.size > prev_final_step_count
1416 #ifdef DEBUG_ANALYZE_QUERY
1417 printf(
"Increase recursion depth limit to %u\n", recursion_depth_limit + 1);
1420 prev_final_step_count = final_step_indices.size;
1421 recursion_depth_limit++;
1422 AnalysisStateSet _states =
states;
1424 deeper_states = _states;
1432 for (
unsigned j = 0; j <
states.size; j++) {
1440 if (next_states.size > 0) {
1445 if (comparison == 0) {
1446 #ifdef DEBUG_ANALYZE_QUERY
1447 printf(
"Skip iteration for state %u\n", j);
1451 }
else if (comparison > 0) {
1452 #ifdef DEBUG_ANALYZE_QUERY
1453 printf(
"Terminate iteration at state %u\n", j);
1455 while (j <
states.size) {
1473 unsigned subgraph_index, exists;
1475 if (!exists)
continue;
1485 .state = parse_state,
1486 .child_index = child_index,
1491 if (!
action->shift.extra) {
1493 successor.child_index++;
1498 }
else if (lookahead_iterator.
next_state != 0) {
1499 successor.state = lookahead_iterator.
next_state;
1500 successor.child_index++;
1505 unsigned node_index;
1509 &node_index, &exists
1511 while (node_index < subgraph->nodes.size) {
1513 if (node->state != successor.state || node->child_index != successor.child_index)
break;
1520 :
self->language->symbol_metadata[sym].visible
1521 ?
self->language->public_symbol_map[sym]
1527 for (; field_map != field_map_end; field_map++) {
1538 next_state_top->
child_index = successor.child_index;
1540 if (node->done) next_state_top->
done =
true;
1544 bool does_match =
false;
1545 if (visible_symbol) {
1550 !self->language->symbol_metadata[visible_symbol].named
1551 ) does_match =
false;
1552 }
else if (
step->symbol != visible_symbol) {
1559 step->supertype_symbol &&
1561 ) does_match =
false;
1567 else if (sym >= self->language->token_count) {
1568 if (!next_state_top->
done) {
1570 #ifdef DEBUG_ANALYZE_QUERY
1571 printf(
"Exceeded depth limit for state %u\n", j);
1574 did_abort_analysis =
true;
1584 .parent_symbol = sym,
1601 while (next_state.
depth > 0 && next_state_top->
done) {
1613 next_step = &
self->steps.contents[next_state.
step_index];
1616 next_step->
depth <= parent_depth + 1
1619 }
else if (successor.state == parse_state) {
1637 bool did_finish_pattern =
self->steps.contents[next_state.
step_index].
depth != parent_depth + 1;
1638 if (did_finish_pattern) can_finish_pattern =
true;
1639 if (did_finish_pattern || next_state.
depth == 0) {
1656 next_step = &
self->steps.contents[next_state.
step_index];
1665 AnalysisStateSet _states =
states;
1667 next_states = _states;
1672 if (did_abort_analysis) {
1673 for (
unsigned j = parent_step_index + 1; j <
self->steps.size; j++) {
1676 step->depth <= parent_depth ||
1679 if (!
step->is_dead_end) {
1680 step->parent_pattern_guaranteed =
false;
1681 step->root_pattern_guaranteed =
false;
1689 if (!can_finish_pattern) {
1690 assert(final_step_indices.size > 0);
1694 if (
i >= self->step_offsets.size)
i =
self->step_offsets.size - 1;
1695 *error_offset =
self->step_offsets.contents[
i].byte_offset;
1696 all_patterns_are_valid =
false;
1702 for (
unsigned j = 0; j < final_step_indices.size; j++) {
1703 uint32_t final_step_index = final_step_indices.contents[j];
1707 step->depth > parent_depth &&
1710 step->parent_pattern_guaranteed =
false;
1711 step->root_pattern_guaranteed =
false;
1718 for (
unsigned i = 0;
i <
self->patterns.size;
i++) {
1743 if (capture_id ==
NONE)
break;
1744 unsigned index, exists;
1747 step->root_pattern_guaranteed =
false;
1756 bool done =
self->steps.size == 0;
1759 for (
unsigned i = self->steps.size - 1;
i > 0;
i--) {
1764 bool parent_pattern_guaranteed =
false;
1766 if (
step->root_pattern_guaranteed) {
1767 parent_pattern_guaranteed =
true;
1770 if (
step->alternative_index ==
NONE ||
step->alternative_index <
i) {
1773 step = &
self->steps.contents[
step->alternative_index];
1777 if (!parent_pattern_guaranteed) {
1778 QueryStep *prev_step = &
self->steps.contents[
i - 1];
1791 #ifdef DEBUG_ANALYZE_QUERY
1793 for (
unsigned i = 0;
i <
self->steps.size;
i++) {
1799 " %u: {symbol: %s, field: %s, depth: %u, parent_pattern_guaranteed: %d, root_pattern_guaranteed: %d}\n",
1806 step->parent_pattern_guaranteed,
1807 step->root_pattern_guaranteed
1814 for (
unsigned i = 0;
i < subgraphs.size;
i++) {
1819 for (
unsigned i = 0;
i < state_pool.size;
i++) {
1832 return all_patterns_are_valid;
1845 bool failed_match =
false;
1846 unsigned match_count = 0;
1847 unsigned start_i = 0;
1848 for (
unsigned i = 0;
i <
self->negated_fields.size;
i++) {
1849 TSFieldId existing_field_id =
self->negated_fields.contents[
i];
1854 if (existing_field_id == 0) {
1855 if (match_count == field_count) {
1856 step->negated_field_list_id = start_i;
1861 failed_match =
false;
1868 match_count < field_count &&
1869 existing_field_id == field_ids[match_count] &&
1878 failed_match =
true;
1882 step->negated_field_list_id =
self->negated_fields.size;
1883 array_extend(&self->negated_fields, field_count, field_ids);
1891 const char *string_start =
stream->input;
1894 const char *prev_position =
stream->input;
1896 bool is_escaped =
false;
1920 if (
stream->next ==
'\\') {
1922 prev_position =
stream->input + 1;
1924 }
else if (
stream->next ==
'"') {
1928 }
else if (
stream->next ==
'\n') {
1951 const char *predicate_name =
stream->input;
1955 &self->predicate_values,
1960 .type = TSQueryPredicateStepTypeString,
1966 if (
stream->next ==
')') {
1970 .type = TSQueryPredicateStepTypeDone,
1977 else if (
stream->next ==
'@') {
1982 const char *capture_name =
stream->input;
1992 if (capture_id == -1) {
1998 .type = TSQueryPredicateStepTypeCapture,
1999 .value_id = capture_id,
2004 else if (
stream->next ==
'"') {
2008 &self->predicate_values,
2009 self->string_buffer.contents,
2010 self->string_buffer.size
2013 .type = TSQueryPredicateStepTypeString,
2020 const char *symbol_start =
stream->input;
2024 &self->predicate_values,
2029 .type = TSQueryPredicateStepTypeString,
2055 CaptureQuantifiers *capture_quantifiers
2060 const uint32_t starting_step_index =
self->steps.size;
2064 self->step_offsets.size == 0 ||
2065 array_back(&self->step_offsets)->step_index != starting_step_index
2068 .step_index = starting_step_index,
2069 .byte_offset = stream_offset(stream),
2074 if (
stream->next ==
'[') {
2082 uint32_t start_index =
self->steps.size;
2088 &branch_capture_quantifiers
2092 if (
stream->next ==
']' && branch_step_indices.size > 0) {
2104 if(start_index == starting_step_index) {
2110 array_push(&branch_step_indices, start_index);
2118 for (
unsigned i = 0;
i < branch_step_indices.size - 1;
i++) {
2119 uint32_t step_index = branch_step_indices.contents[
i];
2120 uint32_t next_step_index = branch_step_indices.contents[
i + 1];
2121 QueryStep *start_step = &
self->steps.contents[step_index];
2122 QueryStep *end_step = &
self->steps.contents[next_step_index - 1];
2136 else if (
stream->next ==
'(') {
2142 bool child_is_immediate =
false;
2145 if (
stream->next ==
'.') {
2146 child_is_immediate =
true;
2155 &child_capture_quantifiers
2158 if (
stream->next ==
')') {
2171 child_is_immediate =
false;
2189 const char *node_name =
stream->input;
2201 else if (
length == 1 && node_name[0] ==
'_') {
2225 step->supertype_symbol =
step->symbol;
2229 step->is_named =
true;
2234 if (
stream->next ==
'/') {
2240 const char *node_name =
stream->input;
2250 if (!
step->symbol) {
2259 bool child_is_immediate =
false;
2260 uint16_t last_child_step_index = 0;
2266 if (
stream->next ==
'!') {
2291 negated_field_ids[negated_field_count] =
field_id;
2292 negated_field_count++;
2299 if (
stream->next ==
'.') {
2300 child_is_immediate =
true;
2305 uint16_t step_index =
self->steps.size;
2311 &child_capture_quantifiers
2314 if (
stream->next ==
')') {
2315 if (child_is_immediate) {
2316 if (last_child_step_index == 0) {
2320 self->steps.contents[last_child_step_index].is_last_child =
true;
2323 if (negated_field_count) {
2326 starting_step_index,
2344 last_child_step_index = step_index;
2345 child_is_immediate =
false;
2353 else if (
stream->next ==
'_') {
2362 else if (
stream->next ==
'"') {
2363 const char *string_start =
stream->input;
2370 self->string_buffer.contents,
2371 self->string_buffer.size,
2389 if (
stream->next !=
':') {
2403 &field_capture_quantifiers
2422 uint32_t step_index = starting_step_index;
2428 step->alternative_index > step_index &&
2429 step->alternative_index < self->steps.size
2431 step_index =
step->alternative_index;
2432 step = &
self->steps.contents[step_index];
2452 if (
stream->next ==
'+') {
2466 else if (
stream->next ==
'*') {
2478 QueryStep *
step = &
self->steps.contents[starting_step_index];
2479 while (
step->alternative_index !=
NONE) {
2480 step = &
self->steps.contents[
step->alternative_index];
2482 step->alternative_index =
self->steps.size;
2486 else if (
stream->next ==
'?') {
2492 QueryStep *
step = &
self->steps.contents[starting_step_index];
2493 while (
step->alternative_index !=
NONE) {
2494 step = &
self->steps.contents[
step->alternative_index];
2496 step->alternative_index =
self->steps.size;
2500 else if (
stream->next ==
'@') {
2503 const char *capture_name =
stream->input;
2518 uint32_t step_index = starting_step_index;
2524 step->alternative_index > step_index &&
2525 step->alternative_index < self->steps.size
2527 step_index =
step->alternative_index;
2528 step = &
self->steps.contents[step_index];
2574 .wildcard_root_pattern_count = 0,
2575 .language = language,
2584 uint32_t pattern_index =
self->patterns.size;
2585 uint32_t start_step_index =
self->steps.size;
2586 uint32_t start_predicate_step_index =
self->predicate_steps.size;
2588 .steps = (Slice) {.offset = start_step_index},
2589 .predicate_steps = (
Slice) {.offset = start_predicate_step_index},
2597 pattern->
steps.
length =
self->steps.size - start_step_index;
2611 array_push(&self->capture_quantifiers, capture_quantifiers);
2623 QueryStep *second_step = &
self->steps.contents[start_step_index + 1];
2625 wildcard_root_alternative_index =
step->alternative_index;
2626 start_step_index += 1;
2634 bool is_rooted =
true;
2636 for (
uint32_t step_index = start_step_index + 1; step_index <
self->steps.size; step_index++) {
2638 if (
step->depth == start_depth) {
2645 .step_index = start_step_index,
2646 .pattern_index = pattern_index,
2647 .is_rooted = is_rooted
2650 self->wildcard_root_pattern_count++;
2655 if (
step->alternative_index !=
NONE) {
2656 start_step_index =
step->alternative_index;
2658 }
else if (wildcard_root_alternative_index !=
NONE) {
2659 start_step_index = wildcard_root_alternative_index;
2660 wildcard_root_alternative_index =
NONE;
2688 for (
uint32_t index = 0; index <
self->capture_quantifiers.size; index++) {
2689 CaptureQuantifiers *capture_quantifiers =
array_get(&self->capture_quantifiers, index);
2698 return self->patterns.size;
2702 return self->captures.slices.size;
2706 return self->predicate_values.slices.size;
2722 CaptureQuantifiers *capture_quantifiers =
array_get(&self->capture_quantifiers, pattern_index);
2739 Slice slice =
self->patterns.contents[pattern_index].predicate_steps;
2740 *step_count = slice.
length;
2741 if (self->predicate_steps.contents ==
NULL) {
2744 return &
self->predicate_steps.contents[slice.
offset];
2751 return self->patterns.contents[pattern_index].start_byte;
2759 for (
unsigned i = 0;
i <
self->step_offsets.size;
i++) {
2760 StepOffset *step_offset = &
self->step_offsets.contents[
i];
2761 if (step_offset->
byte_offset > byte_offset)
break;
2764 if (step_index < self->steps.size) {
2765 return self->steps.contents[step_index].root_pattern_guaranteed;
2777 QueryStep *next_step = &
self->steps.contents[step_index + 1];
2794 for (
unsigned i = 0;
i <
self->steps.size;
i++) {
2807 for (
unsigned i = 0;
i <
self->pattern_map.size;
i++) {
2809 if (pattern->pattern_index == pattern_index) {
2823 .did_exceed_match_limit =
false,
2831 .start_point = {0, 0},
2848 return self->did_exceed_match_limit;
2852 return self->capture_list_pool.max_capture_list_count;
2856 self->capture_list_pool.max_capture_list_count =
limit;
2868 self->next_state_id = 0;
2870 self->ascending =
false;
2871 self->halted =
false;
2872 self->query = query;
2873 self->did_exceed_match_limit =
false;
2881 if (end_byte == 0) {
2884 self->start_byte = start_byte;
2885 self->end_byte = end_byte;
2893 if (end_point.
row == 0 && end_point.
column == 0) {
2896 self->start_point = start_point;
2897 self->end_point = end_point;
2907 bool *root_pattern_guaranteed
2909 bool result =
false;
2913 for (
unsigned i = 0;
i <
self->states.size;
i++) {
2915 if (
state->dead)
continue;
2918 &self->capture_list_pool,
2919 state->capture_list_id
2921 if (
state->consumed_capture_count >= captures->size) {
2925 TSNode node = captures->contents[
state->consumed_capture_count].node;
2930 state->consumed_capture_count++;
2938 node_start_byte < *byte_offset ||
2939 (node_start_byte == *byte_offset &&
state->pattern_index < *pattern_index)
2942 if (root_pattern_guaranteed) {
2943 *root_pattern_guaranteed =
step->root_pattern_guaranteed;
2944 }
else if (
step->root_pattern_guaranteed) {
2950 *byte_offset = node_start_byte;
2951 *pattern_index =
state->pattern_index;
2959 if (left.
id != right.
id) {
2962 if (left_start < right_start)
return -1;
2963 if (left_start > right_start)
return 1;
2966 if (left_node_count > right_node_count)
return -1;
2967 if (left_node_count < right_node_count)
return 1;
2977 bool *left_contains_right,
2978 bool *right_contains_left
2981 &self->capture_list_pool,
2985 &self->capture_list_pool,
2988 *left_contains_right =
true;
2989 *right_contains_left =
true;
2990 unsigned i = 0, j = 0;
2992 if (i < left_captures->
size) {
2993 if (j < right_captures->
size) {
3002 *right_contains_left =
false;
3006 *left_contains_right =
false;
3010 *right_contains_left =
false;
3011 *left_contains_right =
false;
3018 *right_contains_left =
false;
3022 if (j < right_captures->
size) {
3023 *left_contains_right =
false;
3030 #ifdef DEBUG_EXECUTE_QUERY
3031 #define LOG(...) fprintf(stderr, __VA_ARGS__)
3040 QueryStep *
step = &
self->query->steps.contents[pattern->step_index];
3062 uint32_t index =
self->states.size;
3064 QueryState *prev_state = &
self->states.contents[index - 1];
3071 prev_state->
step_index == pattern->step_index
3073 if (prev_state->
pattern_index <= pattern->pattern_index)
break;
3079 " start state. pattern:%u, step:%u\n",
3080 pattern->pattern_index,
3085 .capture_list_id = NONE,
3086 .step_index = pattern->step_index,
3087 .pattern_index = pattern->pattern_index,
3088 .start_depth = start_depth,
3089 .consumed_capture_count = 0,
3090 .seeking_immediate_match = true,
3091 .has_in_progress_alternatives = false,
3092 .needs_parent = step->depth == 1,
3103 unsigned state_index_to_preserve
3112 self->did_exceed_match_limit =
true;
3113 uint32_t state_index, byte_offset, pattern_index;
3122 state_index != state_index_to_preserve
3125 " abandon state. index:%u, pattern:%u, offset:%u.\n",
3126 state_index, pattern_index, byte_offset
3128 QueryState *other_state = &
self->states.contents[state_index];
3131 other_state->
dead =
true;
3133 &self->capture_list_pool,
3134 state->capture_list_id
3139 LOG(
" ran out of capture lists");
3153 if (
state->dead)
return;
3155 if (!capture_list) {
3162 if (
step->capture_ids[j] ==
NONE)
break;
3165 " capture node. type:%s, pattern:%u, capture_id:%u, capture_count:%u\n",
3167 state->pattern_index,
3189 if (!new_captures)
return NULL;
3191 &self->capture_list_pool,
3192 state->capture_list_id
3198 *state_ref = &
self->states.contents[state_index];
3199 return &
self->states.contents[state_index + 1];
3208 bool stop_on_definite_step
3210 bool did_match =
false;
3213 while (self->states.size > 0) {
3216 &self->capture_list_pool,
3217 state.capture_list_id
3222 if (did_match || self->halted)
return did_match;
3225 if (self->ascending) {
3227 "leave node. depth:%u, type:%s\n",
3234 self->ascending =
false;
3238 LOG(
"halt at root\n");
3239 self->halted =
true;
3244 for (
unsigned i = 0,
n = self->states.size;
i <
n;
i++) {
3251 if (
state->start_depth > self->depth || self->halted) {
3252 LOG(
" finish pattern %u\n",
state->pattern_index);
3264 " failed to match. pattern:%u, step:%u\n",
3265 state->pattern_index,
3269 &self->capture_list_pool,
3270 state->capture_list_id
3276 if (deleted_count > 0) {
3277 self->states.contents[
i - deleted_count] = *
state;
3280 self->states.size -= deleted_count;
3290 bool has_later_siblings;
3291 bool has_later_named_siblings;
3292 bool can_have_later_siblings_with_this_field;
3295 unsigned supertype_count = 8;
3299 &has_later_siblings,
3300 &has_later_named_siblings,
3301 &can_have_later_siblings_with_this_field,
3306 "enter node. depth:%u, type:%s, field:%s, row:%u state_count:%u, finished_state_count:%u\n",
3312 self->finished_states.size
3315 bool node_intersects_range = (
3330 for (
unsigned i = 0;
i <
self->query->wildcard_root_pattern_count;
i++) {
3331 PatternEntry *pattern = &
self->query->pattern_map.contents[
i];
3335 QueryStep *
step = &
self->query->steps.contents[pattern->step_index];
3337 (node_intersects_range || (!pattern->is_rooted && parent_intersects_range)) &&
3339 (!
step->supertype_symbol || supertype_count > 0)
3348 PatternEntry *pattern = &
self->query->pattern_map.contents[
i];
3350 QueryStep *
step = &
self->query->steps.contents[pattern->step_index];
3355 (node_intersects_range || (!pattern->is_rooted && parent_intersects_range)) &&
3363 if (
i == self->query->pattern_map.size)
break;
3364 pattern = &
self->query->pattern_map.contents[
i];
3365 step = &
self->query->steps.contents[pattern->step_index];
3366 }
while (
step->symbol == symbol);
3370 for (
unsigned i = 0, copy_count = 0;
i <
self->states.size;
i += 1 + copy_count) {
3373 state->has_in_progress_alternatives =
false;
3383 bool node_does_match =
false;
3385 node_does_match = is_named || !
step->is_named;
3387 node_does_match = symbol ==
step->symbol;
3389 bool later_sibling_can_match = has_later_siblings;
3390 if ((
step->is_immediate && is_named) ||
state->seeking_immediate_match) {
3391 later_sibling_can_match =
false;
3393 if (
step->is_last_child && has_later_named_siblings) {
3394 node_does_match =
false;
3396 if (
step->supertype_symbol) {
3397 bool has_supertype =
false;
3398 for (
unsigned j = 0; j < supertype_count; j++) {
3399 if (supertypes[j] ==
step->supertype_symbol) {
3400 has_supertype =
true;
3404 if (!has_supertype) node_does_match =
false;
3408 if (!can_have_later_siblings_with_this_field) {
3409 later_sibling_can_match =
false;
3412 node_does_match =
false;
3416 if (
step->negated_field_list_id) {
3417 TSFieldId *negated_field_ids = &
self->query->negated_fields.contents[
step->negated_field_list_id];
3419 TSFieldId negated_field_id = *negated_field_ids;
3420 if (negated_field_id) {
3421 negated_field_ids++;
3423 node_does_match =
false;
3433 if (!node_does_match) {
3434 if (!later_sibling_can_match) {
3436 " discard state. pattern:%u, step:%u\n",
3437 state->pattern_index,
3441 &self->capture_list_pool,
3442 state->capture_list_id
3455 if (later_sibling_can_match && (
3456 step->contains_captures ||
3461 " split state for capture. pattern:%u, step:%u\n",
3462 state->pattern_index,
3472 if (
state->needs_parent) {
3475 LOG(
" missing parent node\n");
3478 state->needs_parent =
false;
3481 skipped_wildcard_step--;
3485 skipped_wildcard_step->
depth > 0
3488 LOG(
" capture wildcard parent\n");
3492 skipped_wildcard_step,
3500 if (
step->capture_ids[0] !=
NONE) {
3511 state->step_index++;
3512 state->seeking_immediate_match =
false;
3514 " advance state. pattern:%u, step:%u\n",
3515 state->pattern_index,
3519 QueryStep *next_step = &
self->query->steps.contents[
state->step_index];
3525 unsigned end_index =
i + 1;
3526 for (
unsigned j =
i; j < end_index; j++) {
3528 QueryStep *next_step = &
self->query->steps.contents[
state->step_index];
3543 state->step_index++;
3550 " split state for branch. pattern:%u, from_step:%u, to_step:%u, immediate:%d, capture_count: %u\n",
3568 for (
unsigned i = 0;
i <
self->states.size;
i++) {
3579 bool did_remove =
false;
3580 for (
unsigned j =
i + 1; j <
self->states.size; j++) {
3581 QueryState *other_state = &
self->states.contents[j];
3592 bool left_contains_right, right_contains_left;
3597 &left_contains_right,
3598 &right_contains_left
3600 if (left_contains_right) {
3603 " drop shorter state. pattern: %u, step_index: %u\n",
3604 state->pattern_index,
3614 if (right_contains_left) {
3617 " drop shorter state. pattern: %u, step_index: %u\n",
3618 state->pattern_index,
3627 state->has_in_progress_alternatives =
true;
3635 " keep state. pattern: %u, start_depth: %u, step_index: %u, capture_count: %u\n",
3636 state->pattern_index,
3641 QueryStep *next_step = &
self->query->steps.contents[
state->step_index];
3643 if (
state->has_in_progress_alternatives) {
3644 LOG(
" defer finishing pattern %u\n",
state->pattern_index);
3646 LOG(
" finish pattern %u\n",
state->pattern_index);
3658 bool should_descend = node_intersects_range;
3659 if (!should_descend) {
3660 for (
unsigned i = 0;
i <
self->states.size;
i++) {
3662 QueryStep *next_step = &
self->query->steps.contents[
state->step_index];
3665 state->start_depth + next_step->
depth > self->depth
3667 should_descend =
true;
3673 if (!should_descend) {
3675 " not descending. node end byte: %u, start byte: %u\n",
3684 self->ascending =
true;
3694 if (self->finished_states.size == 0) {
3705 &self->capture_list_pool,
3706 state->capture_list_id
3708 match->captures = captures->contents;
3709 match->capture_count = captures->size;
3719 for (
unsigned i = 0;
i <
self->finished_states.size;
i++) {
3721 if (
state->id == match_id) {
3723 &self->capture_list_pool,
3724 state->capture_list_id
3733 for (
unsigned i = 0;
i <
self->states.size;
i++) {
3735 if (
state->id == match_id) {
3737 &self->capture_list_pool,
3738 state->capture_list_id
3756 uint32_t first_unfinished_capture_byte;
3757 uint32_t first_unfinished_pattern_index;
3758 uint32_t first_unfinished_state_index;
3759 bool first_unfinished_state_is_definite =
false;
3762 &first_unfinished_state_index,
3763 &first_unfinished_capture_byte,
3764 &first_unfinished_pattern_index,
3765 &first_unfinished_state_is_definite
3771 uint32_t first_finished_capture_byte = first_unfinished_capture_byte;
3772 uint32_t first_finished_pattern_index = first_unfinished_pattern_index;
3773 for (
unsigned i = 0;
i <
self->finished_states.size;) {
3776 &self->capture_list_pool,
3777 state->capture_list_id
3781 if (
state->consumed_capture_count >= captures->size) {
3783 &self->capture_list_pool,
3784 state->capture_list_id
3791 TSNode node = captures->contents[
state->consumed_capture_count].node;
3793 state->consumed_capture_count++;
3799 node_start_byte < first_finished_capture_byte ||
3801 node_start_byte == first_finished_capture_byte &&
3802 state->pattern_index < first_finished_pattern_index
3805 first_finished_state =
state;
3806 first_finished_capture_byte = node_start_byte;
3807 first_finished_pattern_index =
state->pattern_index;
3816 if (first_finished_state) {
3817 state = first_finished_state;
3818 }
else if (first_unfinished_state_is_definite) {
3819 state = &
self->states.contents[first_unfinished_state_index];
3829 &self->capture_list_pool,
3830 state->capture_list_id
3832 match->captures = captures->contents;
3833 match->capture_count = captures->size;
3834 *capture_index =
state->consumed_capture_count;
3835 state->consumed_capture_count++;
3841 " abandon state. index:%u, pattern:%u, offset:%u.\n",
3842 first_unfinished_state_index,
3843 first_unfinished_pattern_index,
3844 first_unfinished_capture_byte
3847 &self->capture_list_pool,
3848 self->states.contents[first_unfinished_state_index].capture_list_id
3850 array_erase(&self->states, first_unfinished_state_index);
3857 self->finished_states.size == 0
const char * ts_node_type(TSNode)
TSNode ts_node_child_by_field_id(TSNode, TSFieldId)
#define TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION
bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *)
@ TSQueryPredicateStepTypeCapture
void ts_tree_cursor_delete(TSTreeCursor *)
uint32_t ts_node_start_byte(TSNode)
void ts_tree_cursor_reset(TSTreeCursor *, TSNode)
bool ts_node_is_null(TSNode)
TSSymbol ts_node_symbol(TSNode)
TSPoint ts_node_start_point(TSNode)
TSFieldId ts_language_field_id_for_name(const TSLanguage *, const char *, uint32_t)
const char * ts_language_symbol_name(const TSLanguage *, TSSymbol)
#define TREE_SITTER_LANGUAGE_VERSION
bool ts_tree_cursor_goto_parent(TSTreeCursor *)
const char * ts_language_field_name_for_id(const TSLanguage *, TSFieldId)
uint32_t ts_node_end_byte(TSNode)
bool ts_node_is_named(TSNode)
struct TSQueryCursor TSQueryCursor
TSNode ts_tree_cursor_current_node(const TSTreeCursor *)
TSSymbol ts_language_symbol_for_name(const TSLanguage *self, const char *string, uint32_t length, bool is_named)
TSPoint ts_node_end_point(TSNode)
bool ts_tree_cursor_goto_first_child(TSTreeCursor *)
#define array_extend(self, count, contents)
#define array_insert_sorted_by(self, field, value)
#define array_erase(self, index)
#define array_get(self, index)
#define array_assign(self, other)
#define array_push_all(self, other)
#define array_push(self, element)
#define array_search_sorted_with(self, compare, needle, index, exists)
#define array_reserve(self, new_capacity)
#define array_insert(self, index, element)
#define array_delete(self)
#define array_clear(self)
#define array_grow_by(self, count)
#define array_search_sorted_by(self, field, needle, index, exists)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
static states step(struct re_guts *, sopno, sopno, states, int, states)
TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *self, TSSymbol symbol)
static void ts_language_field_map(const TSLanguage *self, uint32_t production_id, const TSFieldMapEntry **start, const TSFieldMapEntry **end)
static bool ts_language_state_is_primary(const TSLanguage *self, TSStateId state)
static bool ts_lookahead_iterator_next(LookaheadIterator *self)
static void ts_language_aliases_for_symbol(const TSLanguage *self, TSSymbol original_symbol, const TSSymbol **start, const TSSymbol **end)
static TSSymbol ts_language_alias_at(const TSLanguage *self, uint32_t production_id, uint32_t child_index)
static LookaheadIterator ts_language_lookaheads(const TSLanguage *self, TSStateId state)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void list(RzEgg *egg)
assert(limit<=UINT32_MAX/2)
static uint32_t const uint8_t uint32_t uint32_t limit
static bool point_lt(TSPoint a, TSPoint b)
static bool point_lte(TSPoint a, TSPoint b)
static bool point_gt(TSPoint a, TSPoint b)
static int is_immediate(ut32 instr)
@ TSParseActionTypeReduce
#define ts_builtin_sym_error
const TSParseAction * actions
bool seeking_immediate_match
bool has_in_progress_alternatives
uint16_t consumed_capture_count
uint16_t capture_ids[MAX_STEP_CAPTURE_COUNT]
bool parent_pattern_guaranteed
bool alternative_is_immediate
uint16_t alternative_index
bool root_pattern_guaranteed
uint16_t negated_field_list_id
TSSymbol supertype_symbol
static void ts_query__add_negated_fields(TSQuery *self, uint16_t step_index, TSFieldId *field_ids, uint16_t field_count)
static bool analysis_state__has_supertype(AnalysisState *self, TSSymbol symbol)
static void capture_list_pool_reset(CaptureListPool *self)
uint32_t ts_query_string_count(const TSQuery *self)
uint32_t ts_query_pattern_count(const TSQuery *self)
static void stream_scan_identifier(Stream *stream)
static void capture_quantifiers_mul(CaptureQuantifiers *self, TSQuantifier quantifier)
void ts_query_cursor_exec(TSQueryCursor *self, const TSQuery *query, TSNode node)
TSQuantifier ts_query_capture_quantifier_for_id(const TSQuery *self, uint32_t pattern_index, uint32_t capture_index)
static bool ts_query_cursor__first_in_progress_capture(TSQueryCursor *self, uint32_t *state_index, uint32_t *byte_offset, uint32_t *pattern_index, bool *root_pattern_guaranteed)
bool ts_query_cursor_next_match(TSQueryCursor *self, TSQueryMatch *match)
const char * ts_query_string_value_for_id(const TSQuery *self, uint32_t index, uint32_t *length)
#define MAX_STATE_PREDECESSOR_COUNT
static void state_predecessor_map_delete(StatePredecessorMap *self)
static void capture_quantifiers_add_for_id(CaptureQuantifiers *self, uint16_t id, TSQuantifier quantifier)
static int symbol_table_id_for_name(const SymbolTable *self, const char *name, uint32_t length)
#define MAX_ANALYSIS_STATE_DEPTH
static TSQueryError ts_query__parse_predicate(TSQuery *self, Stream *stream)
uint32_t ts_query_start_byte_for_pattern(const TSQuery *self, uint32_t pattern_index)
void ts_query_delete(TSQuery *self)
static bool ts_query_cursor__advance(TSQueryCursor *self, bool stop_on_definite_step)
static AnalysisStateEntry * analysis_state__top(AnalysisState *self)
void ts_query_cursor_remove_match(TSQueryCursor *self, uint32_t match_id)
static void capture_quantifiers_join_all(CaptureQuantifiers *self, CaptureQuantifiers *quantifiers)
static const TSSymbol WILDCARD_SYMBOL
bool ts_query__step_is_fallible(const TSQuery *self, uint16_t step_index)
static SymbolTable symbol_table_new(void)
static CaptureQuantifiers capture_quantifiers_new(void)
TSQuery * ts_query_new(const TSLanguage *language, const char *source, uint32_t source_len, uint32_t *error_offset, TSQueryError *error_type)
static void state_predecessor_map_add(StatePredecessorMap *self, TSStateId state, TSStateId predecessor)
static const CaptureList * capture_list_pool_get(const CaptureListPool *self, uint16_t id)
static void analysis_state_set__delete(AnalysisStateSet *self)
void ts_query_cursor_set_match_limit(TSQueryCursor *self, uint32_t limit)
static uint16_t capture_list_pool_acquire(CaptureListPool *self)
static uint32_t stream_offset(Stream *self)
static bool ts_query__analyze_patterns(TSQuery *self, unsigned *error_offset)
void ts_query_disable_capture(TSQuery *self, const char *name, uint32_t length)
static StatePredecessorMap state_predecessor_map_new(const TSLanguage *language)
static void stream_skip_whitespace(Stream *self)
static QueryState * ts_query_cursor__copy_state(TSQueryCursor *self, QueryState **state_ref)
static TSQueryError ts_query__parse_pattern(TSQuery *self, Stream *stream, uint32_t depth, bool is_immediate, CaptureQuantifiers *capture_quantifiers)
static void capture_quantifiers_delete(CaptureQuantifiers *self)
static uint16_t symbol_table_insert_name(SymbolTable *self, const char *name, uint32_t length)
static TSQueryError ts_query__parse_string_literal(TSQuery *self, Stream *stream)
static void ts_query__pattern_map_insert(TSQuery *self, TSSymbol symbol, PatternEntry new_entry)
#define MAX_STEP_CAPTURE_COUNT
bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *self)
static CaptureList * ts_query_cursor__prepare_to_capture(TSQueryCursor *self, QueryState *state, unsigned state_index_to_preserve)
static unsigned analysis_state__recursion_depth(const AnalysisState *self)
static bool ts_query__pattern_map_search(const TSQuery *self, TSSymbol needle, uint32_t *result)
uint32_t ts_query_cursor_match_limit(const TSQueryCursor *self)
static TSQuantifier quantifier_mul(TSQuantifier left, TSQuantifier right)
static AnalysisState * analysis_state__clone(AnalysisState const *self)
static void query_step__add_capture(QueryStep *self, uint16_t capture_id)
bool ts_query_cursor_next_capture(TSQueryCursor *self, TSQueryMatch *match, uint32_t *capture_index)
#define MAX_NEGATED_FIELD_COUNT
static int analysis_state__compare_position(AnalysisState *const *self, AnalysisState *const *other)
static AnalysisState * analysis_state_pool__clone_or_reuse(AnalysisStatePool *self, AnalysisState *borrowed_item)
static const TSStateId * state_predecessor_map_get(const StatePredecessorMap *self, TSStateId state, unsigned *count)
static void capture_quantifiers_replace(CaptureQuantifiers *self, CaptureQuantifiers *quantifiers)
TSQueryCursor * ts_query_cursor_new(void)
void ts_query_cursor_delete(TSQueryCursor *self)
static CaptureList * capture_list_pool_get_mut(CaptureListPool *self, uint16_t id)
static TSQuantifier quantifier_add(TSQuantifier left, TSQuantifier right)
static void symbol_table_delete(SymbolTable *self)
int ts_query_cursor__compare_nodes(TSNode left, TSNode right)
static void analysis_state_set__push_by_clone(AnalysisStateSet *self, AnalysisStatePool *pool, AnalysisState *borrowed_item)
bool ts_query_is_pattern_guaranteed_at_step(const TSQuery *self, uint32_t byte_offset)
static CaptureListPool capture_list_pool_new(void)
static TSQuantifier capture_quantifier_for_id(const CaptureQuantifiers *self, uint16_t id)
static void capture_quantifiers_clear(CaptureQuantifiers *self)
uint32_t ts_query_capture_count(const TSQuery *self)
static void capture_quantifiers_add_all(CaptureQuantifiers *self, CaptureQuantifiers *quantifiers)
static int analysis_subgraph_node__compare(const AnalysisSubgraphNode *self, const AnalysisSubgraphNode *other)
void ts_query_disable_pattern(TSQuery *self, uint32_t pattern_index)
static Stream stream_new(const char *string, uint32_t length)
static bool capture_list_pool_is_empty(const CaptureListPool *self)
static void capture_list_pool_delete(CaptureListPool *self)
static void ts_query_cursor__add_state(TSQueryCursor *self, const PatternEntry *pattern)
static const uint16_t NONE
static QueryStep query_step__new(TSSymbol symbol, uint16_t depth, bool is_immediate)
static void ts_query_cursor__capture(TSQueryCursor *self, QueryState *state, QueryStep *step, TSNode node)
static void stream_reset(Stream *self, const char *input)
const TSQueryPredicateStep * ts_query_predicates_for_pattern(const TSQuery *self, uint32_t pattern_index, uint32_t *step_count)
static TSQuantifier quantifier_join(TSQuantifier left, TSQuantifier right)
static const TSQueryError PARENT_DONE
static void analysis_state_set__insert_sorted_by_clone(AnalysisStateSet *self, AnalysisStatePool *pool, AnalysisState *borrowed_item)
static const uint16_t PATTERN_DONE_MARKER
static bool stream_is_ident_start(Stream *self)
static int analysis_state__compare(AnalysisState *const *self, AnalysisState *const *other)
static bool stream_advance(Stream *self)
static const char * symbol_table_name_for_id(const SymbolTable *self, uint16_t id, uint32_t *length)
void ts_query_cursor_set_byte_range(TSQueryCursor *self, uint32_t start_byte, uint32_t end_byte)
void ts_query_cursor_set_point_range(TSQueryCursor *self, TSPoint start_point, TSPoint end_point)
static void capture_list_pool_release(CaptureListPool *self, uint16_t id)
const char * ts_query_capture_name_for_id(const TSQuery *self, uint32_t index, uint32_t *length)
static void analysis_state_set__clear(AnalysisStateSet *self, AnalysisStatePool *pool)
#define MAX_ANALYSIS_ITERATION_COUNT
void ts_query_cursor__compare_captures(TSQueryCursor *self, QueryState *left_state, QueryState *right_state, bool *left_contains_right, bool *right_contains_left)
static void query_step__remove_capture(QueryStep *self, uint16_t capture_id)
TSNode ts_tree_cursor_parent_node(const TSTreeCursor *_self)
void ts_tree_cursor_current_status(const TSTreeCursor *_self, TSFieldId *field_id, bool *has_later_siblings, bool *has_later_named_siblings, bool *can_have_later_siblings_with_this_field, TSSymbol *supertypes, unsigned *supertype_count)
static uint32_t ts_decode_utf8(const uint8_t *string, uint32_t length, int32_t *code_point)
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)