Skip to content

Commit

Permalink
ts/tree.c(ts-tree-cursor-goto-first-child-for-point): new procedure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Z572 committed Jun 29, 2023
1 parent 6161400 commit 54cd7e4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/tcursor.scm
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
(let ((cursor (ts-tree-cursor-new root)))
(test-equal "ts-tree-cursor-goto-first-child-for-byte: out of range"
#f (ts-tree-cursor-goto-first-child-for-byte cursor 50)))
(let ((cursor (ts-tree-cursor-new root)))
(test-equal "ts-tree-cursor-goto-first-child-for-point"
3 (begin (ts-tree-cursor-goto-first-child cursor)
(ts-tree-cursor-goto-first-child-for-point cursor (cons 0 4)))))
(let ((cursor (ts-tree-cursor-new root)))
(test-equal "ts-tree-cursor-goto-first-child-for-point: out of range"
#f (ts-tree-cursor-goto-first-child-for-byte cursor (cons 0 50))))

(let ((cursor (ts-tree-cursor-new root)))
(test-equal "ts-tree-cursor-goto-parent: no parent"
Expand Down
20 changes: 20 additions & 0 deletions ts/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,26 @@ SCM_DEFINE(tstc_goto_first_child_for_byte, "ts-tree-cursor-goto-first-child-for-
return success;
}
#undef FUNC_NAME

SCM_DEFINE(tstc_goto_first_child_for_point, "ts-tree-cursor-goto-first-child-for-point", 2, 0, 0,
(SCM cursor, SCM point),
"")
#define FUNC_NAME s_tstc_goto_first_child_for_point
{
ASSERT_TSTC(cursor);
Tcursor *tc = FR(cursor);
int64_t index = ts_tree_cursor_goto_first_child_for_point(&tc->cursor, cons_to_point(point));
SCM success;
if (index == -1) {
success= SCM_BOOL_F;
} else {
success=scm_from_int64(index);
}
scm_remember_upto_here_1(cursor);
return success;
}
#undef FUNC_NAME

void init_ts_tree() {
#ifndef SCM_MAGIC_SNARFER
#include "tree.x"
Expand Down
1 change: 1 addition & 0 deletions ts/tree.scm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ts-tree-cursor-goto-parent
ts-tree-cursor-goto-first-child
ts-tree-cursor-goto-first-child-for-byte
ts-tree-cursor-goto-first-child-for-point
ts-tree-cursor-goto-next-sibling
ts-tree-cursor-new
ts-tree-cursor-reset!
Expand Down

0 comments on commit 54cd7e4

Please sign in to comment.