1///|
2priv type TSTreeCursor
3
4///|
5struct TreeCursor {
6  
TSTreeCursor
cursor
:
type TSTreeCursor
TSTreeCursor
7
TSTree
tree
:
type TSTree
TSTree
8
@string.StringView
text
:
type @string.StringView

A @string.View represents a view of a String that maintains proper Unicode character boundaries. It allows safe access to a substring while handling multi-byte characters correctly.

@string.View
9} 10 11///| 12#borrow(node) 13extern "c" fn ts_tree_cursor_new(node :
type TSNode Bytes
TSNode
) ->
type TSTreeCursor
TSTreeCursor
= "moonbit_ts_tree_cursor_new"
14 15///| 16/// Create a new tree cursor starting from the given node. 17/// 18/// A tree cursor allows you to walk a syntax tree more efficiently than is 19/// possible using the `Node` functions. It is a mutable object that is always 20/// on a certain syntax node, and can be moved imperatively to different nodes. 21/// 22/// Note that the given node is considered the root of the cursor, 23/// and the cursor cannot walk outside this node. 24pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(node : Node) -> TreeCursor

Create a new tree cursor starting from the given node.

A tree cursor allows you to walk a syntax tree more efficiently than is possible using the Node functions. It is a mutable object that is always on a certain syntax node, and can be moved imperatively to different nodes.

Note that the given node is considered the root of the cursor, and the cursor cannot walk outside this node.

new
(
Node
node
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
{
25 let
TSTreeCursor
cursor
=
(node : TSNode) -> TSTreeCursor
ts_tree_cursor_new
(
Node
node
.
TSNode
node
)
26
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::{
TSTreeCursor
cursor
,
TSTree
tree
:
Node
node
.
TSTree
tree
,
@string.StringView
text
:
Node
node
.
@string.StringView
text
}
27} 28 29///| 30#borrow(self, node) 31extern "c" fn ts_tree_cursor_reset(self :
type TSTreeCursor
TSTreeCursor
, node :
type TSNode Bytes
TSNode
) = "moonbit_ts_tree_cursor_reset"
32 33///| 34/// Re-initialize a tree cursor to start at the original node that the cursor was 35/// constructed with. 36pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor, node : Node) -> Unit

Re-initialize a tree cursor to start at the original node that the cursor was constructed with.

reset
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
,
Node
node
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Unit
Unit
{
37
(self : TSTreeCursor, node : TSNode) -> Unit
ts_tree_cursor_reset
(
TreeCursor
self
.
TSTreeCursor
cursor
,
Node
node
.
TSNode
node
)
38} 39 40///| 41#borrow(self, other) 42extern "c" fn ts_tree_cursor_reset_to( 43 self :
type TSTreeCursor
TSTreeCursor
,
44 other :
type TSTreeCursor
TSTreeCursor
45) = "moonbit_ts_tree_cursor_reset_to" 46 47///| 48/// Re-initialize a tree cursor to the same position as another cursor. 49/// 50/// Unlike TreeCursor::reset, this will not lose parent information and 51/// allows reusing already created cursors. 52pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor, other : TreeCursor) -> Unit

Re-initialize a tree cursor to the same position as another cursor.

Unlike TreeCursor::reset, this will not lose parent information and allows reusing already created cursors.

reset_to
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
,
TreeCursor
other
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
Unit
Unit
{
53
(self : TSTreeCursor, other : TSTreeCursor) -> Unit
ts_tree_cursor_reset_to
(
TreeCursor
self
.
TSTreeCursor
cursor
,
TreeCursor
other
.
TSTreeCursor
cursor
)
54} 55 56///| 57#borrow(self) 58extern "c" fn ts_tree_cursor_current_node(self :
type TSTreeCursor
TSTreeCursor
) ->
type TSNode Bytes
TSNode
= "moonbit_ts_tree_cursor_current_node"
59 60///| 61/// Get the tree cursor's current node. 62pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> Node

Get the tree cursor's current node.

