1///|
2type Node
3
4///|
5extern "js" fn ts_node_tree(self : 
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Tree {
  tree: TSTree
  text: @string.StringView
}
Tree
=
6 #|(node) => { 7 #| return node.tree; 8 #|} 9 10///| 11extern "js" fn ts_node_type(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
String
String
=
12 #|(node) => { 13 #| return node.type; 14 #|} 15 16///| 17/// Get the node's type as a string. 18pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> @string.StringView

Get the node's type as a string.

type_
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
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
{
19
(self : TSNode, tree : TSTree) -> ?
ts_node_type
(
Node
self
)
20} 21 22///| 23/// Get the node's type as a numerical id. 24pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Symbol

Get the node's type as a numerical id.

symbol
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Symbol UInt
Symbol
{
25
Node
self
.
(self : Node) -> Language

Get the node's language.

language
().
(self : Language, name : @string.StringView) -> Symbol?

Get the numerical id for the given node type string.

symbol_for_name
(
Node
self
.
(self : Node) -> @string.StringView

Get the node's type as a string.

type_
()).
(self : Symbol?) -> Symbol

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
26} 27 28///| 29/// Get the node's language. 30pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Language

Get the node's language.

language
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Language @tree_sitter_language.Language
Language
{
31
(self : TSTree) -> Language
ts_tree_language
(
(self : Node) -> Tree
ts_node_tree
(
Node
self
))
32} 33 34///| 35extern "js" fn ts_node_grammar_type(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
String
String
=
36 #|(node) => { 37 #| return node.grammarType; 38 #|} 39 40///| 41/// Get the node's type as it appears in the grammar ignoring aliases as a string. 42pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> @string.StringView

Get the node's type as it appears in the grammar ignoring aliases as a string.

grammar_type
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
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
{
43
(self : TSNode, tree : TSTree) -> ?
ts_node_grammar_type
(
Node
self
)
44} 45 46///| 47extern "js" fn ts_node_grammar_symbol(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Symbol UInt
Symbol
=
48 #|(node) => { 49 #| return node.grammarId; 50 #|} 51 52///| 53/// Get the node's type as a numerical id as it appears in the grammar ignoring 54/// aliases. This should be used in `Language::next_state` instead of 55/// `Node::symbol`. 56pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Symbol

Get the node's type as a numerical id as it appears in the grammar ignoring aliases. This should be used in Language::next_state instead of Node::symbol.

grammar_symbol
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Symbol UInt
Symbol
{
57 return
(self : TSNode, tree : TSTree) -> Symbol
ts_node_grammar_symbol
(
Node
self
)
58} 59 60///| 61extern "js" fn ts_node_start_byte(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Int
Int
=
62 #|(node) => { 63 #| return node.startIndex; 64 #|} 65 66///| 67/// Get the node's start byte. 68pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Int

Get the node's start byte.

start_byte
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Int
Int
{
69 return
(self : TSNode, tree : TSTree) -> Int
ts_node_start_byte
(
Node
self
)
70} 71 72///| 73extern "js" fn ts_node_start_point(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Point
Point
=
74 #|(node) => { 75 #| return node.startPosition; 76 #|} 77 78///| 79/// Get the node's start position in terms of rows and columns. 80pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Point

Get the node's start position in terms of rows and columns.

start_point
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Point
Point
{
81 return
(self : TSNode, tree : TSTree) -> Point
ts_node_start_point
(
Node
self
)
82} 83 84///| 85extern "js" fn ts_node_end_byte(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Int
Int
=
86 #|(node) => { 87 #| return node.endIndex; 88 #|} 89 90///| 91/// Get the node's end byte. 92pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Int

Get the node's end byte.

end_byte
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Int
Int
{
93 return
(self : TSNode, tree : TSTree) -> Int
ts_node_end_byte
(
Node
self
)
94} 95 96///| 97extern "js" fn ts_node_string(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
String
String
=
98 #|(node) => { 99 #| return node.toString(); 100 #|} 101 102///| 103/// Get an S-expression representing the node as a string. 104pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> @string.StringView

Get an S-expression representing the node as a string.

string
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
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
{
105
(self : TSNode, tree : TSTree) -> Bytes
ts_node_string
(
Node
self
)
106} 107 108///| 109pub impl
trait Show {
  output(Self, &Logger) -> Unit
  to_string(Self) -> String
}
Show
for
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
with
(self : Node, logger : &Logger) -> Unit
output
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
&Logger
logger
: &
trait Logger {
  write_string(Self, String) -> Unit
  write_substring(Self, String, Int, Int) -> Unit
  write_char(Self, Char) -> Unit
}

Trait for a logger, where debug logs can be written into

@builtin.Logger
) ->
Unit
Unit
{
110 try { 111
Node
self
.
(self : Node) -> @string.StringView

Get an S-expression representing the node as a string.

string
() |>
(source : @string.StringView) -> Array[@sexp.Sexp]!@sexp.SexpError
@sexp.parse
!() |>
(list : Array[@sexp.Sexp]) -> Array[@sexp.Sexp]
@sexp.pretty
() |>
(list : Array[@sexp.Sexp], logger : &Logger, indent~ : Int = ..) -> Unit
@sexp.print_to
(
&Logger
logger
)
112 } catch { 113 _ =>
&Logger
logger
.
(&Logger, String) -> Unit
write_string
(
Node
self
.
(self : Node) -> @string.StringView

Get an S-expression representing the node as a string.

string
().
(self : @string.StringView) -> String

Returns a new String containing a copy of the characters in this view.

Examples

let str = "Hello World"
let view = str[0:5]  // "Hello"
inspect!(view.to_string(), content="Hello")
to_string
())
114 } 115} 116 117///| 118/// Get the node's end position in terms of rows and columns. 119extern "js" fn ts_node_end_point(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Point
Point
=
120 #|(node) => { 121 #| return node.endPosition; 122 #|} 123 124///| 125pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Point
end_point
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Point
Point
{
126 return
(self : TSNode, tree : TSTree) -> Point

Get the node's end position in terms of rows and columns.

ts_node_end_point
(
Node
self
)
127} 128 129///| 130extern "js" fn ts_node_is_null(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
=
131 #|(node) => { 132 #| return node == null || node == undefined; 133 #|} 134 135///| 136/// Check if the node is null. Functions like `Node::child` and 137/// `Node::next_sibling` will return a null node to indicate that no such node 138/// was found. 139pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Bool

