@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,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for parsing
|
|
3
|
+
*
|
|
4
|
+
* The `includedRanges` property is an array of {@link Range} objects that
|
|
5
|
+
* represent the ranges of text that the parser should include when parsing.
|
|
6
|
+
*
|
|
7
|
+
* The `progressCallback` property is a function that is called periodically
|
|
8
|
+
* during parsing to check whether parsing should be cancelled.
|
|
9
|
+
*
|
|
10
|
+
* See {@link Parser#parse} for more information.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A stateful object that is passed into the progress callback {@link ParseOptions#progressCallback}
|
|
14
|
+
* to provide the current state of the parser.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*
|
|
19
|
+
* Global variable for transferring data across the FFI boundary
|
|
20
|
+
*/
|
|
21
|
+
export let TRANSFER_BUFFER: any;
|
|
22
|
+
/**
|
|
23
|
+
* The latest ABI version that is supported by the current version of the
|
|
24
|
+
* library.
|
|
25
|
+
*
|
|
26
|
+
* When Languages are generated by the Tree-sitter CLI, they are
|
|
27
|
+
* assigned an ABI version number that corresponds to the current CLI version.
|
|
28
|
+
* The Tree-sitter library is generally backwards-compatible with languages
|
|
29
|
+
* generated using older CLI versions, but is not forwards-compatible.
|
|
30
|
+
*/
|
|
31
|
+
export let LANGUAGE_VERSION: any;
|
|
32
|
+
/**
|
|
33
|
+
* The earliest ABI version that is supported by the current version of the
|
|
34
|
+
* library.
|
|
35
|
+
*/
|
|
36
|
+
export let MIN_COMPATIBLE_VERSION: any;
|
|
37
|
+
/**
|
|
38
|
+
* A stateful object that is used to produce a {@link Tree} based on some
|
|
39
|
+
* source code.
|
|
40
|
+
*/
|
|
41
|
+
export class Parser {
|
|
42
|
+
/**
|
|
43
|
+
* This must always be called before creating a Parser.
|
|
44
|
+
*
|
|
45
|
+
* You can optionally pass in options to configure the Wasm module, the most common
|
|
46
|
+
* one being `locateFile` to help the module find the `.wasm` file.
|
|
47
|
+
*/
|
|
48
|
+
static init(moduleOptions: any): Promise<void>;
|
|
49
|
+
/** @internal */
|
|
50
|
+
0: number;
|
|
51
|
+
/** @internal */
|
|
52
|
+
1: number;
|
|
53
|
+
/** @internal */
|
|
54
|
+
logCallback: null;
|
|
55
|
+
/** The parser's current language. */
|
|
56
|
+
language: null;
|
|
57
|
+
/** @internal */
|
|
58
|
+
initialize(): void;
|
|
59
|
+
/** Delete the parser, freeing its resources. */
|
|
60
|
+
delete(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Set the language that the parser should use for parsing.
|
|
63
|
+
*
|
|
64
|
+
* If the language was not successfully assigned, an error will be thrown.
|
|
65
|
+
* This happens if the language was generated with an incompatible
|
|
66
|
+
* version of the Tree-sitter CLI. Check the language's version using
|
|
67
|
+
* {@link Language#version} and compare it to this library's
|
|
68
|
+
* {@link LANGUAGE_VERSION} and {@link MIN_COMPATIBLE_VERSION} constants.
|
|
69
|
+
*/
|
|
70
|
+
setLanguage(language: any): this;
|
|
71
|
+
/**
|
|
72
|
+
* Parse a slice of UTF8 text.
|
|
73
|
+
*
|
|
74
|
+
* @param {string | ParseCallback} callback - The UTF8-encoded text to parse or a callback function.
|
|
75
|
+
*
|
|
76
|
+
* @param {Tree | null} [oldTree] - A previous syntax tree parsed from the same document. If the text of the
|
|
77
|
+
* document has changed since `oldTree` was created, then you must edit `oldTree` to match
|
|
78
|
+
* the new text using {@link Tree#edit}.
|
|
79
|
+
*
|
|
80
|
+
* @param {ParseOptions} [options] - Options for parsing the text.
|
|
81
|
+
* This can be used to set the included ranges, or a progress callback.
|
|
82
|
+
*
|
|
83
|
+
* @returns {Tree | null} A {@link Tree} if parsing succeeded, or `null` if:
|
|
84
|
+
* - The parser has not yet had a language assigned with {@link Parser#setLanguage}.
|
|
85
|
+
* - The progress callback returned true.
|
|
86
|
+
*/
|
|
87
|
+
parse(callback: string | ParseCallback, oldTree?: Tree | null, options?: ParseOptions): Tree | null;
|
|
88
|
+
/**
|
|
89
|
+
* Instruct the parser to start the next parse from the beginning.
|
|
90
|
+
*
|
|
91
|
+
* If the parser previously failed because of a timeout, cancellation,
|
|
92
|
+
* or callback, then by default, it will resume where it left off on the
|
|
93
|
+
* next call to {@link Parser#parse} or other parsing functions.
|
|
94
|
+
* If you don't want to resume, and instead intend to use this parser to
|
|
95
|
+
* parse some other document, you must call `reset` first.
|
|
96
|
+
*/
|
|
97
|
+
reset(): void;
|
|
98
|
+
/** Get the ranges of text that the parser will include when parsing. */
|
|
99
|
+
getIncludedRanges(): any[];
|
|
100
|
+
/**
|
|
101
|
+
* @deprecated since version 0.25.0, prefer passing a progress callback to {@link Parser#parse}
|
|
102
|
+
*
|
|
103
|
+
* Get the duration in microseconds that parsing is allowed to take.
|
|
104
|
+
*
|
|
105
|
+
* This is set via {@link Parser#setTimeoutMicros}.
|
|
106
|
+
*/
|
|
107
|
+
getTimeoutMicros(): any;
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated since version 0.25.0, prefer passing a progress callback to {@link Parser#parse}
|
|
110
|
+
*
|
|
111
|
+
* Set the maximum duration in microseconds that parsing should be allowed
|
|
112
|
+
* to take before halting.
|
|
113
|
+
*
|
|
114
|
+
* If parsing takes longer than this, it will halt early, returning `null`.
|
|
115
|
+
* See {@link Parser#parse} for more information.
|
|
116
|
+
*/
|
|
117
|
+
setTimeoutMicros(timeout: any): void;
|
|
118
|
+
/** Set the logging callback that a parser should use during parsing. */
|
|
119
|
+
setLogger(callback: any): this;
|
|
120
|
+
/** Get the parser's current logger. */
|
|
121
|
+
getLogger(): null;
|
|
122
|
+
}
|
|
123
|
+
import { Tree } from "./tree.js";
|
|
124
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/tree_sitter/parser.js"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH;;;GAGG;AACH;;;;GAIG;AACH,gCAA0B;AAE1B;;;;;;;;GAQG;AACH,iCAA2B;AAE3B;;;GAGG;AACH,uCAAiC;AAEjC;;;GAGG;AACH;IAaI;;;;;OAKG;IACH,+CAKC;IAvBD,gBAAgB;IAChB,UAAQ;IAER,gBAAgB;IAChB,UAAO;IAEP,gBAAgB;IAChB,kBAAkB;IAElB,qCAAqC;IACrC,eAAe;IAsBf,gBAAgB;IAChB,mBAOC;IAED,gDAAgD;IAChD,eAKC;IAED;;;;;;;;OAQG;IACH,iCAkBC;IAED;;;;;;;;;;;;;;;OAeG;IACH,gBAbW,MAAM,GAAG,aAAa,YAEtB,IAAI,GAAG,IAAI,YAIX,YAAY,GAGV,IAAI,GAAG,IAAI,CAyDvB;IAED;;;;;;;;OAQG;IACH,cAEC;IAED,wEAAwE;IACxE,2BAgBC;IAED;;;;;;OAMG;IACH,wBAEC;IAED;;;;;;;;OAQG;IACH,qCAEC;IAED,wEAAwE;IACxE,+BASC;IAED,uCAAuC;IACvC,kBAEC;CACJ;qBA5QoB,WAAW"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { C, INTERNAL, SIZE_OF_INT, SIZE_OF_RANGE, setModule } from "./constants.js";
|
|
2
|
+
import { Language } from "./language.js";
|
|
3
|
+
import { marshalRange, unmarshalRange } from "./marshal.js";
|
|
4
|
+
import { checkModule, initializeBinding } from "./bindings.js";
|
|
5
|
+
import { Tree } from "./tree.js";
|
|
6
|
+
/**
|
|
7
|
+
* Options for parsing
|
|
8
|
+
*
|
|
9
|
+
* The `includedRanges` property is an array of {@link Range} objects that
|
|
10
|
+
* represent the ranges of text that the parser should include when parsing.
|
|
11
|
+
*
|
|
12
|
+
* The `progressCallback` property is a function that is called periodically
|
|
13
|
+
* during parsing to check whether parsing should be cancelled.
|
|
14
|
+
*
|
|
15
|
+
* See {@link Parser#parse} for more information.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* A stateful object that is passed into the progress callback {@link ParseOptions#progressCallback}
|
|
19
|
+
* to provide the current state of the parser.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*
|
|
24
|
+
* Global variable for transferring data across the FFI boundary
|
|
25
|
+
*/
|
|
26
|
+
export let TRANSFER_BUFFER;
|
|
27
|
+
/**
|
|
28
|
+
* The latest ABI version that is supported by the current version of the
|
|
29
|
+
* library.
|
|
30
|
+
*
|
|
31
|
+
* When Languages are generated by the Tree-sitter CLI, they are
|
|
32
|
+
* assigned an ABI version number that corresponds to the current CLI version.
|
|
33
|
+
* The Tree-sitter library is generally backwards-compatible with languages
|
|
34
|
+
* generated using older CLI versions, but is not forwards-compatible.
|
|
35
|
+
*/
|
|
36
|
+
export let LANGUAGE_VERSION;
|
|
37
|
+
/**
|
|
38
|
+
* The earliest ABI version that is supported by the current version of the
|
|
39
|
+
* library.
|
|
40
|
+
*/
|
|
41
|
+
export let MIN_COMPATIBLE_VERSION;
|
|
42
|
+
/**
|
|
43
|
+
* A stateful object that is used to produce a {@link Tree} based on some
|
|
44
|
+
* source code.
|
|
45
|
+
*/
|
|
46
|
+
export class Parser {
|
|
47
|
+
/**
|
|
48
|
+
* This must always be called before creating a Parser.
|
|
49
|
+
*
|
|
50
|
+
* You can optionally pass in options to configure the Wasm module, the most common
|
|
51
|
+
* one being `locateFile` to help the module find the `.wasm` file.
|
|
52
|
+
*/
|
|
53
|
+
static async init(moduleOptions) {
|
|
54
|
+
setModule(await initializeBinding(moduleOptions));
|
|
55
|
+
TRANSFER_BUFFER = C._ts_init();
|
|
56
|
+
LANGUAGE_VERSION = C.getValue(TRANSFER_BUFFER, "i32");
|
|
57
|
+
MIN_COMPATIBLE_VERSION = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create a new parser.
|
|
61
|
+
*/
|
|
62
|
+
constructor() {
|
|
63
|
+
/** @internal */
|
|
64
|
+
Object.defineProperty(this, 0, {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
configurable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
value: 0
|
|
69
|
+
}); // Internal handle for Wasm
|
|
70
|
+
/** @internal */
|
|
71
|
+
Object.defineProperty(this, 1, {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: 0
|
|
76
|
+
}); // Internal handle for Wasm
|
|
77
|
+
/** @internal */
|
|
78
|
+
Object.defineProperty(this, "logCallback", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: null
|
|
83
|
+
});
|
|
84
|
+
/** The parser's current language. */
|
|
85
|
+
Object.defineProperty(this, "language", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
configurable: true,
|
|
88
|
+
writable: true,
|
|
89
|
+
value: null
|
|
90
|
+
});
|
|
91
|
+
this.initialize();
|
|
92
|
+
}
|
|
93
|
+
/** @internal */
|
|
94
|
+
initialize() {
|
|
95
|
+
if (!checkModule()) {
|
|
96
|
+
throw new Error("cannot construct a Parser before calling `init()`");
|
|
97
|
+
}
|
|
98
|
+
C._ts_parser_new_wasm();
|
|
99
|
+
this[0] = C.getValue(TRANSFER_BUFFER, "i32");
|
|
100
|
+
this[1] = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
101
|
+
}
|
|
102
|
+
/** Delete the parser, freeing its resources. */
|
|
103
|
+
delete() {
|
|
104
|
+
C._ts_parser_delete(this[0]);
|
|
105
|
+
C._free(this[1]);
|
|
106
|
+
this[0] = 0;
|
|
107
|
+
this[1] = 0;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Set the language that the parser should use for parsing.
|
|
111
|
+
*
|
|
112
|
+
* If the language was not successfully assigned, an error will be thrown.
|
|
113
|
+
* This happens if the language was generated with an incompatible
|
|
114
|
+
* version of the Tree-sitter CLI. Check the language's version using
|
|
115
|
+
* {@link Language#version} and compare it to this library's
|
|
116
|
+
* {@link LANGUAGE_VERSION} and {@link MIN_COMPATIBLE_VERSION} constants.
|
|
117
|
+
*/
|
|
118
|
+
setLanguage(language) {
|
|
119
|
+
let address;
|
|
120
|
+
if (!language) {
|
|
121
|
+
address = 0;
|
|
122
|
+
this.language = null;
|
|
123
|
+
}
|
|
124
|
+
else if (language.constructor === Language) {
|
|
125
|
+
address = language[0];
|
|
126
|
+
const version = C._ts_language_version(address);
|
|
127
|
+
if (version < MIN_COMPATIBLE_VERSION || LANGUAGE_VERSION < version) {
|
|
128
|
+
throw new Error(`Incompatible language version ${version}. ` + `Compatibility range ${MIN_COMPATIBLE_VERSION} through ${LANGUAGE_VERSION}.`);
|
|
129
|
+
}
|
|
130
|
+
this.language = language;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
throw new Error("Argument must be a Language");
|
|
134
|
+
}
|
|
135
|
+
C._ts_parser_set_language(this[0], address);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Parse a slice of UTF8 text.
|
|
140
|
+
*
|
|
141
|
+
* @param {string | ParseCallback} callback - The UTF8-encoded text to parse or a callback function.
|
|
142
|
+
*
|
|
143
|
+
* @param {Tree | null} [oldTree] - A previous syntax tree parsed from the same document. If the text of the
|
|
144
|
+
* document has changed since `oldTree` was created, then you must edit `oldTree` to match
|
|
145
|
+
* the new text using {@link Tree#edit}.
|
|
146
|
+
*
|
|
147
|
+
* @param {ParseOptions} [options] - Options for parsing the text.
|
|
148
|
+
* This can be used to set the included ranges, or a progress callback.
|
|
149
|
+
*
|
|
150
|
+
* @returns {Tree | null} A {@link Tree} if parsing succeeded, or `null` if:
|
|
151
|
+
* - The parser has not yet had a language assigned with {@link Parser#setLanguage}.
|
|
152
|
+
* - The progress callback returned true.
|
|
153
|
+
*/
|
|
154
|
+
parse(callback, oldTree, options) {
|
|
155
|
+
if (typeof callback === "string") {
|
|
156
|
+
C.currentParseCallback = (index) => callback.slice(index);
|
|
157
|
+
}
|
|
158
|
+
else if (typeof callback === "function") {
|
|
159
|
+
C.currentParseCallback = callback;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
throw new Error("Argument must be a string or a function");
|
|
163
|
+
}
|
|
164
|
+
if (options?.progressCallback) {
|
|
165
|
+
C.currentProgressCallback = options.progressCallback;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
C.currentProgressCallback = null;
|
|
169
|
+
}
|
|
170
|
+
if (this.logCallback) {
|
|
171
|
+
C.currentLogCallback = this.logCallback;
|
|
172
|
+
C._ts_parser_enable_logger_wasm(this[0], 1);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
C.currentLogCallback = null;
|
|
176
|
+
C._ts_parser_enable_logger_wasm(this[0], 0);
|
|
177
|
+
}
|
|
178
|
+
let rangeCount = 0;
|
|
179
|
+
let rangeAddress = 0;
|
|
180
|
+
if (options?.includedRanges) {
|
|
181
|
+
rangeCount = options.includedRanges.length;
|
|
182
|
+
rangeAddress = C._calloc(rangeCount, SIZE_OF_RANGE);
|
|
183
|
+
let address = rangeAddress;
|
|
184
|
+
for (let i = 0; i < rangeCount; i++) {
|
|
185
|
+
marshalRange(address, options.includedRanges[i]);
|
|
186
|
+
address += SIZE_OF_RANGE;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const treeAddress = C._ts_parser_parse_wasm(this[0], this[1], oldTree ? oldTree[0] : 0, rangeAddress, rangeCount);
|
|
190
|
+
if (!treeAddress) {
|
|
191
|
+
C.currentParseCallback = null;
|
|
192
|
+
C.currentLogCallback = null;
|
|
193
|
+
C.currentProgressCallback = null;
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
if (!this.language) {
|
|
197
|
+
throw new Error("Parser must have a language to parse");
|
|
198
|
+
}
|
|
199
|
+
const result = new Tree(INTERNAL, treeAddress, this.language, C.currentParseCallback);
|
|
200
|
+
C.currentParseCallback = null;
|
|
201
|
+
C.currentLogCallback = null;
|
|
202
|
+
C.currentProgressCallback = null;
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Instruct the parser to start the next parse from the beginning.
|
|
207
|
+
*
|
|
208
|
+
* If the parser previously failed because of a timeout, cancellation,
|
|
209
|
+
* or callback, then by default, it will resume where it left off on the
|
|
210
|
+
* next call to {@link Parser#parse} or other parsing functions.
|
|
211
|
+
* If you don't want to resume, and instead intend to use this parser to
|
|
212
|
+
* parse some other document, you must call `reset` first.
|
|
213
|
+
*/
|
|
214
|
+
reset() {
|
|
215
|
+
C._ts_parser_reset(this[0]);
|
|
216
|
+
}
|
|
217
|
+
/** Get the ranges of text that the parser will include when parsing. */
|
|
218
|
+
getIncludedRanges() {
|
|
219
|
+
C._ts_parser_included_ranges_wasm(this[0]);
|
|
220
|
+
const count = C.getValue(TRANSFER_BUFFER, "i32");
|
|
221
|
+
const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
222
|
+
const result = new Array(count);
|
|
223
|
+
if (count > 0) {
|
|
224
|
+
let address = buffer;
|
|
225
|
+
for (let i = 0; i < count; i++) {
|
|
226
|
+
result[i] = unmarshalRange(address);
|
|
227
|
+
address += SIZE_OF_RANGE;
|
|
228
|
+
}
|
|
229
|
+
C._free(buffer);
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* @deprecated since version 0.25.0, prefer passing a progress callback to {@link Parser#parse}
|
|
235
|
+
*
|
|
236
|
+
* Get the duration in microseconds that parsing is allowed to take.
|
|
237
|
+
*
|
|
238
|
+
* This is set via {@link Parser#setTimeoutMicros}.
|
|
239
|
+
*/
|
|
240
|
+
getTimeoutMicros() {
|
|
241
|
+
return C._ts_parser_timeout_micros(this[0]);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* @deprecated since version 0.25.0, prefer passing a progress callback to {@link Parser#parse}
|
|
245
|
+
*
|
|
246
|
+
* Set the maximum duration in microseconds that parsing should be allowed
|
|
247
|
+
* to take before halting.
|
|
248
|
+
*
|
|
249
|
+
* If parsing takes longer than this, it will halt early, returning `null`.
|
|
250
|
+
* See {@link Parser#parse} for more information.
|
|
251
|
+
*/
|
|
252
|
+
setTimeoutMicros(timeout) {
|
|
253
|
+
C._ts_parser_set_timeout_micros(this[0], 0, timeout);
|
|
254
|
+
}
|
|
255
|
+
/** Set the logging callback that a parser should use during parsing. */
|
|
256
|
+
setLogger(callback) {
|
|
257
|
+
if (!callback) {
|
|
258
|
+
this.logCallback = null;
|
|
259
|
+
}
|
|
260
|
+
else if (typeof callback !== "function") {
|
|
261
|
+
throw new Error("Logger callback must be a function");
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
this.logCallback = callback;
|
|
265
|
+
}
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
/** Get the parser's current logger. */
|
|
269
|
+
getLogger() {
|
|
270
|
+
return this.logCallback;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
export namespace CaptureQuantifier {
|
|
2
|
+
let Zero: number;
|
|
3
|
+
let ZeroOrOne: number;
|
|
4
|
+
let ZeroOrMore: number;
|
|
5
|
+
let One: number;
|
|
6
|
+
let OneOrMore: number;
|
|
7
|
+
}
|
|
8
|
+
export namespace QueryErrorKind {
|
|
9
|
+
let Syntax: number;
|
|
10
|
+
let NodeName: number;
|
|
11
|
+
let FieldName: number;
|
|
12
|
+
let CaptureName: number;
|
|
13
|
+
let PatternStructure: number;
|
|
14
|
+
}
|
|
15
|
+
/** An error that occurred while parsing a query string. */
|
|
16
|
+
/** Information about a {@link QueryError}. */
|
|
17
|
+
/** Error thrown when parsing a tree-sitter query fails */
|
|
18
|
+
export class QueryError extends Error {
|
|
19
|
+
/** Formats an error message based on the error kind and info */
|
|
20
|
+
static formatMessage(kind: any, info: any): string | undefined;
|
|
21
|
+
constructor(kind: any, info: any, index: any, length: any);
|
|
22
|
+
}
|
|
23
|
+
export class Query {
|
|
24
|
+
/**
|
|
25
|
+
* Create a new query from a string containing one or more S-expression
|
|
26
|
+
* patterns.
|
|
27
|
+
*
|
|
28
|
+
* The query is associated with a particular language, and can only be run
|
|
29
|
+
* on syntax nodes parsed with that language. References to Queries can be
|
|
30
|
+
* shared between multiple threads.
|
|
31
|
+
*
|
|
32
|
+
* @link {@see https://tree-sitter.github.io/tree-sitter/using-parsers/queries}
|
|
33
|
+
*/
|
|
34
|
+
constructor(language: any, source: any);
|
|
35
|
+
/** @internal */
|
|
36
|
+
0: number;
|
|
37
|
+
/** @internal */
|
|
38
|
+
exceededMatchLimit: boolean;
|
|
39
|
+
/** @internal */
|
|
40
|
+
textPredicates: any[];
|
|
41
|
+
/** The names of the captures used in the query. */
|
|
42
|
+
captureNames: any[];
|
|
43
|
+
/** The quantifiers of the captures used in the query. */
|
|
44
|
+
captureQuantifiers: any[];
|
|
45
|
+
/**
|
|
46
|
+
* The other user-defined predicates associated with the given index.
|
|
47
|
+
*
|
|
48
|
+
* This includes predicates with operators other than:
|
|
49
|
+
* - `match?`
|
|
50
|
+
* - `eq?` and `not-eq?`
|
|
51
|
+
* - `any-of?` and `not-any-of?`
|
|
52
|
+
* - `is?` and `is-not?`
|
|
53
|
+
* - `set!`
|
|
54
|
+
*/
|
|
55
|
+
predicates: any[];
|
|
56
|
+
/** The properties for predicates with the operator `set!`. */
|
|
57
|
+
setProperties: any[];
|
|
58
|
+
/** The properties for predicates with the operator `is?`. */
|
|
59
|
+
assertedProperties: any[];
|
|
60
|
+
/** The properties for predicates with the operator `is-not?`. */
|
|
61
|
+
refutedProperties: any[];
|
|
62
|
+
/** The maximum number of in-progress matches for this cursor. */
|
|
63
|
+
matchLimit: any;
|
|
64
|
+
/** Delete the query, freeing its resources. */
|
|
65
|
+
delete(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Iterate over all of the matches in the order that they were found.
|
|
68
|
+
*
|
|
69
|
+
* Each match contains the index of the pattern that matched, and a list of
|
|
70
|
+
* captures. Because multiple patterns can match the same set of nodes,
|
|
71
|
+
* one match may contain captures that appear *before* some of the
|
|
72
|
+
* captures from a previous match.
|
|
73
|
+
*
|
|
74
|
+
* @param {Node} node - The node to execute the query on.
|
|
75
|
+
*
|
|
76
|
+
* @param {QueryOptions} options - Options for query execution.
|
|
77
|
+
*/
|
|
78
|
+
matches(node: Node, options?: QueryOptions): any[];
|
|
79
|
+
/**
|
|
80
|
+
* Iterate over all of the individual captures in the order that they
|
|
81
|
+
* appear.
|
|
82
|
+
*
|
|
83
|
+
* This is useful if you don't care about which pattern matched, and just
|
|
84
|
+
* want a single, ordered sequence of captures.
|
|
85
|
+
*
|
|
86
|
+
* @param {Node} node - The node to execute the query on.
|
|
87
|
+
*
|
|
88
|
+
* @param {QueryOptions} options - Options for query execution.
|
|
89
|
+
*/
|
|
90
|
+
captures(node: Node, options?: QueryOptions): any[];
|
|
91
|
+
/** Get the predicates for a given pattern. */
|
|
92
|
+
predicatesForPattern(patternIndex: any): any;
|
|
93
|
+
/**
|
|
94
|
+
* Disable a certain capture within a query.
|
|
95
|
+
*
|
|
96
|
+
* This prevents the capture from being returned in matches, and also
|
|
97
|
+
* avoids any resource usage associated with recording the capture.
|
|
98
|
+
*/
|
|
99
|
+
disableCapture(captureName: any): void;
|
|
100
|
+
/**
|
|
101
|
+
* Disable a certain pattern within a query.
|
|
102
|
+
*
|
|
103
|
+
* This prevents the pattern from matching, and also avoids any resource
|
|
104
|
+
* usage associated with the pattern. This throws an error if the pattern
|
|
105
|
+
* index is out of bounds.
|
|
106
|
+
*/
|
|
107
|
+
disablePattern(patternIndex: any): void;
|
|
108
|
+
/**
|
|
109
|
+
* Check if, on its last execution, this cursor exceeded its maximum number
|
|
110
|
+
* of in-progress matches.
|
|
111
|
+
*/
|
|
112
|
+
didExceedMatchLimit(): boolean;
|
|
113
|
+
/** Get the byte offset where the given pattern starts in the query's source. */
|
|
114
|
+
startIndexForPattern(patternIndex: any): any;
|
|
115
|
+
/** Get the byte offset where the given pattern ends in the query's source. */
|
|
116
|
+
endIndexForPattern(patternIndex: any): any;
|
|
117
|
+
/** Get the number of patterns in the query. */
|
|
118
|
+
patternCount(): any;
|
|
119
|
+
/** Get the index for a given capture name. */
|
|
120
|
+
captureIndexForName(captureName: any): number;
|
|
121
|
+
/** Check if a given pattern within a query has a single root node. */
|
|
122
|
+
isPatternRooted(patternIndex: any): boolean;
|
|
123
|
+
/** Check if a given pattern within a query has a single root node. */
|
|
124
|
+
isPatternNonLocal(patternIndex: any): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Check if a given step in a query is 'definite'.
|
|
127
|
+
*
|
|
128
|
+
* A query step is 'definite' if its parent pattern will be guaranteed to
|
|
129
|
+
* match successfully once it reaches the step.
|
|
130
|
+
*/
|
|
131
|
+
isPatternGuaranteedAtStep(byteIndex: any): boolean;
|
|
132
|
+
}
|
|
133
|
+
import { Node } from "./node.js";
|
|
134
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/tree_sitter/query.js"],"names":[],"mappings":";;;;;;;;;;;;;;AA+EA,2DAA2D;AAC3D,8CAA8C;AAC9C,0DAA0D;AAC1D;IAMI,gEAAgE;IAChE,+DAaC;IAnBD,2DAGC;CAiBJ;AAqMD;IAwCI;;;;;;;;;OASG;IACH,wCAwGC;IAzJD,gBAAgB;IAChB,UAAO;IAEP,gBAAgB;IAChB,4BAAkB;IAElB,gBAAgB;IAChB,sBAAc;IAEd,mDAAmD;IACnD,oBAAY;IAEZ,yDAAyD;IACzD,0BAAkB;IAElB;;;;;;;;;OASG;IACH,kBAAU;IAEV,8DAA8D;IAC9D,qBAAa;IAEb,6DAA6D;IAC7D,0BAAkB;IAElB,iEAAiE;IACjE,yBAAiB;IAEjB,iEAAiE;IACjE,gBAAU;IAsHV,+CAA+C;IAC/C,eAGC;IAED;;;;;;;;;;;OAWG;IACH,cAJW,IAAI,YAEJ,YAAY,SAkEtB;IAED;;;;;;;;;;OAUG;IACH,eAJW,IAAI,YAEJ,YAAY,SAmEtB;IAED,8CAA8C;IAC9C,6CAEC;IAED;;;;;OAKG;IACH,uCAMC;IAED;;;;;;OAMG;IACH,wCAKC;IAED;;;OAGG;IACH,+BAEC;IAED,gFAAgF;IAChF,6CAKC;IAED,8EAA8E;IAC9E,2CAKC;IAED,+CAA+C;IAC/C,oBAEC;IAED,8CAA8C;IAC9C,8CAEC;IAED,sEAAsE;IACtE,4CAEC;IAED,sEAAsE;IACtE,8CAEC;IAED;;;;;OAKG;IACH,mDAEC;CACJ;qBA/rBoB,WAAW"}
|