Ts tree cursor copy (#363)

* add ts_tree_cursor_copy fn

* indentation
This commit is contained in:
Andrey Zaytsev 2019-06-16 19:52:37 +02:00 committed by Max Brunsfeld
parent 0e046fc6c0
commit 7f2233ddaf
2 changed files with 11 additions and 0 deletions

View file

@ -593,6 +593,8 @@ bool ts_tree_cursor_goto_first_child(TSTreeCursor *);
* if no such child was found.
*/
int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *, uint32_t);
TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *);
/**********************/
/* Section - Language */

View file

@ -291,3 +291,12 @@ const char *ts_tree_cursor_current_field_name(const TSTreeCursor *_self) {
return NULL;
}
}
TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor *_cursor) {
const TreeCursor *cursor = (const TreeCursor *)_cursor;
TSTreeCursor res = {NULL, NULL, {0, 0}};
TreeCursor *copy = (TreeCursor *)&res;
copy->tree = cursor->tree;
array_push_all(&copy->stack, &cursor->stack);
return res;
}