Check if the node is null. Functions like Node::child and Node::next_sibling will return a null node to indicate that no such node was found.

is_null
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
{
140 return
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
Node
self
)
141} 142 143///| 144extern "js" fn ts_node_is_named(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
=
145 #|(node) => { 146 #| return node.isNamed; 147 #|} 148 149///| 150/// Check if the node is *named*. Named nodes correspond to named rules in the 151/// grammar, whereas *anonymous* nodes correspond to string literals in the 152/// grammar. 153pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Bool

Check if the node is named. Named nodes correspond to named rules in the grammar, whereas anonymous nodes correspond to string literals in the grammar.

is_named
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
{
154 return
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_named
(
Node
self
)
155} 156 157///| 158extern "js" fn ts_node_is_missing(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
=
159 #|(node) => { 160 #| return node.isMissing; 161 #|} 162 163///| 164/// Check if the node is *missing*. Missing nodes are inserted by the parser in 165/// order to recover from certain kinds of syntax errors. 166pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Bool

Check if the node is missing. Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.

is_missing
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
{
167 return
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_missing
(
Node
self
)
168} 169 170///| 171extern "js" fn ts_node_is_extra(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
=
172 #|(node) => { 173 #| return node.isExtra; 174 #|} 175 176///| 177/// Check if the node is *extra*. Extra nodes represent things like comments, 178/// which are not required the grammar, but can appear anywhere. 179pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Bool

Check if the node is extra. Extra nodes represent things like comments, which are not required the grammar, but can appear anywhere.

is_extra
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
{
180 return
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_extra
(
Node
self
)
181} 182 183///| 184extern "js" fn ts_node_has_changes(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
=
185 #|(node) => { 186 #| return node.hasChanges; 187 #|} 188 189///| 190/// Check if a syntax node has been edited. 191pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Bool

Check if a syntax node has been edited.

has_changes
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
{
192 return
(self : TSNode, tree : TSTree) -> Bool
ts_node_has_changes
(
Node
self
)
193} 194 195///| 196extern "js" fn ts_node_has_error(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
=
197 #|(node) => { 198 #| return node.hasError; 199 #|} 200 201///| 202/// Check if the node is a syntax error or contains any syntax errors. 203pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Bool

Check if the node is a syntax error or contains any syntax errors.

has_error
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
{
204 return
(self : TSNode, tree : TSTree) -> Bool
ts_node_has_error
(
Node
self
)
205} 206 207///| 208extern "js" fn ts_node_is_error(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
=
209 #|(node) => { 210 #| return node.isError; 211 #|} 212 213///| 214/// Check if the node is a syntax error. 215pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Bool

Check if the node is a syntax error.

is_error
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
{
216 return
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_error
(
Node
self
)
217} 218 219///| 220extern "js" fn ts_node_parse_state(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type StateId UInt16
StateId
=
221 #|(node) => { 222 #| return node.parseState; 223 #|} 224 225///| 226/// Get this node's parse state. 227pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> StateId

Get this node's parse state.

parse_state
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type StateId UInt16
StateId
{
228 return
(self : TSNode, tree : TSTree) -> StateId
ts_node_parse_state
(
Node
self
)
229} 230 231///| 232extern "js" fn ts_node_next_parse_state(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type StateId UInt16
StateId
=
233 #|(node) => { 234 #| return node.nextParseState; 235 #|} 236 237///| 238/// Get the parse state after this node. 239pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> StateId

Get the parse state after this node.

next_parse_state
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type StateId UInt16
StateId
{
240 return
(self : TSNode, tree : TSTree) -> StateId
ts_node_next_parse_state
(
Node
self
)
241} 242 243///| 244extern "js" fn ts_node_parent(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
245 #|(node) => { 246 #| return node.parent; 247 #|} 248 249///| 250/// Get the node's immediate parent. 251/// Prefer `Node::child_with_descendant` for iterating over the node's ancestors. 252pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Node?

