1///|
2type QueryCapture
3
4///|
5pub extern "js" fn type QueryCapture
QueryCapture::pattern_index(self : type QueryCapture
QueryCapture) -> Int
Int =
6 #|(self) => {
7 #| return self.patternIndex;
8 #|}
9
10///|
11pub extern "js" fn type QueryCapture
QueryCapture::name(self : type QueryCapture
QueryCapture) -> String
String =
12 #|(self) => {
13 #| return self.name;
14 #|}
15
16///|
17pub extern "js" fn type QueryCapture
QueryCapture::node(self : type QueryCapture
QueryCapture) -> struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node =
18 #|(self) => {
19 #| return self.node;
20 #|}
21
22///|
23priv type TSQueryMatch
24
25///|
26extern "js" fn type TSQueryMatch
TSQueryMatch::captures(
27 self : type TSQueryMatch
TSQueryMatch
28) -> type Array[T]
Array[type QueryCapture
QueryCapture] =
29 #|(self) => {
30 #| return self.captures;
31 #|}
32
33///|
34extern "js" fn type TSQueryMatch
TSQueryMatch::pattern_index(self : type TSQueryMatch
TSQueryMatch) -> Int
Int =
35 #|(self) => {
36 #| return self.patternIndex;
37 #|}
38
39///|
40struct QueryMatch {
41 Query
query : type Query
Query
42 TSQueryMatch
query_match : type TSQueryMatch
TSQueryMatch
43}
44
45///|
46pub fn struct QueryMatch {
query: Query
query_match: TSQueryMatch
}
QueryMatch::(self : QueryMatch) -> Array[QueryCapture]
captures(QueryMatch
self : struct QueryMatch {
query: Query
query_match: TSQueryMatch
}
QueryMatch) -> type Array[T]
Array[type QueryCapture
QueryCapture] {
47 QueryMatch
self.TSQueryMatch
query_match.(self : TSQueryMatch) -> Array[QueryCapture]
captures()
48}
49
50///|
51pub fn struct QueryMatch {
query: Query
query_match: TSQueryMatch
}
QueryMatch::(self : QueryMatch) -> Int
pattern_index(QueryMatch
self : struct QueryMatch {
query: Query
query_match: TSQueryMatch
}
QueryMatch) -> Int
Int {
52 QueryMatch
self.TSQueryMatch
query_match.(self : TSQueryMatch) -> Int
pattern_index()
53}
54
55///|
56pub fn struct QueryMatch {
query: Query
query_match: TSQueryMatch
}
QueryMatch::(self : QueryMatch) -> Array[Array[QueryPredicateStep]]
predicates(QueryMatch
self : struct QueryMatch {
query: Query
query_match: TSQueryMatch
}
QueryMatch) -> type Array[T]
Array[type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
QueryPredicate] {
57 QueryMatch
self.Query
query.(self : Query, pattern_index : Int) -> Array[Array[QueryPredicateStep]]
predicates_for_pattern(QueryMatch
self.(self : QueryMatch) -> Int
pattern_index())
58}
59
60///|
61struct QueryCursor {
62 mut Query?
query : type Query
Query?
63 mut Node?
node : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node?
64}
65
66///|
67pub fn 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() -> struct QueryCursor {
mut query: Query?
mut node: Node?
}
QueryCursor {
68 struct QueryCursor {
mut query: Query?
mut node: Node?
}
QueryCursor::{ Query?
query: Query?
None, Node?
node: Node?
None }
69}
70
71///|
72pub fn struct QueryCursor {
mut query: Query?
mut node: Node?
}
QueryCursor::(self : QueryCursor, query : Query, node : Node) -> Unit
Start running a given query on a given node, with optional options.
exec(
73 QueryCursor
self : struct QueryCursor {
mut query: Query?
mut node: Node?
}
QueryCursor,
74 Query
query : type Query
Query,
75 Node
node : struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node
76) -> Unit
Unit {
77 QueryCursor
self.Query?
query = (Query) -> Query?
Some(Query
query)
78 QueryCursor
self.Node?
node = (Node) -> Node?
Some(Node
node)
79}
80
81///|
82pub fn struct QueryCursor {
mut query: Query?
mut node: Node?
}
QueryCursor::(self : QueryCursor) -> Iter[QueryMatch]
matches(QueryCursor
self : struct QueryCursor {
mut query: Query?
mut node: Node?
}
QueryCursor) -> type Iter[T]
Iter[struct QueryMatch {
query: Query
query_match: TSQueryMatch
}
QueryMatch] {
83 guard QueryCursor
self.Query?
query is (Query) -> Query?
Some(Query
query) (Bool, Bool) -> Bool
&& QueryCursor
self.Node?
node is (Node) -> Node?
Some(Node
node) else {
84 type Iter[T]
Iter::() -> Iter[QueryMatch]
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()
85 }
86 Query
query.(self : Query, node : Node) -> Array[QueryMatch]
matches(Node
node).(self : Array[QueryMatch]) -> Iter[QueryMatch]
Creates an iterator over the elements of the array.
Parameters:
array : The array to create an iterator from.
Returns an iterator that yields each element of the array in order.
Example:
test "Array::iter" {
let arr = [1, 2, 3]
let mut sum = 0
arr.iter().each(fn(x) { sum = sum + x })
inspect!(sum, content="6")
}
iter()
87}
88