2014-10-03 16:06:08 -07:00
|
|
|
#include <stdbool.h>
|
2019-01-04 17:33:34 -08:00
|
|
|
#include "./subtree.h"
|
|
|
|
|
#include "./tree.h"
|
|
|
|
|
#include "./language.h"
|
2014-07-17 23:29:11 -07:00
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
typedef struct {
|
2018-09-17 13:12:13 -07:00
|
|
|
Subtree parent;
|
2018-05-10 22:22:37 -07:00
|
|
|
const TSTree *tree;
|
2018-05-09 10:16:10 -07:00
|
|
|
Length position;
|
|
|
|
|
uint32_t child_index;
|
2019-02-07 17:18:33 -08:00
|
|
|
uint32_t structural_child_index;
|
|
|
|
|
const TSSymbol *alias_sequence;
|
2018-11-13 15:35:14 -08:00
|
|
|
} NodeChildIterator;
|
2014-07-17 23:29:11 -07:00
|
|
|
|
2018-05-16 15:44:04 -07:00
|
|
|
// TSNode - constructors
|
2015-08-16 10:51:34 -07:00
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
TSNode ts_node_new(
|
|
|
|
|
const TSTree *tree,
|
|
|
|
|
const Subtree *subtree,
|
|
|
|
|
Length position,
|
|
|
|
|
TSSymbol alias
|
|
|
|
|
) {
|
2018-05-09 10:16:10 -07:00
|
|
|
return (TSNode) {
|
2018-05-16 16:05:08 -07:00
|
|
|
{position.bytes, position.extent.row, position.extent.column, alias},
|
2018-05-16 16:20:33 -07:00
|
|
|
subtree,
|
|
|
|
|
tree,
|
2018-05-09 10:16:10 -07:00
|
|
|
};
|
2015-08-16 10:54:02 -07:00
|
|
|
}
|
|
|
|
|
|
2019-03-21 16:06:06 -07:00
|
|
|
static inline TSNode ts_node__null(void) {
|
2018-05-16 16:05:08 -07:00
|
|
|
return ts_node_new(NULL, NULL, length_zero(), 0);
|
2018-05-16 15:44:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TSNode - accessors
|
|
|
|
|
|
2018-06-14 11:12:04 -07:00
|
|
|
uint32_t ts_node_start_byte(TSNode self) {
|
2018-05-22 08:50:04 -07:00
|
|
|
return self.context[0];
|
2018-05-16 15:44:04 -07:00
|
|
|
}
|
|
|
|
|
|
2018-06-14 11:12:04 -07:00
|
|
|
TSPoint ts_node_start_point(TSNode self) {
|
2018-05-22 08:50:04 -07:00
|
|
|
return (TSPoint) {self.context[1], self.context[2]};
|
2018-05-16 15:44:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t ts_node__alias(const TSNode *self) {
|
|
|
|
|
return self->context[3];
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 13:12:13 -07:00
|
|
|
static inline Subtree ts_node__subtree(TSNode self) {
|
|
|
|
|
return *(const Subtree *)self.id;
|
2018-05-16 16:20:33 -07:00
|
|
|
}
|
|
|
|
|
|
2018-11-13 15:35:14 -08:00
|
|
|
// NodeChildIterator
|
2018-05-16 15:44:04 -07:00
|
|
|
|
2018-11-13 15:35:14 -08:00
|
|
|
static inline NodeChildIterator ts_node_iterate_children(const TSNode *node) {
|
2018-09-17 13:12:13 -07:00
|
|
|
Subtree subtree = ts_node__subtree(*node);
|
|
|
|
|
if (ts_subtree_child_count(subtree) == 0) {
|
2019-02-07 17:18:33 -08:00
|
|
|
return (NodeChildIterator) {NULL_SUBTREE, node->tree, length_zero(), 0, 0, NULL};
|
2018-09-17 13:12:13 -07:00
|
|
|
}
|
2019-02-07 17:18:33 -08:00
|
|
|
const TSSymbol *alias_sequence = ts_language_alias_sequence(
|
|
|
|
|
node->tree->language,
|
2019-02-12 11:06:18 -08:00
|
|
|
subtree.ptr->production_id
|
2019-02-07 17:18:33 -08:00
|
|
|
);
|
2018-11-13 15:35:14 -08:00
|
|
|
return (NodeChildIterator) {
|
2018-06-21 12:53:17 -07:00
|
|
|
.tree = node->tree,
|
2018-05-16 15:44:04 -07:00
|
|
|
.parent = subtree,
|
2018-05-22 08:50:04 -07:00
|
|
|
.position = {ts_node_start_byte(*node), ts_node_start_point(*node)},
|
2018-05-09 10:16:10 -07:00
|
|
|
.child_index = 0,
|
2019-02-07 17:18:33 -08:00
|
|
|
.structural_child_index = 0,
|
|
|
|
|
.alias_sequence = alias_sequence,
|
2018-05-09 10:16:10 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 17:18:33 -08:00
|
|
|
static inline bool ts_node_child_iterator_done(NodeChildIterator *self) {
|
|
|
|
|
return self->child_index == self->parent.ptr->child_count;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
static inline bool ts_node_child_iterator_next(
|
|
|
|
|
NodeChildIterator *self,
|
|
|
|
|
TSNode *result
|
|
|
|
|
) {
|
2019-02-07 17:18:33 -08:00
|
|
|
if (!self->parent.ptr || ts_node_child_iterator_done(self)) return false;
|
2020-10-22 16:21:47 -07:00
|
|
|
const Subtree *child = &ts_subtree_children(self->parent)[self->child_index];
|
2018-05-09 10:16:10 -07:00
|
|
|
TSSymbol alias_symbol = 0;
|
2019-02-07 17:18:33 -08:00
|
|
|
if (!ts_subtree_extra(*child)) {
|
|
|
|
|
if (self->alias_sequence) {
|
|
|
|
|
alias_symbol = self->alias_sequence[self->structural_child_index];
|
|
|
|
|
}
|
|
|
|
|
self->structural_child_index++;
|
2018-05-09 10:16:10 -07:00
|
|
|
}
|
2018-05-22 08:50:04 -07:00
|
|
|
if (self->child_index > 0) {
|
2018-09-17 13:12:13 -07:00
|
|
|
self->position = length_add(self->position, ts_subtree_padding(*child));
|
2018-05-22 08:50:04 -07:00
|
|
|
}
|
2018-05-16 15:44:04 -07:00
|
|
|
*result = ts_node_new(
|
|
|
|
|
self->tree,
|
|
|
|
|
child,
|
|
|
|
|
self->position,
|
|
|
|
|
alias_symbol
|
|
|
|
|
);
|
2018-09-17 13:12:13 -07:00
|
|
|
self->position = length_add(self->position, ts_subtree_size(*child));
|
2018-05-09 10:16:10 -07:00
|
|
|
self->child_index++;
|
|
|
|
|
return true;
|
2015-12-04 10:45:30 -08:00
|
|
|
}
|
|
|
|
|
|
2018-05-16 15:44:04 -07:00
|
|
|
// TSNode - private
|
|
|
|
|
|
2015-12-04 10:45:30 -08:00
|
|
|
static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous) {
|
2018-09-17 13:12:13 -07:00
|
|
|
Subtree tree = ts_node__subtree(self);
|
2017-08-01 13:28:18 -07:00
|
|
|
if (include_anonymous) {
|
2018-09-17 13:12:13 -07:00
|
|
|
return ts_subtree_visible(tree) || ts_node__alias(&self);
|
2017-07-18 21:24:34 -07:00
|
|
|
} else {
|
2019-08-29 14:28:44 -07:00
|
|
|
TSSymbol alias = ts_node__alias(&self);
|
|
|
|
|
if (alias) {
|
|
|
|
|
return ts_language_symbol_metadata(self.tree->language, alias).named;
|
|
|
|
|
} else {
|
|
|
|
|
return ts_subtree_visible(tree) && ts_subtree_named(tree);
|
|
|
|
|
}
|
2017-07-18 21:24:34 -07:00
|
|
|
}
|
2015-11-22 13:32:20 -08:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
static inline uint32_t ts_node__relevant_child_count(
|
|
|
|
|
TSNode self,
|
|
|
|
|
bool include_anonymous
|
|
|
|
|
) {
|
2018-09-17 13:12:13 -07:00
|
|
|
Subtree tree = ts_node__subtree(self);
|
|
|
|
|
if (ts_subtree_child_count(tree) > 0) {
|
2016-12-20 13:12:01 -08:00
|
|
|
if (include_anonymous) {
|
2018-09-17 13:12:13 -07:00
|
|
|
return tree.ptr->visible_child_count;
|
2016-12-20 13:12:01 -08:00
|
|
|
} else {
|
2018-09-17 13:12:13 -07:00
|
|
|
return tree.ptr->named_child_count;
|
2016-12-20 13:12:01 -08:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-11-22 13:32:20 -08:00
|
|
|
}
|
2015-11-18 16:34:50 -08:00
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
static inline TSNode ts_node__child(
|
|
|
|
|
TSNode self,
|
|
|
|
|
uint32_t child_index,
|
|
|
|
|
bool include_anonymous
|
|
|
|
|
) {
|
2015-12-04 10:45:30 -08:00
|
|
|
TSNode result = self;
|
2015-08-14 16:34:12 -07:00
|
|
|
bool did_descend = true;
|
2015-12-04 10:45:30 -08:00
|
|
|
|
2015-08-14 16:34:12 -07:00
|
|
|
while (did_descend) {
|
|
|
|
|
did_descend = false;
|
2015-08-14 16:11:37 -07:00
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
TSNode child;
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t index = 0;
|
2018-11-13 15:35:14 -08:00
|
|
|
NodeChildIterator iterator = ts_node_iterate_children(&result);
|
2018-05-09 10:16:10 -07:00
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
2015-12-04 10:45:30 -08:00
|
|
|
if (ts_node__is_relevant(child, include_anonymous)) {
|
2018-05-29 16:00:32 -07:00
|
|
|
if (index == child_index) {
|
|
|
|
|
return child;
|
|
|
|
|
}
|
2015-08-14 16:34:12 -07:00
|
|
|
index++;
|
|
|
|
|
} else {
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t grandchild_index = child_index - index;
|
2018-05-09 10:16:10 -07:00
|
|
|
uint32_t grandchild_count = ts_node__relevant_child_count(child, include_anonymous);
|
2015-09-07 21:11:37 -07:00
|
|
|
if (grandchild_index < grandchild_count) {
|
2015-08-14 16:34:12 -07:00
|
|
|
did_descend = true;
|
2015-12-04 10:45:30 -08:00
|
|
|
result = child;
|
2015-08-14 16:34:12 -07:00
|
|
|
child_index = grandchild_index;
|
2015-08-16 10:27:26 -07:00
|
|
|
break;
|
2015-08-14 16:34:12 -07:00
|
|
|
}
|
2015-09-07 21:11:37 -07:00
|
|
|
index += grandchild_count;
|
2015-08-14 16:34:12 -07:00
|
|
|
}
|
2015-08-14 16:11:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-16 10:54:02 -07:00
|
|
|
return ts_node__null();
|
2014-07-17 23:29:11 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
static bool ts_subtree_has_trailing_empty_descendant(
|
|
|
|
|
Subtree self,
|
|
|
|
|
Subtree other
|
|
|
|
|
) {
|
2018-09-17 13:12:13 -07:00
|
|
|
for (unsigned i = ts_subtree_child_count(self) - 1; i + 1 > 0; i--) {
|
2020-10-22 16:21:47 -07:00
|
|
|
Subtree child = ts_subtree_children(self)[i];
|
2018-09-17 13:12:13 -07:00
|
|
|
if (ts_subtree_total_bytes(child) > 0) break;
|
|
|
|
|
if (child.ptr == other.ptr || ts_subtree_has_trailing_empty_descendant(child, other)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-30 20:19:26 -07:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-09 13:23:47 -07:00
|
|
|
static inline TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous) {
|
2018-09-17 13:12:13 -07:00
|
|
|
Subtree self_subtree = ts_node__subtree(self);
|
|
|
|
|
bool self_is_empty = ts_subtree_total_bytes(self_subtree) == 0;
|
2018-05-09 13:23:47 -07:00
|
|
|
uint32_t target_end_byte = ts_node_end_byte(self);
|
2015-09-08 21:43:37 -07:00
|
|
|
|
2018-05-09 13:23:47 -07:00
|
|
|
TSNode node = ts_node_parent(self);
|
|
|
|
|
TSNode earlier_node = ts_node__null();
|
|
|
|
|
bool earlier_node_is_relevant = false;
|
2018-05-09 10:16:10 -07:00
|
|
|
|
2018-09-17 13:12:13 -07:00
|
|
|
while (!ts_node_is_null(node)) {
|
2018-05-09 13:23:47 -07:00
|
|
|
TSNode earlier_child = ts_node__null();
|
|
|
|
|
bool earlier_child_is_relevant = false;
|
|
|
|
|
bool found_child_containing_target = false;
|
2018-05-09 10:16:10 -07:00
|
|
|
|
2018-05-09 13:23:47 -07:00
|
|
|
TSNode child;
|
2018-11-13 15:35:14 -08:00
|
|
|
NodeChildIterator iterator = ts_node_iterate_children(&node);
|
2018-05-09 13:23:47 -07:00
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
2018-08-30 20:19:26 -07:00
|
|
|
if (child.id == self.id) break;
|
2018-09-17 13:12:13 -07:00
|
|
|
if (iterator.position.bytes > target_end_byte) {
|
|
|
|
|
found_child_containing_target = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-08-30 20:19:26 -07:00
|
|
|
|
2018-09-17 13:12:13 -07:00
|
|
|
if (iterator.position.bytes == target_end_byte &&
|
|
|
|
|
(!self_is_empty ||
|
|
|
|
|
ts_subtree_has_trailing_empty_descendant(ts_node__subtree(child), self_subtree))) {
|
2018-08-30 20:19:26 -07:00
|
|
|
found_child_containing_target = true;
|
2018-05-09 13:23:47 -07:00
|
|
|
break;
|
|
|
|
|
}
|
2018-05-09 10:16:10 -07:00
|
|
|
|
2018-05-09 13:23:47 -07:00
|
|
|
if (ts_node__is_relevant(child, include_anonymous)) {
|
|
|
|
|
earlier_child = child;
|
|
|
|
|
earlier_child_is_relevant = true;
|
|
|
|
|
} else if (ts_node__relevant_child_count(child, include_anonymous) > 0) {
|
|
|
|
|
earlier_child = child;
|
|
|
|
|
earlier_child_is_relevant = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-09 10:16:10 -07:00
|
|
|
|
2018-05-09 13:23:47 -07:00
|
|
|
if (found_child_containing_target) {
|
2018-05-16 15:44:04 -07:00
|
|
|
if (!ts_node_is_null(earlier_child)) {
|
2018-05-09 13:23:47 -07:00
|
|
|
earlier_node = earlier_child;
|
|
|
|
|
earlier_node_is_relevant = earlier_child_is_relevant;
|
|
|
|
|
}
|
|
|
|
|
node = child;
|
|
|
|
|
} else if (earlier_child_is_relevant) {
|
|
|
|
|
return earlier_child;
|
2018-05-16 15:44:04 -07:00
|
|
|
} else if (!ts_node_is_null(earlier_child)) {
|
2018-05-09 13:23:47 -07:00
|
|
|
node = earlier_child;
|
|
|
|
|
} else if (earlier_node_is_relevant) {
|
|
|
|
|
return earlier_node;
|
|
|
|
|
} else {
|
|
|
|
|
node = earlier_node;
|
2023-07-24 15:02:37 -05:00
|
|
|
earlier_node = ts_node__null();
|
|
|
|
|
earlier_node_is_relevant = false;
|
2018-05-09 13:23:47 -07:00
|
|
|
}
|
2018-05-09 10:16:10 -07:00
|
|
|
}
|
2018-05-09 13:23:47 -07:00
|
|
|
|
|
|
|
|
return ts_node__null();
|
2015-09-07 21:11:37 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-22 13:32:20 -08:00
|
|
|
static inline TSNode ts_node__next_sibling(TSNode self, bool include_anonymous) {
|
2018-05-09 13:46:46 -07:00
|
|
|
uint32_t target_end_byte = ts_node_end_byte(self);
|
|
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
TSNode node = ts_node_parent(self);
|
2018-05-09 13:46:46 -07:00
|
|
|
TSNode later_node = ts_node__null();
|
|
|
|
|
bool later_node_is_relevant = false;
|
2015-09-08 21:43:37 -07:00
|
|
|
|
2018-09-17 13:12:13 -07:00
|
|
|
while (!ts_node_is_null(node)) {
|
2018-05-09 13:46:46 -07:00
|
|
|
TSNode later_child = ts_node__null();
|
|
|
|
|
bool later_child_is_relevant = false;
|
|
|
|
|
TSNode child_containing_target = ts_node__null();
|
2015-09-08 21:43:37 -07:00
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
TSNode child;
|
2018-11-13 15:35:14 -08:00
|
|
|
NodeChildIterator iterator = ts_node_iterate_children(&node);
|
2018-05-09 10:16:10 -07:00
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
2018-05-09 13:46:46 -07:00
|
|
|
if (iterator.position.bytes < target_end_byte) continue;
|
2018-05-22 08:50:04 -07:00
|
|
|
if (ts_node_start_byte(child) <= ts_node_start_byte(self)) {
|
2018-09-17 13:12:13 -07:00
|
|
|
if (ts_node__subtree(child).ptr != ts_node__subtree(self).ptr) {
|
2018-05-09 13:46:46 -07:00
|
|
|
child_containing_target = child;
|
2018-05-09 10:16:10 -07:00
|
|
|
}
|
2018-05-09 13:46:46 -07:00
|
|
|
} else if (ts_node__is_relevant(child, include_anonymous)) {
|
|
|
|
|
later_child = child;
|
|
|
|
|
later_child_is_relevant = true;
|
|
|
|
|
break;
|
|
|
|
|
} else if (ts_node__relevant_child_count(child, include_anonymous) > 0) {
|
|
|
|
|
later_child = child;
|
|
|
|
|
later_child_is_relevant = false;
|
|
|
|
|
break;
|
2018-05-09 10:16:10 -07:00
|
|
|
}
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
2018-05-09 13:46:46 -07:00
|
|
|
|
2018-05-16 15:44:04 -07:00
|
|
|
if (!ts_node_is_null(child_containing_target)) {
|
|
|
|
|
if (!ts_node_is_null(later_child)) {
|
2018-05-09 13:46:46 -07:00
|
|
|
later_node = later_child;
|
|
|
|
|
later_node_is_relevant = later_child_is_relevant;
|
|
|
|
|
}
|
|
|
|
|
node = child_containing_target;
|
|
|
|
|
} else if (later_child_is_relevant) {
|
|
|
|
|
return later_child;
|
2018-05-16 15:44:04 -07:00
|
|
|
} else if (!ts_node_is_null(later_child)) {
|
2018-05-09 13:46:46 -07:00
|
|
|
node = later_child;
|
|
|
|
|
} else if (later_node_is_relevant) {
|
|
|
|
|
return later_node;
|
|
|
|
|
} else {
|
|
|
|
|
node = later_node;
|
|
|
|
|
}
|
2018-05-09 10:16:10 -07:00
|
|
|
}
|
2015-09-08 21:43:37 -07:00
|
|
|
|
|
|
|
|
return ts_node__null();
|
2015-09-07 21:11:37 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
static inline TSNode ts_node__first_child_for_byte(
|
|
|
|
|
TSNode self,
|
|
|
|
|
uint32_t goal,
|
|
|
|
|
bool include_anonymous
|
|
|
|
|
) {
|
2018-01-09 12:33:51 -08:00
|
|
|
TSNode node = self;
|
|
|
|
|
bool did_descend = true;
|
|
|
|
|
|
|
|
|
|
while (did_descend) {
|
|
|
|
|
did_descend = false;
|
|
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
TSNode child;
|
2018-11-13 15:35:14 -08:00
|
|
|
NodeChildIterator iterator = ts_node_iterate_children(&node);
|
2018-05-09 10:16:10 -07:00
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
2018-01-09 12:33:51 -08:00
|
|
|
if (ts_node_end_byte(child) > goal) {
|
|
|
|
|
if (ts_node__is_relevant(child, include_anonymous)) {
|
|
|
|
|
return child;
|
|
|
|
|
} else if (ts_node_child_count(child) > 0) {
|
|
|
|
|
did_descend = true;
|
|
|
|
|
node = child;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ts_node__null();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
static inline TSNode ts_node__descendant_for_byte_range(
|
|
|
|
|
TSNode self,
|
|
|
|
|
uint32_t range_start,
|
|
|
|
|
uint32_t range_end,
|
|
|
|
|
bool include_anonymous
|
|
|
|
|
) {
|
2016-09-06 21:33:19 -07:00
|
|
|
TSNode node = self;
|
|
|
|
|
TSNode last_visible_node = self;
|
|
|
|
|
|
|
|
|
|
bool did_descend = true;
|
|
|
|
|
while (did_descend) {
|
|
|
|
|
did_descend = false;
|
|
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
TSNode child;
|
2018-11-13 15:35:14 -08:00
|
|
|
NodeChildIterator iterator = ts_node_iterate_children(&node);
|
2018-05-09 10:16:10 -07:00
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
2019-06-13 10:53:59 -07:00
|
|
|
uint32_t node_end = iterator.position.bytes;
|
|
|
|
|
|
|
|
|
|
// The end of this node must extend far enough forward to touch
|
|
|
|
|
// the end of the range and exceed the start of the range.
|
|
|
|
|
if (node_end < range_end) continue;
|
|
|
|
|
if (node_end <= range_start) continue;
|
|
|
|
|
|
|
|
|
|
// The start of this node must extend far enough backward to
|
|
|
|
|
// touch the start of the range.
|
|
|
|
|
if (range_start < ts_node_start_byte(child)) break;
|
|
|
|
|
|
|
|
|
|
node = child;
|
|
|
|
|
if (ts_node__is_relevant(node, include_anonymous)) {
|
|
|
|
|
last_visible_node = node;
|
2016-09-06 21:33:19 -07:00
|
|
|
}
|
2019-06-13 10:53:59 -07:00
|
|
|
did_descend = true;
|
|
|
|
|
break;
|
2016-09-06 21:33:19 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return last_visible_node;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
static inline TSNode ts_node__descendant_for_point_range(
|
|
|
|
|
TSNode self,
|
|
|
|
|
TSPoint range_start,
|
|
|
|
|
TSPoint range_end,
|
|
|
|
|
bool include_anonymous
|
|
|
|
|
) {
|
2016-09-06 21:17:26 -07:00
|
|
|
TSNode node = self;
|
|
|
|
|
TSNode last_visible_node = self;
|
|
|
|
|
|
|
|
|
|
bool did_descend = true;
|
|
|
|
|
while (did_descend) {
|
|
|
|
|
did_descend = false;
|
|
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
TSNode child;
|
2018-11-13 15:35:14 -08:00
|
|
|
NodeChildIterator iterator = ts_node_iterate_children(&node);
|
2018-05-09 10:16:10 -07:00
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
2019-06-13 10:53:59 -07:00
|
|
|
TSPoint node_end = iterator.position.extent;
|
|
|
|
|
|
|
|
|
|
// The end of this node must extend far enough forward to touch
|
|
|
|
|
// the end of the range and exceed the start of the range.
|
|
|
|
|
if (point_lt(node_end, range_end)) continue;
|
|
|
|
|
if (point_lte(node_end, range_start)) continue;
|
|
|
|
|
|
|
|
|
|
// The start of this node must extend far enough backward to
|
|
|
|
|
// touch the start of the range.
|
|
|
|
|
if (point_lt(range_start, ts_node_start_point(child))) break;
|
|
|
|
|
|
|
|
|
|
node = child;
|
|
|
|
|
if (ts_node__is_relevant(node, include_anonymous)) {
|
|
|
|
|
last_visible_node = node;
|
2016-09-06 21:17:26 -07:00
|
|
|
}
|
2019-06-13 10:53:59 -07:00
|
|
|
did_descend = true;
|
|
|
|
|
break;
|
2016-09-06 21:17:26 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return last_visible_node;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 15:44:04 -07:00
|
|
|
// TSNode - public
|
2015-09-08 23:16:24 -07:00
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_end_byte(TSNode self) {
|
2018-09-17 13:12:13 -07:00
|
|
|
return ts_node_start_byte(self) + ts_subtree_size(ts_node__subtree(self)).bytes;
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-18 17:53:38 -08:00
|
|
|
TSPoint ts_node_end_point(TSNode self) {
|
2018-09-17 13:12:13 -07:00
|
|
|
return point_add(ts_node_start_point(self), ts_subtree_size(ts_node__subtree(self)).extent);
|
2015-11-18 17:53:38 -08:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
TSSymbol ts_node_symbol(TSNode self) {
|
2019-12-05 17:21:46 -08:00
|
|
|
TSSymbol symbol = ts_node__alias(&self);
|
|
|
|
|
if (!symbol) symbol = ts_subtree_symbol(ts_node__subtree(self));
|
|
|
|
|
return ts_language_public_symbol(self.tree->language, symbol);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2018-05-09 15:28:28 -07:00
|
|
|
const char *ts_node_type(TSNode self) {
|
2019-12-05 17:21:46 -08:00
|
|
|
TSSymbol symbol = ts_node__alias(&self);
|
|
|
|
|
if (!symbol) symbol = ts_subtree_symbol(ts_node__subtree(self));
|
|
|
|
|
return ts_language_symbol_name(self.tree->language, symbol);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2023-06-08 19:37:04 +01:00
|
|
|
const TSLanguage *ts_node_language(TSNode self) {
|
|
|
|
|
return self.tree->language;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 15:55:32 +03:00
|
|
|
TSSymbol ts_node_grammar_symbol(TSNode self) {
|
|
|
|
|
return ts_subtree_symbol(ts_node__subtree(self));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *ts_node_grammar_type(TSNode self) {
|
|
|
|
|
TSSymbol symbol = ts_subtree_symbol(ts_node__subtree(self));
|
|
|
|
|
return ts_language_symbol_name(self.tree->language, symbol);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-09 15:28:28 -07:00
|
|
|
char *ts_node_string(TSNode self) {
|
2024-03-18 02:50:01 -04:00
|
|
|
TSSymbol alias_symbol = ts_node__alias(&self);
|
|
|
|
|
return ts_subtree_string(
|
|
|
|
|
ts_node__subtree(self),
|
|
|
|
|
alias_symbol,
|
|
|
|
|
ts_language_symbol_metadata(self.tree->language, alias_symbol).visible,
|
|
|
|
|
self.tree->language,
|
|
|
|
|
false
|
|
|
|
|
);
|
2016-04-03 23:45:43 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
bool ts_node_eq(TSNode self, TSNode other) {
|
2018-05-22 08:50:04 -07:00
|
|
|
return self.tree == other.tree && self.id == other.id;
|
2015-09-08 23:16:24 -07:00
|
|
|
}
|
|
|
|
|
|
2018-05-16 15:44:04 -07:00
|
|
|
bool ts_node_is_null(TSNode self) {
|
2018-09-17 13:12:13 -07:00
|
|
|
return self.id == 0;
|
2018-05-16 15:44:04 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-19 15:58:29 -07:00
|
|
|
bool ts_node_is_extra(TSNode self) {
|
|
|
|
|
return ts_subtree_extra(ts_node__subtree(self));
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
bool ts_node_is_named(TSNode self) {
|
2019-08-29 14:28:44 -07:00
|
|
|
TSSymbol alias = ts_node__alias(&self);
|
|
|
|
|
return alias
|
|
|
|
|
? ts_language_symbol_metadata(self.tree->language, alias).named
|
2018-09-17 13:12:13 -07:00
|
|
|
: ts_subtree_named(ts_node__subtree(self));
|
2015-09-08 23:16:24 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-28 15:48:35 -08:00
|
|
|
bool ts_node_is_missing(TSNode self) {
|
2018-09-17 13:12:13 -07:00
|
|
|
return ts_subtree_missing(ts_node__subtree(self));
|
2017-12-28 15:48:35 -08:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
bool ts_node_has_changes(TSNode self) {
|
2018-09-17 13:12:13 -07:00
|
|
|
return ts_subtree_has_changes(ts_node__subtree(self));
|
2015-09-18 23:20:06 -07:00
|
|
|
}
|
|
|
|
|
|
2017-06-21 17:26:52 -07:00
|
|
|
bool ts_node_has_error(TSNode self) {
|
2018-09-17 13:12:13 -07:00
|
|
|
return ts_subtree_error_cost(ts_node__subtree(self)) > 0;
|
2017-06-21 17:26:52 -07:00
|
|
|
}
|
|
|
|
|
|
2023-05-17 10:39:37 +03:00
|
|
|
bool ts_node_is_error(TSNode self) {
|
|
|
|
|
TSSymbol symbol = ts_node_symbol(self);
|
|
|
|
|
return symbol == ts_builtin_sym_error;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 00:27:19 +03:00
|
|
|
uint32_t ts_node_descendant_count(TSNode self) {
|
|
|
|
|
return ts_subtree_visible_descendant_count(ts_node__subtree(self)) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 10:39:37 +03:00
|
|
|
TSStateId ts_node_parse_state(TSNode self) {
|
|
|
|
|
return ts_subtree_parse_state(ts_node__subtree(self));
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 15:55:32 +03:00
|
|
|
TSStateId ts_node_next_parse_state(TSNode self) {
|
|
|
|
|
const TSLanguage *language = self.tree->language;
|
|
|
|
|
uint16_t state = ts_node_parse_state(self);
|
2023-08-30 20:03:03 +03:00
|
|
|
if (state == TS_TREE_STATE_NONE) {
|
|
|
|
|
return TS_TREE_STATE_NONE;
|
|
|
|
|
}
|
2023-06-15 15:55:32 +03:00
|
|
|
uint16_t symbol = ts_node_grammar_symbol(self);
|
|
|
|
|
return ts_language_next_state(language, state, symbol);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
TSNode ts_node_parent(TSNode self) {
|
2021-05-20 13:36:57 -07:00
|
|
|
TSNode node = ts_tree_root_node(self.tree);
|
2018-09-17 13:12:13 -07:00
|
|
|
if (node.id == self.id) return ts_node__null();
|
2015-09-08 23:16:24 -07:00
|
|
|
|
2024-04-23 09:19:57 -05:00
|
|
|
while (true) {
|
|
|
|
|
TSNode next_node = ts_node_child_containing_descendant(node, self);
|
|
|
|
|
if (ts_node_is_null(next_node)) break;
|
|
|
|
|
node = next_node;
|
|
|
|
|
}
|
2015-09-08 23:16:24 -07:00
|
|
|
|
2024-04-23 09:19:57 -05:00
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSNode ts_node_child_containing_descendant(TSNode self, TSNode subnode) {
|
|
|
|
|
uint32_t start_byte = ts_node_start_byte(subnode);
|
|
|
|
|
uint32_t end_byte = ts_node_end_byte(subnode);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
NodeChildIterator iter = ts_node_iterate_children(&self);
|
|
|
|
|
do {
|
2018-05-16 15:44:04 -07:00
|
|
|
if (
|
2024-04-23 09:19:57 -05:00
|
|
|
!ts_node_child_iterator_next(&iter, &self)
|
|
|
|
|
|| ts_node_start_byte(self) > start_byte
|
|
|
|
|
|| self.id == subnode.id
|
|
|
|
|
) {
|
|
|
|
|
return ts_node__null();
|
2018-05-09 10:16:10 -07:00
|
|
|
}
|
2024-04-23 09:19:57 -05:00
|
|
|
} while (iter.position.bytes < end_byte || ts_node_child_count(self) == 0);
|
|
|
|
|
} while (!ts_node__is_relevant(self, true));
|
2018-01-09 12:33:51 -08:00
|
|
|
|
2024-04-23 09:19:57 -05:00
|
|
|
return self;
|
2018-01-09 12:33:51 -08:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
TSNode ts_node_child(TSNode self, uint32_t child_index) {
|
2015-11-22 13:32:20 -08:00
|
|
|
return ts_node__child(self, child_index, true);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
TSNode ts_node_named_child(TSNode self, uint32_t child_index) {
|
2015-11-22 13:32:20 -08:00
|
|
|
return ts_node__child(self, child_index, false);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:29:20 -08:00
|
|
|
TSNode ts_node_child_by_field_id(TSNode self, TSFieldId field_id) {
|
2019-02-07 17:18:33 -08:00
|
|
|
recur:
|
|
|
|
|
if (!field_id || ts_node_child_count(self) == 0) return ts_node__null();
|
|
|
|
|
|
2019-02-08 16:06:29 -08:00
|
|
|
const TSFieldMapEntry *field_map, *field_map_end;
|
2019-02-07 17:18:33 -08:00
|
|
|
ts_language_field_map(
|
|
|
|
|
self.tree->language,
|
2019-02-12 11:06:18 -08:00
|
|
|
ts_node__subtree(self).ptr->production_id,
|
2019-02-07 17:18:33 -08:00
|
|
|
&field_map,
|
|
|
|
|
&field_map_end
|
|
|
|
|
);
|
|
|
|
|
if (field_map == field_map_end) return ts_node__null();
|
|
|
|
|
|
|
|
|
|
// The field mappings are sorted by their field id. Scan all
|
|
|
|
|
// the mappings to find the ones for the given field id.
|
|
|
|
|
while (field_map->field_id < field_id) {
|
|
|
|
|
field_map++;
|
|
|
|
|
if (field_map == field_map_end) return ts_node__null();
|
|
|
|
|
}
|
|
|
|
|
while (field_map_end[-1].field_id > field_id) {
|
|
|
|
|
field_map_end--;
|
|
|
|
|
if (field_map == field_map_end) return ts_node__null();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSNode child;
|
|
|
|
|
NodeChildIterator iterator = ts_node_iterate_children(&self);
|
|
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
|
|
|
|
if (!ts_subtree_extra(ts_node__subtree(child))) {
|
|
|
|
|
uint32_t index = iterator.structural_child_index - 1;
|
|
|
|
|
if (index < field_map->child_index) continue;
|
|
|
|
|
|
|
|
|
|
// Hidden nodes' fields are "inherited" by their visible parent.
|
|
|
|
|
if (field_map->inherited) {
|
|
|
|
|
|
|
|
|
|
// If this is the *last* possible child node for this field,
|
|
|
|
|
// then perform a tail call to avoid recursion.
|
|
|
|
|
if (field_map + 1 == field_map_end) {
|
|
|
|
|
self = child;
|
|
|
|
|
goto recur;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 11:06:18 -08:00
|
|
|
// Otherwise, descend into this child, but if it doesn't contain
|
|
|
|
|
// the field, continue searching subsequent children.
|
2019-02-07 17:18:33 -08:00
|
|
|
else {
|
|
|
|
|
TSNode result = ts_node_child_by_field_id(child, field_id);
|
|
|
|
|
if (result.id) return result;
|
|
|
|
|
field_map++;
|
|
|
|
|
if (field_map == field_map_end) return ts_node__null();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (ts_node__is_relevant(child, true)) {
|
2019-02-07 12:29:20 -08:00
|
|
|
return child;
|
|
|
|
|
}
|
2019-02-07 17:18:33 -08:00
|
|
|
|
2021-02-10 16:14:24 -08:00
|
|
|
// If the field refers to a hidden node with visible children,
|
|
|
|
|
// return the first visible child.
|
|
|
|
|
else if (ts_node_child_count(child) > 0 ) {
|
|
|
|
|
return ts_node_child(child, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Otherwise, continue searching subsequent children.
|
2019-02-07 17:18:33 -08:00
|
|
|
else {
|
2021-01-22 18:23:50 +01:00
|
|
|
field_map++;
|
|
|
|
|
if (field_map == field_map_end) return ts_node__null();
|
2019-02-07 17:18:33 -08:00
|
|
|
}
|
2019-02-07 12:29:20 -08:00
|
|
|
}
|
|
|
|
|
}
|
2019-02-07 17:18:33 -08:00
|
|
|
|
2019-01-22 12:02:17 -08:00
|
|
|
return ts_node__null();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-25 19:54:23 +02:00
|
|
|
static inline const char *ts_node__field_name_from_language(TSNode self, uint32_t structural_child_index) {
|
|
|
|
|
const TSFieldMapEntry *field_map, *field_map_end;
|
|
|
|
|
ts_language_field_map(
|
|
|
|
|
self.tree->language,
|
|
|
|
|
ts_node__subtree(self).ptr->production_id,
|
|
|
|
|
&field_map,
|
|
|
|
|
&field_map_end
|
|
|
|
|
);
|
|
|
|
|
for (; field_map != field_map_end; field_map++) {
|
|
|
|
|
if (!field_map->inherited && field_map->child_index == structural_child_index) {
|
|
|
|
|
return self.tree->language->field_names[field_map->field_id];
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-04 00:58:48 +01:00
|
|
|
return NULL;
|
2023-02-25 19:54:23 +02:00
|
|
|
}
|
2021-11-04 00:58:48 +01:00
|
|
|
|
2023-02-25 19:54:23 +02:00
|
|
|
const char *ts_node_field_name_for_child(TSNode self, uint32_t child_index) {
|
|
|
|
|
TSNode result = self;
|
|
|
|
|
bool did_descend = true;
|
|
|
|
|
const char *inherited_field_name = NULL;
|
2021-05-15 00:18:32 +00:00
|
|
|
|
2023-02-25 19:54:23 +02:00
|
|
|
while (did_descend) {
|
|
|
|
|
did_descend = false;
|
|
|
|
|
|
|
|
|
|
TSNode child;
|
|
|
|
|
uint32_t index = 0;
|
|
|
|
|
NodeChildIterator iterator = ts_node_iterate_children(&result);
|
|
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
|
|
|
|
if (ts_node__is_relevant(child, true)) {
|
|
|
|
|
if (index == child_index) {
|
2024-04-30 19:07:15 -04:00
|
|
|
if (ts_node_is_extra(child)) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2023-02-25 19:54:23 +02:00
|
|
|
const char *field_name = ts_node__field_name_from_language(result, iterator.structural_child_index - 1);
|
|
|
|
|
if (field_name) return field_name;
|
|
|
|
|
return inherited_field_name;
|
|
|
|
|
}
|
|
|
|
|
index++;
|
|
|
|
|
} else {
|
|
|
|
|
uint32_t grandchild_index = child_index - index;
|
|
|
|
|
uint32_t grandchild_count = ts_node__relevant_child_count(child, true);
|
|
|
|
|
if (grandchild_index < grandchild_count) {
|
|
|
|
|
const char *field_name = ts_node__field_name_from_language(result, iterator.structural_child_index - 1);
|
|
|
|
|
if (field_name) inherited_field_name = field_name;
|
|
|
|
|
|
|
|
|
|
did_descend = true;
|
|
|
|
|
result = child;
|
|
|
|
|
child_index = grandchild_index;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
index += grandchild_count;
|
|
|
|
|
}
|
2021-05-15 00:18:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-02-25 19:54:23 +02:00
|
|
|
|
2021-05-15 00:18:32 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:29:20 -08:00
|
|
|
TSNode ts_node_child_by_field_name(
|
|
|
|
|
TSNode self,
|
|
|
|
|
const char *name,
|
|
|
|
|
uint32_t name_length
|
|
|
|
|
) {
|
|
|
|
|
TSFieldId field_id = ts_language_field_id_for_name(
|
|
|
|
|
self.tree->language,
|
|
|
|
|
name,
|
|
|
|
|
name_length
|
|
|
|
|
);
|
|
|
|
|
return ts_node_child_by_field_id(self, field_id);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_child_count(TSNode self) {
|
2018-09-17 13:12:13 -07:00
|
|
|
Subtree tree = ts_node__subtree(self);
|
|
|
|
|
if (ts_subtree_child_count(tree) > 0) {
|
|
|
|
|
return tree.ptr->visible_child_count;
|
2016-12-20 13:12:01 -08:00
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-09-08 23:16:24 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_named_child_count(TSNode self) {
|
2018-09-17 13:12:13 -07:00
|
|
|
Subtree tree = ts_node__subtree(self);
|
|
|
|
|
if (ts_subtree_child_count(tree) > 0) {
|
|
|
|
|
return tree.ptr->named_child_count;
|
2016-12-20 13:12:01 -08:00
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
TSNode ts_node_next_sibling(TSNode self) {
|
2015-11-22 13:32:20 -08:00
|
|
|
return ts_node__next_sibling(self, true);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
TSNode ts_node_next_named_sibling(TSNode self) {
|
2015-11-22 13:32:20 -08:00
|
|
|
return ts_node__next_sibling(self, false);
|
2015-09-08 23:16:24 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
TSNode ts_node_prev_sibling(TSNode self) {
|
2015-11-22 13:32:20 -08:00
|
|
|
return ts_node__prev_sibling(self, true);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
TSNode ts_node_prev_named_sibling(TSNode self) {
|
2015-11-22 13:32:20 -08:00
|
|
|
return ts_node__prev_sibling(self, false);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2018-01-09 12:33:51 -08:00
|
|
|
TSNode ts_node_first_child_for_byte(TSNode self, uint32_t byte) {
|
|
|
|
|
return ts_node__first_child_for_byte(self, byte, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSNode ts_node_first_named_child_for_byte(TSNode self, uint32_t byte) {
|
|
|
|
|
return ts_node__first_child_for_byte(self, byte, false);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
TSNode ts_node_descendant_for_byte_range(
|
|
|
|
|
TSNode self,
|
|
|
|
|
uint32_t start,
|
|
|
|
|
uint32_t end
|
|
|
|
|
) {
|
|
|
|
|
return ts_node__descendant_for_byte_range(self, start, end, true);
|
2016-09-06 21:33:19 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
TSNode ts_node_named_descendant_for_byte_range(
|
|
|
|
|
TSNode self,
|
|
|
|
|
uint32_t start,
|
|
|
|
|
uint32_t end
|
|
|
|
|
) {
|
|
|
|
|
return ts_node__descendant_for_byte_range(self, start, end, false);
|
2016-09-06 21:33:19 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
TSNode ts_node_descendant_for_point_range(
|
|
|
|
|
TSNode self,
|
|
|
|
|
TSPoint start,
|
|
|
|
|
TSPoint end
|
|
|
|
|
) {
|
|
|
|
|
return ts_node__descendant_for_point_range(self, start, end, true);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 10:53:59 -07:00
|
|
|
TSNode ts_node_named_descendant_for_point_range(
|
|
|
|
|
TSNode self,
|
|
|
|
|
TSPoint start,
|
|
|
|
|
TSPoint end
|
|
|
|
|
) {
|
|
|
|
|
return ts_node__descendant_for_point_range(self, start, end, false);
|
2014-08-25 09:31:27 -07:00
|
|
|
}
|
2018-07-11 16:17:46 -07:00
|
|
|
|
|
|
|
|
void ts_node_edit(TSNode *self, const TSInputEdit *edit) {
|
|
|
|
|
uint32_t start_byte = ts_node_start_byte(*self);
|
|
|
|
|
TSPoint start_point = ts_node_start_point(*self);
|
|
|
|
|
|
|
|
|
|
if (start_byte >= edit->old_end_byte) {
|
|
|
|
|
start_byte = edit->new_end_byte + (start_byte - edit->old_end_byte);
|
|
|
|
|
start_point = point_add(edit->new_end_point, point_sub(start_point, edit->old_end_point));
|
|
|
|
|
} else if (start_byte > edit->start_byte) {
|
|
|
|
|
start_byte = edit->new_end_byte;
|
|
|
|
|
start_point = edit->new_end_point;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self->context[0] = start_byte;
|
|
|
|
|
self->context[1] = start_point.row;
|
|
|
|
|
self->context[2] = start_point.column;
|
|
|
|
|
}
|