Get the node's immediate parent. Prefer Node::child_with_descendant for iterating over the node's ancestors.

parent
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
253 let
TSNode
parent
=
(self : TSNode, tree : TSTree) -> TSNode
ts_node_parent
(
Node
self
)
254 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
parent
) {
255
Node?
None
256 } else { 257
(Node) -> Node?
Some
(
TSNode
parent
)
258 } 259} 260 261///| 262extern "js" fn ts_node_child_with_descendant( 263 self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
264 descendant :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
265) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
266 #|(node, descendant) => { 267 #| return node.childWithDescendant(descendant); 268 #|} 269 270///| 271/// Get the node that contains `descendant`. 272/// 273/// Note that this can return `descendant` itself. 274pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, descendant : Node) -> Node?

Get the node that contains descendant.

Note that this can return descendant itself.

child_with_descendant
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
Node
descendant
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
275 let
TSNode
child
=
(self : TSNode, self_tree : TSTree, descendant : TSNode, descendant_tree : TSTree) -> TSNode
ts_node_child_with_descendant
(
Node
self
,
Node
descendant
)
276 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
child
) {
277
Node?
None
278 } else { 279
(Node) -> Node?
Some
(
TSNode
child
)
280 } 281} 282 283///| 284extern "js" fn ts_node_child(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
, index :
UInt
UInt
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
285 #|(node, index) => { 286 #| return node.child(index); 287 #|} 288 289///| 290fn
(value : Int) -> UInt
int_to_uint
(
Int
value
:
Int
Int
) ->
UInt
UInt
{
291 guard
Int
value
(self_ : Int, other : Int) -> Bool
>=
0
292
Int
value
.
(self : Int) -> UInt

reinterpret the signed int as unsigned int, when the value is non-negative, i.e, 0..=2^31-1, the value is the same. When the value is negative, it turns into a large number, for example, -1 turns into 2^32-1

reinterpret_as_uint
()
293} 294 295///| 296fn
(value : UInt) -> Int
uint_to_int
(
UInt
value
:
UInt
UInt
) ->
Int
Int
{
297 guard
UInt
value
(self_ : UInt, other : UInt) -> Bool
<=
Int

Maximum value of an integer.

@int.max_value
.
(self : Int) -> UInt

reinterpret the signed int as unsigned int, when the value is non-negative, i.e, 0..=2^31-1, the value is the same. When the value is negative, it turns into a large number, for example, -1 turns into 2^32-1

reinterpret_as_uint
()
298
UInt
value
.
(self : UInt) -> Int

reinterpret the unsigned int as signed int For number within the range of 0..=2^31-1, the value is the same. For number within the range of 2^31..=2^32-1, the value is negative

reinterpret_as_int
()
299} 300 301///| 302/// Get the node's child at the given index, where zero represents the first 303/// child. 304pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, index : Int) -> Node?

Get the node's child at the given index, where zero represents the first child.

child
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
Int
index
:
Int
Int
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
305 let
UInt
index
=
(value : Int) -> UInt
int_to_uint
(
Int
index
)
306 let
TSNode
child
=
(self : TSNode, tree : TSTree, index : UInt) -> TSNode
ts_node_child
(
Node
self
,
UInt
index
)
307 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
child
) {
308
Node?
None
309 } else { 310
(Node) -> Node?
Some
(
TSNode
child
)
311 } 312} 313 314///| 315/// Get all children of the node. 316pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Iter[Node]

Get all children of the node.

children
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Iter[T]
Iter
[
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
] {
317
type Iter[T]
Iter
::
(((Node) -> IterResult) -> IterResult) -> Iter[Node]

Do not use this method, it is for internal use only.

new
(fn(
(Node) -> IterResult
yield_
) {
318 for
UInt
i
in
UInt
0U
..<
(self : TSNode, tree : TSTree) -> UInt
ts_node_child_count
(
Node
self
) {
319 let
TSNode
child
=
(self : TSNode, tree : TSTree, index : UInt) -> TSNode
ts_node_child
(
Node
self
,
UInt
i
)
320 match
(Node) -> IterResult
yield_
(
TSNode
child
) {
321
IterResult
IterEnd
=> return
IterResult
IterEnd
322
IterResult
IterContinue
=> continue
323 } 324 } 325
IterResult
IterContinue
326 }) 327} 328 329///| 330extern "js" fn ts_node_field_name_for_child( 331 self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
332 child_index :
UInt
UInt
333) ->
String
String
=
334 #|(node, tree, child_index) => { 335 #| return node.fieldNameForChild(child_index); 336 #|} 337 338///| 339/// Get the field name for node's child at the given index, where zero represents 340/// the first child. Returns `None`, if no field is found. 341pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, child_index : Int) -> @string.StringView?

Get the field name for node's child at the given index, where zero represents the first child. Returns None, if no field is found.

