2014-10-03 16:06:08 -07:00
|
|
|
#include <stdbool.h>
|
2014-07-17 23:29:11 -07:00
|
|
|
#include "runtime/node.h"
|
|
|
|
|
#include "runtime/tree.h"
|
2015-07-31 15:47:48 -07:00
|
|
|
#include "runtime/document.h"
|
2014-07-17 23:29:11 -07:00
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
TSNode ts_node_make(const Tree *tree, uint32_t chars, uint32_t byte, uint32_t row) {
|
2015-12-04 20:56:33 -08:00
|
|
|
return (TSNode){.data = tree, .offset = { chars, byte, row } };
|
2014-07-17 23:29:11 -07:00
|
|
|
}
|
|
|
|
|
|
2015-09-08 23:16:24 -07:00
|
|
|
/*
|
|
|
|
|
* Private
|
|
|
|
|
*/
|
2015-08-16 10:51:34 -07:00
|
|
|
|
2015-08-16 10:54:02 -07:00
|
|
|
static inline TSNode ts_node__null() {
|
2015-12-04 10:45:30 -08:00
|
|
|
return ts_node_make(NULL, 0, 0, 0);
|
2015-08-16 10:54:02 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-09 20:59:05 -08:00
|
|
|
static inline const Tree *ts_node__tree(TSNode self) {
|
2015-10-14 21:52:13 -07:00
|
|
|
return self.data;
|
2014-07-17 23:29:11 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
static inline uint32_t ts_node__offset_char(TSNode self) {
|
2015-12-04 10:45:30 -08:00
|
|
|
return self.offset[0];
|
2015-07-31 15:47:48 -07:00
|
|
|
}
|
2014-07-18 13:24:03 -07:00
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
static inline uint32_t ts_node__offset_byte(TSNode self) {
|
2015-12-04 10:45:30 -08:00
|
|
|
return self.offset[1];
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
static inline uint32_t ts_node__offset_row(TSNode self) {
|
2015-12-04 10:45:30 -08:00
|
|
|
return self.offset[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool ts_node__is_relevant(TSNode self, bool include_anonymous) {
|
2016-11-09 20:59:05 -08:00
|
|
|
const Tree *tree = ts_node__tree(self);
|
2017-07-31 11:45:24 -07:00
|
|
|
if (tree->context.alias_symbol > 0) {
|
2017-07-18 21:24:34 -07:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return include_anonymous ? tree->visible : tree->visible && tree->named;
|
|
|
|
|
}
|
2015-11-22 13:32:20 -08:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
static inline uint32_t ts_node__relevant_child_count(TSNode self,
|
2015-12-04 20:56:33 -08:00
|
|
|
bool include_anonymous) {
|
2016-11-09 20:59:05 -08:00
|
|
|
const Tree *tree = ts_node__tree(self);
|
2016-12-20 13:12:01 -08:00
|
|
|
if (tree->child_count > 0) {
|
|
|
|
|
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
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
static inline TSNode ts_node__direct_parent(TSNode self, uint32_t *index) {
|
2016-11-09 20:59:05 -08:00
|
|
|
const Tree *tree = ts_node__tree(self);
|
2015-12-04 10:45:30 -08:00
|
|
|
*index = tree->context.index;
|
2015-12-04 20:56:33 -08:00
|
|
|
return ts_node_make(tree->context.parent,
|
|
|
|
|
ts_node__offset_char(self) - tree->context.offset.chars,
|
|
|
|
|
ts_node__offset_byte(self) - tree->context.offset.bytes,
|
2016-09-09 21:11:02 -07:00
|
|
|
ts_node__offset_row(self) - tree->context.offset.extent.row);
|
2015-12-04 10:45:30 -08:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
static inline TSNode ts_node__direct_child(TSNode self, uint32_t i) {
|
2016-11-09 20:59:05 -08:00
|
|
|
const Tree *child_tree = ts_node__tree(self)->children[i];
|
2015-12-04 10:45:30 -08:00
|
|
|
return ts_node_make(
|
2015-12-04 20:56:33 -08:00
|
|
|
child_tree, ts_node__offset_char(self) + child_tree->context.offset.chars,
|
2015-12-04 10:45:30 -08:00
|
|
|
ts_node__offset_byte(self) + child_tree->context.offset.bytes,
|
2016-09-09 21:11:02 -07:00
|
|
|
ts_node__offset_row(self) + child_tree->context.offset.extent.row);
|
2015-12-04 10:45:30 -08:00
|
|
|
}
|
2015-08-16 10:27:26 -07:00
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
static inline TSNode ts_node__child(TSNode self, uint32_t child_index,
|
2015-12-04 10:45:30 -08:00
|
|
|
bool include_anonymous) {
|
|
|
|
|
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
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t index = 0;
|
|
|
|
|
for (uint32_t i = 0; i < ts_node__tree(result)->child_count; i++) {
|
2015-12-04 10:45:30 -08:00
|
|
|
TSNode child = ts_node__direct_child(result, i);
|
|
|
|
|
if (ts_node__is_relevant(child, include_anonymous)) {
|
2015-08-14 16:34:12 -07:00
|
|
|
if (index == child_index)
|
2015-12-04 10:45:30 -08:00
|
|
|
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;
|
|
|
|
|
uint32_t grandchild_count =
|
2015-12-04 10:45:30 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2015-11-22 13:32:20 -08:00
|
|
|
static inline TSNode ts_node__prev_sibling(TSNode self, bool include_anonymous) {
|
2015-12-04 10:45:30 -08:00
|
|
|
TSNode result = self;
|
2015-09-08 21:43:37 -07:00
|
|
|
|
|
|
|
|
do {
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t index;
|
2015-12-04 10:45:30 -08:00
|
|
|
result = ts_node__direct_parent(result, &index);
|
|
|
|
|
if (!result.data)
|
2015-09-08 21:43:37 -07:00
|
|
|
break;
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
for (uint32_t i = index - 1; i + 1 > 0; i--) {
|
2015-12-04 10:45:30 -08:00
|
|
|
TSNode child = ts_node__direct_child(result, i);
|
|
|
|
|
if (ts_node__is_relevant(child, include_anonymous))
|
|
|
|
|
return child;
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t grandchild_count =
|
2015-12-04 20:56:33 -08:00
|
|
|
ts_node__relevant_child_count(child, include_anonymous);
|
2015-09-08 21:43:37 -07:00
|
|
|
if (grandchild_count > 0)
|
2015-12-04 10:45:30 -08:00
|
|
|
return ts_node__child(child, grandchild_count - 1, include_anonymous);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
2015-12-22 14:20:58 -08:00
|
|
|
} while (!ts_node__tree(result)->visible);
|
2015-09-08 21:43:37 -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) {
|
2015-12-04 10:45:30 -08:00
|
|
|
TSNode result = self;
|
2015-09-08 21:43:37 -07:00
|
|
|
|
|
|
|
|
do {
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t index;
|
2015-12-04 10:45:30 -08:00
|
|
|
result = ts_node__direct_parent(result, &index);
|
|
|
|
|
if (!result.data)
|
2015-09-08 21:43:37 -07:00
|
|
|
break;
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
for (uint32_t i = index + 1; i < ts_node__tree(result)->child_count; i++) {
|
2015-12-04 10:45:30 -08:00
|
|
|
TSNode child = ts_node__direct_child(result, i);
|
|
|
|
|
if (ts_node__is_relevant(child, include_anonymous))
|
|
|
|
|
return child;
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t grandchild_count =
|
2015-12-04 20:56:33 -08:00
|
|
|
ts_node__relevant_child_count(child, include_anonymous);
|
2015-09-08 21:43:37 -07:00
|
|
|
if (grandchild_count > 0)
|
2015-12-04 10:45:30 -08:00
|
|
|
return ts_node__child(child, 0, include_anonymous);
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
2015-12-22 14:20:58 -08:00
|
|
|
} while (!ts_node__tree(result)->visible);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
static inline TSNode ts_node__descendant_for_char_range(TSNode self, uint32_t min,
|
|
|
|
|
uint32_t max,
|
2016-09-06 21:17:26 -07:00
|
|
|
bool include_anonymous) {
|
2015-12-04 10:45:30 -08:00
|
|
|
TSNode node = self;
|
|
|
|
|
TSNode last_visible_node = self;
|
2015-08-16 10:27:26 -07:00
|
|
|
|
2015-07-31 15:47:48 -07:00
|
|
|
bool did_descend = true;
|
|
|
|
|
while (did_descend) {
|
|
|
|
|
did_descend = false;
|
2015-08-14 16:34:12 -07:00
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
for (uint32_t i = 0; i < ts_node__tree(node)->child_count; i++) {
|
2015-12-04 10:45:30 -08:00
|
|
|
TSNode child = ts_node__direct_child(node, i);
|
|
|
|
|
if (ts_node_start_char(child) > min)
|
2015-07-31 15:47:48 -07:00
|
|
|
break;
|
2015-12-04 10:45:30 -08:00
|
|
|
if (ts_node_end_char(child) > max) {
|
|
|
|
|
node = child;
|
|
|
|
|
if (ts_node__is_relevant(node, include_anonymous))
|
|
|
|
|
last_visible_node = node;
|
2015-07-31 15:47:48 -07:00
|
|
|
did_descend = true;
|
2015-08-16 10:27:26 -07:00
|
|
|
break;
|
2015-07-31 15:47:48 -07:00
|
|
|
}
|
2014-07-18 18:52:08 -07:00
|
|
|
}
|
2014-07-20 20:27:33 -07:00
|
|
|
}
|
2015-08-14 16:34:12 -07:00
|
|
|
|
2015-12-04 10:45:30 -08:00
|
|
|
return last_visible_node;
|
2014-07-17 23:29:11 -07:00
|
|
|
}
|
2014-08-25 09:31:27 -07:00
|
|
|
|
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;
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
for (uint32_t i = 0; i < ts_node__tree(node)->child_count; i++) {
|
2016-09-06 21:33:19 -07:00
|
|
|
TSNode child = ts_node__direct_child(node, i);
|
|
|
|
|
if (ts_node_start_byte(child) > min)
|
|
|
|
|
break;
|
|
|
|
|
if (ts_node_end_byte(child) > max) {
|
|
|
|
|
node = child;
|
|
|
|
|
if (ts_node__is_relevant(node, include_anonymous))
|
|
|
|
|
last_visible_node = node;
|
|
|
|
|
did_descend = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return last_visible_node;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 14:02:49 -07: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;
|
|
|
|
|
|
|
|
|
|
bool did_descend = true;
|
|
|
|
|
while (did_descend) {
|
|
|
|
|
did_descend = false;
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
for (uint32_t i = 0; i < ts_node__tree(node)->child_count; i++) {
|
2016-09-06 21:17:26 -07:00
|
|
|
TSNode child = ts_node__direct_child(node, i);
|
2016-11-09 20:59:05 -08:00
|
|
|
if (point_gt(ts_node_start_point(child), min))
|
2016-09-06 21:17:26 -07:00
|
|
|
break;
|
2016-11-09 20:59:05 -08:00
|
|
|
if (point_gt(ts_node_end_point(child), max)) {
|
2016-09-06 21:17:26 -07:00
|
|
|
node = child;
|
|
|
|
|
if (ts_node__is_relevant(node, include_anonymous))
|
|
|
|
|
last_visible_node = node;
|
|
|
|
|
did_descend = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return last_visible_node;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-08 23:16:24 -07:00
|
|
|
/*
|
|
|
|
|
* Public
|
|
|
|
|
*/
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_start_char(TSNode self) {
|
2015-12-04 10:45:30 -08:00
|
|
|
return ts_node__offset_char(self) + ts_node__tree(self)->padding.chars;
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_end_char(TSNode self) {
|
2015-12-03 22:59:27 -08:00
|
|
|
return ts_node_start_char(self) + ts_node__tree(self)->size.chars;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t ts_node_start_byte(TSNode self) {
|
2015-12-04 10:45:30 -08:00
|
|
|
return ts_node__offset_byte(self) + 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) {
|
2016-11-09 20:59:05 -08:00
|
|
|
const Tree *tree = ts_node__tree(self);
|
2016-09-09 21:11:02 -07:00
|
|
|
return (TSPoint){ ts_node__offset_row(self) + tree->padding.extent.row,
|
2015-12-04 20:56:33 -08:00
|
|
|
ts_tree_start_column(tree) };
|
2015-11-18 17:53:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSPoint ts_node_end_point(TSNode self) {
|
2016-11-09 20:59:05 -08:00
|
|
|
const Tree *tree = ts_node__tree(self);
|
2016-09-09 21:11:02 -07:00
|
|
|
return (TSPoint){ ts_node__offset_row(self) + tree->padding.extent.row +
|
|
|
|
|
tree->size.extent.row,
|
2015-12-04 20:56:33 -08:00
|
|
|
ts_tree_end_column(tree) };
|
2015-11-18 17:53:38 -08:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
TSSymbol ts_node_symbol(TSNode self) {
|
2017-07-18 12:01:52 -07:00
|
|
|
const Tree *tree = ts_node__tree(self);
|
2017-07-31 11:45:24 -07:00
|
|
|
return tree->context.alias_symbol ? tree->context.alias_symbol : tree->symbol;
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-02-19 15:41:30 -08:00
|
|
|
TSSymbolIterator ts_node_symbols(TSNode self) {
|
2016-11-09 20:59:05 -08:00
|
|
|
const Tree *tree = ts_node__tree(self);
|
2016-02-19 15:41:30 -08:00
|
|
|
return (TSSymbolIterator){
|
2016-02-23 09:45:27 -08:00
|
|
|
.value = tree->symbol, .done = false, .data = (void *)tree,
|
2016-02-19 15:41:30 -08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ts_symbol_iterator_next(TSSymbolIterator *self) {
|
2016-11-09 20:59:05 -08:00
|
|
|
const Tree *tree = (const Tree *)self->data;
|
|
|
|
|
const Tree *parent = tree->context.parent;
|
2016-02-19 15:41:30 -08:00
|
|
|
if (!self->done && parent) {
|
|
|
|
|
if (parent->child_count == 1 && !parent->visible) {
|
|
|
|
|
self->value = parent->symbol;
|
|
|
|
|
self->data = (void *)parent;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self->done = true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-06 21:43:59 -07:00
|
|
|
const char *ts_node_type(TSNode self, const TSDocument *document) {
|
2017-07-18 12:01:52 -07:00
|
|
|
return ts_language_symbol_name(document->parser.language, ts_node_symbol(self));
|
2015-09-08 21:43:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-04-03 23:45:43 -07:00
|
|
|
char *ts_node_string(TSNode self, const TSDocument *document) {
|
2016-04-22 14:55:56 -07:00
|
|
|
return ts_tree_string(ts_node__tree(self), document->parser.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) {
|
|
|
|
|
return ts_tree_eq(ts_node__tree(self), ts_node__tree(other)) &&
|
2015-12-04 10:45:30 -08:00
|
|
|
self.offset[0] == other.offset[0] &&
|
2015-12-04 20:56:33 -08:00
|
|
|
self.offset[1] == other.offset[1] && self.offset[2] == other.offset[2];
|
2015-09-08 23:16:24 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 21:52:13 -07:00
|
|
|
bool ts_node_is_named(TSNode self) {
|
2017-07-14 10:19:58 -07:00
|
|
|
const Tree *tree = ts_node__tree(self);
|
2017-07-31 11:45:24 -07:00
|
|
|
return tree->context.alias_symbol ? tree->context.alias_is_named : tree->named;
|
2015-09-08 23:16:24 -07:00
|
|
|
}
|
|
|
|
|
|
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) {
|
2015-12-04 10:45:30 -08:00
|
|
|
TSNode result = self;
|
2016-11-14 12:15:24 -08:00
|
|
|
uint32_t index;
|
2015-09-08 23:16:24 -07:00
|
|
|
|
|
|
|
|
do {
|
2015-12-04 10:45:30 -08:00
|
|
|
result = ts_node__direct_parent(result, &index);
|
|
|
|
|
if (!result.data)
|
2015-09-08 23:16:24 -07:00
|
|
|
return ts_node__null();
|
2015-12-22 14:20:58 -08:00
|
|
|
} while (!ts_node__tree(result)->visible);
|
2015-09-08 23:16:24 -07:00
|
|
|
|
2015-12-04 10:45:30 -08:00
|
|
|
return result;
|
2015-09-08 23:16:24 -07: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) {
|
2016-12-20 13:12:01 -08:00
|
|
|
const Tree *tree = ts_node__tree(self);
|
|
|
|
|
if (tree->child_count > 0) {
|
|
|
|
|
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) {
|
2016-12-20 13:12:01 -08:00
|
|
|
const Tree *tree = ts_node__tree(self);
|
|
|
|
|
if (tree->child_count > 0) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
TSNode ts_node_descendant_for_char_range(TSNode self, uint32_t min, uint32_t max) {
|
2016-09-06 21:17:26 -07:00
|
|
|
return ts_node__descendant_for_char_range(self, min, max, true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:15:24 -08:00
|
|
|
TSNode ts_node_named_descendant_for_char_range(TSNode self, uint32_t min,
|
|
|
|
|
uint32_t max) {
|
2016-09-06 21:17:26 -07:00
|
|
|
return ts_node__descendant_for_char_range(self, min, max, 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
|
|
|
}
|