1///|
2type Tree
3
4///|
5priv trait Nullable {
6 is_null(Self) -> Bool
7 to_option(Self) -> Self? = _
8}
9
10///|
11impl trait Nullable {
is_null(Self) -> Bool
to_option(Self) -> Self?
}
Nullable with (self : Self) -> Self?
to_option(Self
self : type parameter Self
Self) -> type parameter Self
Self? {
12 if Self
self.(Self) -> Bool
is_null() {
13 return Self?
None
14 }
15 (Self) -> Self?
Some(Self
self)
16}
17
18///|
19extern "js" fn ts_tree_null() -> struct Tree {
tree: TSTree
text: @string.StringView
}
Tree =
20 #|() => {
21 #| return null;
22 #|}
23
24///|
25extern "js" fn ts_tree_is_null(self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> Bool
Bool =
26 #|(tree) => {
27 #| return tree === null || tree === undefined;
28 #|}
29
30///|
31impl trait Nullable {
is_null(Self) -> Bool
to_option(Self) -> Self?
}
Nullable for struct Tree {
tree: TSTree
text: @string.StringView
}
Tree with (self : Tree) -> Bool
is_null(Tree
self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> Bool
Bool {
32 (self : TSTree) -> Bool
ts_tree_is_null(Tree
self)
33}
34
35///|
36extern "js" fn ts_tree_copy(self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> struct Tree {
tree: TSTree
text: @string.StringView
}
Tree =
37 #|(tree) => {
38 #| return tree.copy();
39 #|}
40
41///|
42/// Create a shallow copy of the syntax tree. This is very fast.
43///
44/// You need to copy a syntax tree in order to use it on more than one thread at
45/// a time, as syntax trees are not thread safe.
46pub fn struct Tree {
tree: TSTree
text: @string.StringView
}
Tree::(self : Tree) -> Tree
Create a shallow copy of the syntax tree. This is very fast.
You need to copy a syntax tree in order to use it on more than one thread at
a time, as syntax trees are not thread safe.
copy(Tree
self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> struct Tree {
tree: TSTree
text: @string.StringView
}
Tree {
47 (self : TSTree) -> TSTree
ts_tree_copy(Tree
self)
48}
49
50///|
51extern "js" fn ts_tree_root_node(self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node =
52 #|(tree) => {
53 #| return tree.rootNode;
54 #|}
55
56///| Get the root node of the syntax tree.
57pub fn struct Tree {
tree: TSTree
text: @string.StringView
}
Tree::(self : Tree) -> Node
Get the root node of the syntax tree.
root_node(Tree
self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node {
58 (self : TSTree) -> TSNode
ts_tree_root_node(Tree
self)
59}
60
61///|
62extern "js" fn ts_tree_root_node_with_offset(
63 self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree,
64 offset_bytes : UInt
UInt,
65 offset_extent : type Point
Point
66) -> struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node =
67 #|(tree, offsetBytes, offsetExtent) => {
68 #| return tree.rootNodeWithOffset(offset_bytes, offset_extent);
69 #|}
70
71///|
72/// Get the root node of the syntax tree, but with its position
73/// shifted forward by the given offset.
74pub fn struct Tree {
tree: TSTree
text: @string.StringView
}
Tree::(self : Tree, offset_bytes : Int, offset_extent : Point) -> Node
Get the root node of the syntax tree, but with its position
shifted forward by the given offset.
root_node_with_offset(
75 Tree
self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree,
76 Int
offset_bytes : Int
Int,
77 Point
offset_extent : type Point
Point
78) -> struct Node {
node: TSNode
tree: TSTree
text: @string.StringView
}
Node {
79 (self : TSTree, offset_bytes : UInt, offset_extent : Point) -> TSNode
ts_tree_root_node_with_offset(Tree
self, (value : Int) -> UInt
int_to_uint(Int
offset_bytes), Point
offset_extent)
80}
81
82///|
83extern "js" fn ts_tree_language(self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> type Language @tree_sitter_language.Language
Language =
84 #|(tree) => {
85 #| return tree.language;
86 #|}
87
88///|
89/// Get the language that was used to parse the syntax tree.
90pub fn struct Tree {
tree: TSTree
text: @string.StringView
}
Tree::(self : Tree) -> Language
Get the language that was used to parse the syntax tree.
language(Tree
self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> type Language @tree_sitter_language.Language
Language {
91 (self : TSTree) -> Language
ts_tree_language(Tree
self)
92}
93
94///|
95extern "js" fn ts_tree_included_ranges(self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> type Array[T]
Array[type Range FixedArray[UInt]
Range] =
96 #|(tree) => {
97 #| return tree.getIncludedRanges();
98 #|}
99
100///|
101/// Get the array of included ranges that was used to parse the syntax tree.
102pub fn struct Tree {
tree: TSTree
text: @string.StringView
}
Tree::(self : Tree) -> Array[Range]
Get the array of included ranges that was used to parse the syntax tree.
included_ranges(Tree
self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> type Array[T]
Array[type Range FixedArray[UInt]
Range] {
103 (self : TSTree) -> FixedArray[UInt]
ts_tree_included_ranges(Tree
self)
104}
105
106///|
107extern "js" fn ts_tree_edit(self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree, edit : type InputEdit FixedArray[UInt]
InputEdit) =
108 #|(tree, edit) => {
109 #| return tree.edit(edit);
110 #|}
111
112///|
113/// Edit the syntax tree to keep it in sync with source code that has been
114/// edited.
115///
116/// You must describe the edit both in terms of byte offsets and in terms of
117/// (row, column) coordinates.
118pub fn struct Tree {
tree: TSTree
text: @string.StringView
}
Tree::(self : Tree, edit : InputEdit) -> Unit
Edit the syntax tree to keep it in sync with source code that has been
edited.
You must describe the edit both in terms of byte offsets and in terms of
(row, column) coordinates.
edit(Tree
self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree, InputEdit
edit : type InputEdit FixedArray[UInt]
InputEdit) -> Unit
Unit {
119 (self : TSTree, edit : InputEdit) -> Unit
ts_tree_edit(Tree
self, InputEdit
edit)
120}
121
122///|
123extern "js" fn ts_tree_get_changed_ranges(
124 self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree,
125 other : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree
126) -> type Array[T]
Array[type Range FixedArray[UInt]
Range] =
127 #|(tree, other) => {
128 #| return tree.getChangedRanges(other);
129 #|}
130
131///|
132/// Compare an old edited syntax tree to a new syntax tree representing the same
133/// document, returning an array of ranges whose syntactic structure has changed.
134///
135/// For this to work correctly, the old syntax tree must have been edited such
136/// that its ranges match up to the new tree. Generally, you'll want to call
137/// this function right after calling one of the Parser::parse functions.
138/// You need to pass the old tree that was passed to parse, as well as the new
139/// tree that was returned from that function.
140///
141/// The returned ranges indicate areas where the hierarchical structure of syntax
142/// nodes (from root to leaf) has changed between the old and new trees. Characters
143/// outside these ranges have identical ancestor nodes in both trees.
144///
145/// Note that the returned ranges may be slightly larger than the exact changed areas,
146/// but Tree-sitter attempts to make them as small as possible.
147pub fn struct Tree {
tree: TSTree
text: @string.StringView
}
Tree::(self : Tree, other : Tree) -> Array[Range]
Compare an old edited syntax tree to a new syntax tree representing the same
document, returning an array of ranges whose syntactic structure has changed.
For this to work correctly, the old syntax tree must have been edited such
that its ranges match up to the new tree. Generally, you'll want to call
this function right after calling one of the Parser::parse functions.
You need to pass the old tree that was passed to parse, as well as the new
tree that was returned from that function.
The returned ranges indicate areas where the hierarchical structure of syntax
nodes (from root to leaf) has changed between the old and new trees. Characters
outside these ranges have identical ancestor nodes in both trees.
Note that the returned ranges may be slightly larger than the exact changed areas,
but Tree-sitter attempts to make them as small as possible.
get_changed_ranges(Tree
self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree, Tree
other : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree) -> type Array[T]
Array[type Range FixedArray[UInt]
Range] {
148 (self : TSTree, other : TSTree) -> FixedArray[UInt]
ts_tree_get_changed_ranges(Tree
self, Tree
other)
149}
150
151///|
152pub fn struct Tree {
tree: TSTree
text: @string.StringView
}
Tree::(self : Tree, query : @string.StringView) -> QueryCursor!QueryError
query(Tree
self : struct Tree {
tree: TSTree
text: @string.StringView
}
Tree, @string.StringView
query : 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 QueryCursor {
mut query: Query?
mut node: Node?
}
QueryCursor!type! QueryError {
Syntax(UInt)
NodeType(UInt)
Field(UInt)
Capture(UInt)
Structure(UInt)
Language(UInt)
}
QueryError {
153 Tree
self.(self : Tree) -> Node
Get the root node of the syntax tree.
root_node().(self : Node, source : @string.StringView) -> QueryCursor!QueryError
query!(@string.StringView
query)
154}
155