field_name_for_child
(
342
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
343
Int
child_index
:
Int
Int
344) ->
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
? {
345 let
UInt
child_index
=
(value : Int) -> UInt
int_to_uint
(
Int
child_index
)
346 let
@string.StringView?
field_name
=
(self : TSNode, tree : TSTree, child_index : UInt) -> ?
ts_node_field_name_for_child
(
Node
self
,
UInt
child_index
).
() -> @string.StringView?
to_option
()
347 if
@string.StringView?
field_name
is
(@string.StringView) -> @string.StringView?
Some
(
@string.StringView
field_name
) {
348 return
(@string.StringView) -> @string.StringView?
Some
(
@string.StringView
field_name
)
349 } else { 350 return
@string.StringView?
None
351 } 352} 353 354///| 355extern "js" fn ts_node_field_name_for_named_child( 356 self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
357 child_index :
UInt
UInt
358) ->
String
String
=
359 #|(node, child_index) => { 360 #| return node.fieldNameForNamedChild(child_index); 361 #|} 362 363///| 364/// Get the field name for node's named child at the given index, where zero 365/// represents the first named child. Returns `None`, if no field is found. 366pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, child_index : Int) -> @string.StringView?

Get the field name for node's named child at the given index, where zero represents the first named child. Returns None, if no field is found.

field_name_for_named_child
(
367
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
368
Int
child_index
:
Int
Int
369) ->
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
? {
370 let
UInt
child_index
=
(value : Int) -> UInt
int_to_uint
(
Int
child_index
)
371 let
@string.StringView?
field_name
=
(self : TSNode, tree : TSTree, child_index : UInt) -> ?
ts_node_field_name_for_named_child
(
Node
self
,
UInt
child_index
).
() -> @string.StringView?
to_option
()
372 if
@string.StringView?
field_name
is
(@string.StringView) -> @string.StringView?
Some
(
@string.StringView
field_name
) {
373 return
(@string.StringView) -> @string.StringView?
Some
(
@string.StringView
field_name
)
374 } else { 375 return
@string.StringView?
None
376 } 377} 378 379///| 380extern "js" fn ts_node_child_count(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
UInt
UInt
=
381 #|(node) => { 382 #| return node.childCount; 383 #|} 384 385///| 386/// Get the node's number of children. 387pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Int

Get the node's number of children.

child_count
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Int
Int
{
388
(value : UInt) -> Int
uint_to_int
(
(self : TSNode, tree : TSTree) -> UInt
ts_node_child_count
(
Node
self
))
389} 390 391///| 392extern "js" fn ts_node_named_child(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
, child_index :
UInt
UInt
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
393 #|(node, tree, child_index) => { 394 #| return node.namedChild(child_index); 395 #|} 396 397///| 398/// Get the node's *named* child at the given index. 399/// 400/// See also `Node::is_named`. 401pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, child_index : Int) -> Node?

Get the node's named child at the given index.

See also Node::is_named.

named_child
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
Int
child_index
:
Int
Int
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
402 let
UInt
child_index
=
(value : Int) -> UInt
int_to_uint
(
Int
child_index
)
403 let
TSNode
child
=
(self : TSNode, tree : TSTree, child_index : UInt) -> TSNode
ts_node_named_child
(
Node
self
,
UInt
child_index
)
404 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
child
) {
405
Node?
None
406 } else { 407
(Node) -> Node?
Some
(
TSNode
child
)
408 } 409} 410 411///| 412extern "js" fn ts_node_named_child_count(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
UInt
UInt
=
413 #|(node) => { 414 #| return node.namedChildCount; 415 #|} 416 417///| 418/// Get the node's number of *named* children. 419/// 420/// See also `Node::is_named`. 421pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Int

Get the node's number of named children.

See also Node::is_named.

named_child_count
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Int
Int
{
422
(value : UInt) -> Int
uint_to_int
(
(self : TSNode, tree : TSTree) -> UInt
ts_node_named_child_count
(
Node
self
))
423} 424 425///| 426/// Get all named children of the node. 427pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Iter[Node]

Get all named children of the node.

named_children
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Iter[T]
Iter
[
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
] {
428
type Iter[T]
Iter
::
(((Node) -> IterResult) -> IterResult) -> Iter[Node]

Do not use this method, it is for internal use only.

new
(fn(
(Node) -> IterResult
yield_
) {
429 for
UInt
i
in
UInt
0U
..<
(self : TSNode, tree : TSTree) -> UInt
ts_node_named_child_count
(
Node
self
) {
430 let
TSNode
child
=
(self : TSNode, tree : TSTree, child_index : UInt) -> TSNode
ts_node_named_child
(
Node
self
,
UInt
i
)
431 match
(Node) -> IterResult
yield_
(
TSNode
child
) {
432
IterResult
IterEnd
=> return
IterResult
IterEnd
433
IterResult
IterContinue
=> continue
434 } 435 } 436
IterResult
IterContinue
437 }) 438} 439 440///| 441/// Get the node's child with the given field name. 442extern "js" fn ts_node_child_by_field_name(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
, name :
String
String
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
443 #|(node, name) => { 444 #| return node.childForFieldName(name); 445 #|} 446 447///| 448/// Get the node's child with the given field name. 449pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, name : @string.StringView) -> Node?

Get the node's child with the given field name.

child_by_field_name
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
@string.StringView
name
:
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
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
450 let
TSNode
child
=
(self : TSNode, tree : TSTree, name : Bytes) -> TSNode

Get the node's child with the given field name.

