Add ts_tree_cursor_reset function

This commit is contained in:
Max Brunsfeld 2018-10-21 10:39:05 -07:00
parent fa1f4aa86a
commit af01846fd7
3 changed files with 12 additions and 6 deletions

View file

@ -135,11 +135,12 @@ void ts_node_edit(TSNode *, const TSInputEdit *);
TSTreeCursor ts_tree_cursor_new(TSNode);
void ts_tree_cursor_delete(TSTreeCursor *);
void ts_tree_cursor_reset(TSTreeCursor *, TSNode);
TSNode ts_tree_cursor_current_node(const TSTreeCursor *);
bool ts_tree_cursor_goto_parent(TSTreeCursor *);
bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *);
bool ts_tree_cursor_goto_first_child(TSTreeCursor *);
int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *, uint32_t);
bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *);
bool ts_tree_cursor_goto_parent(TSTreeCursor *);
TSNode ts_tree_cursor_current_node(const TSTreeCursor *);
uint32_t ts_language_symbol_count(const TSLanguage *);
const char *ts_language_symbol_name(const TSLanguage *, TSSymbol);

View file

@ -48,7 +48,8 @@ void ts_tree_edit(TSTree *self, const TSInputEdit *edit) {
TSRange *ts_tree_get_changed_ranges(const TSTree *self, const TSTree *other, uint32_t *count) {
TSRange *result;
TreeCursor cursor1, cursor2;
TreeCursor cursor1 = {array_new(), NULL};
TreeCursor cursor2 = {array_new(), NULL};
TSNode root = ts_tree_root_node(self);
ts_tree_cursor_init(&cursor1, root);
ts_tree_cursor_init(&cursor2, root);

View file

@ -66,14 +66,18 @@ static inline bool ts_tree_cursor_child_iterator_next(ChildIterator *self,
// TSTreeCursor - lifecycle
TSTreeCursor ts_tree_cursor_new(TSNode node) {
TSTreeCursor self;
TSTreeCursor self = {{0, 0}, NULL, NULL};
ts_tree_cursor_init((TreeCursor *)&self, node);
return self;
}
void ts_tree_cursor_reset(TSTreeCursor *_self, TSNode node) {
ts_tree_cursor_init((TreeCursor *)_self, node);
}
void ts_tree_cursor_init(TreeCursor *self, TSNode node) {
self->tree = node.tree;
array_init(&self->stack);
array_clear(&self->stack);
array_push(&self->stack, ((TreeCursorEntry) {
.subtree = (const Subtree *)node.id,
.position = {