2014-10-03 16:06:08 -07:00
|
|
|
#include <stdbool.h>
|
2018-05-10 15:11:14 -07:00
|
|
|
#include "runtime/subtree.h"
|
2018-05-10 22:22:37 -07:00
|
|
|
#include "runtime/tree.h"
|
2018-05-09 10:16:10 -07:00
|
|
|
#include "runtime/language.h"
|
2014-07-17 23:29:11 -07:00
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
// NodeChildIterator
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2018-05-10 15:11:14 -07:00
|
|
|
const 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;
|
|
|
|
|
uint32_t structural_child_index;
|
|
|
|
|
const TSSymbol *alias_sequence;
|
|
|
|
|
} NodeChildIterator;
|
2014-07-17 23:29:11 -07:00
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
// TSNode - Private
|
2015-08-16 10:51:34 -07:00
|
|
|
|
2015-08-16 10:54:02 -07:00
|
|
|
static inline TSNode ts_node__null() {
|
2018-05-09 10:16:10 -07:00
|
|
|
return (TSNode) {
|
|
|
|
|
.subtree = NULL,
|
2018-05-10 22:22:37 -07:00
|
|
|
.tree = NULL,
|
2018-05-09 10:16:10 -07:00
|
|
|
.position = {0, 0},
|
|
|
|
|
.byte = 0,
|
|
|
|
|
};
|
2015-08-16 10:54:02 -07:00
|
|
|
}
|
|
|
|
|
|
2018-05-10 15:11:14 -07:00
|
|
|
static inline const Subtree *ts_node__tree(TSNode self) {
|
2018-05-09 10:16:10 -07:00
|
|
|
return self.subtree;
|
2014-07-17 23:29:11 -07:00
|
|
|
}
|
|
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
static inline NodeChildIterator ts_node_child_iterator_begin(const TSNode *node) {
|
2018-05-10 15:11:14 -07:00
|
|
|
const Subtree *tree = ts_node__tree(*node);
|
2018-05-09 10:16:10 -07:00
|
|
|
const TSSymbol *alias_sequence = ts_language_alias_sequence(
|
2018-05-10 22:22:37 -07:00
|
|
|
node->tree->language,
|
2018-05-09 10:16:10 -07:00
|
|
|
tree->alias_sequence_id
|
|
|
|
|
);
|
|
|
|
|
return (NodeChildIterator) {
|
|
|
|
|
.parent = tree,
|
2018-05-10 22:22:37 -07:00
|
|
|
.tree = node->tree,
|
2018-05-09 10:16:10 -07:00
|
|
|
.position = {node->byte, node->position},
|
|
|
|
|
.child_index = 0,
|
|
|
|
|
.structural_child_index = 0,
|
|
|
|
|
.alias_sequence = alias_sequence,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool ts_node_child_iterator_next(NodeChildIterator *self, TSNode *result) {
|
|
|
|
|
if (self->child_index == self->parent->children.size) return false;
|
2018-05-10 15:11:14 -07:00
|
|
|
Subtree *child = self->parent->children.contents[self->child_index];
|
2018-05-09 10:16:10 -07:00
|
|
|
TSSymbol alias_symbol = 0;
|
|
|
|
|
if (!child->extra) {
|
|
|
|
|
if (self->alias_sequence) {
|
|
|
|
|
alias_symbol = self->alias_sequence[self->structural_child_index];
|
|
|
|
|
}
|
|
|
|
|
self->structural_child_index++;
|
|
|
|
|
}
|
|
|
|
|
*result = (TSNode) {
|
|
|
|
|
.subtree = child,
|
2018-05-10 22:22:37 -07:00
|
|
|
.tree = self->tree,
|
2018-05-09 10:16:10 -07:00
|
|
|
.position = self->position.extent,
|
|
|
|
|
.byte = self->position.bytes,
|
|
|
|
|
.alias_symbol = alias_symbol,
|
|
|
|
|
};
|
2018-05-10 15:11:14 -07:00
|
|
|
self->position = length_add(self->position, ts_subtree_total_size(child));
|
2018-05-09 10:16:10 -07:00
|
|
|
self->child_index++;
|
|
|
|
|
return true;
|
2015-12-04 10:45:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous) {
|
2018-05-10 15:11:14 -07:00
|
|
|
const Subtree *tree = ts_node__tree(self);
|
2017-08-01 13:28:18 -07:00
|
|
|
if (include_anonymous) {
|
2018-05-09 10:16:10 -07:00
|
|
|
return tree->visible || self.alias_symbol;
|
2017-07-18 21:24:34 -07:00
|
|
|
} else {
|
2018-05-09 10:16:10 -07:00
|
|
|
return (
|
|
|
|
|
(tree->visible && tree->named) ||
|
|
|
|
|
(
|
|
|
|
|
self.alias_symbol &&
|
|
|
|
|
ts_language_symbol_metadata(
|
2018-05-10 22:22:37 -07:00
|
|
|
self.tree->language,
|
2018-05-09 10:16:10 -07:00
|
|
|
self.alias_symbol
|
|
|
|
|
).named
|
|
|
|
|
)
|
|
|
|
|
);
|
2017-07-18 21:24:34 -07:00
|
|
|
}
|
2015-11-22 13:32:20 -08:00
|
|
|
}
|
|
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
static inline uint32_t ts_node__relevant_child_count(TSNode self, bool include_anonymous) {
|
2018-05-10 15:11:14 -07:00
|
|
|
const Subtree *tree = ts_node__tree(self);
|
2018-04-02 18:04:26 -07:00
|
|
|
if (tree->children.size > 0) {
|
2016-12-20 13:12:01 -08:00
|
|
|
if (include_anonymous) {
|
|
|
|
|
return tree->visible_child_count;
|
|
|
|
|
} else {
|
|
|
|
|
return tree->named_child_count;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-11-22 13:32:20 -08:00
|
|
|
}
|
2015-11-18 16:34:50 -08:00
|
|
|
|
2018-05-09 10:16:10 -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-05-09 10:16:10 -07:00
|
|
|
NodeChildIterator iterator = ts_node_child_iterator_begin(&result);
|
|
|
|
|
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-09 10:16:10 -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
|
|
|
}
|
|
|
|
|
|
2018-05-09 13:23:47 -07:00
|
|
|
static inline TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous) {
|
|
|
|
|
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-05-09 13:23:47 -07:00
|
|
|
while (node.subtree) {
|
|
|
|
|
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;
|
|
|
|
|
NodeChildIterator iterator = ts_node_child_iterator_begin(&node);
|
|
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
|
|
|
|
if (iterator.position.bytes >= target_end_byte) {
|
|
|
|
|
found_child_containing_target = child.subtree != self.subtree;
|
|
|
|
|
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) {
|
|
|
|
|
if (earlier_child.subtree) {
|
|
|
|
|
earlier_node = earlier_child;
|
|
|
|
|
earlier_node_is_relevant = earlier_child_is_relevant;
|
|
|
|
|
}
|
|
|
|
|
node = child;
|
|
|
|
|
} else if (earlier_child_is_relevant) {
|
|
|
|
|
return earlier_child;
|
|
|
|
|
} else if (earlier_child.subtree) {
|
|
|
|
|
node = earlier_child;
|
|
|
|
|
} else if (earlier_node_is_relevant) {
|
|
|
|
|
return earlier_node;
|
|
|
|
|
} else {
|
|
|
|
|
node = earlier_node;
|
|
|
|
|
}
|
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-05-09 13:46:46 -07:00
|
|
|
while (node.subtree) {
|
|
|
|
|
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;
|
|
|
|
|
NodeChildIterator iterator = ts_node_child_iterator_begin(&node);
|
|
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
2018-05-09 13:46:46 -07:00
|
|
|
if (iterator.position.bytes < target_end_byte) continue;
|
|
|
|
|
if (child.byte <= self.byte) {
|
|
|
|
|
if (child.subtree != self.subtree) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
if (child_containing_target.subtree) {
|
|
|
|
|
if (later_child.subtree) {
|
|
|
|
|
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;
|
|
|
|
|
} else if (later_child.subtree) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-11-09 20:59:05 -08:00
|
|
|
static inline bool point_gt(TSPoint a, TSPoint b) {
|
2016-09-06 21:17:26 -07:00
|
|
|
return a.row > b.row || (a.row == b.row && a.column > b.column);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-09 12:33:51 -08:00
|
|
|
static inline TSNode ts_node__first_child_for_byte(TSNode self, uint32_t goal,
|
|
|
|
|
bool include_anonymous) {
|
|
|
|
|
TSNode node = self;
|
|
|
|
|
bool did_descend = true;
|
|
|
|
|
|
|
|
|
|
while (did_descend) {
|
|
|
|
|
did_descend = false;
|
|
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
TSNode child;
|
|
|
|
|
NodeChildIterator iterator = ts_node_child_iterator_begin(&node);
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
static inline TSNode ts_node__descendant_for_byte_range(TSNode self, uint32_t min,
|
|
|
|
|
uint32_t max,
|
2016-09-06 21:33:19 -07:00
|
|
|
bool include_anonymous) {
|
|
|
|
|
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;
|
|
|
|
|
NodeChildIterator iterator = ts_node_child_iterator_begin(&node);
|
|
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
|
|
|
|
if (iterator.position.bytes > max) {
|
|
|
|
|
if (child.byte > min) break;
|
2016-09-06 21:33:19 -07:00
|
|
|
node = child;
|
2017-12-20 16:26:38 -08:00
|
|
|
if (ts_node__is_relevant(node, include_anonymous)) last_visible_node = node;
|
2016-09-06 21:33:19 -07:00
|
|
|
did_descend = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return last_visible_node;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 16:26:38 -08:00
|
|
|
static inline TSNode ts_node__descendant_for_point_range(TSNode self, TSPoint min,
|
|
|
|
|
TSPoint max,
|
|
|
|
|
bool include_anonymous) {
|
2016-09-06 21:17:26 -07:00
|
|
|
TSNode node = self;
|
|
|
|
|
TSNode last_visible_node = self;
|
2017-12-27 11:55:52 -08:00
|
|
|
TSPoint start_position = ts_node_start_point(self);
|
|
|
|
|
TSPoint end_position = ts_node_end_point(self);
|
2016-09-06 21:17:26 -07:00
|
|
|
|
|
|
|
|
bool did_descend = true;
|
|
|
|
|
while (did_descend) {
|
|
|
|
|
did_descend = false;
|
|
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
TSNode child;
|
|
|
|
|
NodeChildIterator iterator = ts_node_child_iterator_begin(&node);
|
|
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
2018-05-10 15:11:14 -07:00
|
|
|
const Subtree *child_tree = ts_node__tree(child);
|
2018-05-09 10:16:10 -07:00
|
|
|
if (iterator.child_index != 1) {
|
|
|
|
|
start_position = point_add(start_position, child_tree->padding.extent);
|
|
|
|
|
}
|
2017-12-27 11:55:52 -08:00
|
|
|
end_position = point_add(start_position, child_tree->size.extent);
|
|
|
|
|
if (point_gt(end_position, max)) {
|
|
|
|
|
if (point_gt(start_position, min)) break;
|
2016-09-06 21:17:26 -07:00
|
|
|
node = child;
|
2017-12-20 16:26:38 -08:00
|
|
|
if (ts_node__is_relevant(node, include_anonymous)) last_visible_node = node;
|
2016-09-06 21:17:26 -07:00
|
|
|
did_descend = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-12-27 11:55:52 -08:00
|
|
|
start_position = end_position;
|
2016-09-06 21:17:26 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return last_visible_node;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
// TSNode - Public
|
2015-09-08 23:16:24 -07:00
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_start_byte(TSNode self) {
|
2018-05-09 10:16:10 -07:00
|
|
|
return self.byte + ts_node__tree(self)->padding.bytes;
|
2015-12-03 22:59:27 -08:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_end_byte(TSNode self) {
|
2015-12-03 22:59:27 -08:00
|
|
|
return ts_node_start_byte(self) + ts_node__tree(self)->size.bytes;
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2015-11-18 17:53:38 -08:00
|
|
|
TSPoint ts_node_start_point(TSNode self) {
|
2018-05-09 10:16:10 -07:00
|
|
|
return point_add(self.position, ts_node__tree(self)->padding.extent);
|
2015-11-18 17:53:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSPoint ts_node_end_point(TSNode self) {
|
2018-05-09 10:16:10 -07:00
|
|
|
return point_add(ts_node_start_point(self), ts_node__tree(self)->size.extent);
|
2015-11-18 17:53:38 -08:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
TSSymbol ts_node_symbol(TSNode self) {
|
2018-05-10 15:11:14 -07:00
|
|
|
const Subtree *tree = ts_node__tree(self);
|
2018-05-09 10:16:10 -07:00
|
|
|
return self.alias_symbol ? self.alias_symbol : tree->symbol;
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2018-05-09 15:28:28 -07:00
|
|
|
const char *ts_node_type(TSNode self) {
|
2018-05-10 22:22:37 -07:00
|
|
|
return ts_language_symbol_name(self.tree->language, ts_node_symbol(self));
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2018-05-09 15:28:28 -07:00
|
|
|
char *ts_node_string(TSNode self) {
|
2018-05-10 22:22:37 -07:00
|
|
|
return ts_subtree_string(ts_node__tree(self), 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-09 10:16:10 -07:00
|
|
|
return (
|
2018-05-10 15:11:14 -07:00
|
|
|
ts_subtree_eq(ts_node__tree(self), ts_node__tree(other)) &&
|
2018-05-09 10:16:10 -07:00
|
|
|
self.byte == other.byte
|
|
|
|
|
);
|
2015-09-08 23:16:24 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
bool ts_node_is_named(TSNode self) {
|
2018-05-10 15:11:14 -07:00
|
|
|
const Subtree *tree = ts_node__tree(self);
|
2018-05-09 10:16:10 -07:00
|
|
|
return self.alias_symbol
|
2018-05-10 22:22:37 -07:00
|
|
|
? ts_language_symbol_metadata(self.tree->language, self.alias_symbol).named
|
2018-05-09 10:16:10 -07:00
|
|
|
: tree->named;
|
2015-09-08 23:16:24 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-28 15:48:35 -08:00
|
|
|
bool ts_node_is_missing(TSNode self) {
|
2018-05-10 15:11:14 -07:00
|
|
|
const Subtree *tree = ts_node__tree(self);
|
2017-12-28 15:48:35 -08:00
|
|
|
return tree->is_missing;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
bool ts_node_has_changes(TSNode self) {
|
2015-12-22 14:20:58 -08:00
|
|
|
return ts_node__tree(self)->has_changes;
|
2015-09-18 23:20:06 -07:00
|
|
|
}
|
|
|
|
|
|
2017-06-21 17:26:52 -07:00
|
|
|
bool ts_node_has_error(TSNode self) {
|
|
|
|
|
return ts_node__tree(self)->error_cost > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
TSNode ts_node_parent(TSNode self) {
|
2018-05-10 22:22:37 -07:00
|
|
|
TSNode node = ts_tree_root_node(self.tree);
|
2018-05-09 10:16:10 -07:00
|
|
|
uint32_t end_byte = ts_node_end_byte(self);
|
|
|
|
|
if (node.subtree == self.subtree) return ts_node__null();
|
2015-09-08 23:16:24 -07:00
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
TSNode last_visible_node = node;
|
|
|
|
|
bool did_descend = true;
|
|
|
|
|
while (did_descend) {
|
|
|
|
|
did_descend = false;
|
2015-09-08 23:16:24 -07:00
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
TSNode child;
|
|
|
|
|
NodeChildIterator iterator = ts_node_child_iterator_begin(&node);
|
|
|
|
|
while (ts_node_child_iterator_next(&iterator, &child)) {
|
|
|
|
|
if (child.byte > self.byte || child.subtree == self.subtree) break;
|
|
|
|
|
if (iterator.position.bytes >= end_byte) {
|
|
|
|
|
node = child;
|
|
|
|
|
if (ts_node__is_relevant(child, true)) {
|
|
|
|
|
last_visible_node = node;
|
|
|
|
|
}
|
|
|
|
|
did_descend = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-01-09 12:33:51 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-09 10:16:10 -07:00
|
|
|
return last_visible_node;
|
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
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_child_count(TSNode self) {
|
2018-05-10 15:11:14 -07:00
|
|
|
const Subtree *tree = ts_node__tree(self);
|
2018-04-02 18:04:26 -07:00
|
|
|
if (tree->children.size > 0) {
|
2016-12-20 13:12:01 -08:00
|
|
|
return tree->visible_child_count;
|
|
|
|
|
} 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-05-10 15:11:14 -07:00
|
|
|
const Subtree *tree = ts_node__tree(self);
|
2018-04-02 18:04:26 -07:00
|
|
|
if (tree->children.size > 0) {
|
2016-12-20 13:12:01 -08:00
|
|
|
return tree->named_child_count;
|
|
|
|
|
} 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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
TSNode ts_node_descendant_for_byte_range(TSNode self, uint32_t min, uint32_t max) {
|
2016-09-06 21:33:19 -07:00
|
|
|
return ts_node__descendant_for_byte_range(self, min, max, true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
TSNode ts_node_named_descendant_for_byte_range(TSNode self, uint32_t min,
|
|
|
|
|
uint32_t max) {
|
2016-09-06 21:33:19 -07:00
|
|
|
return ts_node__descendant_for_byte_range(self, min, max, false);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-06 21:17:26 -07:00
|
|
|
TSNode ts_node_descendant_for_point_range(TSNode self, TSPoint min, TSPoint max) {
|
|
|
|
|
return ts_node__descendant_for_point_range(self, min, max, true);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-10-05 14:02:49 -07:00
|
|
|
TSNode ts_node_named_descendant_for_point_range(TSNode self, TSPoint min,
|
|
|
|
|
TSPoint max) {
|
2016-09-06 21:17:26 -07:00
|
|
|
return ts_node__descendant_for_point_range(self, min, max, false);
|
2014-08-25 09:31:27 -07:00
|
|
|
}
|