1///|
2type Query
3
4///|
5extern "js" fn type Query
Query::null() -> type Query
Query =
6 #|() => {
7 #| return null;
8 #|}
9
10///|
11type! QueryError {
12 Syntax(UInt)
13 NodeType(UInt)
14 Field(UInt)
15 Capture(UInt)
16 Structure(UInt)
17 Language(UInt)
18} derive(Show)
19
20///|
21fn type! QueryError {
Syntax(UInt)
NodeType(UInt)
Field(UInt)
Capture(UInt)
Structure(UInt)
Language(UInt)
}
QueryError::(self : QueryError) -> UInt
offset(QueryError
self : type! QueryError {
Syntax(UInt)
NodeType(UInt)
Field(UInt)
Capture(UInt)
Structure(UInt)
Language(UInt)
}
QueryError) -> UInt
UInt {
22 match QueryError
self {
23 QueryError::(UInt) -> QueryError
Syntax(UInt
offset) => UInt
offset
24 QueryError::(UInt) -> QueryError
NodeType(UInt
offset) => UInt
offset
25 QueryError::(UInt) -> QueryError
Field(UInt
offset) => UInt
offset
26 QueryError::(UInt) -> QueryError
Capture(UInt
offset) => UInt
offset
27 QueryError::(UInt) -> QueryError
Structure(UInt
offset) => UInt
offset
28 QueryError::(UInt) -> QueryError
Language(UInt
offset) => UInt
offset
29 }
30}
31
32///|
33fn type! QueryError {
Syntax(UInt)
NodeType(UInt)
Field(UInt)
Capture(UInt)
Structure(UInt)
Language(UInt)
}
QueryError::(offset : UInt, type_ : UInt) -> QueryError
from(UInt
offset : UInt
UInt, UInt
type_ : UInt
UInt) -> type! QueryError {
Syntax(UInt)
NodeType(UInt)
Field(UInt)
Capture(UInt)
Structure(UInt)
Language(UInt)
}
QueryError {
34 match UInt
type_ {
35 1 => QueryError::(UInt) -> QueryError
Syntax(UInt
offset)
36 2 => QueryError::(UInt) -> QueryError
NodeType(UInt
offset)
37 3 => QueryError::(UInt) -> QueryError
Field(UInt
offset)
38 4 => QueryError::(UInt) -> QueryError
Capture(UInt
offset)
39 5 => QueryError::(UInt) -> QueryError
Structure(UInt
offset)
40 6 => QueryError::(UInt) -> QueryError
Language(UInt
offset)
41 UInt
type_ => (msg : String) -> QueryError
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 QueryError type: \{UInt
type_}")
42 }
43}
44
45///|
46extern "js" fn ts_query_new(
47 ts : type TS
TS,
48 language : type Language @tree_sitter_language.Language
Language,
49 source : String
String,
50 error : type FixedArray[A]
FixedArray[UInt
UInt]
51) -> type Query
Query =
52 #|(ts, language, source, error) => {
53 #| try {
54 #| const query = new ts.Query(language, source);
55 #| error[1] = 0;
56 #| return query;
57 #| } catch (queryError) {
58 #| error[0] = queryError.index;
59 #| error[1] = queryError.type;
60 #| return null;
61 #| }
62 #|}
63
64///|
65/// Create a new query from a string containing one or more S-expression
66/// patterns. The query is associated with a particular language, and can
67/// only be run on syntax nodes parsed with that language.
68///
69/// If all of the given patterns are valid, this returns a `Query`.
70/// If a pattern is invalid, this raises a `QueryError`.
71pub fn 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(
72 Language
language : type Language @tree_sitter_language.Language
Language,
73 @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
74) -> type Query
Query!type! QueryError {
Syntax(UInt)
NodeType(UInt)
Field(UInt)
Capture(UInt)
Structure(UInt)
Language(UInt)
}
QueryError {
75 let FixedArray[UInt]
error = type FixedArray[A]
FixedArray::(len : Int, init : UInt) -> FixedArray[UInt]
Creates a new fixed-size array with the specified length, initializing all
elements with the given value.
Parameters:
length : The length of the array to create. Must be non-negative.
initial_value : The value used to initialize all elements in the array.
Returns a new fixed-size array of type FixedArray[T] with length
elements, where each element is initialized to initial_value.
Throws a panic if length is negative.
Example:
test "FixedArray::make" {
let arr = FixedArray::make(3, 42)
inspect!(arr[0], content="42")
inspect!(arr.length(), content="3")
}
test "panic FixedArray::make/negative_length" {
ignore(FixedArray::make(-1, 0))
}
WARNING: A common pitfall is creating with the same initial value, for example:
test {
let two_dimension_array = FixedArray::make(10, FixedArray::make(10, 0))
two_dimension_array[0][5] = 10
assert_eq!(two_dimension_array[5][5], 10)
}
This is because all the cells reference to the same object (the FixedArray[Int] in this case).
One should use makei() instead which creates an object for each index.
make(2, 0U)
76 let Query
query = (ts : TS, language : Language, source : String, error : FixedArray[UInt]) -> Query
ts_query_new(TS
ts, Language
language, @string.StringView
source.(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(), FixedArray[UInt]
error)
77 if FixedArray[UInt]
error[1] (self : UInt, other : UInt) -> Bool
Compares two unsigned 32-bit integers for equality.
Parameters:
self : The first unsigned integer operand.
other : The second unsigned integer operand to compare with.
Returns true if both integers have the same value, false otherwise.
Example:
test "UInt::op_equal" {
let a = 42U
let b = 42U
let c = 24U
inspect!(a == b, content="true")
inspect!(a == c, content="false")
}
== 0 {
78 Query
query
79 } else {
80 raise type! QueryError {
Syntax(UInt)
NodeType(UInt)
Field(UInt)
Capture(UInt)
Structure(UInt)
Language(UInt)
}
QueryError::(offset : UInt, type_ : UInt) -> QueryError
from(FixedArray[UInt]
error[0], FixedArray[UInt]
error[1])
81 }
82}
83
84///|
85extern "js" fn ts_query_pattern_count(self : type Query
Query) -> UInt
UInt =
86 #|() => {
87 #| return self.patternCount;
88 #|}
89
90///|
91/// Get the number of patterns in the query.
92pub fn type Query
Query::(self : Query) -> Int
Get the number of patterns in the query.
pattern_count(Query
self : type Query
Query) -> Int
Int {
93 Query
self |> (self : Query) -> UInt
ts_query_pattern_count() |> (value : UInt) -> Int
uint_to_int()
94}
95
96///|
97extern "js" fn ts_query_capture_count(self : type Query
Query) -> UInt
UInt =
98 #|() => {
99 #| return self.captureCount;
100 #|}
101
102///|
103/// Get the number of captures in the query.
104pub fn type Query
Query::(self : Query) -> Int
Get the number of captures in the query.
capture_count(Query
self : type Query
Query) -> Int
Int {
105 Query
self |> (self : Query) -> UInt
ts_query_capture_count() |> (value : UInt) -> Int
uint_to_int()
106}
107
108///|
109extern "js" fn ts_query_string_count(self : type Query
Query) -> UInt
UInt =
110 #|() => {
111 #| return self.stringCount;
112 #|}
113
114///|
115/// Get the number of string literals in the query.
116pub fn type Query
Query::(self : Query) -> Int
Get the number of string literals in the query.
string_count(Query
self : type Query
Query) -> Int
Int {
117 Query
self |> (self : Query) -> UInt
ts_query_string_count() |> (value : UInt) -> Int
uint_to_int()
118}
119
120///|
121extern "js" fn ts_query_start_byte_for_pattern(
122 self : type Query
Query,
123 pattern_index : UInt
UInt
124) -> UInt
UInt =
125 #|(patternIndex) => {
126 #| return self.startIndexForPattern(patternIndex);
127 #|}
128
129///|
130/// Get the byte offset where the given pattern starts in the query's source.
131///
132/// This can be useful when combining queries by concatenating their source
133/// code strings.
134pub fn type Query
Query::(self : Query, pattern_index : Int) -> Int
Get the byte offset where the given pattern starts in the query's source.
This can be useful when combining queries by concatenating their source
code strings.
start_byte_for_pattern(Query
self : type Query
Query, Int
pattern_index : Int
Int) -> Int
Int {
135 let UInt
pattern_index = (value : Int) -> UInt
int_to_uint(Int
pattern_index)
136 (self : Query, pattern_index : UInt) -> UInt
ts_query_start_byte_for_pattern(Query
self, UInt
pattern_index) |> (value : UInt) -> Int
uint_to_int()
137}
138
139///|
140extern "js" fn ts_query_end_byte_for_pattern(
141 self : type Query
Query,
142 pattern_index : UInt
UInt
143) -> UInt
UInt =
144 #|(patternIndex) => {
145 #| return self.endIndexForPattern(patternIndex);
146 #|}
147
148///|
149/// Get the byte offset where the given pattern ends in the query's source.
150///
151/// This can be useful when combining queries by concatenating their source
152/// code strings.
153pub fn type Query
Query::(self : Query, pattern_index : Int) -> Int
Get the byte offset where the given pattern ends in the query's source.
This can be useful when combining queries by concatenating their source
code strings.
end_byte_for_pattern(Query
self : type Query
Query, Int
pattern_index : Int
Int) -> Int
Int {
154 let UInt
pattern_index = (value : Int) -> UInt
int_to_uint(Int
pattern_index)
155 (self : Query, pattern_index : UInt) -> UInt
ts_query_end_byte_for_pattern(Query
self, UInt
pattern_index) |> (value : UInt) -> Int
uint_to_int()
156}
157
158///|
159priv enum QueryPredicateStepType {
160 Capture
161 String
162} derive(Show)
163
164///|
165fn enum QueryPredicateStepType {
Done
Capture
String
}
QueryPredicateStepType::(value : String) -> QueryPredicateStepType
of_string(String
value : String
String) -> enum QueryPredicateStepType {
Done
Capture
String
}
QueryPredicateStepType {
166 match String
value {
167 "capture" => QueryPredicateStepType::QueryPredicateStepType
Capture
168 "string" => QueryPredicateStepType::QueryPredicateStepType
String
169 String
value => (msg : String) -> QueryPredicateStepType
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 QueryPredicateStepType: \{String
value}")
170 }
171}
172
173///|
174priv type TSQueryPredicateStep
175
176///|
177extern "js" fn type TSQueryPredicateStep
TSQueryPredicateStep::type_(
178 self : type TSQueryPredicateStep
TSQueryPredicateStep
179) -> String
String =
180 #|(self) => {
181 #| return self.type;
182 #|}
183
184///|
185extern "js" fn type TSQueryPredicateStep
TSQueryPredicateStep::value(
186 self : type TSQueryPredicateStep
TSQueryPredicateStep
187) -> String
String =
188 #|(self) => {
189 #| if (self.type == "capture") {
190 #| return self.name;
191 #| } else if (self.type == "string") {
192 #| return self.value;
193 #| }
194 #|}
195
196///|
197pub enum QueryPredicateStep {
198 Capture(String)
199 String(String)
200}
201
202///|
203pub impl trait Show {
output(Self, &Logger) -> Unit
to_string(Self) -> String
}
Show for enum QueryPredicateStep {
Capture(String)
String(String)
}
QueryPredicateStep with (self : QueryPredicateStep, logger : &Logger) -> Unit
output(
204 QueryPredicateStep
self,
205 &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
206) -> Unit
Unit {
207 match QueryPredicateStep
self {
208 (String) -> QueryPredicateStep
Capture(String
name) => &Logger
logger.(&Logger, String) -> Unit
write_string("@\{String
name}")
209 (String) -> QueryPredicateStep
String(String
value) => &Logger
logger.(&Logger, String) -> Unit
write_string(String
value.(self : String) -> String
Returns a valid MoonBit string literal representation of a string,
add quotes and escape special characters.
escape())
210 }
211}
212
213///|
214pub impl trait ToJson {
to_json(Self) -> Json
}
ToJson for enum QueryPredicateStep {
Capture(String)
String(String)
}
QueryPredicateStep with (self : QueryPredicateStep) -> Json
to_json(QueryPredicateStep
self) -> enum Json {
Null
True
False
Number(Double)
String(String)
Array(Array[Json])
Object(Map[String, Json])
}
Json {
215 QueryPredicateStep
self.(self : QueryPredicateStep) -> String
to_string().(self : String) -> Json
to_json()
216}
217
218///|
219priv type TSQueryPredicate
220
221///|
222extern "js" fn type TSQueryPredicate
TSQueryPredicate::operator(self : type TSQueryPredicate
TSQueryPredicate) -> String
String =
223 #|(self) => {
224 #| return self.operator;
225 #|}
226
227///|
228extern "js" fn type TSQueryPredicate
TSQueryPredicate::operands(
229 self : type TSQueryPredicate
TSQueryPredicate
230) -> type Array[T]
Array[type TSQueryPredicateStep
TSQueryPredicateStep] =
231 #|(self) => {
232 #| return self.operands;
233 #|}
234
235///|
236extern "js" fn ts_query_predicates_for_pattern(
237 self : type Query
Query,
238 pattern_index : Int
Int
239) -> type Array[T]
Array[type TSQueryPredicate
TSQueryPredicate] =
240 #|(self, patternIndex) => {
241 #| return self.predicates[patternIndex];
242 #|}
243
244///|
245typealias QueryPredicate = Array[QueryPredicateStep]
246
247///|
248pub fn type Query
Query::(self : Query, pattern_index : Int) -> Array[Array[QueryPredicateStep]]
predicates_for_pattern(
249 Query
self : type Query
Query,
250 Int
pattern_index : Int
Int
251) -> type Array[T]
Array[type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
QueryPredicate] {
252 let FixedArray[UInt]
ts_predicates = (self : Query, pattern_index : UInt) -> FixedArray[UInt]
ts_query_predicates_for_pattern(Query
self, Int
pattern_index)
253 let Array[Array[QueryPredicateStep]]
predicates = []
254 for UInt
ts_predicate in FixedArray[UInt]
ts_predicates {
255 let String
operator = UInt
ts_predicate.() -> String
operator()
256 let Unit
operands = UInt
ts_predicate.() -> Unit
operands()
257 let Array[QueryPredicateStep]
predicate = [QueryPredicateStep::(String) -> QueryPredicateStep
String(String
operator)]
258 for Unit
operand in Unit
operands {
259 let QueryPredicateStepType
type_ = enum QueryPredicateStepType {
Done
Capture
String
}
QueryPredicateStepType::(value : String) -> QueryPredicateStepType
of_string(Unit
operand.() -> String
type_())
260 let String
value = Unit
operand.() -> String
value()
261 match QueryPredicateStepType
type_ {
262 QueryPredicateStepType::QueryPredicateStepType
Capture =>
263 Array[QueryPredicateStep]
predicate.(self : Array[QueryPredicateStep], value : QueryPredicateStep) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push(QueryPredicateStep::(String) -> QueryPredicateStep
Capture(String
value))
264 QueryPredicateStepType::QueryPredicateStepType
String =>
265 Array[QueryPredicateStep]
predicate.(self : Array[QueryPredicateStep], value : QueryPredicateStep) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push(QueryPredicateStep::(String) -> QueryPredicateStep
String(String
value))
266 }
267 }
268 Array[Array[QueryPredicateStep]]
predicates.(self : Array[Array[QueryPredicateStep]], value : Array[QueryPredicateStep]) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push(Array[QueryPredicateStep]
predicate)
269 }
270 Array[Array[QueryPredicateStep]]
predicates
271}
272
273///|
274extern "js" fn ts_query_is_pattern_rooted(
275 self : type Query
Query,
276 pattern_index : UInt
UInt
277) -> Bool
Bool =
278 #|(query, patternIndex) => {
279 #| return query.isPatternRooted(patternIndex);
280 #|}
281
282///|
283/// Check if the given pattern in the query has a single root node.
284pub fn type Query
Query::(self : Query, pattern_index : Int) -> Bool
Check if the given pattern in the query has a single root node.
is_pattern_rooted(Query
self : type Query
Query, Int
pattern_index : Int
Int) -> Bool
Bool {
285 (self : Query, pattern_index : UInt) -> Bool
ts_query_is_pattern_rooted(Query
self, (value : Int) -> UInt
int_to_uint(Int
pattern_index))
286}
287
288///|
289extern "js" fn ts_query_is_pattern_non_local(
290 self : type Query
Query,
291 pattern_index : UInt
UInt
292) -> Bool
Bool =
293 #|(query, patternIndex) => {
294 #| return query.isPatternNonLocal(patternIndex);
295 #|}
296
297///|
298/// Check if the given pattern in the query is 'non local'.
299///
300/// A non-local pattern has multiple root nodes and can match within a
301/// repeating sequence of nodes, as specified by the grammar. Non-local
302/// patterns disable certain optimizations that would otherwise be possible
303/// when executing a query on a specific range of a syntax tree.
304pub fn type Query
Query::(self : Query, pattern_index : Int) -> Bool
Check if the given pattern in the query is 'non local'.
A non-local pattern has multiple root nodes and can match within a
repeating sequence of nodes, as specified by the grammar. Non-local
patterns disable certain optimizations that would otherwise be possible
when executing a query on a specific range of a syntax tree.
is_pattern_non_local(Query
self : type Query
Query, Int
pattern_index : Int
Int) -> Bool
Bool {
305 (self : Query, pattern_index : UInt) -> Bool
ts_query_is_pattern_non_local(Query
self, (value : Int) -> UInt
int_to_uint(Int
pattern_index))
306}
307
308///|
309extern "js" fn ts_query_is_pattern_guaranteed_at_step(
310 self : type Query
Query,
311 byte_offset : UInt
UInt
312) -> Bool
Bool =
313 #|(query, byteIndex) => {
314 #| return query.isPatternGuaranteedAtStep(byteIndex);
315 #|}
316
317///|
318/// Check if a given pattern is guaranteed to match once a given step is reached.
319/// The step is specified by its byte offset in the query's source code.
320pub fn type Query
Query::(self : Query, byte_offset : Int) -> Bool
Check if a given pattern is guaranteed to match once a given step is reached.
The step is specified by its byte offset in the query's source code.
is_pattern_guaranteed_at_step(
321 Query
self : type Query
Query,
322 Int
byte_offset : Int
Int
323) -> Bool
Bool {
324 (self : Query, byte_offset : UInt) -> Bool
ts_query_is_pattern_guaranteed_at_step(Query
self, (value : Int) -> UInt
int_to_uint(Int
byte_offset))
325}
326
327///|
328extern "js" fn ts_query_capture_name_for_id(
329 self : type Query
Query,
330 capture_id : UInt
UInt
331) -> String
String =
332 #|(query, captureId) => {
333 #| return query.captureNames[captureId];
334 #|}
335
336///|
337/// Get the name of one of the query's captures. Each capture is associated with a
338/// numeric id based on the order that it appeared in the query's source.
339pub fn type Query
Query::(self : Query, capture_id : Int) -> @string.StringView
Get the name of one of the query's captures. Each capture is associated with a
numeric id based on the order that it appeared in the query's source.
capture_name_for_id(
340 Query
self : type Query
Query,
341 Int
capture_id : Int
Int
342) -> 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 {
343 let UInt
capture_id = (value : Int) -> UInt
int_to_uint(Int
capture_id)
344 (self : Query, capture_id : UInt, FixedArray[UInt]) -> ?
ts_query_capture_name_for_id(Query
self, UInt
capture_id)
345}
346
347///|
348pub enum Quantifier {
349 Zero
350 ZeroOrOne
351 ZeroOrMore
352 One
353 OneOrMore
354} derive(Show)
355
356///|
357fn enum Quantifier {
Zero
ZeroOrOne
ZeroOrMore
One
OneOrMore
}
Quantifier::(value : UInt) -> Quantifier
of_uint(UInt
value : UInt
UInt) -> enum Quantifier {
Zero
ZeroOrOne
ZeroOrMore
One
OneOrMore
}
Quantifier {
358 match UInt
value {
359 0 => Quantifier::Quantifier
Zero
360 1 => Quantifier::Quantifier
ZeroOrOne
361 2 => Quantifier::Quantifier
ZeroOrMore
362 3 => Quantifier::Quantifier
One
363 4 => Quantifier::Quantifier
OneOrMore
364 UInt
value => (msg : String) -> Quantifier
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 Quantifier: \{UInt
value}")
365 }
366}
367
368///|
369extern "js" fn ts_query_capture_quantifier_for_id(
370 self : type Query
Query,
371 pattern_index : UInt
UInt,
372 capture_index : UInt
UInt
373) -> UInt
UInt =
374 #|(query, patternIndex, captureIndex) => {
375 #| return query.captureQuantifiers[patternIndex][captureIndex];
376 #|}
377
378///|
379/// Get the quantifier of the query's captures. Each capture is
380/// associated with a numeric id based on the order that it appeared in the query's source.
381pub fn type Query
Query::(self : Query, pattern_index : Int, capture_index : Int) -> Quantifier
Get the quantifier of the query's captures. Each capture is
associated with a numeric id based on the order that it appeared in the query's source.
capture_quantifier_for_id(
382 Query
self : type Query
Query,
383 Int
pattern_index : Int
Int,
384 Int
capture_index : Int
Int
385) -> enum Quantifier {
Zero
ZeroOrOne
ZeroOrMore
One
OneOrMore
}
Quantifier {
386 let UInt
pattern_index = (value : Int) -> UInt
int_to_uint(Int
pattern_index)
387 let UInt
capture_index = (value : Int) -> UInt
int_to_uint(Int
capture_index)
388 enum Quantifier {
Zero
ZeroOrOne
ZeroOrMore
One
OneOrMore
}
Quantifier::(value : UInt) -> Quantifier
of_uint(
389 (self : Query, pattern_index : UInt, capture_index : UInt) -> UInt
ts_query_capture_quantifier_for_id(Query
self, UInt
pattern_index, UInt
capture_index),
390 )
391}
392
393///|
394extern "js" fn ts_query_disable_capture(self : type Query
Query, name : String
String) =
395 #|(query, name) => {
396 #| return query.disableCapture(name);
397 #|}
398
399///|
400/// Disable a certain capture within a query.
401///
402/// This prevents the capture from being returned in matches, and also avoids
403/// any resource usage associated with recording the capture. Currently, there
404/// is no way to undo this.
405pub fn type Query
Query::(self : Query, name : @string.StringView) -> Unit
Disable a certain capture within a query.
This prevents the capture from being returned in matches, and also avoids
any resource usage associated with recording the capture. Currently, there
is no way to undo this.
disable_capture(Query
self : type Query
Query, @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) -> Unit
Unit {
406 (self : Query, name : Bytes) -> Unit
ts_query_disable_capture(Query
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())
407}
408
409///|
410extern "js" fn ts_query_disable_pattern(self : type Query
Query, pattern_index : UInt
UInt) =
411 #|(query, patternIndex) => {
412 #| return query.disablePattern(patternIndex);
413 #|}
414
415///|
416/// Disable a certain pattern within a query.
417///
418/// This prevents the pattern from matching and removes most of the overhead
419/// associated with the pattern. Currently, there is no way to undo this.
420pub fn type Query
Query::(self : Query, pattern_index : Int) -> Unit
Disable a certain pattern within a query.
This prevents the pattern from matching and removes most of the overhead
associated with the pattern. Currently, there is no way to undo this.
disable_pattern(Query
self : type Query
Query, Int
pattern_index : Int
Int) -> Unit
Unit {
421 (self : Query, pattern_index : UInt) -> Unit
ts_query_disable_pattern(Query
self, (value : Int) -> UInt
int_to_uint(Int
pattern_index))
422}
423
424///|
425extern "js" fn ts_query_matches(
426 self : type Query
Query,
427 node : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node
428) -> type Array[T]
Array[type TSQueryMatch
TSQueryMatch] =
429 #|(query, node) => {
430 #| return query.matches(node);
431 #|}
432
433///|
434pub fn type Query
Query::(self : Query, node : Node) -> Array[QueryMatch]
matches(Query
self : type Query
Query, Node
node : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node) -> type Array[T]
Array[struct QueryMatch {
query: Query
query_match: TSQueryMatch
}
QueryMatch] {
435 let Array[TSQueryMatch]
ts_matches = (self : Query, node : Node) -> Array[TSQueryMatch]
ts_query_matches(Query
self, Node
node)
436 let Array[QueryMatch]
matches = []
437 for TSQueryMatch
ts_match in Array[TSQueryMatch]
ts_matches {
438 let QueryMatch
query_match = struct QueryMatch {
query: Query
query_match: TSQueryMatch
}
QueryMatch::{ Query
query: Query
self, TSQueryMatch
query_match: TSQueryMatch
ts_match }
439 Array[QueryMatch]
matches.(self : Array[QueryMatch], value : QueryMatch) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push(QueryMatch
query_match)
440 }
441 Array[QueryMatch]
matches
442}
443
444///|
445pub extern "js" fn type Query
Query::captures(
446 self : type Query
Query,
447 node : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node
448) -> type Array[T]
Array[type QueryCapture
QueryCapture] =
449 #|(query, node) => {
450 #| return query.captures(node);
451 #|}
452