1///|
2priv type TSNode Bytes
Bytes
3
4///|
5struct Node {
6 TSNode
node : type TSNode Bytes
TSNode
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(self, tree)
13extern "c" fn ts_node_type(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> @c.Pointer[Byte
Byte] = "moonbit_ts_node_type"
14
15///|
16/// Get the node's type as a string.
17pub fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : Node) -> String
Get the node's type as a string.
type_(Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node) -> String
String {
18 return (c_string : ?, length? : Int) -> String?
decode_c_string((self : TSNode, tree : TSTree) -> ?
ts_node_type(Node
self.TSNode
node, Node
self.TSTree
tree)).(self : String?) -> String
Extract the value in Some.
If the value is None, it throws a panic.
unwrap()
19}
20
21///|
22#borrow(self, tree)
23extern "c" fn ts_node_symbol(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> type Symbol UInt
Symbol = "moonbit_ts_node_symbol"
24
25///|
26/// Get the node's type as a numerical id.
27pub 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 {
28 return (self : TSNode, tree : TSTree) -> Symbol
ts_node_symbol(Node
self.TSNode
node, Node
self.TSTree
tree)
29}
30
31///|
32#borrow(self, tree)
33extern "c" fn ts_node_language(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> type Language @tree_sitter_language.Language
Language = "moonbit_ts_node_language"
34
35///|
36/// Get the node's language.
37pub 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 {
38 return (self : TSNode, tree : TSTree) -> Language
ts_node_language(Node
self.TSNode
node, Node
self.TSTree
tree)
39}
40
41///|
42#borrow(self, tree)
43extern "c" fn ts_node_grammar_type(
44 self : type TSNode Bytes
TSNode,
45 tree : type TSTree
TSTree
46) -> @c.Pointer[Byte
Byte] = "moonbit_ts_node_grammar_type"
47
48///|
49/// Get the node's type as it appears in the grammar ignoring aliases as a string.
50pub fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : Node) -> String
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) -> String
String {
51 return (c_string : ?, length? : Int) -> String?
decode_c_string((self : TSNode, tree : TSTree) -> ?
ts_node_grammar_type(Node
self.TSNode
node, Node
self.TSTree
tree)).(self : String?) -> String
Extract the value in Some.
If the value is None, it throws a panic.
unwrap()
52}
53
54///|
55#borrow(self, tree)
56extern "c" fn ts_node_grammar_symbol(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> type Symbol UInt
Symbol = "moonbit_ts_node_grammar_symbol"
57
58///|
59/// Get the node's type as a numerical id as it appears in the grammar ignoring
60/// aliases. This should be used in `Language::next_state` instead of
61/// `Node::symbol`.
62pub 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 {
63 return (self : TSNode, tree : TSTree) -> Symbol
ts_node_grammar_symbol(Node
self.TSNode
node, Node
self.TSTree
tree)
64}
65
66///|
67#borrow(self, tree)
68extern "c" fn ts_node_start_byte(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Int
Int = "moonbit_ts_node_start_byte"
69
70///|
71/// Get the node's start byte.
72pub 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 {
73 return (self : TSNode, tree : TSTree) -> Int
ts_node_start_byte(Node
self.TSNode
node, Node
self.TSTree
tree)
74}
75
76///|
77#borrow(self, tree)
78extern "c" fn ts_node_start_point(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> type Point
Point = "moonbit_ts_node_start_point"
79
80///|
81/// Get the node's start position in terms of rows and columns.
82pub 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 {
83 return (self : TSNode, tree : TSTree) -> Point
ts_node_start_point(Node
self.TSNode
node, Node
self.TSTree
tree)
84}
85
86///|
87#borrow(self, tree)
88extern "c" fn ts_node_end_byte(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Int
Int = "moonbit_ts_node_end_byte"
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.TSNode
node, Node
self.TSTree
tree)
94}
95
96///|
97#borrow(self, tree)
98extern "c" fn ts_node_string(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Bytes
Bytes = "moonbit_ts_node_string"
99
100///|
101/// Get the node's end position in terms of rows and columns.
102#borrow(self, tree)
103extern "c" fn ts_node_end_point(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> type Point
Point = "moonbit_ts_node_end_point"
104
105///|
106pub 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 {
107 return (self : TSNode, tree : TSTree) -> Point
Get the node's end position in terms of rows and columns.
ts_node_end_point(Node
self.TSNode
node, Node
self.TSTree
tree)
108}
109
110///|
111pub fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : Node) -> Range
range(Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node) -> type Range FixedArray[UInt]
Range {
112 return type Range FixedArray[UInt]
Range::(start_pointer : Point, end_pointer : Point, start_byte : Int, end_byte : Int) -> Range
new(
113 Node
self.(self : Node) -> Point
Get the node's start position in terms of rows and columns.
start_point(),
114 Node
self.(self : Node) -> Point
end_point(),
115 Node
self.(self : Node) -> Int
Get the node's start byte.
start_byte(),
116 Node
self.(self : Node) -> Int
Get the node's end byte.
end_byte(),
117 )
118}
119
120///|
121/// Get an S-expression representing the node as a string.
122pub fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : Node) -> String
Get an S-expression representing the node as a string.
string(Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node) -> String
String {
123 return (encoding~ : @encoding.Encoding, input : @bytes.View) -> String
@encoding.decode_lossy(
124 @encoding.Encoding
encoding=@encoding.Encoding
UTF8,
125 (self : TSNode, tree : TSTree) -> Bytes
ts_node_string(Node
self.TSNode
node, Node
self.TSTree
tree),
126 )
127}
128
129///|
130pub 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 {
131 try {
132 (source : @string.StringView) -> Array[@sexp.Sexp]!@sexp.SexpError
@sexp.parse!(Node
self.(self : Node) -> @string.StringView
Get an S-expression representing the node as a string.
string()) |> (list : Array[@sexp.Sexp]) -> Array[@sexp.Sexp]
@sexp.pretty() |> (list : Array[@sexp.Sexp], logger : &Logger, indent~ : Int = ..) -> Unit
@sexp.print_to(&Logger
logger)
133 } catch {
134 _ => &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())
135 }
136}
137
138///|
139#borrow(self, tree)
140extern "c" fn ts_node_is_null(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Bool
Bool = "moonbit_ts_node_is_null"
141
142///|
143/// Check if the node is null. Functions like `Node::child` and
144/// `Node::next_sibling` will return a null node to indicate that no such node
145/// was found.
146pub 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 {
147 return (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(Node
self.TSNode
node, Node
self.TSTree
tree)
148}
149
150///|
151#borrow(self, tree)
152extern "c" fn ts_node_is_named(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Bool
Bool = "moonbit_ts_node_is_named"
153
154///|
155/// Check if the node is *named*. Named nodes correspond to named rules in the
156/// grammar, whereas *anonymous* nodes correspond to string literals in the
157/// grammar.
158pub 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 {
159 return (self : TSNode, tree : TSTree) -> Bool
ts_node_is_named(Node
self.TSNode
node, Node
self.TSTree
tree)
160}
161
162///|
163#borrow(self, tree)
164extern "c" fn ts_node_is_missing(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Bool
Bool = "moonbit_ts_node_is_missing"
165
166///|
167/// Check if the node is *missing*. Missing nodes are inserted by the parser in
168/// order to recover from certain kinds of syntax errors.
169pub 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 {
170 return (self : TSNode, tree : TSTree) -> Bool
ts_node_is_missing(Node
self.TSNode
node, Node
self.TSTree
tree)
171}
172
173///|
174#borrow(self, tree)
175extern "c" fn ts_node_is_extra(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Bool
Bool = "moonbit_ts_node_is_extra"
176
177///|
178/// Check if the node is *extra*. Extra nodes represent things like comments,
179/// which are not required the grammar, but can appear anywhere.
180pub 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 {
181 return (self : TSNode, tree : TSTree) -> Bool
ts_node_is_extra(Node
self.TSNode
node, Node
self.TSTree
tree)
182}
183
184///|
185#borrow(self, tree)
186extern "c" fn ts_node_has_changes(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Bool
Bool = "moonbit_ts_node_has_changes"
187
188///|
189/// Check if a syntax node has been edited.
190pub 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 {
191 return (self : TSNode, tree : TSTree) -> Bool
ts_node_has_changes(Node
self.TSNode
node, Node
self.TSTree
tree)
192}
193
194///|
195#borrow(self, tree)
196extern "c" fn ts_node_has_error(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Bool
Bool = "moonbit_ts_node_has_error"
197
198///|
199/// Check if the node is a syntax error or contains any syntax errors.
200pub 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 {
201 return (self : TSNode, tree : TSTree) -> Bool
ts_node_has_error(Node
self.TSNode
node, Node
self.TSTree
tree)
202}
203
204///|
205#borrow(self, tree)
206extern "c" fn ts_node_is_error(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Bool
Bool = "moonbit_ts_node_is_error"
207
208///|
209/// Check if the node is a syntax error.
210pub 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 {
211 return (self : TSNode, tree : TSTree) -> Bool
ts_node_is_error(Node
self.TSNode
node, Node
self.TSTree
tree)
212}
213
214///|
215#borrow(self, tree)
216extern "c" fn ts_node_parse_state(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> type StateId UInt16
StateId = "moonbit_ts_node_parse_state"
217
218///|
219/// Get this node's parse state.
220pub 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 {
221 return (self : TSNode, tree : TSTree) -> StateId
ts_node_parse_state(Node
self.TSNode
node, Node
self.TSTree
tree)
222}
223
224///|
225#borrow(self, tree)
226extern "c" fn ts_node_next_parse_state(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> type StateId UInt16
StateId = "moonbit_ts_node_next_parse_state"
227
228///|
229/// Get the parse state after this node.
230pub 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 {
231 return (self : TSNode, tree : TSTree) -> StateId
ts_node_next_parse_state(Node
self.TSNode
node, Node
self.TSTree
tree)
232}
233
234///|
235#borrow(self, tree)
236extern "c" fn ts_node_parent(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> type TSNode Bytes
TSNode = "moonbit_ts_node_parent"
237
238///|
239/// Get the node's immediate parent.
240/// Prefer `Node::child_with_descendant` for iterating over the node's ancestors.
241pub 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? {
242 let TSNode
parent = (self : TSNode, tree : TSTree) -> TSNode
ts_node_parent(Node
self.TSNode
node, Node
self.TSTree
tree)
243 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
parent, Node
self.TSTree
tree) {
244 Node?
None
245 } else {
246 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
parent })
247 }
248}
249
250///|
251#borrow(self, self_tree, descendant, descendant_tree)
252extern "c" fn ts_node_child_with_descendant(
253 self : type TSNode Bytes
TSNode,
254 self_tree : type TSTree
TSTree,
255 descendant : type TSNode Bytes
TSNode,
256 descendant_tree : type TSTree
TSTree
257) -> type TSNode Bytes
TSNode = "moonbit_ts_node_child_with_descendant"
258
259///|
260/// Get the node that contains `descendant`.
261///
262/// Note that this can return `descendant` itself.
263pub 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? {
264 let TSNode
child = (self : TSNode, self_tree : TSTree, descendant : TSNode, descendant_tree : TSTree) -> TSNode
ts_node_child_with_descendant(
265 Node
self.TSNode
node,
266 Node
self.TSTree
tree,
267 Node
descendant.TSNode
node,
268 Node
descendant.TSTree
tree,
269 )
270 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
child, Node
self.TSTree
tree) {
271 Node?
None
272 } else {
273 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
child })
274 }
275}
276
277///|
278#borrow(self, tree)
279extern "c" fn ts_node_child(
280 self : type TSNode Bytes
TSNode,
281 tree : type TSTree
TSTree,
282 index : UInt
UInt
283) -> type TSNode Bytes
TSNode = "moonbit_ts_node_child"
284
285///|
286fn (value : Int) -> UInt
int_to_uint(Int
value : Int
Int) -> UInt
UInt {
287 guard Int
value (self_ : Int, other : Int) -> Bool
>= 0
288 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()
289}
290
291///|
292fn (value : UInt) -> Int
uint_to_int(UInt
value : UInt
UInt) -> Int
Int {
293 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()
294 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()
295}
296
297///|
298/// Get the node's child at the given index, where zero represents the first
299/// child.
300pub 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? {
301 let UInt
index = (value : Int) -> UInt
int_to_uint(Int
index)
302 let TSNode
child = (self : TSNode, tree : TSTree, index : UInt) -> TSNode
ts_node_child(Node
self.TSNode
node, Node
self.TSTree
tree, UInt
index)
303 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
child, Node
self.TSTree
tree) {
304 Node?
None
305 } else {
306 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
child })
307 }
308}
309
310///|
311/// Get all children of the node.
312pub 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] {
313 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_) {
314 for UInt
i in UInt
0U..<(self : TSNode, tree : TSTree) -> UInt
ts_node_child_count(Node
self.TSNode
node, Node
self.TSTree
tree) {
315 let TSNode
child = (self : TSNode, tree : TSTree, index : UInt) -> TSNode
ts_node_child(Node
self.TSNode
node, Node
self.TSTree
tree, UInt
i)
316 match (Node) -> IterResult
yield_({ ..Node
self, TSNode
node: TSNode
child }) {
317 IterResult
IterEnd => return IterResult
IterEnd
318 IterResult
IterContinue => continue
319 }
320 }
321 IterResult
IterContinue
322 })
323}
324
325///|
326#borrow(self, tree)
327extern "c" fn ts_node_field_name_for_child(
328 self : type TSNode Bytes
TSNode,
329 tree : type TSTree
TSTree,
330 child_index : UInt
UInt
331) -> @c.Pointer[Byte
Byte] = "moonbit_ts_node_field_name_for_child"
332
333///|
334/// Get the field name for node's child at the given index, where zero represents
335/// the first child. Returns `None`, if no field is found.
336pub fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : Node, child_index : Int) -> String?
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(Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node, Int
child_index : Int
Int) -> String
String? {
337 let UInt
child_index = (value : Int) -> UInt
int_to_uint(Int
child_index)
338 let ?
field_name = (self : TSNode, tree : TSTree, child_index : UInt) -> ?
ts_node_field_name_for_child(
339 Node
self.TSNode
node,
340 Node
self.TSTree
tree,
341 UInt
child_index,
342 )
343 (c_string : ?, length? : Int) -> String?
decode_c_string(?
field_name)
344}
345
346///|
347#borrow(self, tree)
348extern "c" fn ts_node_field_name_for_named_child(
349 self : type TSNode Bytes
TSNode,
350 tree : type TSTree
TSTree,
351 child_index : UInt
UInt
352) -> @c.Pointer[Byte
Byte] = "moonbit_ts_node_field_name_for_named_child"
353
354///|
355/// Get the field name for node's named child at the given index, where zero
356/// represents the first named child. Returns `None`, if no field is found.
357pub fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : Node, child_index : Int) -> String?
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(
358 Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node,
359 Int
child_index : Int
Int
360) -> String
String? {
361 let UInt
child_index = (value : Int) -> UInt
int_to_uint(Int
child_index)
362 let ?
field_name = (self : TSNode, tree : TSTree, child_index : UInt) -> ?
ts_node_field_name_for_named_child(
363 Node
self.TSNode
node,
364 Node
self.TSTree
tree,
365 UInt
child_index,
366 )
367 (c_string : ?, length? : Int) -> String?
decode_c_string(?
field_name)
368}
369
370///|
371#borrow(self, tree)
372extern "c" fn ts_node_child_count(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> UInt
UInt = "moonbit_ts_node_child_count"
373
374///|
375/// Get the node's number of children.
376pub 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 {
377 (value : UInt) -> Int
uint_to_int((self : TSNode, tree : TSTree) -> UInt
ts_node_child_count(Node
self.TSNode
node, Node
self.TSTree
tree))
378}
379
380///|
381#borrow(self, tree)
382extern "c" fn ts_node_named_child(
383 self : type TSNode Bytes
TSNode,
384 tree : type TSTree
TSTree,
385 child_index : UInt
UInt
386) -> type TSNode Bytes
TSNode = "moonbit_ts_node_named_child"
387
388///|
389/// Get the node's *named* child at the given index.
390///
391/// See also `Node::is_named`.
392pub 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? {
393 let UInt
child_index = (value : Int) -> UInt
int_to_uint(Int
child_index)
394 let TSNode
child = (self : TSNode, tree : TSTree, child_index : UInt) -> TSNode
ts_node_named_child(Node
self.TSNode
node, Node
self.TSTree
tree, UInt
child_index)
395 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
child, Node
self.TSTree
tree) {
396 Node?
None
397 } else {
398 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
child })
399 }
400}
401
402///|
403#borrow(self, tree)
404extern "c" fn ts_node_named_child_count(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> UInt
UInt = "moonbit_ts_node_named_child_count"
405
406///|
407/// Get the node's number of *named* children.
408///
409/// See also `Node::is_named`.
410pub 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 {
411 (value : UInt) -> Int
uint_to_int((self : TSNode, tree : TSTree) -> UInt
ts_node_named_child_count(Node
self.TSNode
node, Node
self.TSTree
tree))
412}
413
414///|
415/// Get all named children of the node.
416pub 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] {
417 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_) {
418 for UInt
i in UInt
0U..<(self : TSNode, tree : TSTree) -> UInt
ts_node_named_child_count(Node
self.TSNode
node, Node
self.TSTree
tree) {
419 let TSNode
child = (self : TSNode, tree : TSTree, child_index : UInt) -> TSNode
ts_node_named_child(Node
self.TSNode
node, Node
self.TSTree
tree, UInt
i)
420 match (Node) -> IterResult
yield_({ ..Node
self, TSNode
node: TSNode
child }) {
421 IterResult
IterEnd => return IterResult
IterEnd
422 IterResult
IterContinue => continue
423 }
424 }
425 IterResult
IterContinue
426 })
427}
428
429///|
430/// Get the node's child with the given field name.
431#borrow(self, tree, name)
432extern "c" fn ts_node_child_by_field_name(
433 self : type TSNode Bytes
TSNode,
434 tree : type TSTree
TSTree,
435 name : Bytes
Bytes
436) -> type TSNode Bytes
TSNode = "moonbit_ts_node_child_by_field_name"
437
438///|
439/// Get the node's child with the given field name.
440pub 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? {
441 let Bytes
name_bytes = (encoding~ : @encoding.Encoding, string : @string.StringView) -> Bytes
Encode a given string to the specified character encoding and returns the resulting bytes.
Parameters
encoding : The target encoding format.
src: The input string to be encoded.
Returns
A bytes representing the encoded string in the selected format.
Examples
let src = "Hello, World!"
let encoded_bytes = encode(UTF8, src)
@encoding.encode(@encoding.Encoding
encoding=@encoding.Encoding
UTF8, @string.StringView
name)
442 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.TSNode
node, Node
self.TSTree
tree, Bytes
name_bytes)
443 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
child, Node
self.TSTree
tree) {
444 Node?
None
445 } else {
446 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
child })
447 }
448}
449
450///|
451#borrow(self, tree)
452extern "c" fn ts_node_child_by_field_id(
453 self : type TSNode Bytes
TSNode,
454 tree : type TSTree
TSTree,
455 id : type FieldId UInt16
FieldId
456) -> type TSNode Bytes
TSNode = "moonbit_ts_node_child_by_field_id"
457
458///|
459/// Get the node's child with the given numerical field id.
460///
461/// You can convert a field name to an id using the
462/// `Language::field_id_for_name` function.
463pub 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? {
464 let TSNode
child = (self : TSNode, tree : TSTree, id : FieldId) -> TSNode
ts_node_child_by_field_id(Node
self.TSNode
node, Node
self.TSTree
tree, FieldId
id)
465 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
child, Node
self.TSTree
tree) {
466 Node?
None
467 } else {
468 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
child })
469 }
470}
471
472///|
473#borrow(self, tree)
474extern "c" fn ts_node_next_sibling(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> type TSNode Bytes
TSNode = "moonbit_ts_node_next_sibling"
475
476///|
477/// Get the node's next sibling.
478pub 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? {
479 let TSNode
next_sibling = (self : TSNode, tree : TSTree) -> TSNode
ts_node_next_sibling(Node
self.TSNode
node, Node
self.TSTree
tree)
480 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
next_sibling, Node
self.TSTree
tree) {
481 Node?
None
482 } else {
483 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
next_sibling })
484 }
485}
486
487///|
488#borrow(self, tree)
489extern "c" fn ts_node_prev_sibling(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> type TSNode Bytes
TSNode = "moonbit_ts_node_prev_sibling"
490
491///|
492/// Get the node's previous sibling.
493pub 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? {
494 let TSNode
prev_sibling = (self : TSNode, tree : TSTree) -> TSNode
ts_node_prev_sibling(Node
self.TSNode
node, Node
self.TSTree
tree)
495 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
prev_sibling, Node
self.TSTree
tree) {
496 Node?
None
497 } else {
498 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
prev_sibling })
499 }
500}
501
502///|
503#borrow(self, tree)
504extern "c" fn ts_node_next_named_sibling(
505 self : type TSNode Bytes
TSNode,
506 tree : type TSTree
TSTree
507) -> type TSNode Bytes
TSNode = "moonbit_ts_node_next_named_sibling"
508
509///|
510/// Get the node's next *named* sibling.
511pub 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? {
512 let TSNode
next_named_sibling = (self : TSNode, tree : TSTree) -> TSNode
ts_node_next_named_sibling(Node
self.TSNode
node, Node
self.TSTree
tree)
513 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
next_named_sibling, Node
self.TSTree
tree) {
514 Node?
None
515 } else {
516 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
next_named_sibling })
517 }
518}
519
520///|
521#borrow(self, tree)
522extern "c" fn ts_node_prev_named_sibling(
523 self : type TSNode Bytes
TSNode,
524 tree : type TSTree
TSTree
525) -> type TSNode Bytes
TSNode = "moonbit_ts_node_prev_named_sibling"
526
527///|
528/// Get the node's previous *named* sibling.
529pub 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? {
530 let TSNode
prev_named_sibling = (self : TSNode, tree : TSTree) -> TSNode
ts_node_prev_named_sibling(Node
self.TSNode
node, Node
self.TSTree
tree)
531 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
prev_named_sibling, Node
self.TSTree
tree) {
532 Node?
None
533 } else {
534 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
prev_named_sibling })
535 }
536}
537
538///|
539#borrow(self, tree)
540extern "c" fn ts_node_first_child_for_byte(
541 self : type TSNode Bytes
TSNode,
542 tree : type TSTree
TSTree,
543 byte : UInt
UInt
544) -> type TSNode Bytes
TSNode = "moonbit_ts_node_first_child_for_byte"
545
546///|
547/// Get the node's first child that contains or starts after the given byte offset.
548pub 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? {
549 let UInt
byte = (value : Int) -> UInt
int_to_uint(Int
byte)
550 let TSNode
child = (self : TSNode, tree : TSTree, byte : UInt) -> TSNode
ts_node_first_child_for_byte(Node
self.TSNode
node, Node
self.TSTree
tree, UInt
byte)
551 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
child, Node
self.TSTree
tree) {
552 Node?
None
553 } else {
554 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
child })
555 }
556}
557
558///|
559#borrow(self, tree)
560extern "c" fn ts_node_first_named_child_for_byte(
561 self : type TSNode Bytes
TSNode,
562 tree : type TSTree
TSTree,
563 byte : UInt
UInt
564) -> type TSNode Bytes
TSNode = "moonbit_ts_node_first_named_child_for_byte"
565
566///|
567/// Get the node's first named child that contains or starts after the given byte offset.
568pub 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? {
569 let UInt
byte = (value : Int) -> UInt
int_to_uint(Int
byte)
570 let TSNode
child = (self : TSNode, tree : TSTree, byte : UInt) -> TSNode
ts_node_first_named_child_for_byte(Node
self.TSNode
node, Node
self.TSTree
tree, UInt
byte)
571 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
child, Node
self.TSTree
tree) {
572 Node?
None
573 } else {
574 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
child })
575 }
576}
577
578///|
579#borrow(self, tree)
580extern "c" fn ts_node_descendant_count(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> Int
Int = "moonbit_ts_node_descendant_count"
581
582///|
583/// Get the node's number of descendants, including one for the node itself.
584pub 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 {
585 return (self : TSNode, tree : TSTree) -> Int
ts_node_descendant_count(Node
self.TSNode
node, Node
self.TSTree
tree)
586}
587
588///|
589#borrow(self, tree)
590extern "c" fn ts_node_descendant_for_byte_range(
591 self : type TSNode Bytes
TSNode,
592 tree : type TSTree
TSTree,
593 start_byte : UInt
UInt,
594 end_byte : UInt
UInt
595) -> type TSNode Bytes
TSNode = "moonbit_ts_node_descendant_for_byte_range"
596
597///|
598/// Get the smallest node within this node that spans the given range of bytes.
599pub 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(
600 Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node,
601 Int
start_byte : Int
Int,
602 Int
end_byte : Int
Int
603) -> struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node? {
604 let UInt
start_byte = (value : Int) -> UInt
int_to_uint(Int
start_byte)
605 let UInt
end_byte = (value : Int) -> UInt
int_to_uint(Int
end_byte)
606 let TSNode
descendant = (self : TSNode, tree : TSTree, start_byte : UInt, end_byte : UInt) -> TSNode
ts_node_descendant_for_byte_range(
607 Node
self.TSNode
node,
608 Node
self.TSTree
tree,
609 UInt
start_byte,
610 UInt
end_byte,
611 )
612 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
descendant, Node
self.TSTree
tree) {
613 Node?
None
614 } else {
615 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
descendant })
616 }
617}
618
619///|
620#borrow(self, tree, start_point, end_point)
621extern "c" fn ts_node_descendant_for_point_range(
622 self : type TSNode Bytes
TSNode,
623 tree : type TSTree
TSTree,
624 start_point : type Point
Point,
625 end_point : type Point
Point
626) -> type TSNode Bytes
TSNode = "moonbit_ts_node_descendant_for_point_range"
627
628///|
629/// Get the smallest node within this node that spans the given range of
630/// (row, column) positions.
631pub 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(
632 Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node,
633 Point
start_point : type Point
Point,
634 Point
end_point : type Point
Point
635) -> struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node? {
636 let TSNode
descendant = (self : TSNode, tree : TSTree, start_point : Point, end_point : Point) -> TSNode
ts_node_descendant_for_point_range(
637 Node
self.TSNode
node,
638 Node
self.TSTree
tree,
639 Point
start_point,
640 Point
end_point,
641 )
642 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
descendant, Node
self.TSTree
tree) {
643 Node?
None
644 } else {
645 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
descendant })
646 }
647}
648
649///|
650#borrow(self, tree)
651extern "c" fn ts_node_named_descendant_for_byte_range(
652 self : type TSNode Bytes
TSNode,
653 tree : type TSTree
TSTree,
654 start_byte : UInt
UInt,
655 end_byte : UInt
UInt
656) -> type TSNode Bytes
TSNode = "moonbit_ts_node_named_descendant_for_byte_range"
657
658///|
659/// Get the smallest named node within this node that spans the given range of
660/// bytes.
661pub 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(
662 Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node,
663 Int
start_byte : Int
Int,
664 Int
end_byte : Int
Int
665) -> struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node? {
666 let UInt
start_byte = (value : Int) -> UInt
int_to_uint(Int
start_byte)
667 let UInt
end_byte = (value : Int) -> UInt
int_to_uint(Int
end_byte)
668 let TSNode
descendant = (self : TSNode, tree : TSTree, start_byte : UInt, end_byte : UInt) -> TSNode
ts_node_named_descendant_for_byte_range(
669 Node
self.TSNode
node,
670 Node
self.TSTree
tree,
671 UInt
start_byte,
672 UInt
end_byte,
673 )
674 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
descendant, Node
self.TSTree
tree) {
675 Node?
None
676 } else {
677 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
descendant })
678 }
679}
680
681///|
682#borrow(self, tree, start_point, end_point)
683extern "c" fn ts_node_named_descendant_for_point_range(
684 self : type TSNode Bytes
TSNode,
685 tree : type TSTree
TSTree,
686 start_point : type Point
Point,
687 end_point : type Point
Point
688) -> type TSNode Bytes
TSNode = "moonbit_ts_node_named_descendant_for_point_range"
689
690///|
691/// Get the smallest named node within this node that spans the given
692/// (row, column) positions.
693pub 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(
694 Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node,
695 Point
start_point : type Point
Point,
696 Point
end_point : type Point
Point
697) -> struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node? {
698 let TSNode
descendant = (self : TSNode, tree : TSTree, start_point : Point, end_point : Point) -> TSNode
ts_node_named_descendant_for_point_range(
699 Node
self.TSNode
node,
700 Node
self.TSTree
tree,
701 Point
start_point,
702 Point
end_point,
703 )
704 if (self : TSNode, tree : TSTree) -> Bool
ts_node_is_null(TSNode
descendant, Node
self.TSTree
tree) {
705 Node?
None
706 } else {
707 (Node) -> Node?
Some({ ..Node
self, TSNode
node: TSNode
descendant })
708 }
709}
710
711///|
712#borrow(self, tree, edit)
713extern "c" fn ts_node_edit(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree, edit : type InputEdit FixedArray[UInt]
InputEdit) = "moonbit_ts_node_edit"
714
715///|
716/// Edit the node to keep it in-sync with source code that has been edited.
717///
718/// This function is only rarely needed. When you edit a syntax tree with the
719/// `Tree::edit` function, all of the nodes that you retrieve from the tree
720/// afterward will already reflect the edit. You only need to use `Node::edit`
721/// when you have a `Node` instance that you want to keep and continue to use
722/// after an edit.
723pub 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 {
724 (self : TSNode, tree : TSTree, edit : InputEdit) -> Unit
ts_node_edit(Node
self.TSNode
node, Node
self.TSTree
tree, InputEdit
edit)
725}
726
727///|
728#borrow(self, self_tree, other, other_tree)
729extern "c" fn ts_node_eq(
730 self : type TSNode Bytes
TSNode,
731 self_tree : type TSTree
TSTree,
732 other : type TSNode Bytes
TSNode,
733 other_tree : type TSTree
TSTree
734) -> Bool
Bool = "moonbit_ts_node_eq"
735
736///|
737/// Check if two nodes are identical.
738pub 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 {
739 (self : TSNode, self_tree : TSTree, other : TSNode, other_tree : TSTree) -> Bool
ts_node_eq(Node
self.TSNode
node, Node
self.TSTree
tree, Node
other.TSNode
node, Node
other.TSTree
tree)
740}
741
742///|
743pub 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 {
744 (self : TSNode, self_tree : TSTree, other : TSNode, other_tree : TSTree) -> Bool
ts_node_eq(Node
self.TSNode
node, Node
self.TSTree
tree, Node
other.TSNode
node, Node
other.TSTree
tree)
745}
746
747///|
748pub 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 {
749 {
750 "node": Node
self.(self : Node) -> @string.StringView
Get an S-expression representing the node as a string.
string().(self : @string.StringView) -> Json
to_json(),
751 "text": Node
self.(self : Node) -> @string.StringView
text().(self : @string.StringView) -> Json
to_json(),
752 "range": {
753 "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(),
754 "end": Node
self.(self : Node) -> Point
end_point().(self : Point) -> Json
to_json(),
755 },
756 }
757}
758
759///|
760#borrow(self)
761extern "c" fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::id_as_uint64(self : type TSNode Bytes
TSNode, tree : type TSTree
TSTree) -> UInt64
UInt64 = "moonbit_ts_node_id_as_uint64"
762
763///|
764pub 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) {
765 let UInt64
id = struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : TSNode, tree : TSTree) -> UInt64
id_as_uint64(Node
self.TSNode
node, Node
self.TSTree
tree)
766 Hasher
hasher.(self : Hasher, value : UInt64) -> 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(UInt64
id)
767}
768
769///|
770pub fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : Node) -> TreeCursor
walk(Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node) -> struct TreeCursor {
cursor: TSTreeCursor
tree: TSTree
text: @string.StringView
}
TreeCursor {
771 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
self)
772}
773
774///|
775pub fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : Node, source : @string.StringView) -> QueryCursor!QueryError
query(
776 Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node,
777 @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
778) -> struct QueryCursor {
mut query: Query?
mut node: Node?
}
QueryCursor!type! QueryError {
Syntax(UInt)
NodeType(UInt)
Field(UInt)
Capture(UInt)
Structure(UInt)
Language(UInt)
}
QueryError {
779 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)
780 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:
- 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.
- 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()
781 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)
782 return QueryCursor
query_cursor
783}
784
785///|
786pub 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 {
787 let Int
start = Node
self.(self : Node) -> Int
Get the node's start byte.
start_byte()
788 let Int
end = Node
self.(self : Node) -> Int
Get the node's end byte.
end_byte()
789 let @string.StringView
text = Node
self.@string.StringView
text.(self : @string.StringView, start_offset~ : Int, end_offset~ : Int) -> @string.StringView
Returns a new view of the view with the given start and end offsets.
view(Int
start_offset=Int
start, Int
end_offset=Int
end)
790 return @string.StringView
text
791}
792
793///|
794pub fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : Node) -> Iter[Symbol]
symbols(Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node) -> type Iter[T]
Iter[type Symbol UInt
Symbol] {
795 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(Node
self.(self : Node) -> Language
Get the node's language.
language(), Node
self.(self : Node) -> StateId
Get this node's parse state.
parse_state())
796 guard LookaheadIterator?
iterator is (LookaheadIterator) -> LookaheadIterator?
Some(LookaheadIterator
iterator) else { type Iter[T]
Iter::() -> Iter[Symbol]
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() }
797 type Iter[T]
Iter::(((Symbol) -> IterResult) -> IterResult) -> Iter[Symbol]
Do not use this method, it is for internal use only.
new(fn((Symbol) -> IterResult
yield_) {
798 while LookaheadIterator
iterator.(self : LookaheadIterator) -> Bool
Advance the lookahead iterator to the next symbol.
This returns true if there is a new symbol and false otherwise.
next() {
799 let Symbol
symbol = LookaheadIterator
iterator.(self : LookaheadIterator) -> Symbol
Get the current symbol of the lookahead iterator.
current_symbol()
800 match (Symbol) -> IterResult
yield_(Symbol
symbol) {
801 IterResult
IterEnd => break IterResult
IterEnd
802 IterResult
IterContinue => continue
803 }
804 } else {
805 IterResult
IterContinue
806 }
807 })
808}
809
810///|
811pub 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] {
812 let Language
language = Node
self.(self : Node) -> Language
Get the node's language.
language()
813 type Iter[T]
Iter::(((String) -> IterResult) -> IterResult) -> Iter[String]
Do not use this method, it is for internal use only.
new(fn((String) -> IterResult
yield_) {
814 for Symbol
symbol in Node
self.(self : Node) -> Iter[Symbol]
symbols() {
815 guard Language
language.(self : Language, symbol : Symbol) -> @string.StringView?
Get a node type string for the given numerical id.
symbol_name(Symbol
symbol) is (@string.StringView) -> @string.StringView?
Some(@string.StringView
name) else { continue }
816 match (String) -> IterResult
yield_(@string.StringView
name) {
817 IterResult
IterContinue => continue
818 IterResult
IterEnd => break IterResult
IterEnd
819 }
820 } else {
821 IterResult
IterContinue
822 }
823 })
824}
825
826///|
827pub fn struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node::(self : Node) -> Iter[Symbol]
next_symbols(Node
self : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node) -> type Iter[T]
Iter[type Symbol UInt
Symbol] {
828 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(
829 Node
self.(self : Node) -> Language
Get the node's language.
language(),
830 Node
self.(self : Node) -> StateId
Get the parse state after this node.
next_parse_state(),
831 )
832 guard LookaheadIterator?
iterator is (LookaheadIterator) -> LookaheadIterator?
Some(LookaheadIterator
iterator) else { type Iter[T]
Iter::() -> Iter[Symbol]
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() }
833 type Iter[T]
Iter::(((Symbol) -> IterResult) -> IterResult) -> Iter[Symbol]
Do not use this method, it is for internal use only.
new(fn((Symbol) -> IterResult
yield_) {
834 while LookaheadIterator
iterator.(self : LookaheadIterator) -> Bool
Advance the lookahead iterator to the next symbol.
This returns true if there is a new symbol and false otherwise.
next() {
835 let Symbol
symbol = LookaheadIterator
iterator.(self : LookaheadIterator) -> Symbol
Get the current symbol of the lookahead iterator.
current_symbol()
836 match (Symbol) -> IterResult
yield_(Symbol
symbol) {
837 IterResult
IterEnd => break IterResult
IterEnd
838 IterResult
IterContinue => continue
839 }
840 } else {
841 IterResult
IterContinue
842 }
843 })
844}
845
846///|
847pub 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] {
848 let Language
language = Node
self.(self : Node) -> Language
Get the node's language.
language()
849 type Iter[T]
Iter::(((String) -> IterResult) -> IterResult) -> Iter[String]
Do not use this method, it is for internal use only.
new(fn((String) -> IterResult
yield_) {
850 for Symbol
symbol in Node
self.(self : Node) -> Iter[Symbol]
next_symbols() {
851 guard Language
language.(self : Language, symbol : Symbol) -> @string.StringView?
Get a node type string for the given numerical id.
symbol_name(Symbol
symbol) is (@string.StringView) -> @string.StringView?
Some(@string.StringView
name) else { continue }
852 match (String) -> IterResult
yield_(@string.StringView
name) {
853 IterResult
IterContinue => continue
854 IterResult
IterEnd => break IterResult
IterEnd
855 }
856 } else {
857 IterResult
IterContinue
858 }
859 })
860}
861