@kerebron/tree-sitter 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +1 -2
  2. package/esm/{deno-tree-sitter/main/extended → extended}/base_node.d.ts +9 -12
  3. package/esm/extended/base_node.d.ts.map +1 -0
  4. package/esm/{deno-tree-sitter/main/extended → extended}/base_node.js +14 -14
  5. package/esm/extended/base_node.js.map +1 -0
  6. package/esm/extended/node_extended.d.ts +243 -0
  7. package/esm/extended/node_extended.d.ts.map +1 -0
  8. package/esm/{deno-tree-sitter/main/extended → extended}/node_extended.js +196 -186
  9. package/esm/extended/node_extended.js.map +1 -0
  10. package/esm/{deno-tree-sitter/main/extended → extended}/parser.d.ts +19 -17
  11. package/esm/extended/parser.d.ts.map +1 -0
  12. package/esm/extended/parser.js +61 -0
  13. package/esm/extended/parser.js.map +1 -0
  14. package/esm/{deno-tree-sitter/main/extended → extended}/soft_node.d.ts +4 -3
  15. package/esm/extended/soft_node.d.ts.map +1 -0
  16. package/esm/{deno-tree-sitter/main/extended → extended}/soft_node.js +1 -1
  17. package/esm/extended/soft_node.js.map +1 -0
  18. package/esm/extended/soft_text_node.d.ts +9 -0
  19. package/esm/extended/soft_text_node.d.ts.map +1 -0
  20. package/esm/{deno-tree-sitter/main/extended → extended}/soft_text_node.js +2 -2
  21. package/esm/extended/soft_text_node.js.map +1 -0
  22. package/esm/extended/whitespace_node.d.ts +9 -0
  23. package/esm/extended/whitespace_node.d.ts.map +1 -0
  24. package/esm/{deno-tree-sitter/main/extended → extended}/whitespace_node.js +2 -2
  25. package/esm/extended/whitespace_node.js.map +1 -0
  26. package/esm/extras/misc.d.ts +2 -0
  27. package/esm/extras/misc.d.ts.map +1 -0
  28. package/esm/{deno-tree-sitter/main/extras → extras}/misc.js +2 -2
  29. package/esm/extras/misc.js.map +1 -0
  30. package/esm/mod.d.ts +1 -6
  31. package/esm/mod.d.ts.map +1 -1
  32. package/esm/mod.js +1 -7
  33. package/esm/mod.js.map +1 -1
  34. package/package.json +4 -1
  35. package/src/extended/base_node.ts +175 -0
  36. package/src/extended/node_extended.ts +651 -0
  37. package/src/extended/parser.ts +96 -0
  38. package/src/extended/soft_node.ts +32 -0
  39. package/src/extended/soft_text_node.ts +11 -0
  40. package/src/extended/whitespace_node.ts +11 -0
  41. package/src/extras/misc.ts +15 -0
  42. package/src/mod.ts +1 -8
  43. package/esm/deno-tree-sitter/main/extended/base_node.d.ts.map +0 -1
  44. package/esm/deno-tree-sitter/main/extended/base_node.js.map +0 -1
  45. package/esm/deno-tree-sitter/main/extended/node_extended.d.ts +0 -237
  46. package/esm/deno-tree-sitter/main/extended/node_extended.d.ts.map +0 -1
  47. package/esm/deno-tree-sitter/main/extended/node_extended.js.map +0 -1
  48. package/esm/deno-tree-sitter/main/extended/parser.d.ts.map +0 -1
  49. package/esm/deno-tree-sitter/main/extended/parser.js +0 -87
  50. package/esm/deno-tree-sitter/main/extended/parser.js.map +0 -1
  51. package/esm/deno-tree-sitter/main/extended/soft_node.d.ts.map +0 -1
  52. package/esm/deno-tree-sitter/main/extended/soft_node.js.map +0 -1
  53. package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts +0 -10
  54. package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts.map +0 -1
  55. package/esm/deno-tree-sitter/main/extended/soft_text_node.js.map +0 -1
  56. package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts +0 -10
  57. package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts.map +0 -1
  58. package/esm/deno-tree-sitter/main/extended/whitespace_node.js.map +0 -1
  59. package/esm/deno-tree-sitter/main/extras/misc.d.ts +0 -2
  60. package/esm/deno-tree-sitter/main/extras/misc.d.ts.map +0 -1
  61. package/esm/deno-tree-sitter/main/extras/misc.js.map +0 -1
  62. package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts +0 -14
  63. package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts.map +0 -1
  64. package/esm/deno-tree-sitter/main/tree_sitter/bindings.js +0 -22
  65. package/esm/deno-tree-sitter/main/tree_sitter/bindings.js.map +0 -1
  66. package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts +0 -60
  67. package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts.map +0 -1
  68. package/esm/deno-tree-sitter/main/tree_sitter/constants.js +0 -67
  69. package/esm/deno-tree-sitter/main/tree_sitter/constants.js.map +0 -1
  70. package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts +0 -137
  71. package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts.map +0 -1
  72. package/esm/deno-tree-sitter/main/tree_sitter/language.js +0 -265
  73. package/esm/deno-tree-sitter/main/tree_sitter/language.js.map +0 -1
  74. package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts +0 -41
  75. package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts.map +0 -1
  76. package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.js +0 -66
  77. package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.js.map +0 -1
  78. package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts +0 -85
  79. package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts.map +0 -1
  80. package/esm/deno-tree-sitter/main/tree_sitter/marshal.js +0 -174
  81. package/esm/deno-tree-sitter/main/tree_sitter/marshal.js.map +0 -1
  82. package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts +0 -260
  83. package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts.map +0 -1
  84. package/esm/deno-tree-sitter/main/tree_sitter/node.js +0 -558
  85. package/esm/deno-tree-sitter/main/tree_sitter/node.js.map +0 -1
  86. package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts +0 -124
  87. package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts.map +0 -1
  88. package/esm/deno-tree-sitter/main/tree_sitter/parser.js +0 -253
  89. package/esm/deno-tree-sitter/main/tree_sitter/parser.js.map +0 -1
  90. package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts +0 -134
  91. package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts.map +0 -1
  92. package/esm/deno-tree-sitter/main/tree_sitter/query.js +0 -621
  93. package/esm/deno-tree-sitter/main/tree_sitter/query.js.map +0 -1
  94. package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts +0 -49
  95. package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts.map +0 -1
  96. package/esm/deno-tree-sitter/main/tree_sitter/tree.js +0 -131
  97. package/esm/deno-tree-sitter/main/tree_sitter/tree.js.map +0 -1
  98. package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts +0 -165
  99. package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts.map +0 -1
  100. package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.js +0 -281
  101. package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.js.map +0 -1
  102. package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts +0 -3
  103. package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts.map +0 -1
  104. package/esm/deno-tree-sitter/main/tree_sitter_wasm.js +0 -0
  105. package/esm/deno-tree-sitter/main/tree_sitter_wasm.js.map +0 -1
  106. package/esm/deno-tree-sitter/main/wasm_loader.d.ts +0 -29
  107. package/esm/deno-tree-sitter/main/wasm_loader.d.ts.map +0 -1
  108. package/esm/deno-tree-sitter/main/wasm_loader.js +0 -1703
  109. package/esm/deno-tree-sitter/main/wasm_loader.js.map +0 -1
  110. package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts +0 -3
  111. package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts.map +0 -1
  112. package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.js +0 -9
  113. package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.js.map +0 -1
  114. package/src/deno-tree-sitter/main/extended/base_node.js +0 -174
  115. package/src/deno-tree-sitter/main/extended/node_extended.js +0 -588
  116. package/src/deno-tree-sitter/main/extended/parser.js +0 -87
  117. package/src/deno-tree-sitter/main/extended/soft_node.js +0 -32
  118. package/src/deno-tree-sitter/main/extended/soft_text_node.js +0 -11
  119. package/src/deno-tree-sitter/main/extended/whitespace_node.js +0 -11
  120. package/src/deno-tree-sitter/main/extras/misc.js +0 -12
  121. package/src/deno-tree-sitter/main/tree_sitter/bindings.js +0 -26
  122. package/src/deno-tree-sitter/main/tree_sitter/constants.js +0 -79
  123. package/src/deno-tree-sitter/main/tree_sitter/language.js +0 -289
  124. package/src/deno-tree-sitter/main/tree_sitter/lookahead_iterator.js +0 -74
  125. package/src/deno-tree-sitter/main/tree_sitter/marshal.js +0 -186
  126. package/src/deno-tree-sitter/main/tree_sitter/node.js +0 -616
  127. package/src/deno-tree-sitter/main/tree_sitter/parser.js +0 -273
  128. package/src/deno-tree-sitter/main/tree_sitter/query.js +0 -705
  129. package/src/deno-tree-sitter/main/tree_sitter/tree.js +0 -145
  130. package/src/deno-tree-sitter/main/tree_sitter/tree_cursor.js +0 -314
  131. package/src/deno-tree-sitter/main/tree_sitter_wasm.js +0 -0
  132. package/src/deno-tree-sitter/main/wasm_loader.js +0 -1702
  133. package/src/deno-tree-sitter/main/wasm_loader_with_defaults.js +0 -9
