Skip to content

Commit

Permalink
Add procedure ts-node-descendant-for-point-range
Browse files Browse the repository at this point in the history
  • Loading branch information
Tilman List authored and Z572 committed Mar 21, 2024
1 parent 958a045 commit 2501c1a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/api.scm
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,20 @@

(test-equal "ts-node-descendant-for-byte-range: named"
(ts-node-child root 0 #t)
(ts-node-descendant-for-byte-range (ts-node-child root 0) 0 2 #t)))
(ts-node-descendant-for-byte-range (ts-node-child root 0) 0 2 #t))

(test-equal "ts-node-descendant-for-point-range"
(ts-node-child root 0)
(ts-node-descendant-for-point-range (ts-node-child root 0)
(cons 0 0)
(cons 0 2)))

(test-equal "ts-node-descendant-for-point-range: named"
(ts-node-child root 0 #t)
(ts-node-descendant-for-point-range (ts-node-child root 0)
(cons 0 0)
(cons 0 2)
#t)))
(let* ((source "[1")
(parser (make <ts-parser>
#:language json-language))
Expand Down
19 changes: 19 additions & 0 deletions ts/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,25 @@ SCM_DEFINE(tsn_descendant_for_byte_range, "ts-node-descendant-for-byte-range", 3
}
#undef FUNC_NAME

SCM_DEFINE(tsn_descendant_for_point_range, "ts-node-descendant-for-point-range", 3, 1, 0,
(SCM o,SCM start,SCM end,SCM named), "")
#define FUNC_NAME s_tsn_descendant_for_point_range
{
ASSERT_TSN(o);
Node *node=FR(o);
scm_remember_upto_here_1(o);
TSNode t_node=node_ref(node);
TSPoint t_point_start = cons_to_point(start);
TSPoint t_point_end = cons_to_point(end);
scm_remember_upto_here_2(start,end);
SCM sn=make_node((SCM_UNBNDP(named) ? false :scm_to_bool(named))
? ts_node_named_descendant_for_point_range(t_node,t_point_start,t_point_end)
: ts_node_descendant_for_point_range(t_node,t_point_start,t_point_end));
scm_remember_upto_here_2(o,named);
return sn;
}
#undef FUNC_NAME



SCM_DEFINE(tsn_eq, "%ts-node-eq?", 2, 0, 0,
Expand Down
1 change: 1 addition & 0 deletions ts/tree.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ts-node-child-count
ts-node-childs
ts-node-descendant-for-byte-range
ts-node-descendant-for-point-range
ts-node-end-byte
ts-node-end-point
ts-node-extra?
Expand Down

0 comments on commit 2501c1a

Please sign in to comment.