current_node
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
{
63 return
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::{
64
TSNode
node
:
(self : TSTreeCursor) -> TSNode
ts_tree_cursor_current_node
(
TreeCursor
self
.
TSTreeCursor
cursor
),
65
TSTree
tree
:
TreeCursor
self
.
TSTree
tree
,
66
@string.StringView
text
:
TreeCursor
self
.
@string.StringView
text
,
67 } 68} 69 70///| 71#borrow(self) 72extern "c" fn ts_tree_cursor_current_field_name( 73 self :
type TSTreeCursor
TSTreeCursor
74) -> @c.Pointer[
Byte
Byte
] = "moonbit_ts_tree_cursor_current_field_name"
75 76///| 77/// Get the field name of the tree cursor's current node. 78/// 79/// This returns `None` if the current node doesn't have a field. 80/// See also `Node::child_by_field_name`. 81pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> String?

Get the field name of the tree cursor's current node.

This returns None if the current node doesn't have a field. See also Node::child_by_field_name.

current_field_name
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
String
String
? {
82 let
?
name
=
(self : TSTreeCursor) -> ?
ts_tree_cursor_current_field_name
(
TreeCursor
self
.
TSTreeCursor
cursor
)
83
(c_string : ?, length? : Int) -> String?
decode_c_string
(
?
name
)
84} 85 86///| 87#borrow(self) 88extern "c" fn ts_tree_cursor_current_field_id(self :
type TSTreeCursor
TSTreeCursor
) ->
type FieldId UInt16
FieldId
= "moonbit_ts_tree_cursor_current_field_id"
89 90///| 91/// Get the field id of the tree cursor's current node. 92/// 93/// This returns zero if the current node doesn't have a field. 94/// See also `Node::child_by_field_id`, `Language::field_id_for_name`. 95pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> FieldId

Get the field id of the tree cursor's current node.

This returns zero if the current node doesn't have a field. See also Node::child_by_field_id, Language::field_id_for_name.

current_field_id
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
type FieldId UInt16
FieldId
{
96
(self : TSTreeCursor) -> FieldId
ts_tree_cursor_current_field_id
(
TreeCursor
self
.
TSTreeCursor
cursor
)
97} 98 99///| 100#borrow(self) 101extern "c" fn ts_tree_cursor_goto_parent(self :
type TSTreeCursor
TSTreeCursor
) ->
Bool
Bool
= "moonbit_ts_tree_cursor_goto_parent"
102 103///| 104/// Move the cursor to the parent of its current node. 105/// 106/// This returns `true` if the cursor successfully moved, and returns `false` 107/// if there was no parent node (the cursor was already on the root node). 108/// 109/// Note that the node the cursor was constructed with is considered the root 110/// of the cursor, and the cursor cannot walk outside this node. 111pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> Bool

Move the cursor to the parent of its current node.

This returns true if the cursor successfully moved, and returns false if there was no parent node (the cursor was already on the root node).

Note that the node the cursor was constructed with is considered the root of the cursor, and the cursor cannot walk outside this node.

goto_parent
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
Bool
Bool
{
112
(self : TSTreeCursor) -> Bool
ts_tree_cursor_goto_parent
(
TreeCursor
self
.
TSTreeCursor
cursor
)
113} 114 115///| 116#borrow(self) 117extern "c" fn ts_tree_cursor_goto_next_sibling(self :
type TSTreeCursor
TSTreeCursor
) ->
Bool
Bool
= "moonbit_ts_tree_cursor_goto_next_sibling"
118 119///| 120/// Move the cursor to the next sibling of its current node. 121/// 122/// This returns `true` if the cursor successfully moved, and returns `false` 123/// if there was no next sibling node. 124/// 125/// Note that the node the cursor was constructed with is considered the root 126/// of the cursor, and the cursor cannot walk outside this node. 127pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> Bool

Move the cursor to the next sibling of its current node.

This returns true if the cursor successfully moved, and returns false if there was no next sibling node.

Note that the node the cursor was constructed with is considered the root of the cursor, and the cursor cannot walk outside this node.

goto_next_sibling
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
Bool
Bool
{
128
(self : TSTreeCursor) -> Bool
ts_tree_cursor_goto_next_sibling
(
TreeCursor
self
.
TSTreeCursor
cursor
)
129} 130 131///| 132#borrow(self) 133extern "c" fn ts_tree_cursor_goto_previous_sibling(self :
type TSTreeCursor
TSTreeCursor
) ->
Bool
Bool
= "moonbit_ts_tree_cursor_goto_previous_sibling"
134 135///| 136/// Move the cursor to the previous sibling of its current node. 137/// 138/// This returns `true` if the cursor successfully moved, and returns `false` if 139/// there was no previous sibling node. 140/// 141/// Note, that this function may be slower than `TreeCursor::goto_next_sibling` 142/// due to how node positions are stored. In the worst case, this will need to 143/// iterate through all the children up to the previous sibling node to recalculate 144/// its position. Also note that the node the cursor was constructed with is 145/// considered the root of the cursor, and the cursor cannot walk outside this node. 146pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> Bool