@@ -1,145 +0,0 @@
1
- import { INTERNAL, assertInternal, SIZE_OF_NODE, SIZE_OF_INT, SIZE_OF_RANGE, C } from "./constants.js"
2
- import { Language } from "./language.js"
3
- import { Node } from "./node.js"
4
- import { TreeCursor } from "./tree_cursor.js"
5
- import { marshalEdit, marshalPoint, unmarshalNode, unmarshalRange } from "./marshal.js"
6
- import { TRANSFER_BUFFER } from "./parser.js"
7
-
8
- /** @internal */
9
- export function getText(tree, startIndex, endIndex, startPosition) {
10
- const length = endIndex - startIndex
11
- let result = tree.textCallback(startIndex, startPosition)
12
- if (result) {
13
- startIndex += result.length
14
- while (startIndex < endIndex) {
15
- const string = tree.textCallback(startIndex, startPosition)
16
- if (string && string.length > 0) {
17
- startIndex += string.length
18
- result += string
19
- } else {
20
- break
21
- }
22
- }
23
- if (startIndex > endIndex) {
24
- result = result.slice(0, length)
25
- }
26
- }
27
- return result ?? ""
28
- }
29
-
30
- /** A tree that represents the syntactic structure of a source code file. */
31
- export class Tree {
32
- /** @internal */
33
- [0] = 0 // Internal handle for Wasm
34
-
35
- /** @internal */
36
- textCallback
37
-
38
- /** The language that was used to parse the syntax tree. */
39
- language
40
-
41
- /** @internal */
42
- constructor(internal, address, language, textCallback) {
43
- assertInternal(internal)
44
- this[0] = address
45
- this.language = language
46
- this.textCallback = textCallback
47
- }
48
-
49
- /** Create a shallow copy of the syntax tree. This is very fast. */
50
- copy() {
51
- const address = C._ts_tree_copy(this[0])
52
- return new Tree(INTERNAL, address, this.language, this.textCallback)
53
- }
54
-
55
- /** Delete the syntax tree, freeing its resources. */
56
- delete() {
57
- C._ts_tree_delete(this[0])
58
- this[0] = 0
59
- }
60
-
61
- /** Get the root node of the syntax tree. */
62
- get rootNode() {
63
- C._ts_tree_root_node_wasm(this[0])
64
- return unmarshalNode(this)
65
- }
66
-
67
- /**
68
- * Get the root node of the syntax tree, but with its position shifted
69
- * forward by the given offset.
70
- */
71
- rootNodeWithOffset(offsetBytes, offsetExtent) {
72
- const address = TRANSFER_BUFFER + SIZE_OF_NODE
73
- C.setValue(address, offsetBytes, "i32")
74
- marshalPoint(address + SIZE_OF_INT, offsetExtent)
75
- C._ts_tree_root_node_with_offset_wasm(this[0])
76
- return unmarshalNode(this)
77
- }
78
-
79
- /**
80
- * Edit the syntax tree to keep it in sync with source code that has been
81
- * edited.
82
- *
83
- * You must describe the edit both in terms of byte offsets and in terms of
84
- * row/column coordinates.
85
- */
86
- edit(edit) {
87
- marshalEdit(edit)
88
- C._ts_tree_edit_wasm(this[0])
89
- }
90
-
91
- /** Create a new {@link TreeCursor} starting from the root of the tree. */
92
- walk() {
93
- return this.rootNode.walk()
94
- }
95
-
96
- /**
97
- * Compare this old edited syntax tree to a new syntax tree representing
98
- * the same document, returning a sequence of ranges whose syntactic
99
- * structure has changed.
100
- *
101
- * For this to work correctly, this syntax tree must have been edited such
102
- * that its ranges match up to the new tree. Generally, you'll want to
103
- * call this method right after calling one of the [`Parser::parse`]
104
- * functions. Call it on the old tree that was passed to parse, and
105
- * pass the new tree that was returned from `parse`.
106
- */
107
- getChangedRanges(other) {
108
- if (!(other instanceof Tree)) {
109
- throw new TypeError("Argument must be a Tree")
110
- }
111
-
112
- C._ts_tree_get_changed_ranges_wasm(this[0], other[0])
113
- const count = C.getValue(TRANSFER_BUFFER, "i32")
114
- const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32")
115
- const result = new Array(count)
116
-
117
- if (count > 0) {
118
- let address = buffer
119
- for (let i = 0; i < count; i++) {
120
- result[i] = unmarshalRange(address)
121
- address += SIZE_OF_RANGE
122
- }
123
- C._free(buffer)
124
- }
125
- return result
126
- }
127
-
128
- /** Get the included ranges that were used to parse the syntax tree. */
129
- getIncludedRanges() {
130
- C._ts_tree_included_ranges_wasm(this[0])
131
- const count = C.getValue(TRANSFER_BUFFER, "i32")
132
- const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32")
133
- const result = new Array(count)
134
-
135
- if (count > 0) {
136
- let address = buffer
137
- for (let i = 0; i < count; i++) {
138
- result[i] = unmarshalRange(address)
139
- address += SIZE_OF_RANGE
140
- }
141
- C._free(buffer)
142
- }
143
- return result
144
- }
145
- }
@@ -1,314 +0,0 @@
1
- import { INTERNAL, assertInternal, SIZE_OF_NODE, SIZE_OF_CURSOR, C } from "./constants.js"
2
- import { marshalNode, marshalPoint, marshalTreeCursor, unmarshalNode, unmarshalPoint, unmarshalTreeCursor } from "./marshal.js"
3
- import { Node } from "./node.js"
4
- import { TRANSFER_BUFFER } from "./parser.js"
5
- import { getText, Tree } from "./tree.js"
6
-
7
- /** A stateful object for walking a syntax {@link Tree} efficiently. */
8
- export class TreeCursor {
9
- /** @internal */
10
- [0] = 0; // Internal handle for Wasm
11
-
12
- /** @internal */
13
- [1] = 0; // Internal handle for Wasm
14
-
15
- /** @internal */
16
- [2] = 0; // Internal handle for Wasm
17
-
18
- /** @internal */
19
- [3] = 0 // Internal handle for Wasm
20
-
21
- /** @internal */
22
- tree
23
-
24
- /** @internal */
25
- constructor(internal, tree) {
26
- assertInternal(internal)
27
- this.tree = tree
28
- unmarshalTreeCursor(this)
29
- }
30
-
31
- /** Creates a deep copy of the tree cursor. This allocates new memory. */
32
- copy() {
33
- const copy = new TreeCursor(INTERNAL, this.tree)
34
- C._ts_tree_cursor_copy_wasm(this.tree[0])
35
- unmarshalTreeCursor(copy)
36
- return copy
37
- }
38
-
39
- /** Delete the tree cursor, freeing its resources. */
40
- delete() {
41
- marshalTreeCursor(this)
42
- C._ts_tree_cursor_delete_wasm(this.tree[0])
43
- this[0] = this[1] = this[2] = 0
44
- }
45
-
46
- /** Get the tree cursor's current {@link Node}. */
47
- get currentNode() {
48
- marshalTreeCursor(this)
49
- C._ts_tree_cursor_current_node_wasm(this.tree[0])
50
- return unmarshalNode(this.tree)
51
- }
52
-
53
- /**
54
- * Get the numerical field id of this tree cursor's current node.
55
- *
56
- * See also {@link TreeCursor#currentFieldName}.
57
- */
58
- get currentFieldId() {
59
- marshalTreeCursor(this)
60
- return C._ts_tree_cursor_current_field_id_wasm(this.tree[0])
61
- }
62
-
63
- /** Get the field name of this tree cursor's current node. */
64
- get currentFieldName() {
65
- return this.tree.language.fields[this.currentFieldId]
66
- }
67
-
68
- /**
69
- * Get the depth of the cursor's current node relative to the original
70
- * node that the cursor was constructed with.
71
- */
72
- get currentDepth() {
73
- marshalTreeCursor(this)
74
- return C._ts_tree_cursor_current_depth_wasm(this.tree[0])
75
- }
76
-
77
- /**
78
- * Get the index of the cursor's current node out of all of the
79
- * descendants of the original node that the cursor was constructed with.
80
- */
81
- get currentDescendantIndex() {
82
- marshalTreeCursor(this)
83
- return C._ts_tree_cursor_current_descendant_index_wasm(this.tree[0])
84
- }
85
-
86
- /** Get the type of the cursor's current node. */
87
- get nodeType() {
88
- return this.tree.language.types[this.nodeTypeId] || "ERROR"
89
- }
90
-
91
- /** Get the type id of the cursor's current node. */
92
- get nodeTypeId() {
93
- marshalTreeCursor(this)
94
- return C._ts_tree_cursor_current_node_type_id_wasm(this.tree[0])
95
- }
96
-
97
- /** Get the state id of the cursor's current node. */
98
- get nodeStateId() {
99
- marshalTreeCursor(this)
100
- return C._ts_tree_cursor_current_node_state_id_wasm(this.tree[0])
101
- }
102
-
103
- /** Get the id of the cursor's current node. */
104
- get nodeId() {
105
- marshalTreeCursor(this)
106
- return C._ts_tree_cursor_current_node_id_wasm(this.tree[0])
107
- }
108
-
109
- /**
110
- * Check if the cursor's current node is *named*.
111
- *
112
- * Named nodes correspond to named rules in the grammar, whereas
113
- * *anonymous* nodes correspond to string literals in the grammar.
114
- */
115
- get nodeIsNamed() {
116
- marshalTreeCursor(this)
117
- return C._ts_tree_cursor_current_node_is_named_wasm(this.tree[0]) === 1
118
- }
119
-
120
- /**
121
- * Check if the cursor's current node is *missing*.
122
- *
123
- * Missing nodes are inserted by the parser in order to recover from
124
- * certain kinds of syntax errors.
125
- */
126
- get nodeIsMissing() {
127
- marshalTreeCursor(this)
128
- return C._ts_tree_cursor_current_node_is_missing_wasm(this.tree[0]) === 1
129
- }
130
-
131
- /** Get the string content of the cursor's current node. */
132
- get nodeText() {
133
- marshalTreeCursor(this)
134
- const startIndex = C._ts_tree_cursor_start_index_wasm(this.tree[0])
135
- const endIndex = C._ts_tree_cursor_end_index_wasm(this.tree[0])
136
- C._ts_tree_cursor_start_position_wasm(this.tree[0])
137
- const startPosition = unmarshalPoint(TRANSFER_BUFFER)
138
- return getText(this.tree, startIndex, endIndex, startPosition)
139
- }
140
-
141
- /** Get the start position of the cursor's current node. */
142
- get startPosition() {
143
- marshalTreeCursor(this)
144
- C._ts_tree_cursor_start_position_wasm(this.tree[0])
145
- return unmarshalPoint(TRANSFER_BUFFER)
146
- }
147
-
148
- /** Get the end position of the cursor's current node. */
149
- get endPosition() {
150
- marshalTreeCursor(this)
151
- C._ts_tree_cursor_end_position_wasm(this.tree[0])
152
- return unmarshalPoint(TRANSFER_BUFFER)
153
- }
154
-
155
- /** Get the start index of the cursor's current node. */
156
- get startIndex() {
157
- marshalTreeCursor(this)
158
- return C._ts_tree_cursor_start_index_wasm(this.tree[0])
159
- }
160
-
161
- /** Get the end index of the cursor's current node. */
162
- get endIndex() {
163
- marshalTreeCursor(this)
164
- return C._ts_tree_cursor_end_index_wasm(this.tree[0])
165
- }
166
-
167
- /**
168
- * Move this cursor to the first child of its current node.
169
- *
170
- * This returns `true` if the cursor successfully moved, and returns
171
- * `false` if there were no children.
172
- */
173
- gotoFirstChild() {
174
- marshalTreeCursor(this)
175
- const result = C._ts_tree_cursor_goto_first_child_wasm(this.tree[0])
176
- unmarshalTreeCursor(this)
177
- return result === 1
178
- }
179
-
180
- /**
181
- * Move this cursor to the last child of its current node.
182
- *
183
- * This returns `true` if the cursor successfully moved, and returns
184
- * `false` if there were no children.
185
- *
186
- * Note that this function may be slower than
187
- * {@link TreeCursor#gotoFirstChild} because it needs to
188
- * iterate through all the children to compute the child's position.
189
- */
190
- gotoLastChild() {
191
- marshalTreeCursor(this)
192
- const result = C._ts_tree_cursor_goto_last_child_wasm(this.tree[0])
193
- unmarshalTreeCursor(this)
194
- return result === 1
195
- }
196
-
197
- /**
198
- * Move this cursor to the parent of its current node.
199
- *
200
- * This returns `true` if the cursor successfully moved, and returns
201
- * `false` if there was no parent node (the cursor was already on the
202
- * root node).
203
- *
204
- * Note that the node the cursor was constructed with is considered the root
205
- * of the cursor, and the cursor cannot walk outside this node.
206
- */
207
- gotoParent() {
208
- marshalTreeCursor(this)
209
- const result = C._ts_tree_cursor_goto_parent_wasm(this.tree[0])
210
- unmarshalTreeCursor(this)
211
- return result === 1
212
- }
213
-
214
- /**
215
- * Move this cursor to the next sibling of its current node.
216
- *
217
- * This returns `true` if the cursor successfully moved, and returns
218
- * `false` if there was no next sibling node.
219
- *
220
- * Note that the node the cursor was constructed with is considered the root
221
- * of the cursor, and the cursor cannot walk outside this node.
222
- */
223
- gotoNextSibling() {
224
- marshalTreeCursor(this)
225
- const result = C._ts_tree_cursor_goto_next_sibling_wasm(this.tree[0])
226
- unmarshalTreeCursor(this)
227
- return result === 1
228
- }
229
-
230
- /**
231
- * Move this cursor to the previous sibling of its current node.
232
- *
233
- * This returns `true` if the cursor successfully moved, and returns
234
- * `false` if there was no previous sibling node.
235
- *
236
- * Note that this function may be slower than
237
- * {@link TreeCursor#gotoNextSibling} due to how node
238
- * positions are stored. In the worst case, this will need to iterate
239
- * through all the children up to the previous sibling node to recalculate
240
- * its position. Also note that the node the cursor was constructed with is
241
- * considered the root of the cursor, and the cursor cannot walk outside this node.
242
- */
243
- gotoPreviousSibling() {
244
- marshalTreeCursor(this)
245
- const result = C._ts_tree_cursor_goto_previous_sibling_wasm(this.tree[0])
246
- unmarshalTreeCursor(this)
247
- return result === 1
248
- }
249
-
250
- /**
251
- * Move the cursor to the node that is the nth descendant of
252
- * the original node that the cursor was constructed with, where
253
- * zero represents the original node itself.
254
- */
255
- gotoDescendant(goalDescendantIndex) {
256
- marshalTreeCursor(this)
257
- C._ts_tree_cursor_goto_descendant_wasm(this.tree[0], goalDescendantIndex)
258
- unmarshalTreeCursor(this)
259
- }
260
-
261
- /**
262
- * Move this cursor to the first child of its current node that contains or
263
- * starts after the given byte offset.
264
- *
265
- * This returns `true` if the cursor successfully moved to a child node, and returns
266
- * `false` if no such child was found.
267
- */
268
- gotoFirstChildForIndex(goalIndex) {
269
- marshalTreeCursor(this)
270
- C.setValue(TRANSFER_BUFFER + SIZE_OF_CURSOR, goalIndex, "i32")
271
- const result = C._ts_tree_cursor_goto_first_child_for_index_wasm(this.tree[0])
272
- unmarshalTreeCursor(this)
273
- return result === 1
274
- }
275
-
276
- /**
277
- * Move this cursor to the first child of its current node that contains or
278
- * starts after the given byte offset.
279
- *
280
- * This returns the index of the child node if one was found, and returns
281
- * `null` if no such child was found.
282
- */
283
- gotoFirstChildForPosition(goalPosition) {
284
- marshalTreeCursor(this)
285
- marshalPoint(TRANSFER_BUFFER + SIZE_OF_CURSOR, goalPosition)
286
- const result = C._ts_tree_cursor_goto_first_child_for_position_wasm(this.tree[0])
287
- unmarshalTreeCursor(this)
288
- return result === 1
289
- }
290
-
291
- /**
292
- * Re-initialize this tree cursor to start at the original node that the
293
- * cursor was constructed with.
294
- */
295
- reset(node) {
296
- marshalNode(node)
297
- marshalTreeCursor(this, TRANSFER_BUFFER + SIZE_OF_NODE)
298
- C._ts_tree_cursor_reset_wasm(this.tree[0])
299
- unmarshalTreeCursor(this)
300
- }
301
-
302
- /**
303
- * Re-initialize a tree cursor to the same position as another cursor.
304
- *
305
- * Unlike {@link TreeCursor#reset}, this will not lose parent
306
- * information and allows reusing already created cursors.
307
- */
308
- resetTo(cursor) {
309
- marshalTreeCursor(this, TRANSFER_BUFFER)
310
- marshalTreeCursor(cursor, TRANSFER_BUFFER + SIZE_OF_CURSOR)
311
- C._ts_tree_cursor_reset_to_wasm(this.tree[0], cursor.tree[0])
312
- unmarshalTreeCursor(this)
313
- }
314
- }