From 7f2233ddaff7cb75a5672a6d1624bbef471bebd4 Mon Sep 17 00:00:00 2001 From: Andrey Zaytsev Date: Sun, 16 Jun 2019 19:52:37 +0200 Subject: [PATCH] Ts tree cursor copy (#363) * add ts_tree_cursor_copy fn * indentation --- lib/include/tree_sitter/api.h | 2 ++ lib/src/tree_cursor.c | 9 +++++++++ 2 files changed, 11 insertions(+) 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; +}