Move the cursor to the previous sibling of its current node.

This returns true if the cursor successfully moved, and returns false if there was no previous sibling node.

Note, that this function may be slower than TreeCursor::goto_next_sibling due to how node positions are stored. In the worst case, this will need to iterate through all the children up to the previous sibling node to recalculate its position. Also note that the node the cursor was constructed with is considered the root of the cursor, and the cursor cannot walk outside this node.

goto_previous_sibling
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
Bool
Bool
{
147
(self : TSTreeCursor) -> Bool
ts_tree_cursor_goto_previous_sibling
(
TreeCursor
self
.
TSTreeCursor
cursor
)
148} 149 150///| 151#borrow(self) 152extern "c" fn ts_tree_cursor_goto_first_child(self :
type TSTreeCursor
TSTreeCursor
) ->
Bool
Bool
= "moonbit_ts_tree_cursor_goto_first_child"
153 154///| 155/// Move the cursor to the first child of its current node. 156/// 157/// This returns `true` if the cursor successfully moved, and returns `false` 158/// if there were no children. 159pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> Bool

Move the cursor to the first child of its current node.

This returns true if the cursor successfully moved, and returns false if there were no children.

goto_first_child
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
Bool
Bool
{
160
(self : TSTreeCursor) -> Bool
ts_tree_cursor_goto_first_child
(
TreeCursor
self
.
TSTreeCursor
cursor
)
161} 162 163///| 164#borrow(self) 165extern "c" fn ts_tree_cursor_goto_last_child(self :
type TSTreeCursor
TSTreeCursor
) ->
Bool
Bool
= "moonbit_ts_tree_cursor_goto_last_child"
166 167///| 168/// Move the cursor to the last child of its current node. 169/// 170/// This returns `true` if the cursor successfully moved, and returns `false` if 171/// there were no children. 172/// 173/// Note that this function may be slower than TreeCursor::goto_first_child 174/// because it needs to iterate through all the children to compute the child's 175/// position. 176pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> Bool

Move the cursor to the last child of its current node.

This returns true if the cursor successfully moved, and returns false if there were no children.

Note that this function may be slower than TreeCursor::goto_first_child because it needs to iterate through all the children to compute the child's position.

goto_last_child
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
Bool
Bool
{
177
(self : TSTreeCursor) -> Bool
ts_tree_cursor_goto_last_child
(
TreeCursor
self
.
TSTreeCursor
cursor
)
178} 179 180///| 181#borrow(self) 182extern "c" fn ts_tree_cursor_goto_descendant( 183 self :
type TSTreeCursor
TSTreeCursor
,
184 goal_descendant_index :
UInt
UInt
185) ->
Unit
Unit
= "moonbit_ts_tree_cursor_goto_descendant"
186 187///| 188/// Move the cursor to the node that is the nth descendant of 189/// the original node that the cursor was constructed with, where 190/// zero represents the original node itself. 191pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor, goal_descendant_index : Int) -> Unit

Move the cursor to the node that is the nth descendant of the original node that the cursor was constructed with, where zero represents the original node itself.

goto_descendant
(
192
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
,
193
Int
goal_descendant_index
:
Int
Int
194) ->
Unit
Unit
{
195
(self : TSTreeCursor, goal_descendant_index : UInt) -> Unit
ts_tree_cursor_goto_descendant
(
196
TreeCursor
self
.
TSTreeCursor
cursor
,
197
(value : Int) -> UInt
int_to_uint
(
Int
goal_descendant_index
),
198 ) 199} 200 201///| 202#borrow(self) 203extern "c" fn ts_tree_cursor_current_descendant_index( 204 self :
type TSTreeCursor
TSTreeCursor
205) ->
UInt
UInt
= "moonbit_ts_tree_cursor_current_descendant_index"
206 207///| 208/// Get the index of the cursor's current node out of all of the 209/// descendants of the original node that the cursor was constructed with. 210pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> Int