ts_node_child_by_field_name
(
Node
self
,
@string.StringView
name
.
(self : @string.StringView) -> String

Returns a new String containing a copy of the characters in this view.

Examples

let str = "Hello World"
let view = str[0:5]  // "Hello"
inspect!(view.to_string(), content="Hello")
to_string
())
451 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
child
) {
452
Node?
None
453 } else { 454
(Node) -> Node?
Some
(
TSNode
child
)
455 } 456} 457 458///| 459extern "js" fn ts_node_child_by_field_id(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
, id :
type FieldId UInt16
FieldId
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
460 #|(node, id) => { 461 #| return node.childForFieldId(id); 462 #|} 463 464///| 465/// Get the node's child with the given numerical field id. 466/// 467/// You can convert a field name to an id using the 468/// `Language::field_id_for_name` function. 469pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, id : FieldId) -> Node?

Get the node's child with the given numerical field id.

You can convert a field name to an id using the Language::field_id_for_name function.

child_by_field_id
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
FieldId
id
:
type FieldId UInt16
FieldId
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
470 let
TSNode
child
=
(self : TSNode, tree : TSTree, id : FieldId) -> TSNode
ts_node_child_by_field_id
(
Node
self
,
FieldId
id
)
471 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
child
) {
472
Node?
None
473 } else { 474
(Node) -> Node?
Some
(
TSNode
child
)
475 } 476} 477 478///| 479extern "js" fn ts_node_next_sibling(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
480 #|(node) => { 481 #| return node.nextSibling; 482 #|} 483 484///| 485/// Get the node's next sibling. 486pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Node?

Get the node's next sibling.

next_sibling
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
487 let
TSNode
next_sibling
=
(self : TSNode, tree : TSTree) -> TSNode
ts_node_next_sibling
(
Node
self
)
488 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
next_sibling
) {
489
Node?
None
490 } else { 491
(Node) -> Node?
Some
(
TSNode
next_sibling
)
492 } 493} 494 495///| 496extern "js" fn ts_node_prev_sibling(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
497 #|(node) => { 498 #| return node.prevSibling; 499 #|} 500 501///| 502/// Get the node's previous sibling. 503pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Node?

Get the node's previous sibling.

prev_sibling
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
504 let
TSNode
prev_sibling
=
(self : TSNode, tree : TSTree) -> TSNode
ts_node_prev_sibling
(
Node
self
)
505 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
prev_sibling
) {
506
Node?
None
507 } else { 508
(Node) -> Node?
Some
(
TSNode
prev_sibling
)
509 } 510} 511 512///| 513extern "js" fn ts_node_next_named_sibling(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
514 #|(node) => { 515 #| return node.nextNamedSibling; 516 #|} 517 518///| 519/// Get the node's next *named* sibling. 520pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Node?

Get the node's next named sibling.

next_named_sibling
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
521 let
TSNode
next_named_sibling
=
(self : TSNode, tree : TSTree) -> TSNode
ts_node_next_named_sibling
(
Node
self
)
522 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
next_named_sibling
) {
523
Node?
None
524 } else { 525
(Node) -> Node?
Some
(
TSNode
next_named_sibling
)
526 } 527} 528 529///| 530extern "js" fn ts_node_prev_named_sibling(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
= "moonbit_ts_node_prev_named_sibling"
531 532///| 533/// Get the node's previous *named* sibling. 534pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Node?

Get the node's previous named sibling.

prev_named_sibling
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
535 let
TSNode
prev_named_sibling
=
(self : TSNode, tree : TSTree) -> TSNode
ts_node_prev_named_sibling
(
Node
self
)
536 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
prev_named_sibling
) {
537
Node?
None
538 } else { 539
(Node) -> Node?
Some
(
TSNode
prev_named_sibling
)
540 } 541} 542 543///| 544extern "js" fn ts_node_first_child_for_byte(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
, byte :
UInt
UInt
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
545 #|(node, byte) => { 546 #| return node.firstChildForIndex(byte); 547 #|} 548 549///| 550/// Get the node's first child that contains or starts after the given byte offset. 551pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, byte : Int) -> Node?

Get the node's first child that contains or starts after the given byte offset.

first_child_for_byte
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
Int
byte
:
Int
Int
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
552 let
UInt
byte
=
(value : Int) -> UInt
int_to_uint
(
Int
byte
)
553 let
TSNode
child
=
(self : TSNode, tree : TSTree, byte : UInt) -> TSNode
ts_node_first_child_for_byte
(
Node
self
,
UInt
byte
)
554 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
child
) {
555
Node?
None
556 } else { 557
(Node) -> Node?
Some
(
TSNode
child
)
558 } 559} 560 561///| 562extern "js" fn ts_node_first_named_child_for_byte( 563 self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
564 byte :
UInt
UInt
565) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
566 #|(node, byte) => { 567 #| return node.firstNamedChildForIndex(byte); 568 #|} 569 570///| 571/// Get the node's first named child that contains or starts after the given byte offset. 572pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, byte : Int) -> Node?

Get the node's first named child that contains or starts after the given byte offset.

