Skip to content

Commit

Permalink
ts/tree.c(ts-tree-cursor-goto-first-child-for-byte): new procedure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Z572 committed Jun 29, 2023
1 parent d92581c commit 6161400
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/tcursor.scm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
(begin (ts-tree-cursor-goto-parent cursor)
(ts-tree-cursor-current-node cursor))))

(let ((cursor (ts-tree-cursor-new root)))
(test-equal "ts-tree-cursor-goto-first-child-for-byte"
3 (begin (ts-tree-cursor-goto-first-child cursor)
(ts-tree-cursor-goto-first-child-for-byte cursor 4))))
(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-parent: no parent"
#f (ts-tree-cursor-goto-parent cursor)))
Expand Down
20 changes: 19 additions & 1 deletion ts/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,25 @@ SCM_DEFINE(tstc_goto_next_sibling, "ts-tree-cursor-goto-next-sibling", 1, 0, 0,
scm_remember_upto_here_1(cursor);
return success;
}

#undef FUNC_NAME
SCM_DEFINE(tstc_goto_first_child_for_byte, "ts-tree-cursor-goto-first-child-for-byte", 2, 0, 0,
(SCM cursor, SCM byte),
"")
#define FUNC_NAME s_tstc_goto_first_child_for_byte
{
ASSERT_TSTC(cursor);
Tcursor *tc = FR(cursor);
int64_t index = ts_tree_cursor_goto_first_child_for_byte(&tc->cursor, scm_to_uint32(byte));
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 @@ -35,6 +35,7 @@
ts-tree-cursor-current-node
ts-tree-cursor-goto-parent
ts-tree-cursor-goto-first-child
ts-tree-cursor-goto-first-child-for-byte
ts-tree-cursor-goto-next-sibling
ts-tree-cursor-new
ts-tree-cursor-reset!
Expand Down

0 comments on commit 6161400

Please sign in to comment.