diff --git a/lib/include/tree_sitter/api.h b/lib/include/tree_sitter/api.h index d8189930..b07f929f 100644 --- a/lib/include/tree_sitter/api.h +++ b/lib/include/tree_sitter/api.h @@ -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 */ diff --git a/lib/src/tree_cursor.c b/lib/src/tree_cursor.c index 35aeebb3..7103fc41 100644 --- a/lib/src/tree_cursor.c +++ b/lib/src/tree_cursor.c @@ -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(©->stack, &cursor->stack); + return res; +}