1///|
2fn async_suspend[T](f : ((type parameter T
T) -> Unit
Unit) -> Unit
Unit) -> type parameter T
T = "%async.suspend"
3
4///|
5type Language
6
7///|
8extern "js" fn ts_language_load_bytes(
9 ts : type TS
TS,
10 bytes : Bytes
Bytes,
11 resolve : (type Language @tree_sitter_language.Language
Language) -> Unit
Unit
12) -> Unit
Unit =
13 #|(ts, bytes, resolve) => {
14 #| console.log("ts", ts);
15 #| return ts.Language.load(bytes).then(resolve);
16 #|}
17
18///|
19pub async fn type Language @tree_sitter_language.Language
Language::(bytes : Bytes) -> Language!Async
load(Bytes
bytes : Bytes
Bytes) -> type Language @tree_sitter_language.Language
Language!Async {
20 (f : ((Language) -> Unit) -> Unit) -> Language
async_suspend(fn((Language) -> Unit
resolve) { (ts : TS, bytes : Bytes, resolve : (Language) -> Unit) -> Unit
ts_language_load_bytes(TS
ts, Bytes
bytes, (Language) -> Unit
resolve) })
21}
22
23///|
24extern "js" fn ts_language_is_null(language : type Language @tree_sitter_language.Language
Language) -> Bool
Bool =
25 #|(language) => {
26 #| return language == null || language == undefined;
27 #|}
28
29///|
30impl trait Nullable {
is_null(Self) -> Bool
to_option(Self) -> Self?
}
Nullable for type Language @tree_sitter_language.Language
Language with (self : Language) -> Bool
is_null(Language
self : type Language @tree_sitter_language.Language
Language) -> Bool
Bool {
31 (language : Language) -> Bool
ts_language_is_null(Language
self)
32}
33
34///|
35extern "js" fn ts_language_symbol_count(self : type Language @tree_sitter_language.Language
Language) -> UInt
UInt =
36 #|(language) => {
37 #| return language.nodeTypeCount;
38 #|}
39
40///|
41/// Get the number of distinct node types in the language.
42pub fn type Language @tree_sitter_language.Language
Language::(self : Language) -> Int
Get the number of distinct node types in the language.
symbol_count(Language
self : type Language @tree_sitter_language.Language
Language) -> Int
Int {
43 (value : UInt) -> Int
uint_to_int((self : Language) -> UInt
ts_language_symbol_count(Language
self))
44}
45
46///|
47extern "js" fn ts_language_state_count(self : type Language @tree_sitter_language.Language
Language) -> UInt
UInt =
48 #|(language) => {
49 #| return language.stateCount;
50 #|}
51
52///|
53/// Get the number of valid states in this language.
54pub fn type Language @tree_sitter_language.Language
Language::(self : Language) -> Int
Get the number of valid states in this language.
state_count(Language
self : type Language @tree_sitter_language.Language
Language) -> Int
Int {
55 (value : UInt) -> Int
uint_to_int((self : Language) -> UInt
ts_language_state_count(Language
self))
56}
57
58///|
59type Symbol UInt derive(Eq)
60
61///|
62/// Get the numerical id for the given node type string.
63extern "js" fn ts_language_symbol_for_name_(
64 self : type Language @tree_sitter_language.Language
Language,
65 name : Bytes
Bytes
66) -> UInt16
UInt16 =
67 #|(language, name) => {
68 #| return language.idForNodeType(name, true) || language.idForNodeType(name, false);
69 #|}
70
71///|
72/// Get the numerical id for the given node type string.
73pub fn type Language @tree_sitter_language.Language
Language::(self : Language, name : @string.StringView) -> Symbol?
Get the numerical id for the given node type string.
symbol_for_name(
74 Language
self : type Language @tree_sitter_language.Language
Language,
75 @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
76) -> type Symbol UInt
Symbol? {
77 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)
78 let UInt16
symbol = (self : Language, name : Bytes) -> UInt16
Get the numerical id for the given node type string.
ts_language_symbol_for_name_(Language
self, Bytes
name_bytes)
79 if UInt16
symbol (self : UInt16, that : UInt16) -> Bool
== 0 {
80 return Symbol?
None
81 } else {
82 return (Symbol) -> Symbol?
Some(UInt16
symbol.(self : UInt16) -> Int
Converts an unsigned 16-bit integer to a 32-bit signed integer. The value is
zero-extended to fill the higher bits.
Parameters:
value : The unsigned 16-bit integer to be converted.
Returns a 32-bit signed integer. Since the input value is always non-negative
and less than 65536, the conversion never results in overflow.
Example:
test "UInt16::to_int" {
let x = Int::to_uint16(42)
inspect!(x.to_int(), content="42")
let max = Int::to_uint16(65535) // maximum value of UInt16
inspect!(max.to_int(), content="65535")
}
to_int().(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())
83 }
84}
85
86///|
87type FieldId UInt16
88
89///|
90extern "js" fn ts_language_field_count(self : type Language @tree_sitter_language.Language
Language) -> Int
Int =
91 #|(language) => {
92 #| return language.fieldCount;
93 #|}
94
95///|
96/// Get the number of distinct field names in the language.
97pub fn type Language @tree_sitter_language.Language
Language::(self : Language) -> Int
Get the number of distinct field names in the language.
field_count(Language
self : type Language @tree_sitter_language.Language
Language) -> Int
Int {
98 (self : Language) -> Int
ts_language_field_count(Language
self)
99}
100
101///|
102extern "js" fn js_string_is_null(string : String
String) -> Bool
Bool =
103 #|(string) => {
104 #| return string == null || string == undefined;
105 #|}
106
107///|
108impl trait Nullable {
is_null(Self) -> Bool
to_option(Self) -> Self?
}
Nullable for String
String with (self : String) -> Bool
is_null(String
self : String
String) -> Bool
Bool {
109 (string : String) -> Bool
js_string_is_null(String
self)
110}
111
112///|
113extern "js" fn ts_language_field_name_for_id(
114 self : type Language @tree_sitter_language.Language
Language,
115 id : type FieldId UInt16
FieldId
116) -> String
String =
117 #|(language, id) => {
118 #| return language.fieldNameForId(id);
119 #|}
120
121///|
122/// Get the field name string for the given numerical id.
123pub fn type Language @tree_sitter_language.Language
Language::(self : Language, id : FieldId) -> @string.StringView?
Get the field name string for the given numerical id.
field_name_for_id(
124 Language
self : type Language @tree_sitter_language.Language
Language,
125 FieldId
id : type FieldId UInt16
FieldId
126) -> 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? {
127 if (self : Language, id : FieldId) -> ?
ts_language_field_name_for_id(Language
self, FieldId
id).() -> @string.StringView?
to_option() is (@string.StringView) -> @string.StringView?
Some(@string.StringView
string) {
128 (@string.StringView) -> @string.StringView?
Some(@string.StringView
string)
129 } else {
130 @string.StringView?
None
131 }
132}
133
134///|
135extern "js" fn ts_language_field_id_for_name(
136 self : type Language @tree_sitter_language.Language
Language,
137 name : String
String
138) -> UInt
UInt =
139 #|(language, name) => {
140 #| return language.fieldIdForName(name);
141 #|}
142
143///|
144/// Get the numerical id for the given field name string.
145pub fn type Language @tree_sitter_language.Language
Language::(self : Language, name : @string.StringView) -> Int
Get the numerical id for the given field name string.
field_id_for_name(Language
self : type Language @tree_sitter_language.Language
Language, @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) -> Int
Int {
146 (self : Language, name : Bytes) -> UInt
ts_language_field_id_for_name(Language
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()) |> (value : UInt) -> Int
uint_to_int()
147}
148
149///|
150extern "js" fn ts_language_supertypes(self : type Language @tree_sitter_language.Language
Language) -> type Array[T]
Array[type Symbol UInt
Symbol] =
151 #|(language) => {
152 #| return language.supertypes;
153 #|}
154
155///|
156/// Get a list of all supertype symbols for the language.
157pub fn type Language @tree_sitter_language.Language
Language::(self : Language) -> Array[Symbol]
Get a list of all supertype symbols for the language.
supertypes(Language
self : type Language @tree_sitter_language.Language
Language) -> type Array[T]
Array[type Symbol UInt
Symbol] {
158 return (self : Language) -> Array[Symbol]
ts_language_supertypes(Language
self)
159}
160
161///|
162extern "js" fn ts_language_subtypes(self : type Language @tree_sitter_language.Language
Language) -> type Array[T]
Array[type Symbol UInt
Symbol] =
163 #|(language) => {
164 #| return language.subtypes;
165 #|}
166
167///|
168/// Get a list of all subtype symbol ids for a given supertype symbol.
169///
170/// See `Language::supertypes` for fetching all supertype symbols.
171pub fn type Language @tree_sitter_language.Language
Language::(self : Language) -> Array[Symbol]
Get a list of all subtype symbol ids for a given supertype symbol.
See Language::supertypes for fetching all supertype symbols.
subtypes(Language
self : type Language @tree_sitter_language.Language
Language) -> type Array[T]
Array[type Symbol UInt
Symbol] {
172 return (self : Language) -> Array[Symbol]
ts_language_subtypes(Language
self)
173}
174
175///|
176extern "js" fn ts_language_symbol_name(
177 self : type Language @tree_sitter_language.Language
Language,
178 symbol : type Symbol UInt
Symbol
179) -> String
String =
180 #|(language, symbol) => {
181 #| return language.nodeTypeForId(symbol);
182 #|}
183
184///|
185/// Get a node type string for the given numerical id.
186pub fn type Language @tree_sitter_language.Language
Language::(self : Language, symbol : Symbol) -> @string.StringView?
Get a node type string for the given numerical id.
symbol_name(Language
self : type Language @tree_sitter_language.Language
Language, Symbol
symbol : type Symbol UInt
Symbol) -> 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? {
187 if (self : Language, symbol : Symbol) -> ?
ts_language_symbol_name(Language
self, Symbol
symbol).() -> @string.StringView?
to_option() is (@string.StringView) -> @string.StringView?
Some(@string.StringView
name) {
188 (@string.StringView) -> @string.StringView?
Some(@string.StringView
name)
189 } else {
190 @string.StringView?
None
191 }
192}
193
194///|
195/// Check whether the given node type id belongs to named nodes, anonymous nodes,
196/// or a hidden nodes.
197enum SymbolType {
198 Regular
199 Anonymous
200 Supertype
201 Auxiliary
202}
203
204///|
205fn enum SymbolType {
Regular
Anonymous
Supertype
Auxiliary
}
Check whether the given node type id belongs to named nodes, anonymous nodes,
or a hidden nodes.
SymbolType::(value : UInt) -> SymbolType
of_int(UInt
value : UInt
UInt) -> enum SymbolType {
Regular
Anonymous
Supertype
Auxiliary
}
Check whether the given node type id belongs to named nodes, anonymous nodes,
or a hidden nodes.
SymbolType {
206 match UInt
value {
207 0 => SymbolType::SymbolType
Regular
208 1 => SymbolType::SymbolType
Anonymous
209 2 => SymbolType::SymbolType
Supertype
210 3 => SymbolType::SymbolType
Auxiliary
211 UInt
value => (msg : String) -> SymbolType
Aborts the program with an error message. Always causes a panic, regardless
of the message provided.
Parameters:
message : A string containing the error message to be displayed when
aborting.
Returns a value of type T. However, this function never actually returns a
value as it always causes a panic.
abort("Invalid SymbolType: \{UInt
value}")
212 }
213}
214
215///|
216fn enum SymbolType {
Regular
Anonymous
Supertype
Auxiliary
}
Check whether the given node type id belongs to named nodes, anonymous nodes,
or a hidden nodes.
SymbolType::(self : SymbolType) -> UInt
to_int(SymbolType
self : enum SymbolType {
Regular
Anonymous
Supertype
Auxiliary
}
Check whether the given node type id belongs to named nodes, anonymous nodes,
or a hidden nodes.
SymbolType) -> UInt
UInt {
217 match SymbolType
self {
218 SymbolType::SymbolType
Regular => 0
219 SymbolType::SymbolType
Anonymous => 1
220 SymbolType::SymbolType
Supertype => 2
221 SymbolType::SymbolType
Auxiliary => 3
222 }
223}
224
225///|
226extern "js" fn ts_language_symbol_is_named(
227 self : type Language @tree_sitter_language.Language
Language,
228 symbol : type Symbol UInt
Symbol
229) -> Bool
Bool =
230 #|(language, symbol) => {
231 #| return language.nodeTypeIsNamed(symbol);
232 #|}
233
234///|
235extern "js" fn ts_language_symbol_is_visible(
236 self : type Language @tree_sitter_language.Language
Language,
237 symbol : type Symbol UInt
Symbol
238) -> Bool
Bool =
239 #|(language, symbol) => {
240 #| return language.nodeTypeIsVisible(symbol);
241 #|}
242
243///|
244/// Check whether the given node type id belongs to named nodes, anonymous nodes,
245/// or a hidden nodes.
246///
247/// See also `Node::is_named`. Hidden nodes are never returned from the API.
248pub fn type Language @tree_sitter_language.Language
Language::(self : Language, symbol : Symbol) -> SymbolType
Check whether the given node type id belongs to named nodes, anonymous nodes,
or a hidden nodes.
See also Node::is_named. Hidden nodes are never returned from the API.
symbol_type(Language
self : type Language @tree_sitter_language.Language
Language, Symbol
symbol : type Symbol UInt
Symbol) -> enum SymbolType {
Regular
Anonymous
Supertype
Auxiliary
}
Check whether the given node type id belongs to named nodes, anonymous nodes,
or a hidden nodes.
SymbolType {
249 let Bool
named = (self : Language, symbol : Symbol) -> Bool
ts_language_symbol_is_named(Language
self, Symbol
symbol)
250 let Bool
visible = (self : Language, symbol : Symbol) -> Bool
ts_language_symbol_is_visible(Language
self, Symbol
symbol)
251 let Array[Symbol]
supertypes = Language
self.(self : Language) -> Array[Symbol]
Get a list of all supertype symbols for the language.
supertypes()
252 if Bool
named (Bool, Bool) -> Bool
&& Bool
visible {
253 return SymbolType::SymbolType
Regular
254 } else if Bool
visible {
255 return SymbolType::SymbolType
Anonymous
256 } else if Array[Symbol]
supertypes.(self : Array[Symbol], value : Symbol) -> Bool
Checks whether the array contains an element equal to the given value.
Parameters:
array : The array to search in.
value : The value to search for.
Returns true if the array contains an element equal to the given value,
false otherwise.
Example:
test "Array::contains" {
let arr = [1, 2, 3, 4, 5]
inspect!(arr.contains(3), content="true")
inspect!(arr.contains(6), content="false")
}
test "Array::contains/empty" {
let arr : Array[Int] = []
inspect!(arr.contains(1), content="false")
}
contains(Symbol
symbol) {
257 return SymbolType::SymbolType
Supertype
258 } else {
259 return SymbolType::SymbolType
Auxiliary
260 }
261}
262
263///|
264extern "js" fn ts_language_version(self : type Language @tree_sitter_language.Language
Language) -> UInt
UInt =
265 #|(language) => {
266 #| return language.version;
267 #|}
268
269///|
270/// Get the ABI version number for this language. This version number is used
271/// to ensure that languages were generated by a compatible version of
272/// Tree-sitter.
273///
274/// See also `Parser::set_language`.
275#deprecated("Use `Language::abi_version` instead")
276pub fn type Language @tree_sitter_language.Language
Language::(self : Language) -> Int
Get the ABI version number for this language. This version number is used
to ensure that languages were generated by a compatible version of
Tree-sitter.
See also Parser::set_language.
version(Language
self : type Language @tree_sitter_language.Language
Language) -> Int
Int {
277 (value : UInt) -> Int
uint_to_int((self : Language) -> UInt
ts_language_version(Language
self))
278}
279
280///|
281extern "js" fn ts_language_abi_version(self : type Language @tree_sitter_language.Language
Language) -> UInt
UInt =
282 #|(language) => {
283 #| return language.abiVersion;
284 #|}
285
286///|
287/// Get the ABI version number for this language. This version number is used
288/// to ensure that languages were generated by a compatible version of
289/// Tree-sitter.
290///
291/// See also `Parser::set_language`.
292pub fn type Language @tree_sitter_language.Language
Language::(self : Language) -> Int
Get the ABI version number for this language. This version number is used
to ensure that languages were generated by a compatible version of
Tree-sitter.
See also Parser::set_language.
abi_version(Language
self : type Language @tree_sitter_language.Language
Language) -> Int
Int {
293 (value : UInt) -> Int
uint_to_int((self : Language) -> UInt
ts_language_abi_version(Language
self))
294}
295
296///|
297/// The metadata associated with a language.
298///
299/// Currently, this metadata can be used to check the [Semantic Version](https://semver.org/)
300/// of the language. This version information should be used to signal if a given parser might
301/// be incompatible with existing queries when upgrading between major versions, or minor versions
302/// if it's in zerover.
303type LanguageMetadata
304
305///|
306pub extern "js" fn type LanguageMetadata Bytes
The metadata associated with a language.
Currently, this metadata can be used to check the Semantic Version
of the language. This version information should be used to signal if a given parser might
be incompatible with existing queries when upgrading between major versions, or minor versions
if it's in zerover.
LanguageMetadata::major_version(
307 self : type LanguageMetadata Bytes
The metadata associated with a language.
Currently, this metadata can be used to check the Semantic Version
of the language. This version information should be used to signal if a given parser might
be incompatible with existing queries when upgrading between major versions, or minor versions
if it's in zerover.
LanguageMetadata
308) -> Byte
Byte =
309 #|(metadata) => {
310 #| return metadata.major_version;
311 #|}
312
313///|
314pub extern "js" fn type LanguageMetadata Bytes
The metadata associated with a language.
Currently, this metadata can be used to check the Semantic Version
of the language. This version information should be used to signal if a given parser might
be incompatible with existing queries when upgrading between major versions, or minor versions
if it's in zerover.
LanguageMetadata::minor_version(
315 self : type LanguageMetadata Bytes
The metadata associated with a language.
Currently, this metadata can be used to check the Semantic Version
of the language. This version information should be used to signal if a given parser might
be incompatible with existing queries when upgrading between major versions, or minor versions
if it's in zerover.
LanguageMetadata
316) -> Byte
Byte =
317 #|(metadata) => {
318 #| return metadata.minor_version;
319 #|}
320
321///|
322pub extern "js" fn type LanguageMetadata Bytes
The metadata associated with a language.
Currently, this metadata can be used to check the Semantic Version
of the language. This version information should be used to signal if a given parser might
be incompatible with existing queries when upgrading between major versions, or minor versions
if it's in zerover.
LanguageMetadata::patch_version(
323 self : type LanguageMetadata Bytes
The metadata associated with a language.
Currently, this metadata can be used to check the Semantic Version
of the language. This version information should be used to signal if a given parser might
be incompatible with existing queries when upgrading between major versions, or minor versions
if it's in zerover.
LanguageMetadata
324) -> Byte
Byte =
325 #|(metadata) => {
326 #| return metadata.patch_version;
327 #|}
328
329///|
330extern "js" fn ts_language_metadata(self : type Language @tree_sitter_language.Language
Language) -> type LanguageMetadata Bytes
The metadata associated with a language.
Currently, this metadata can be used to check the Semantic Version
of the language. This version information should be used to signal if a given parser might
be incompatible with existing queries when upgrading between major versions, or minor versions
if it's in zerover.
LanguageMetadata =
331 #|(language) => {
332 #| return language.metadata;
333 #|}
334
335///|
336/// Get the metadata for this language. This information is generated by the
337/// CLI, and relies on the language author providing the correct metadata in
338/// the language's `tree-sitter.json` file.
339///
340/// See also `LanguageMetadata`.
341pub fn type Language @tree_sitter_language.Language
Language::(self : Language) -> LanguageMetadata
Get the metadata for this language. This information is generated by the
CLI, and relies on the language author providing the correct metadata in
the language's tree-sitter.json file.
See also LanguageMetadata.
metadata(Language
self : type Language @tree_sitter_language.Language
Language) -> type LanguageMetadata Bytes
The metadata associated with a language.
Currently, this metadata can be used to check the Semantic Version
of the language. This version information should be used to signal if a given parser might
be incompatible with existing queries when upgrading between major versions, or minor versions
if it's in zerover.
LanguageMetadata {
342 return (self : Language) -> LanguageMetadata
ts_language_metadata(Language
self)
343}
344
345///|
346type StateId UInt16
347
348///|
349extern "js" fn ts_language_next_state(
350 self : type Language @tree_sitter_language.Language
Language,
351 state : type StateId UInt16
StateId,
352 symbol : type Symbol UInt
Symbol
353) -> type StateId UInt16
StateId =
354 #|(language, state, symbol) => {
355 #| return language.nextState(state, symbol);
356 #|}
357
358///|
359/// Get the next parse state. Combine this with lookahead iterators to generate
360/// completion suggestions or valid symbols in error nodes. Use
361/// `Node::grammar_symbol` for valid symbols.
362pub fn type Language @tree_sitter_language.Language
Language::(self : Language, state : StateId, symbol : Symbol) -> StateId
Get the next parse state. Combine this with lookahead iterators to generate
completion suggestions or valid symbols in error nodes. Use
Node::grammar_symbol for valid symbols.
next_state(
363 Language
self : type Language @tree_sitter_language.Language
Language,
364 StateId
state : type StateId UInt16
StateId,
365 Symbol
symbol : type Symbol UInt
Symbol
366) -> type StateId UInt16
StateId {
367 return (self : Language, state : StateId, symbol : Symbol) -> StateId
ts_language_next_state(Language
self, StateId
state, Symbol
symbol)
368}
369
370///|
371extern "js" fn ts_language_name(self : type Language @tree_sitter_language.Language
Language) -> String
String =
372 #|(language) => {
373 #| return language.name;
374 #|}
375
376///|
377/// Get the name of this language. This returns `None` in older parsers.
378pub fn type Language @tree_sitter_language.Language
Language::(self : Language) -> @string.StringView?
Get the name of this language. This returns None in older parsers.
name(Language
self : type Language @tree_sitter_language.Language
Language) -> 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? {
379 if (self : Language) -> ?
ts_language_name(Language
self).() -> @string.StringView?
to_option() is (@string.StringView) -> @string.StringView?
Some(@string.StringView
name) {
380 (@string.StringView) -> @string.StringView?
Some(@string.StringView
name)
381 } else {
382 @string.StringView?
None
383 }
384}
385