first_named_child_for_byte
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
Int
byte
:
Int
Int
) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
573 let
UInt
byte
=
(value : Int) -> UInt
int_to_uint
(
Int
byte
)
574 let
TSNode
child
=
(self : TSNode, tree : TSTree, byte : UInt) -> TSNode
ts_node_first_named_child_for_byte
(
Node
self
,
UInt
byte
)
575 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
child
) {
576
Node?
None
577 } else { 578
(Node) -> Node?
Some
(
TSNode
child
)
579 } 580} 581 582///| 583extern "js" fn ts_node_descendant_count(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Int
Int
=
584 #|(node) => { 585 #| return node.descendantCount; 586 #|} 587 588///| 589/// Get the node's number of descendants, including one for the node itself. 590pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Int

Get the node's number of descendants, including one for the node itself.

descendant_count
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Int
Int
{
591 return
(self : TSNode, tree : TSTree) -> Int
ts_node_descendant_count
(
Node
self
)
592} 593 594///| 595extern "js" fn ts_node_descendant_for_byte_range( 596 self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
597 start_byte :
UInt
UInt
,
598 end_byte :
UInt
UInt
599) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
600 #|(node, start_byte, end_byte) => { 601 #| return node.descendantForIndex(start_byte, end_byte); 602 #|} 603 604///| 605/// Get the smallest node within this node that spans the given range of bytes. 606pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, start_byte : Int, end_byte : Int) -> Node?

Get the smallest node within this node that spans the given range of bytes.

descendant_for_byte_range
(
607
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
608
Int
start_byte
:
Int
Int
,
609
Int
end_byte
:
Int
Int
610) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
611 let
UInt
start_byte
=
(value : Int) -> UInt
int_to_uint
(
Int
start_byte
)
612 let
UInt
end_byte
=
(value : Int) -> UInt
int_to_uint
(
Int
end_byte
)
613 let
TSNode
descendant
=
(self : TSNode, tree : TSTree, start_byte : UInt, end_byte : UInt) -> TSNode
ts_node_descendant_for_byte_range
(
Node
self
,
UInt
start_byte
,
UInt
end_byte
)
614 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
descendant
) {
615
Node?
None
616 } else { 617
(Node) -> Node?
Some
(
TSNode
descendant
)
618 } 619} 620 621///| 622extern "js" fn ts_node_descendant_for_point_range( 623 self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
624 start_point :
type Point
Point
,
625 end_point :
type Point
Point
626) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
627 #|(node, start_point, end_point) => { 628 #| return node.descendantForPosition(start_point, end_point); 629 #|} 630 631///| 632/// Get the smallest node within this node that spans the given range of 633/// (row, column) positions. 634pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, start_point : Point, end_point : Point) -> Node?

Get the smallest node within this node that spans the given range of (row, column) positions.

descendant_for_point_range
(
635
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
636
Point
start_point
:
type Point
Point
,
637
Point
end_point
:
type Point
Point
638) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
639 let
TSNode
descendant
=
(self : TSNode, tree : TSTree, start_point : Point, end_point : Point) -> TSNode
ts_node_descendant_for_point_range
(
640
Node
self
,
Point
start_point
,
Point
end_point
,
641 ) 642 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
descendant
) {
643
Node?
None
644 } else { 645
(Node) -> Node?
Some
(
TSNode
descendant
)
646 } 647} 648 649///| 650extern "js" fn ts_node_named_descendant_for_byte_range( 651 self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
652 start_byte :
UInt
UInt
,
653 end_byte :
UInt
UInt
654) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
655 #|(node, start_byte, end_byte) => { 656 #| return node.namedDescendantForIndex(start_byte, end_byte); 657 #|} 658 659///| 660/// Get the smallest named node within this node that spans the given range of 661/// bytes. 662pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, start_byte : Int, end_byte : Int) -> Node?

Get the smallest named node within this node that spans the given range of bytes.

named_descendant_for_byte_range
(
663
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
664
Int
start_byte
:
Int
Int
,
665
Int
end_byte
:
Int
Int
666) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
667 let
UInt
start_byte
=
(value : Int) -> UInt
int_to_uint
(
Int
start_byte
)
668 let
UInt
end_byte
=
(value : Int) -> UInt
int_to_uint
(
Int
end_byte
)
669 let
TSNode
descendant
=
(self : TSNode, tree : TSTree, start_byte : UInt, end_byte : UInt) -> TSNode
ts_node_named_descendant_for_byte_range
(
670
Node
self
,
UInt
start_byte
,
UInt
end_byte
,
671 ) 672 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
descendant
) {
673
Node?
None
674 } else { 675
(Node) -> Node?
Some
(
TSNode
descendant
)
676 } 677} 678 679///| 680extern "js" fn ts_node_named_descendant_for_point_range( 681 self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
682 start_point :
type Point
Point
,
683 end_point :
type Point
Point
684) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
=
685 #|(node, start_point, end_point) => { 686 #| return node.namedDescendantForPosition(start_point, end_point); 687 #|} 688 689///| 690/// Get the smallest named node within this node that spans the given 691/// (row, column) positions. 692pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, start_point : Point, end_point : Point) -> Node?

Get the smallest named node within this node that spans the given (row, column) positions.

