@kerebron/tree-sitter 0.4.6
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.
- package/LICENSE +23 -0
- package/README.md +4 -0
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/deno-tree-sitter/main/extended/base_node.d.ts +48 -0
- package/esm/deno-tree-sitter/main/extended/base_node.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/base_node.js +154 -0
- package/esm/deno-tree-sitter/main/extended/node_extended.d.ts +237 -0
- package/esm/deno-tree-sitter/main/extended/node_extended.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/node_extended.js +665 -0
- package/esm/deno-tree-sitter/main/extended/parser.d.ts +37 -0
- package/esm/deno-tree-sitter/main/extended/parser.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/parser.js +86 -0
- package/esm/deno-tree-sitter/main/extended/soft_node.d.ts +15 -0
- package/esm/deno-tree-sitter/main/extended/soft_node.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/soft_node.js +32 -0
- package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts +10 -0
- package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/soft_text_node.js +10 -0
- package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts +10 -0
- package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/whitespace_node.js +10 -0
- package/esm/deno-tree-sitter/main/extras/misc.d.ts +2 -0
- package/esm/deno-tree-sitter/main/extras/misc.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extras/misc.js +13 -0
- package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts +14 -0
- package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/bindings.js +21 -0
- package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts +60 -0
- package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/constants.js +66 -0
- package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts +137 -0
- package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/language.js +296 -0
- package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts +41 -0
- package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.js +75 -0
- package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts +85 -0
- package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/marshal.js +173 -0
- package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts +260 -0
- package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/node.js +592 -0
- package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts +124 -0
- package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/parser.js +272 -0
- package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts +134 -0
- package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/query.js +670 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts +49 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree.js +145 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts +165 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.js +305 -0
- package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts +3 -0
- package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter_wasm.js +0 -0
- package/esm/deno-tree-sitter/main/wasm_loader.d.ts +29 -0
- package/esm/deno-tree-sitter/main/wasm_loader.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/wasm_loader.js +1709 -0
- package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts +3 -0
- package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.js +8 -0
- package/esm/mod.d.ts +8 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +8 -0
- package/esm/package.json +3 -0
- package/package.json +16 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export function getText(tree: any, startIndex: any, endIndex: any, startPosition: any): any;
|
|
3
|
+
/** A tree that represents the syntactic structure of a source code file. */
|
|
4
|
+
export class Tree {
|
|
5
|
+
/** @internal */
|
|
6
|
+
constructor(internal: any, address: any, language: any, textCallback: any);
|
|
7
|
+
/** @internal */
|
|
8
|
+
0: number;
|
|
9
|
+
/** @internal */
|
|
10
|
+
textCallback: any;
|
|
11
|
+
/** The language that was used to parse the syntax tree. */
|
|
12
|
+
language: any;
|
|
13
|
+
/** Create a shallow copy of the syntax tree. This is very fast. */
|
|
14
|
+
copy(): Tree;
|
|
15
|
+
/** Delete the syntax tree, freeing its resources. */
|
|
16
|
+
delete(): void;
|
|
17
|
+
/** Get the root node of the syntax tree. */
|
|
18
|
+
get rootNode(): any;
|
|
19
|
+
/**
|
|
20
|
+
* Get the root node of the syntax tree, but with its position shifted
|
|
21
|
+
* forward by the given offset.
|
|
22
|
+
*/
|
|
23
|
+
rootNodeWithOffset(offsetBytes: any, offsetExtent: any): any;
|
|
24
|
+
/**
|
|
25
|
+
* Edit the syntax tree to keep it in sync with source code that has been
|
|
26
|
+
* edited.
|
|
27
|
+
*
|
|
28
|
+
* You must describe the edit both in terms of byte offsets and in terms of
|
|
29
|
+
* row/column coordinates.
|
|
30
|
+
*/
|
|
31
|
+
edit(edit: any): void;
|
|
32
|
+
/** Create a new {@link TreeCursor} starting from the root of the tree. */
|
|
33
|
+
walk(): any;
|
|
34
|
+
/**
|
|
35
|
+
* Compare this old edited syntax tree to a new syntax tree representing
|
|
36
|
+
* the same document, returning a sequence of ranges whose syntactic
|
|
37
|
+
* structure has changed.
|
|
38
|
+
*
|
|
39
|
+
* For this to work correctly, this syntax tree must have been edited such
|
|
40
|
+
* that its ranges match up to the new tree. Generally, you'll want to
|
|
41
|
+
* call this method right after calling one of the [`Parser::parse`]
|
|
42
|
+
* functions. Call it on the old tree that was passed to parse, and
|
|
43
|
+
* pass the new tree that was returned from `parse`.
|
|
44
|
+
*/
|
|
45
|
+
getChangedRanges(other: any): any[];
|
|
46
|
+
/** Get the included ranges that were used to parse the syntax tree. */
|
|
47
|
+
getIncludedRanges(): any[];
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/tree_sitter/tree.js"],"names":[],"mappings":"AAOA,gBAAgB;AAChB,4FAmBC;AAED,4EAA4E;AAC5E;IAUI,gBAAgB;IAChB,2EAKC;IAfD,gBAAgB;IAChB,UAAO;IAEP,gBAAgB;IAChB,kBAAY;IAEZ,2DAA2D;IAC3D,cAAQ;IAUR,mEAAmE;IACnE,aAGC;IAED,qDAAqD;IACrD,eAGC;IAED,4CAA4C;IAC5C,oBAGC;IAED;;;OAGG;IACH,6DAMC;IAED;;;;;;OAMG;IACH,sBAGC;IAED,0EAA0E;IAC1E,YAEC;IAED;;;;;;;;;;OAUG;IACH,oCAmBC;IAED,uEAAuE;IACvE,2BAeC;CACJ"}
|
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
/** @internal */
|
|
8
|
+
export function getText(tree, startIndex, endIndex, startPosition) {
|
|
9
|
+
const length = endIndex - startIndex;
|
|
10
|
+
let result = tree.textCallback(startIndex, startPosition);
|
|
11
|
+
if (result) {
|
|
12
|
+
startIndex += result.length;
|
|
13
|
+
while (startIndex < endIndex) {
|
|
14
|
+
const string = tree.textCallback(startIndex, startPosition);
|
|
15
|
+
if (string && string.length > 0) {
|
|
16
|
+
startIndex += string.length;
|
|
17
|
+
result += string;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (startIndex > endIndex) {
|
|
24
|
+
result = result.slice(0, length);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result ?? "";
|
|
28
|
+
}
|
|
29
|
+
/** A tree that represents the syntactic structure of a source code file. */
|
|
30
|
+
export class Tree {
|
|
31
|
+
/** @internal */
|
|
32
|
+
constructor(internal, address, language, textCallback) {
|
|
33
|
+
/** @internal */
|
|
34
|
+
Object.defineProperty(this, 0, {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: 0
|
|
39
|
+
}); // Internal handle for Wasm
|
|
40
|
+
/** @internal */
|
|
41
|
+
Object.defineProperty(this, "textCallback", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
/** The language that was used to parse the syntax tree. */
|
|
48
|
+
Object.defineProperty(this, "language", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: void 0
|
|
53
|
+
});
|
|
54
|
+
assertInternal(internal);
|
|
55
|
+
this[0] = address;
|
|
56
|
+
this.language = language;
|
|
57
|
+
this.textCallback = textCallback;
|
|
58
|
+
}
|
|
59
|
+
/** Create a shallow copy of the syntax tree. This is very fast. */
|
|
60
|
+
copy() {
|
|
61
|
+
const address = C._ts_tree_copy(this[0]);
|
|
62
|
+
return new Tree(INTERNAL, address, this.language, this.textCallback);
|
|
63
|
+
}
|
|
64
|
+
/** Delete the syntax tree, freeing its resources. */
|
|
65
|
+
delete() {
|
|
66
|
+
C._ts_tree_delete(this[0]);
|
|
67
|
+
this[0] = 0;
|
|
68
|
+
}
|
|
69
|
+
/** Get the root node of the syntax tree. */
|
|
70
|
+
get rootNode() {
|
|
71
|
+
C._ts_tree_root_node_wasm(this[0]);
|
|
72
|
+
return unmarshalNode(this);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get the root node of the syntax tree, but with its position shifted
|
|
76
|
+
* forward by the given offset.
|
|
77
|
+
*/
|
|
78
|
+
rootNodeWithOffset(offsetBytes, offsetExtent) {
|
|
79
|
+
const address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
80
|
+
C.setValue(address, offsetBytes, "i32");
|
|
81
|
+
marshalPoint(address + SIZE_OF_INT, offsetExtent);
|
|
82
|
+
C._ts_tree_root_node_with_offset_wasm(this[0]);
|
|
83
|
+
return unmarshalNode(this);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Edit the syntax tree to keep it in sync with source code that has been
|
|
87
|
+
* edited.
|
|
88
|
+
*
|
|
89
|
+
* You must describe the edit both in terms of byte offsets and in terms of
|
|
90
|
+
* row/column coordinates.
|
|
91
|
+
*/
|
|
92
|
+
edit(edit) {
|
|
93
|
+
marshalEdit(edit);
|
|
94
|
+
C._ts_tree_edit_wasm(this[0]);
|
|
95
|
+
}
|
|
96
|
+
/** Create a new {@link TreeCursor} starting from the root of the tree. */
|
|
97
|
+
walk() {
|
|
98
|
+
return this.rootNode.walk();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Compare this old edited syntax tree to a new syntax tree representing
|
|
102
|
+
* the same document, returning a sequence of ranges whose syntactic
|
|
103
|
+
* structure has changed.
|
|
104
|
+
*
|
|
105
|
+
* For this to work correctly, this syntax tree must have been edited such
|
|
106
|
+
* that its ranges match up to the new tree. Generally, you'll want to
|
|
107
|
+
* call this method right after calling one of the [`Parser::parse`]
|
|
108
|
+
* functions. Call it on the old tree that was passed to parse, and
|
|
109
|
+
* pass the new tree that was returned from `parse`.
|
|
110
|
+
*/
|
|
111
|
+
getChangedRanges(other) {
|
|
112
|
+
if (!(other instanceof Tree)) {
|
|
113
|
+
throw new TypeError("Argument must be a Tree");
|
|
114
|
+
}
|
|
115
|
+
C._ts_tree_get_changed_ranges_wasm(this[0], other[0]);
|
|
116
|
+
const count = C.getValue(TRANSFER_BUFFER, "i32");
|
|
117
|
+
const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
118
|
+
const result = new Array(count);
|
|
119
|
+
if (count > 0) {
|
|
120
|
+
let address = buffer;
|
|
121
|
+
for (let i = 0; i < count; i++) {
|
|
122
|
+
result[i] = unmarshalRange(address);
|
|
123
|
+
address += SIZE_OF_RANGE;
|
|
124
|
+
}
|
|
125
|
+
C._free(buffer);
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
/** Get the included ranges that were used to parse the syntax tree. */
|
|
130
|
+
getIncludedRanges() {
|
|
131
|
+
C._ts_tree_included_ranges_wasm(this[0]);
|
|
132
|
+
const count = C.getValue(TRANSFER_BUFFER, "i32");
|
|
133
|
+
const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
134
|
+
const result = new Array(count);
|
|
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
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/** A stateful object for walking a syntax {@link Tree} efficiently. */
|
|
2
|
+
export class TreeCursor {
|
|
3
|
+
/** @internal */
|
|
4
|
+
constructor(internal: any, tree: any);
|
|
5
|
+
/** @internal */
|
|
6
|
+
0: number;
|
|
7
|
+
/** @internal */
|
|
8
|
+
1: number;
|
|
9
|
+
/** @internal */
|
|
10
|
+
2: number;
|
|
11
|
+
/** @internal */
|
|
12
|
+
3: number;
|
|
13
|
+
/** @internal */
|
|
14
|
+
tree: any;
|
|
15
|
+
/** Creates a deep copy of the tree cursor. This allocates new memory. */
|
|
16
|
+
copy(): TreeCursor;
|
|
17
|
+
/** Delete the tree cursor, freeing its resources. */
|
|
18
|
+
delete(): void;
|
|
19
|
+
/** Get the tree cursor's current {@link Node}. */
|
|
20
|
+
get currentNode(): any;
|
|
21
|
+
/**
|
|
22
|
+
* Get the numerical field id of this tree cursor's current node.
|
|
23
|
+
*
|
|
24
|
+
* See also {@link TreeCursor#currentFieldName}.
|
|
25
|
+
*/
|
|
26
|
+
get currentFieldId(): any;
|
|
27
|
+
/** Get the field name of this tree cursor's current node. */
|
|
28
|
+
get currentFieldName(): any;
|
|
29
|
+
/**
|
|
30
|
+
* Get the depth of the cursor's current node relative to the original
|
|
31
|
+
* node that the cursor was constructed with.
|
|
32
|
+
*/
|
|
33
|
+
get currentDepth(): any;
|
|
34
|
+
/**
|
|
35
|
+
* Get the index of the cursor's current node out of all of the
|
|
36
|
+
* descendants of the original node that the cursor was constructed with.
|
|
37
|
+
*/
|
|
38
|
+
get currentDescendantIndex(): any;
|
|
39
|
+
/** Get the type of the cursor's current node. */
|
|
40
|
+
get nodeType(): any;
|
|
41
|
+
/** Get the type id of the cursor's current node. */
|
|
42
|
+
get nodeTypeId(): any;
|
|
43
|
+
/** Get the state id of the cursor's current node. */
|
|
44
|
+
get nodeStateId(): any;
|
|
45
|
+
/** Get the id of the cursor's current node. */
|
|
46
|
+
get nodeId(): any;
|
|
47
|
+
/**
|
|
48
|
+
* Check if the cursor's current node is *named*.
|
|
49
|
+
*
|
|
50
|
+
* Named nodes correspond to named rules in the grammar, whereas
|
|
51
|
+
* *anonymous* nodes correspond to string literals in the grammar.
|
|
52
|
+
*/
|
|
53
|
+
get nodeIsNamed(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Check if the cursor's current node is *missing*.
|
|
56
|
+
*
|
|
57
|
+
* Missing nodes are inserted by the parser in order to recover from
|
|
58
|
+
* certain kinds of syntax errors.
|
|
59
|
+
*/
|
|
60
|
+
get nodeIsMissing(): boolean;
|
|
61
|
+
/** Get the string content of the cursor's current node. */
|
|
62
|
+
get nodeText(): any;
|
|
63
|
+
/** Get the start position of the cursor's current node. */
|
|
64
|
+
get startPosition(): {
|
|
65
|
+
row: number;
|
|
66
|
+
column: number;
|
|
67
|
+
};
|
|
68
|
+
/** Get the end position of the cursor's current node. */
|
|
69
|
+
get endPosition(): {
|
|
70
|
+
row: number;
|
|
71
|
+
column: number;
|
|
72
|
+
};
|
|
73
|
+
/** Get the start index of the cursor's current node. */
|
|
74
|
+
get startIndex(): any;
|
|
75
|
+
/** Get the end index of the cursor's current node. */
|
|
76
|
+
get endIndex(): any;
|
|
77
|
+
/**
|
|
78
|
+
* Move this cursor to the first child of its current node.
|
|
79
|
+
*
|
|
80
|
+
* This returns `true` if the cursor successfully moved, and returns
|
|
81
|
+
* `false` if there were no children.
|
|
82
|
+
*/
|
|
83
|
+
gotoFirstChild(): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Move this cursor to the last child of its current node.
|
|
86
|
+
*
|
|
87
|
+
* This returns `true` if the cursor successfully moved, and returns
|
|
88
|
+
* `false` if there were no children.
|
|
89
|
+
*
|
|
90
|
+
* Note that this function may be slower than
|
|
91
|
+
* {@link TreeCursor#gotoFirstChild} because it needs to
|
|
92
|
+
* iterate through all the children to compute the child's position.
|
|
93
|
+
*/
|
|
94
|
+
gotoLastChild(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Move this cursor to the parent of its current node.
|
|
97
|
+
*
|
|
98
|
+
* This returns `true` if the cursor successfully moved, and returns
|
|
99
|
+
* `false` if there was no parent node (the cursor was already on the
|
|
100
|
+
* root node).
|
|
101
|
+
*
|
|
102
|
+
* Note that the node the cursor was constructed with is considered the root
|
|
103
|
+
* of the cursor, and the cursor cannot walk outside this node.
|
|
104
|
+
*/
|
|
105
|
+
gotoParent(): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Move this cursor to the next sibling of its current node.
|
|
108
|
+
*
|
|
109
|
+
* This returns `true` if the cursor successfully moved, and returns
|
|
110
|
+
* `false` if there was no next sibling node.
|
|
111
|
+
*
|
|
112
|
+
* Note that the node the cursor was constructed with is considered the root
|
|
113
|
+
* of the cursor, and the cursor cannot walk outside this node.
|
|
114
|
+
*/
|
|
115
|
+
gotoNextSibling(): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Move this cursor to the previous sibling of its current node.
|
|
118
|
+
*
|
|
119
|
+
* This returns `true` if the cursor successfully moved, and returns
|
|
120
|
+
* `false` if there was no previous sibling node.
|
|
121
|
+
*
|
|
122
|
+
* Note that this function may be slower than
|
|
123
|
+
* {@link TreeCursor#gotoNextSibling} due to how node
|
|
124
|
+
* positions are stored. In the worst case, this will need to iterate
|
|
125
|
+
* through all the children up to the previous sibling node to recalculate
|
|
126
|
+
* its position. Also note that the node the cursor was constructed with is
|
|
127
|
+
* considered the root of the cursor, and the cursor cannot walk outside this node.
|
|
128
|
+
*/
|
|
129
|
+
gotoPreviousSibling(): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Move the cursor to the node that is the nth descendant of
|
|
132
|
+
* the original node that the cursor was constructed with, where
|
|
133
|
+
* zero represents the original node itself.
|
|
134
|
+
*/
|
|
135
|
+
gotoDescendant(goalDescendantIndex: any): void;
|
|
136
|
+
/**
|
|
137
|
+
* Move this cursor to the first child of its current node that contains or
|
|
138
|
+
* starts after the given byte offset.
|
|
139
|
+
*
|
|
140
|
+
* This returns `true` if the cursor successfully moved to a child node, and returns
|
|
141
|
+
* `false` if no such child was found.
|
|
142
|
+
*/
|
|
143
|
+
gotoFirstChildForIndex(goalIndex: any): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Move this cursor to the first child of its current node that contains or
|
|
146
|
+
* starts after the given byte offset.
|
|
147
|
+
*
|
|
148
|
+
* This returns the index of the child node if one was found, and returns
|
|
149
|
+
* `null` if no such child was found.
|
|
150
|
+
*/
|
|
151
|
+
gotoFirstChildForPosition(goalPosition: any): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Re-initialize this tree cursor to start at the original node that the
|
|
154
|
+
* cursor was constructed with.
|
|
155
|
+
*/
|
|
156
|
+
reset(node: any): void;
|
|
157
|
+
/**
|
|
158
|
+
* Re-initialize a tree cursor to the same position as another cursor.
|
|
159
|
+
*
|
|
160
|
+
* Unlike {@link TreeCursor#reset}, this will not lose parent
|
|
161
|
+
* information and allows reusing already created cursors.
|
|
162
|
+
*/
|
|
163
|
+
resetTo(cursor: any): void;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=tree_cursor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree_cursor.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/tree_sitter/tree_cursor.js"],"names":[],"mappings":"AAMA,uEAAuE;AACvE;IAgBI,gBAAgB;IAChB,sCAIC;IApBD,gBAAgB;IAChB,UAAQ;IAER,gBAAgB;IAChB,UAAQ;IAER,gBAAgB;IAChB,UAAQ;IAER,gBAAgB;IAChB,UAAO;IAEP,gBAAgB;IAChB,UAAI;IASJ,yEAAyE;IACzE,mBAKC;IAED,qDAAqD;IACrD,eAIC;IAED,kDAAkD;IAClD,uBAIC;IAED;;;;OAIG;IACH,0BAGC;IAED,6DAA6D;IAC7D,4BAEC;IAED;;;OAGG;IACH,wBAGC;IAED;;;OAGG;IACH,kCAGC;IAED,iDAAiD;IACjD,oBAEC;IAED,oDAAoD;IACpD,sBAGC;IAED,qDAAqD;IACrD,uBAGC;IAED,+CAA+C;IAC/C,kBAGC;IAED;;;;;OAKG;IACH,2BAGC;IAED;;;;;OAKG;IACH,6BAGC;IAED,2DAA2D;IAC3D,oBAOC;IAED,2DAA2D;IAC3D;;;MAIC;IAED,yDAAyD;IACzD;;;MAIC;IAED,wDAAwD;IACxD,sBAGC;IAED,sDAAsD;IACtD,oBAGC;IAED;;;;;OAKG;IACH,0BAKC;IAED;;;;;;;;;OASG;IACH,yBAKC;IAED;;;;;;;;;OASG;IACH,sBAKC;IAED;;;;;;;;OAQG;IACH,2BAKC;IAED;;;;;;;;;;;;OAYG;IACH,+BAKC;IAED;;;;OAIG;IACH,+CAIC;IAED;;;;;;OAMG;IACH,gDAMC;IAED;;;;;;OAMG;IACH,sDAMC;IAED;;;OAGG;IACH,uBAKC;IAED;;;;;OAKG;IACH,2BAKC;CACJ"}
|
|
@@ -0,0 +1,305 @@
|
|
|
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
|
+
/** A stateful object for walking a syntax {@link Tree} efficiently. */
|
|
7
|
+
export class TreeCursor {
|
|
8
|
+
/** @internal */
|
|
9
|
+
constructor(internal, tree) {
|
|
10
|
+
/** @internal */
|
|
11
|
+
Object.defineProperty(this, 0, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: 0
|
|
16
|
+
}); // Internal handle for Wasm
|
|
17
|
+
/** @internal */
|
|
18
|
+
Object.defineProperty(this, 1, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: 0
|
|
23
|
+
}); // Internal handle for Wasm
|
|
24
|
+
/** @internal */
|
|
25
|
+
Object.defineProperty(this, 2, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: 0
|
|
30
|
+
}); // Internal handle for Wasm
|
|
31
|
+
/** @internal */
|
|
32
|
+
Object.defineProperty(this, 3, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: 0
|
|
37
|
+
}); // Internal handle for Wasm
|
|
38
|
+
/** @internal */
|
|
39
|
+
Object.defineProperty(this, "tree", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
45
|
+
assertInternal(internal);
|
|
46
|
+
this.tree = tree;
|
|
47
|
+
unmarshalTreeCursor(this);
|
|
48
|
+
}
|
|
49
|
+
/** Creates a deep copy of the tree cursor. This allocates new memory. */
|
|
50
|
+
copy() {
|
|
51
|
+
const copy = new TreeCursor(INTERNAL, this.tree);
|
|
52
|
+
C._ts_tree_cursor_copy_wasm(this.tree[0]);
|
|
53
|
+
unmarshalTreeCursor(copy);
|
|
54
|
+
return copy;
|
|
55
|
+
}
|
|
56
|
+
/** Delete the tree cursor, freeing its resources. */
|
|
57
|
+
delete() {
|
|
58
|
+
marshalTreeCursor(this);
|
|
59
|
+
C._ts_tree_cursor_delete_wasm(this.tree[0]);
|
|
60
|
+
this[0] = this[1] = this[2] = 0;
|
|
61
|
+
}
|
|
62
|
+
/** Get the tree cursor's current {@link Node}. */
|
|
63
|
+
get currentNode() {
|
|
64
|
+
marshalTreeCursor(this);
|
|
65
|
+
C._ts_tree_cursor_current_node_wasm(this.tree[0]);
|
|
66
|
+
return unmarshalNode(this.tree);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the numerical field id of this tree cursor's current node.
|
|
70
|
+
*
|
|
71
|
+
* See also {@link TreeCursor#currentFieldName}.
|
|
72
|
+
*/
|
|
73
|
+
get currentFieldId() {
|
|
74
|
+
marshalTreeCursor(this);
|
|
75
|
+
return C._ts_tree_cursor_current_field_id_wasm(this.tree[0]);
|
|
76
|
+
}
|
|
77
|
+
/** Get the field name of this tree cursor's current node. */
|
|
78
|
+
get currentFieldName() {
|
|
79
|
+
return this.tree.language.fields[this.currentFieldId];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the depth of the cursor's current node relative to the original
|
|
83
|
+
* node that the cursor was constructed with.
|
|
84
|
+
*/
|
|
85
|
+
get currentDepth() {
|
|
86
|
+
marshalTreeCursor(this);
|
|
87
|
+
return C._ts_tree_cursor_current_depth_wasm(this.tree[0]);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the index of the cursor's current node out of all of the
|
|
91
|
+
* descendants of the original node that the cursor was constructed with.
|
|
92
|
+
*/
|
|
93
|
+
get currentDescendantIndex() {
|
|
94
|
+
marshalTreeCursor(this);
|
|
95
|
+
return C._ts_tree_cursor_current_descendant_index_wasm(this.tree[0]);
|
|
96
|
+
}
|
|
97
|
+
/** Get the type of the cursor's current node. */
|
|
98
|
+
get nodeType() {
|
|
99
|
+
return this.tree.language.types[this.nodeTypeId] || "ERROR";
|
|
100
|
+
}
|
|
101
|
+
/** Get the type id of the cursor's current node. */
|
|
102
|
+
get nodeTypeId() {
|
|
103
|
+
marshalTreeCursor(this);
|
|
104
|
+
return C._ts_tree_cursor_current_node_type_id_wasm(this.tree[0]);
|
|
105
|
+
}
|
|
106
|
+
/** Get the state id of the cursor's current node. */
|
|
107
|
+
get nodeStateId() {
|
|
108
|
+
marshalTreeCursor(this);
|
|
109
|
+
return C._ts_tree_cursor_current_node_state_id_wasm(this.tree[0]);
|
|
110
|
+
}
|
|
111
|
+
/** Get the id of the cursor's current node. */
|
|
112
|
+
get nodeId() {
|
|
113
|
+
marshalTreeCursor(this);
|
|
114
|
+
return C._ts_tree_cursor_current_node_id_wasm(this.tree[0]);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Check if the cursor's current node is *named*.
|
|
118
|
+
*
|
|
119
|
+
* Named nodes correspond to named rules in the grammar, whereas
|
|
120
|
+
* *anonymous* nodes correspond to string literals in the grammar.
|
|
121
|
+
*/
|
|
122
|
+
get nodeIsNamed() {
|
|
123
|
+
marshalTreeCursor(this);
|
|
124
|
+
return C._ts_tree_cursor_current_node_is_named_wasm(this.tree[0]) === 1;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Check if the cursor's current node is *missing*.
|
|
128
|
+
*
|
|
129
|
+
* Missing nodes are inserted by the parser in order to recover from
|
|
130
|
+
* certain kinds of syntax errors.
|
|
131
|
+
*/
|
|
132
|
+
get nodeIsMissing() {
|
|
133
|
+
marshalTreeCursor(this);
|
|
134
|
+
return C._ts_tree_cursor_current_node_is_missing_wasm(this.tree[0]) === 1;
|
|
135
|
+
}
|
|
136
|
+
/** Get the string content of the cursor's current node. */
|
|
137
|
+
get nodeText() {
|
|
138
|
+
marshalTreeCursor(this);
|
|
139
|
+
const startIndex = C._ts_tree_cursor_start_index_wasm(this.tree[0]);
|
|
140
|
+
const endIndex = C._ts_tree_cursor_end_index_wasm(this.tree[0]);
|
|
141
|
+
C._ts_tree_cursor_start_position_wasm(this.tree[0]);
|
|
142
|
+
const startPosition = unmarshalPoint(TRANSFER_BUFFER);
|
|
143
|
+
return getText(this.tree, startIndex, endIndex, startPosition);
|
|
144
|
+
}
|
|
145
|
+
/** Get the start position of the cursor's current node. */
|
|
146
|
+
get startPosition() {
|
|
147
|
+
marshalTreeCursor(this);
|
|
148
|
+
C._ts_tree_cursor_start_position_wasm(this.tree[0]);
|
|
149
|
+
return unmarshalPoint(TRANSFER_BUFFER);
|
|
150
|
+
}
|
|
151
|
+
/** Get the end position of the cursor's current node. */
|
|
152
|
+
get endPosition() {
|
|
153
|
+
marshalTreeCursor(this);
|
|
154
|
+
C._ts_tree_cursor_end_position_wasm(this.tree[0]);
|
|
155
|
+
return unmarshalPoint(TRANSFER_BUFFER);
|
|
156
|
+
}
|
|
157
|
+
/** Get the start index of the cursor's current node. */
|
|
158
|
+
get startIndex() {
|
|
159
|
+
marshalTreeCursor(this);
|
|
160
|
+
return C._ts_tree_cursor_start_index_wasm(this.tree[0]);
|
|
161
|
+
}
|
|
162
|
+
/** Get the end index of the cursor's current node. */
|
|
163
|
+
get endIndex() {
|
|
164
|
+
marshalTreeCursor(this);
|
|
165
|
+
return C._ts_tree_cursor_end_index_wasm(this.tree[0]);
|
|
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
|
+
* Move this cursor to the last child of its current node.
|
|
181
|
+
*
|
|
182
|
+
* This returns `true` if the cursor successfully moved, and returns
|
|
183
|
+
* `false` if there were no children.
|
|
184
|
+
*
|
|
185
|
+
* Note that this function may be slower than
|
|
186
|
+
* {@link TreeCursor#gotoFirstChild} because it needs to
|
|
187
|
+
* iterate through all the children to compute the child's position.
|
|
188
|
+
*/
|
|
189
|
+
gotoLastChild() {
|
|
190
|
+
marshalTreeCursor(this);
|
|
191
|
+
const result = C._ts_tree_cursor_goto_last_child_wasm(this.tree[0]);
|
|
192
|
+
unmarshalTreeCursor(this);
|
|
193
|
+
return result === 1;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Move this cursor to the parent of its current node.
|
|
197
|
+
*
|
|
198
|
+
* This returns `true` if the cursor successfully moved, and returns
|
|
199
|
+
* `false` if there was no parent node (the cursor was already on the
|
|
200
|
+
* root node).
|
|
201
|
+
*
|
|
202
|
+
* Note that the node the cursor was constructed with is considered the root
|
|
203
|
+
* of the cursor, and the cursor cannot walk outside this node.
|
|
204
|
+
*/
|
|
205
|
+
gotoParent() {
|
|
206
|
+
marshalTreeCursor(this);
|
|
207
|
+
const result = C._ts_tree_cursor_goto_parent_wasm(this.tree[0]);
|
|
208
|
+
unmarshalTreeCursor(this);
|
|
209
|
+
return result === 1;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Move this cursor to the next sibling of its current node.
|
|
213
|
+
*
|
|
214
|
+
* This returns `true` if the cursor successfully moved, and returns
|
|
215
|
+
* `false` if there was no next sibling node.
|
|
216
|
+
*
|
|
217
|
+
* Note that the node the cursor was constructed with is considered the root
|
|
218
|
+
* of the cursor, and the cursor cannot walk outside this node.
|
|
219
|
+
*/
|
|
220
|
+
gotoNextSibling() {
|
|
221
|
+
marshalTreeCursor(this);
|
|
222
|
+
const result = C._ts_tree_cursor_goto_next_sibling_wasm(this.tree[0]);
|
|
223
|
+
unmarshalTreeCursor(this);
|
|
224
|
+
return result === 1;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Move this cursor to the previous sibling of its current node.
|
|
228
|
+
*
|
|
229
|
+
* This returns `true` if the cursor successfully moved, and returns
|
|
230
|
+
* `false` if there was no previous sibling node.
|
|
231
|
+
*
|
|
232
|
+
* Note that this function may be slower than
|
|
233
|
+
* {@link TreeCursor#gotoNextSibling} due to how node
|
|
234
|
+
* positions are stored. In the worst case, this will need to iterate
|
|
235
|
+
* through all the children up to the previous sibling node to recalculate
|
|
236
|
+
* its position. Also note that the node the cursor was constructed with is
|
|
237
|
+
* considered the root of the cursor, and the cursor cannot walk outside this node.
|
|
238
|
+
*/
|
|
239
|
+
gotoPreviousSibling() {
|
|
240
|
+
marshalTreeCursor(this);
|
|
241
|
+
const result = C._ts_tree_cursor_goto_previous_sibling_wasm(this.tree[0]);
|
|
242
|
+
unmarshalTreeCursor(this);
|
|
243
|
+
return result === 1;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Move the cursor to the node that is the nth descendant of
|
|
247
|
+
* the original node that the cursor was constructed with, where
|
|
248
|
+
* zero represents the original node itself.
|
|
249
|
+
*/
|
|
250
|
+
gotoDescendant(goalDescendantIndex) {
|
|
251
|
+
marshalTreeCursor(this);
|
|
252
|
+
C._ts_tree_cursor_goto_descendant_wasm(this.tree[0], goalDescendantIndex);
|
|
253
|
+
unmarshalTreeCursor(this);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Move this cursor to the first child of its current node that contains or
|
|
257
|
+
* starts after the given byte offset.
|
|
258
|
+
*
|
|
259
|
+
* This returns `true` if the cursor successfully moved to a child node, and returns
|
|
260
|
+
* `false` if no such child was found.
|
|
261
|
+
*/
|
|
262
|
+
gotoFirstChildForIndex(goalIndex) {
|
|
263
|
+
marshalTreeCursor(this);
|
|
264
|
+
C.setValue(TRANSFER_BUFFER + SIZE_OF_CURSOR, goalIndex, "i32");
|
|
265
|
+
const result = C._ts_tree_cursor_goto_first_child_for_index_wasm(this.tree[0]);
|
|
266
|
+
unmarshalTreeCursor(this);
|
|
267
|
+
return result === 1;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Move this cursor to the first child of its current node that contains or
|
|
271
|
+
* starts after the given byte offset.
|
|
272
|
+
*
|
|
273
|
+
* This returns the index of the child node if one was found, and returns
|
|
274
|
+
* `null` if no such child was found.
|
|
275
|
+
*/
|
|
276
|
+
gotoFirstChildForPosition(goalPosition) {
|
|
277
|
+
marshalTreeCursor(this);
|
|
278
|
+
marshalPoint(TRANSFER_BUFFER + SIZE_OF_CURSOR, goalPosition);
|
|
279
|
+
const result = C._ts_tree_cursor_goto_first_child_for_position_wasm(this.tree[0]);
|
|
280
|
+
unmarshalTreeCursor(this);
|
|
281
|
+
return result === 1;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Re-initialize this tree cursor to start at the original node that the
|
|
285
|
+
* cursor was constructed with.
|
|
286
|
+
*/
|
|
287
|
+
reset(node) {
|
|
288
|
+
marshalNode(node);
|
|
289
|
+
marshalTreeCursor(this, TRANSFER_BUFFER + SIZE_OF_NODE);
|
|
290
|
+
C._ts_tree_cursor_reset_wasm(this.tree[0]);
|
|
291
|
+
unmarshalTreeCursor(this);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Re-initialize a tree cursor to the same position as another cursor.
|
|
295
|
+
*
|
|
296
|
+
* Unlike {@link TreeCursor#reset}, this will not lose parent
|
|
297
|
+
* information and allows reusing already created cursors.
|
|
298
|
+
*/
|
|
299
|
+
resetTo(cursor) {
|
|
300
|
+
marshalTreeCursor(this, TRANSFER_BUFFER);
|
|
301
|
+
marshalTreeCursor(cursor, TRANSFER_BUFFER + SIZE_OF_CURSOR);
|
|
302
|
+
C._ts_tree_cursor_reset_to_wasm(this.tree[0], cursor.tree[0]);
|
|
303
|
+
unmarshalTreeCursor(this);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree_sitter_wasm.d.ts","sourceRoot":"","sources":["../../../src/deno-tree-sitter/main/tree_sitter_wasm.js"],"names":[],"mappings":";AAiEA,4CAm6CoI"}
|
|
Binary file
|