Get the index of the cursor's current node out of all of the descendants of the original node that the cursor was constructed with.

current_descendant_index
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
Int
Int
{
211
(value : UInt) -> Int
uint_to_int
(
(self : TSTreeCursor) -> UInt
ts_tree_cursor_current_descendant_index
(
TreeCursor
self
.
TSTreeCursor
cursor
))
212} 213 214///| 215#borrow(self) 216extern "c" fn ts_tree_cursor_current_depth(self :
type TSTreeCursor
TSTreeCursor
) ->
UInt
UInt
= "moonbit_ts_tree_cursor_current_depth"
217 218///| 219/// Get the depth of the cursor's current node relative to the original 220/// node that the cursor was constructed with. 221pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> Int

Get the depth of the cursor's current node relative to the original node that the cursor was constructed with.

current_depth
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
Int
Int
{
222
(value : UInt) -> Int
uint_to_int
(
(self : TSTreeCursor) -> UInt
ts_tree_cursor_current_depth
(
TreeCursor
self
.
TSTreeCursor
cursor
))
223} 224 225///| 226#borrow(self) 227extern "c" fn ts_tree_cursor_goto_first_child_for_byte( 228 self :
type TSTreeCursor
TSTreeCursor
,
229 goal_byte :
UInt
UInt
230) ->
Bool
Bool
= "moonbit_ts_tree_cursor_goto_first_child_for_byte"
231 232///| 233/// Move the cursor to the first child of its current node that contains or starts after 234/// the given byte offset. 235/// 236/// This returns the index of the child node if one was found, and returns -1 237/// if no such child was found. 238pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor, goal_byte : Int) -> Bool

Move the cursor to the first child of its current node that contains or starts after the given byte offset.

This returns the index of the child node if one was found, and returns -1 if no such child was found.

goto_first_child_for_byte
(
239
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
,
240
Int
goal_byte
:
Int
Int
241) ->
Bool
Bool
{
242
(self : TSTreeCursor, goal_byte : UInt) -> Bool
ts_tree_cursor_goto_first_child_for_byte
(
TreeCursor
self
.
TSTreeCursor
cursor
,
(value : Int) -> UInt
int_to_uint
(
Int
goal_byte
))
243} 244 245///| 246#borrow(self, goal_point) 247extern "c" fn ts_tree_cursor_goto_first_child_for_point( 248 self :
type TSTreeCursor
TSTreeCursor
,
249 goal_point :
type Point
Point
250) ->
Bool
Bool
= "moonbit_ts_tree_cursor_goto_first_child_for_point"
251 252///| 253/// Move the cursor to the first child of its current node that contains or starts after 254/// the given point. 255/// 256/// This returns the index of the child node if one was found, and returns -1 257/// if no such child was found. 258pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor, goal_point : Point) -> Bool

Move the cursor to the first child of its current node that contains or starts after the given point.

This returns the index of the child node if one was found, and returns -1 if no such child was found.

goto_first_child_for_point
(
259
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
,
260
Point
goal_point
:
type Point
Point
261) ->
Bool
Bool
{
262
(self : TSTreeCursor, goal_point : Point) -> Bool
ts_tree_cursor_goto_first_child_for_point
(
TreeCursor
self
.
TSTreeCursor
cursor
,
Point
goal_point
)
263} 264 265///| 266#borrow(self) 267extern "c" fn ts_tree_cursor_copy(self :
type TSTreeCursor
TSTreeCursor
) ->
type TSTreeCursor
TSTreeCursor
= "moonbit_ts_tree_cursor_copy"
268 269///| 270pub fn
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::
(self : TreeCursor) -> TreeCursor
copy
(
TreeCursor
self
:
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
) ->
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
{
271 let
TSTreeCursor
cursor
=
(self : TSTreeCursor) -> TSTreeCursor
ts_tree_cursor_copy
(
TreeCursor
self
.
TSTreeCursor
cursor
)
272
struct TreeCursor {
  cursor: TSTreeCursor
  tree: TSTree
  text: @string.StringView
}
TreeCursor
::{
TSTreeCursor
cursor
,
TSTree
tree
:
TreeCursor
self
.
TSTree
tree
,
@string.StringView
text
:
TreeCursor
self
.
@string.StringView
text
}
273} 274