named_descendant_for_point_range
(
693
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
694
Point
start_point
:
type Point
Point
,
695
Point
end_point
:
type Point
Point
696) ->
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
? {
697 let
TSNode
descendant
=
(self : TSNode, tree : TSTree, start_point : Point, end_point : Point) -> TSNode
ts_node_named_descendant_for_point_range
(
698
Node
self
,
Point
start_point
,
Point
end_point
,
699 ) 700 if
(self : TSNode, tree : TSTree) -> Bool
ts_node_is_null
(
TSNode
descendant
) {
701
Node?
None
702 } else { 703
(Node) -> Node?
Some
(
TSNode
descendant
)
704 } 705} 706 707///| 708extern "js" fn ts_node_edit(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
, edit :
type InputEdit FixedArray[UInt]
InputEdit
) =
709 #|(node, tree, edit) => { 710 #| return node.edit(edit); 711 #|} 712 713///| 714/// Edit the node to keep it in-sync with source code that has been edited. 715/// 716/// This function is only rarely needed. When you edit a syntax tree with the 717/// `Tree::edit` function, all of the nodes that you retrieve from the tree 718/// afterward will already reflect the edit. You only need to use `Node::edit` 719/// when you have a `Node` instance that you want to keep and continue to use 720/// after an edit. 721pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, edit : InputEdit) -> Unit

Edit the node to keep it in-sync with source code that has been edited.

This function is only rarely needed. When you edit a syntax tree with the Tree::edit function, all of the nodes that you retrieve from the tree afterward will already reflect the edit. You only need to use Node::edit when you have a Node instance that you want to keep and continue to use after an edit.

edit
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
InputEdit
edit
:
type InputEdit FixedArray[UInt]
InputEdit
) ->
Unit
Unit
{
722
(self : TSNode, tree : TSTree, edit : InputEdit) -> Unit
ts_node_edit
(
Node
self
,
InputEdit
edit
)
723} 724 725///| 726extern "js" fn ts_node_eq(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
, other :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
=
727 #|(self, other) => { 728 #| return self.equals(other) 729 #|} 730 731///| 732/// Check if two nodes are identical. 733pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, other : Node) -> Bool

Check if two nodes are identical.

