diff --git a/tests/tcursor.scm b/tests/tcursor.scm index c58ea5c..ae15fc1 100644 --- a/tests/tcursor.scm +++ b/tests/tcursor.scm @@ -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" diff --git a/ts/tree.c b/ts/tree.c index b7bef63..2cdc735 100644 --- a/ts/tree.c +++ b/ts/tree.c @@ -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" diff --git a/ts/tree.scm b/ts/tree.scm index 0610ab3..c2f0ad8 100644 --- a/ts/tree.scm +++ b/ts/tree.scm @@ -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!