eq
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
Node
other
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Bool
Bool
{
734
(self : TSNode, self_tree : TSTree, other : TSNode, other_tree : TSTree) -> Bool
ts_node_eq
(
Node
self
,
Node
other
)
735} 736 737///| 738pub impl
trait Eq {
  op_equal(Self, Self) -> Bool
}
Eq
for
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
with
(self : Node, other : Node) -> Bool
op_equal
(
Node
self
,
Node
other
) ->
Bool
Bool
{
739
(self : TSNode, self_tree : TSTree, other : TSNode, other_tree : TSTree) -> Bool
ts_node_eq
(
Node
self
,
Node
other
)
740} 741 742///| 743pub impl
trait ToJson {
  to_json(Self) -> Json
}
ToJson
for
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
with
(self : Node) -> Json
to_json
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
enum Json {
  Null
  True
  False
  Number(Double)
  String(String)
  Array(Array[Json])
  Object(Map[String, Json])
}
Json
{
744 { 745 "node":
Node
self
.
(self : Node) -> @string.StringView

Get an S-expression representing the node as a string.

string
().
(self : @string.StringView) -> Json
to_json
(),
746 "text":
Node
self
.
(self : Node) -> @string.StringView
text
().
(self : @string.StringView) -> Json
to_json
(),
747 "range": { 748 "start":
Node
self
.
(self : Node) -> Point

Get the node's start position in terms of rows and columns.

start_point
().
(self : Point) -> Json
to_json
(),
749 "end":
Node
self
.
(self : Node) -> Point
end_point
().
(self : Point) -> Json
to_json
(),
750 }, 751 } 752} 753 754///| 755extern "js" fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::id(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
Int
Int
=
756 #|(node) => { 757 #| return node.id; 758 #|} 759 760///| 761pub impl
trait Hash {
  hash_combine(Self, Hasher) -> Unit
  hash(Self) -> Int
}
Hash
for
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
with
(self : Node, hasher : Hasher) -> Unit
hash_combine
(
Node
self
,
Hasher
hasher
) {
762 let
Int
id
=
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Int
id
(
Node
self
)
763
Hasher
hasher
.
(self : Hasher, value : Int) -> Unit

Combines a hashable value with the current state of the hasher. This is typically used to incrementally build a hash value from multiple components.

Parameters:

  • self : The hasher instance to update.
  • value : The value to be combined with the current hash state. Must implement the Hash trait.

Example:

test "Hasher::combine" {
  let hasher = Hasher::new()
  hasher.combine(42)
  hasher.combine("hello")
  inspect!(hasher.finalize(), content="860601284")
}
combine
(
Int
id
)
764} 765 766///| 767extern "js" fn ts_node_text(self :
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
String
String
=
768 #|(node) => { 769 #| return node.text; 770 #|} 771 772///| 773pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> @string.StringView
text
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
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
{
774
(self : Node) -> String
ts_node_text
(
Node
self
)
775} 776 777///| 778pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Iter[String]
symbol_names
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Iter[T]
Iter
[
String
String
] {
779 let
Language
language
=
Node
self
.
(self : Node) -> Language

Get the node's language.

language
()
780 let
LookaheadIterator?
iterator
=
type LookaheadIterator
LookaheadIterator
::
(language : Language, state : StateId) -> LookaheadIterator?

Create a new lookahead iterator for the given language and parse state.

This returns None if state is invalid for the language.

Repeatedly using LookaheadIterator::next and LookaheadIterator::current_symbol will generate valid symbols in the given parse state. Newly created lookahead iterators will contain the ERROR symbol.

Lookahead iterators can be useful to generate suggestions and improve syntax error diagnostics. To get symbols valid in an ERROR node, use the lookahead iterator on its first leaf node state. For MISSING nodes, a lookahead iterator created on the previous non-extra leaf node may be appropriate.

new
(
Language
language
,
Node
self
.
(self : Node) -> StateId

Get this node's parse state.

parse_state
())
781 guard
LookaheadIterator?
iterator
is
(LookaheadIterator) -> LookaheadIterator?
Some
(
LookaheadIterator
iterator
) else { return
type Iter[T]
Iter
::
() -> Iter[String]

Creates an empty iterator.

Type Parameters

  • T: The type of the elements in the iterator.

Returns

Returns an empty iterator of type Iter[T].

empty
() }
782
LookaheadIterator
iterator
.
(self : LookaheadIterator) -> Iter[String]
symbol_names
()
783} 784 785///| 786pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node) -> Iter[String]
next_symbol_names
(
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
) ->
type Iter[T]
Iter
[
String
String
] {
787 let
Language
language
=
Node
self
.
(self : Node) -> Language

Get the node's language.

language
()
788 let
LookaheadIterator?
iterator
=
type LookaheadIterator
LookaheadIterator
::
(language : Language, state : StateId) -> LookaheadIterator?

Create a new lookahead iterator for the given language and parse state.

This returns None if state is invalid for the language.

Repeatedly using LookaheadIterator::next and LookaheadIterator::current_symbol will generate valid symbols in the given parse state. Newly created lookahead iterators will contain the ERROR symbol.

Lookahead iterators can be useful to generate suggestions and improve syntax error diagnostics. To get symbols valid in an ERROR node, use the lookahead iterator on its first leaf node state. For MISSING nodes, a lookahead iterator created on the previous non-extra leaf node may be appropriate.

new
(
Language
language
,
Node
self
.
(self : Node) -> StateId

Get the parse state after this node.

next_parse_state
())
789 guard
LookaheadIterator?
iterator
is
(LookaheadIterator) -> LookaheadIterator?
Some
(
LookaheadIterator
iterator
) else { return
type Iter[T]
Iter
::
() -> Iter[String]

Creates an empty iterator.

Type Parameters

  • T: The type of the elements in the iterator.

Returns

Returns an empty iterator of type Iter[T].

empty
() }
790
LookaheadIterator
iterator
.
(self : LookaheadIterator) -> Iter[String]
symbol_names
()
791} 792 793///| 794pub fn
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
::
(self : Node, source : @string.StringView) -> QueryCursor!QueryError
query
(
795
Node
self
:
struct Node {
  node: TSNode
  tree: TSTree
  text: @string.StringView
}
Node
,
796
@string.StringView
source
:
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
797) ->
struct QueryCursor {
  mut query: Query?
  mut node: Node?
}
QueryCursor
!
type! QueryError {
  Syntax(UInt)
  NodeType(UInt)
  Field(UInt)
  Capture(UInt)
  Structure(UInt)
  Language(UInt)
}
QueryError
{
798 let
Query
query
=
type Query
Query
::
(language : Language, source : @string.StringView) -> Query!QueryError

Create a new query from a string containing one or more S-expression patterns. The query is associated with a particular language, and can only be run on syntax nodes parsed with that language.

If all of the given patterns are valid, this returns a Query. If a pattern is invalid, this raises a QueryError.

new
!(
Node
self
.
(self : Node) -> Language

Get the node's language.

language
(),
@string.StringView
source
)
799 let
QueryCursor
query_cursor
=
struct QueryCursor {
  mut query: Query?
  mut node: Node?
}
QueryCursor
::
() -> QueryCursor

Create a new cursor for executing a given query.

The cursor stores the state that is needed to iteratively search for matches. To use the query cursor, first call QueryCursor::exec to start running a given query on a given syntax node. Then, there are two options for consuming the results of the query:

  1. Repeatedly call QueryCursor::next_match to iterate over all of the matches in the order that they were found. Each match contains the index of the pattern that matched, and an array of captures. Because multiple patterns can match the same set of nodes, one match may contain captures that appear before some of the captures from a previous match.
  2. Repeatedly call QueryCursor::next_capture to iterate over all of the individual captures in the order that they appear. This is useful if don't care about which pattern matched, and just want a single ordered sequence of captures.

If you don't care about consuming all of the results, you can stop calling QueryCursor::next_match or QueryCursor::next_capture at any point. You can then start executing another query on another node by calling QueryCursor::exec again.

new
()
800
QueryCursor
query_cursor
.
(self : QueryCursor, query : Query, node : Node, options? : QueryCursorOptions) -> Unit

Start running a given query on a given node, with optional options.

exec
(
Query
query
,
Node
self
)
801 return
QueryCursor
query_cursor
802} 803