@kerebron/tree-sitter 0.4.26 → 0.4.27

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 (65) hide show
  1. package/package.json +2 -1
  2. package/esm/deno-tree-sitter/main/extended/base_node.d.ts +0 -48
  3. package/esm/deno-tree-sitter/main/extended/base_node.d.ts.map +0 -1
  4. package/esm/deno-tree-sitter/main/extended/base_node.js +0 -154
  5. package/esm/deno-tree-sitter/main/extended/node_extended.d.ts +0 -237
  6. package/esm/deno-tree-sitter/main/extended/node_extended.d.ts.map +0 -1
  7. package/esm/deno-tree-sitter/main/extended/node_extended.js +0 -572
  8. package/esm/deno-tree-sitter/main/extended/parser.d.ts +0 -37
  9. package/esm/deno-tree-sitter/main/extended/parser.d.ts.map +0 -1
  10. package/esm/deno-tree-sitter/main/extended/parser.js +0 -86
  11. package/esm/deno-tree-sitter/main/extended/soft_node.d.ts +0 -15
  12. package/esm/deno-tree-sitter/main/extended/soft_node.d.ts.map +0 -1
  13. package/esm/deno-tree-sitter/main/extended/soft_node.js +0 -27
  14. package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts +0 -10
  15. package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts.map +0 -1
  16. package/esm/deno-tree-sitter/main/extended/soft_text_node.js +0 -10
  17. package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts +0 -10
  18. package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts.map +0 -1
  19. package/esm/deno-tree-sitter/main/extended/whitespace_node.js +0 -10
  20. package/esm/deno-tree-sitter/main/extras/misc.d.ts +0 -2
  21. package/esm/deno-tree-sitter/main/extras/misc.d.ts.map +0 -1
  22. package/esm/deno-tree-sitter/main/extras/misc.js +0 -13
  23. package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts +0 -14
  24. package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts.map +0 -1
  25. package/esm/deno-tree-sitter/main/tree_sitter/bindings.js +0 -21
  26. package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts +0 -60
  27. package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts.map +0 -1
  28. package/esm/deno-tree-sitter/main/tree_sitter/constants.js +0 -66
  29. package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts +0 -137
  30. package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts.map +0 -1
  31. package/esm/deno-tree-sitter/main/tree_sitter/language.js +0 -264
  32. package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts +0 -41
  33. package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts.map +0 -1
  34. package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.js +0 -65
  35. package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts +0 -85
  36. package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts.map +0 -1
  37. package/esm/deno-tree-sitter/main/tree_sitter/marshal.js +0 -173
  38. package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts +0 -260
  39. package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts.map +0 -1
  40. package/esm/deno-tree-sitter/main/tree_sitter/node.js +0 -557
  41. package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts +0 -124
  42. package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts.map +0 -1
  43. package/esm/deno-tree-sitter/main/tree_sitter/parser.js +0 -252
  44. package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts +0 -134
  45. package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts.map +0 -1
  46. package/esm/deno-tree-sitter/main/tree_sitter/query.js +0 -620
  47. package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts +0 -49
  48. package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts.map +0 -1
  49. package/esm/deno-tree-sitter/main/tree_sitter/tree.js +0 -130
  50. package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts +0 -165
  51. package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts.map +0 -1
  52. package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.js +0 -280
  53. package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts +0 -3
  54. package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts.map +0 -1
  55. package/esm/deno-tree-sitter/main/tree_sitter_wasm.js +0 -0
  56. package/esm/deno-tree-sitter/main/wasm_loader.d.ts +0 -29
  57. package/esm/deno-tree-sitter/main/wasm_loader.d.ts.map +0 -1
  58. package/esm/deno-tree-sitter/main/wasm_loader.js +0 -1702
  59. package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts +0 -3
  60. package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts.map +0 -1
  61. package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.js +0 -8
  62. package/esm/mod.d.ts +0 -7
  63. package/esm/mod.d.ts.map +0 -1
  64. package/esm/mod.js +0 -7
  65. package/esm/package.json +0 -3
@@ -1,572 +0,0 @@
1
- import { Node } from "../tree_sitter/node.js";
2
- import { Parser } from "../tree_sitter/parser.js";
3
- import { BaseNode, _shadows } from "./base_node.js";
4
- import { WhitespaceNode } from "./whitespace_node.js";
5
- import { SoftTextNode } from "./soft_text_node.js";
6
- import { Query, QueryError } from "../tree_sitter/query.js";
7
- import { _getQueryCaptureTargets } from "../extras/misc.js";
8
- import { Tree } from "../tree_sitter/tree.js";
9
- // NOTE: the tree override is in here because it has a circular type dependency on HardNode
10
- const realRootNodeGetter = Object.getOwnPropertyDescriptor(Tree.prototype, "rootNode").get;
11
- //
12
- // complicated override in order to make the root node pretend to contain soft nodes (ex: leading and trailing whitespace)
13
- //
14
- // hard because a normal change to .startIndex/.endIndex breaks internal methods, so we have to selectively choose who sees the real/faked .startIndex/.endIndex
15
- Object.defineProperty(Tree.prototype, "rootNode", {
16
- get() {
17
- const rootNode = realRootNodeGetter.call(this);
18
- const rootShadow = {};
19
- Object.setPrototypeOf(rootShadow, Object.getPrototypeOf(rootNode));
20
- const descriptors = Object.assign(Object.getOwnPropertyDescriptors(Node.prototype), Object.getOwnPropertyDescriptors(rootNode));
21
- const newDescriptors = {};
22
- for (const [key, setting] of Object.entries(descriptors)) {
23
- if (key == "startIndex" || key == "startPosition") {
24
- continue;
25
- }
26
- else if (key == "text" || key == "replaceInnards") {
27
- // use the faked .startIndex for these methods/getters
28
- newDescriptors[key] = setting;
29
- }
30
- else {
31
- // use the real .startIndex for these methods/getters (get it from the real thing)
32
- // (otherwise stuff breaks when there is a whitespace prefix)
33
- newDescriptors[key] = {
34
- get: () => {
35
- const output = rootNode[key];
36
- if (typeof output == "function") {
37
- return (...args) => output.apply(rootNode, args);
38
- }
39
- return output;
40
- },
41
- set: (value) => rootNode[key] = value,
42
- enumerable: setting.enumerable,
43
- configurable: setting.configurable,
44
- };
45
- }
46
- }
47
- Object.setPrototypeOf(rootShadow, Node.prototype);
48
- Object.defineProperties(rootShadow, newDescriptors);
49
- rootShadow.startIndex = 0;
50
- rootShadow.startPosition = { row: 0, column: 0 };
51
- // if the original file is just whitespace or non-matched text, then fill it with soft nodes even though it'd normally have no children
52
- if (rootShadow.children.length == 0 && rootShadow.endIndex != 0) {
53
- rootShadow._children = _childrenWithSoftNodes(rootShadow, [{ startIndex: rootShadow.endIndex, endIndex: rootShadow.endIndex, endPosition: rootShadow.endPosition }], rootNode.tree.codeString).slice(0, -1);
54
- }
55
- _shadows[rootNode.id] = rootShadow;
56
- return rootShadow;
57
- }
58
- });
59
- // this only exists to help with type hints
60
- export class ExtendedTree extends Tree {
61
- /** @type {HardNode} */
62
- rootNode;
63
- }
64
- // this only exists to help with type hints
65
- class Position {
66
- /** @type {number} */
67
- row;
68
- /** @type {number} */
69
- column;
70
- }
71
- const originalDescriptors = Object.getOwnPropertyDescriptors(Node.prototype);
72
- const originalChildrenGetter = originalDescriptors.children.get;
73
- const originalEndIndex = originalDescriptors.endIndex.get;
74
- const originalEndPosition = originalDescriptors.endPosition.get;
75
- const originalParent = originalDescriptors.parent.get;
76
- const originalTextGetter = originalDescriptors.text.get;
77
- const originalEquals = originalDescriptors.equals.value;
78
- const originalToString = originalDescriptors.toString.value;
79
- export class HardNode extends BaseNode {
80
- /** @internal */
81
- _children;
82
- /** @internal */
83
- _fields;
84
- /** @internal */
85
- _depth;
86
- /** @type {number} */
87
- id;
88
- /** @type {number} */
89
- startIndex;
90
- /** @type {Position} */
91
- startPosition;
92
- /** @type {ExtendedTree} */
93
- tree;
94
- /** @type {string} */
95
- type;
96
- /** @type {Boolean} */
97
- isExtra;
98
- /** @type {Boolean} */
99
- isError;
100
- /** @type {Boolean} */
101
- isMissing;
102
- /** @type {Boolean} */
103
- hasChanges;
104
- /** @type {Boolean} */
105
- hasError;
106
- /**
107
- * @param {HardNode} other -
108
- * @returns {Boolean} output -
109
- */
110
- equals = originalEquals;
111
- /** @type {HardNode} */
112
- get parent() {
113
- const rawParent = originalParent.call(this);
114
- return _shadows[rawParent?.id] || rawParent;
115
- }
116
- /** @type {string} */
117
- get text() {
118
- return originalTextGetter.call(_shadows[this.id] || this);
119
- }
120
- /** @type {Number} */
121
- get endIndex() {
122
- if (this.depth == 0) {
123
- return this.tree.codeString.length;
124
- }
125
- return originalEndIndex.call(this);
126
- }
127
- /** @type {Position} */
128
- get endPosition() {
129
- if (this.depth == 0) {
130
- const rowIndex = (this.tree.codeString.match(/\n/g) || []).length;
131
- const columnIndex = this.tree.codeString.match(new RegExp(`^(?:.*\\r?\\n){${rowIndex}}(.*)`))[1].length;
132
- return { row: rowIndex, column: columnIndex };
133
- }
134
- return originalEndPosition.call(this);
135
- }
136
- /** @type {Array<HardNode|SoftNode>} */
137
- get children() {
138
- if (!this._children) {
139
- // will set this._children
140
- this._children = originalChildrenGetter.call(this);
141
- // add soft nodes if needed
142
- if (this.tree._enableSoftNodes) {
143
- this._children = _childrenWithSoftNodes(this, this._children || [], this.tree.codeString);
144
- }
145
- }
146
- return this._children || [];
147
- }
148
- set children(value) {
149
- this._children = value;
150
- }
151
- /**
152
- * Yields each child
153
- *
154
- * @generator
155
- * @yields {HardNode} The current child or grandchild in the structure.
156
- */
157
- *traverse(arg = { _parentNodes: [] }) {
158
- const { _parentNodes } = arg;
159
- const parentNodes = [this, ..._parentNodes];
160
- if (this.children?.length == 0) {
161
- yield [_parentNodes, this, "-"];
162
- }
163
- else {
164
- yield [_parentNodes, this, "->"];
165
- for (const each of this.children || []) {
166
- if (each instanceof Node) {
167
- for (const eachInner of each.traverse({ _parentNodes: parentNodes })) {
168
- yield eachInner;
169
- }
170
- }
171
- else {
172
- yield [parentNodes, each, "-"];
173
- }
174
- }
175
- yield [_parentNodes, this, "<-"];
176
- }
177
- }
178
- /**
179
- * A generator function that flattens the hierarchical structure of `children` and their descendants.
180
- * It yields each child and their flattened descendants recursively.
181
- *
182
- * @param {Function} opts.filter - A function to filter the flattened elements.
183
- * @param {Boolean} opts.includeSelf -
184
- * @generator
185
- * @yields {HardNode} The current child or grandchild in the structure.
186
- */
187
- *iterFlattened({ filter, includeSelf = false } = {}) {
188
- if (includeSelf) {
189
- yield this;
190
- }
191
- if (typeof filter == "function") {
192
- for (const each of this.children || []) {
193
- if (filter(each)) {
194
- yield each;
195
- }
196
- for (const eachGrandChild of each.iterFlattened({ filter })) {
197
- yield eachGrandChild;
198
- }
199
- }
200
- }
201
- else {
202
- for (const each of this.children || []) {
203
- yield each;
204
- for (const eachGrandChild of each.iterFlattened({ filter })) {
205
- yield eachGrandChild;
206
- }
207
- }
208
- }
209
- }
210
- /** @internal */
211
- iterFlatten() {
212
- throw Error(`did you mean iterFlattened instead of iterFlatten?`);
213
- }
214
- /**
215
- * Flattens the structure of `children` using the provided filter function.
216
- * This method returns an array containing the flattened elements.
217
- *
218
- * @param {Function} opts.filter - A function to filter the flattened elements.
219
- * @param {Boolean} opts.includeSelf -
220
- * @returns {Array} An array containing the flattened elements that pass the filter.
221
- */
222
- flattened({ filter, includeSelf = false } = {}) {
223
- return [...this.iterFlattened({ filter, includeSelf })];
224
- }
225
- /** @internal */
226
- flatten() {
227
- throw Error(`did you mean flattened instead of flatten?`);
228
- }
229
- /**
230
- * Query
231
- *
232
- * @example
233
- * ```js
234
- * import { createParser } from "https://deno.land/x/deno_tree_sitter/main/main.js"
235
- * import javascript from "https://github.com/jeff-hykin/common_tree_sitter_languages/raw/4d8a6d34d7f6263ff570f333cdcf5ded6be89e3d/main/javascript.js"
236
- * const parser = await createParser(javascript) // path or Uint8Array
237
- * const tree = parser.parse('let a = 1;let b = 1;let c = 1;')
238
- *
239
- * tree.rootNode.query(`(identifier) @blahBlahBlah`, {matchLimit: 2})
240
- * // returns:
241
- * [
242
- * {
243
- * pattern: 0,
244
- * captures: [
245
- * {
246
- * name: "blahBlahBlah",
247
- * node: {
248
- * type: "identifier",
249
- * typeId: 1,
250
- * startPosition: { row: 0, column: 4 },
251
- * startIndex: 4,
252
- * endPosition: { row: 0, column: 5 },
253
- * endIndex: 5,
254
- * indent: undefined,
255
- * hasChildren: false,
256
- * children: []
257
- * }
258
- * }
259
- * ]
260
- * },
261
- * {
262
- * pattern: 0,
263
- * captures: [
264
- * {
265
- * name: "blahBlahBlah",
266
- * node: {
267
- * type: "identifier",
268
- * typeId: 1,
269
- * startPosition: { row: 0, column: 14 },
270
- * startIndex: 14,
271
- * endPosition: { row: 0, column: 15 },
272
- * endIndex: 15,
273
- * indent: undefined,
274
- * hasChildren: false,
275
- * children: []
276
- * }
277
- * }
278
- * ]
279
- * },
280
- * {
281
- * pattern: 0,
282
- * captures: [
283
- * {
284
- * name: "blahBlahBlah",
285
- * node: {
286
- * type: "identifier",
287
- * typeId: 1,
288
- * startPosition: { row: 0, column: 24 },
289
- * startIndex: 24,
290
- * endPosition: { row: 0, column: 25 },
291
- * endIndex: 25,
292
- * indent: undefined,
293
- * hasChildren: false,
294
- * children: []
295
- * }
296
- * }
297
- * ]
298
- * }
299
- * ]
300
- * ```
301
- *
302
- * @param {String} queryString - see https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax
303
- * @param options.matchLimit - max number of results
304
- * @param options.startPosition - {row: Number, column: number}
305
- * @param options.endPosition - {row: Number, column: number}
306
- * @param options.maxResultDepth - depth relative to the current node (1 = direct children, 2 = grandchildren, etc)
307
- * @returns {[Object]} output
308
- *
309
- */
310
- query(queryString, options) {
311
- const { matchLimit, startPosition, endPosition, maxResultDepth } = options || {};
312
- const realMaxResultDepth = maxResultDepth == null ? Infinity : maxResultDepth;
313
- let query;
314
- try {
315
- query = new Query(this.tree.language, queryString);
316
- }
317
- catch (error) {
318
- if (error instanceof QueryError) {
319
- error.message = `${error.message} in the following query: ${JSON.stringify(queryString)}`;
320
- }
321
- throw error;
322
- }
323
- const result = query.matches(this, startPosition || this.startPosition, endPosition || this.endPosition, matchLimit);
324
- const results = result.filter((each) => each.captures.every((each) => each.node.depth - this.depth <= realMaxResultDepth));
325
- const codeOrCallback = this.tree.codeString;
326
- // without this soft nodes will be missing
327
- for (const eachResult of results) {
328
- for (const eachCapture of eachResult.captures) {
329
- eachCapture.node.children = _childrenWithSoftNodes(eachCapture.node, eachCapture.node.children, codeOrCallback);
330
- }
331
- }
332
- return result.filter((each) => each.captures.every((each) => each.node.depth - this.depth <= realMaxResultDepth));
333
- }
334
- /**
335
- * quickQuery
336
- *
337
- * @example
338
- * ```js
339
- * import { createParser } from "https://deno.land/x/deno_tree_sitter/main/main.js"
340
- * import javascript from "https://github.com/jeff-hykin/common_tree_sitter_languages/raw/676ffa3b93768b8ac628fd5c61656f7dc41ba413/main/javascript.js"
341
- * const parser = await createParser(javascript) // path or Uint8Array
342
- * const tree = parser.parse('let a = 1;let b = 1;let c = 1;')
343
- * // ex1: no capture names
344
- * const nodes = tree.rootNode.quickQuery(
345
- * `(identifier)`, {matchLimit: 2}
346
- * )
347
- * // ex2: with capture names
348
- * const groups = tree.rootNode.quickQuery(
349
- * `'(binding (attrpath) @myKey (list_expression) @myList ("\\"")? @optionalThing )`
350
- * )
351
- * groups[0].myKey // node
352
- * groups[0].myList // node
353
- * groups[0].optionalThing // node or null
354
- * groups[0][0] // node (the whole match)
355
- * ```
356
- *
357
- * @param {String} queryString - see https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax
358
- * @param options.matchLimit - max number of results
359
- * @param options.startPosition - {row: Number, column: number}
360
- * @param options.endPosition - {row: Number, column: number}
361
- * @param options.maxResultDepth - depth relative to the current node (1 = direct children, 2 = grandchildren, etc)
362
- * @returns {Array<HardNode|Record<any, HardNode>>} nodesOrObjsOfNodes
363
- */
364
- quickQuery(queryString, options) {
365
- const possibleCaptureTargets = _getQueryCaptureTargets(queryString);
366
- //
367
- // get a base capture name
368
- //
369
- let baseCaptureName = "_";
370
- while (possibleCaptureTargets.includes(baseCaptureName)) {
371
- // append until it doesn't conflict
372
- baseCaptureName = `${baseCaptureName}_`;
373
- }
374
- // add the base capture always
375
- queryString = `${queryString} @${baseCaptureName}`;
376
- const output = this.query(queryString, options).map((each) => {
377
- const nodesByCaptureName = Object.fromEntries(each.captures.map((each) => [each.name, each.node]));
378
- // no capture targets means just return the base
379
- if (possibleCaptureTargets.length == 0) {
380
- return nodesByCaptureName[baseCaptureName];
381
- // return named targets
382
- }
383
- else {
384
- // 0 is not allowed as a capture name, so it will never conflict
385
- nodesByCaptureName[0] = nodesByCaptureName[baseCaptureName];
386
- delete nodesByCaptureName[baseCaptureName];
387
- return nodesByCaptureName;
388
- }
389
- });
390
- return output;
391
- }
392
- /**
393
- * quickQueryFirst
394
- *
395
- * @example
396
- * ```js
397
- * import { createParser } from "https://deno.land/x/deno_tree_sitter/main/main.js"
398
- * import javascript from "https://github.com/jeff-hykin/common_tree_sitter_languages/raw/4d8a6d34d7f6263ff570f333cdcf5ded6be89e3d/main/javascript.js"
399
- * const parser = await createParser(javascript) // path or Uint8Array
400
- * const tree = parser.parse('let a = 1;let b = 1;let c = 1;')
401
- *
402
- * // ex1: no capture names
403
- * const node = tree.rootNode.quickQueryFirst(`(identifier)`)
404
- *
405
- * // ex2: with capture names
406
- * const { myKey, myList, optionalThing } = tree.rootNode.quickQueryFirst(
407
- * `'(binding (attrpath) @myKey (list_expression) @myList ("\\"")? @optionalThing )`
408
- * )
409
- * myKey // node
410
- * myList // node
411
- * optionalThing // node or null
412
- * ```
413
- *
414
- * @param {String} queryString - see https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax
415
- * @param options.startPosition - {row: Number, column: number}
416
- * @param options.endPosition - {row: Number, column: number}
417
- * @param options.maxResultDepth - depth relative to the current node (1 = direct children, 2 = grandchildren, etc)
418
- * @returns {HardNode|Record<any,HardNode>|null} nodeOrObjOfNodes
419
- */
420
- quickQueryFirst(queryString, options) {
421
- return this.quickQuery(queryString, { ...options, matchLimit: 1 })[0];
422
- }
423
- get fields() {
424
- if (!this._fields) {
425
- this._fields = {};
426
- let index = -1;
427
- for (let each of this.children || []) {
428
- // skip soft nodes
429
- if (each.typeId <= 0) {
430
- continue;
431
- }
432
- index++;
433
- const name = this.fieldNameForChild(index);
434
- if (name) {
435
- this._fields[name] = each;
436
- }
437
- }
438
- }
439
- return this._fields;
440
- }
441
- get fieldNames() {
442
- return Object.keys(this.fields);
443
- }
444
- getQueryForSelf() {
445
- let current = this;
446
- let chunks = [];
447
- while (current) {
448
- if (current.type) {
449
- if (current.isNamed) {
450
- if (current.type.match(/^([a-zA-Z0-9.\-_\$]+)$/)) {
451
- chunks.push(current.type);
452
- }
453
- else {
454
- chunks.push(JSON.stringify(current.type));
455
- }
456
- }
457
- else {
458
- // TODO: this might not always be correct. Probably should be JSON.stringify(current.text) but theres a risk of .text being massive
459
- chunks.push(JSON.stringify(current.type));
460
- }
461
- }
462
- current = current.parent;
463
- }
464
- return "(" + chunks.reverse().join(" (") + ")".repeat(chunks.length);
465
- }
466
- /** @returns {string} */
467
- asLispString() {
468
- return originalToString.call(this);
469
- }
470
- }
471
- // patch Node with all HardNode properties
472
- const descriptors = Object.getOwnPropertyDescriptors(HardNode.prototype);
473
- delete descriptors.constructor;
474
- Object.defineProperties(Node.prototype, descriptors);
475
- // force it to inherit from BaseNode
476
- Object.setPrototypeOf(Node.prototype, BaseNode.prototype);
477
- export { Node };
478
- // helper
479
- export const _childrenWithSoftNodes = (node, children, string) => {
480
- if (children?.length > 0) {
481
- const newChildren = [];
482
- const childrenCopy = [...children];
483
- let firstChild = childrenCopy.shift();
484
- // helper
485
- const handleGaps = (gapText, getReferencePoint, parentNode) => {
486
- const { index, position } = getReferencePoint();
487
- let start = index;
488
- let startPosition = position;
489
- const chunks = gapText.split(/(?<!\s)(?=\s+)/g);
490
- let colOffset = startPosition.column;
491
- let rowOffset = startPosition.row;
492
- for (const eachGap of chunks) {
493
- if (eachGap.length == 0) {
494
- continue;
495
- }
496
- const end = start + eachGap.length;
497
- if (eachGap.match(/^\s/)) {
498
- const rowOffsetBefore = rowOffset;
499
- const colOffsetBefore = colOffset;
500
- rowOffset += (eachGap.match(/\n/g) || []).length;
501
- // reset column offset on new row
502
- if (rowOffsetBefore != rowOffset) {
503
- colOffset = eachGap.split("\n").slice(-1)[0].length;
504
- }
505
- else {
506
- colOffset += eachGap.length;
507
- }
508
- newChildren.push(new WhitespaceNode({
509
- tree: node.tree,
510
- parent: parentNode,
511
- getReferencePoint,
512
- text: eachGap,
513
- _startIndexOffset: start - index,
514
- _startRowOffset: rowOffsetBefore - position.row,
515
- _startColOffset: colOffsetBefore - position.column,
516
- _endIndexOffset: end - index,
517
- _endRowOffset: rowOffset - position.row,
518
- _endColOffset: colOffset - position.column,
519
- children: [],
520
- }));
521
- // sometimes the gap isn't always whitespace
522
- }
523
- else {
524
- const colOffsetBefore = colOffset;
525
- colOffset += eachGap.length;
526
- newChildren.push(new SoftTextNode({
527
- tree: node.tree,
528
- parent: parentNode,
529
- getReferencePoint,
530
- text: eachGap,
531
- _startIndexOffset: start - index,
532
- _startRowOffset: rowOffset - position.row,
533
- _startColOffset: colOffsetBefore - position.column,
534
- _endIndexOffset: end - index,
535
- _endRowOffset: rowOffset - position.row,
536
- _endColOffset: colOffset - position.column,
537
- children: [],
538
- }));
539
- }
540
- start = end;
541
- }
542
- };
543
- // preceding whitespace
544
- if (node.startIndex != firstChild.startIndex) {
545
- const gapText = string.slice(node.startIndex, firstChild.startIndex);
546
- const thisNode = node;
547
- // whitespace and non-whitespace chunks
548
- handleGaps(gapText, () => ({ index: thisNode.startIndex, position: thisNode.startPosition }), node);
549
- }
550
- // firstChild.indent = indent
551
- newChildren.push(firstChild);
552
- // gaps between sibilings
553
- let prevChild = firstChild;
554
- for (const eachSecondaryNode of childrenCopy) {
555
- if (prevChild.endIndex != eachSecondaryNode.startIndex) {
556
- const gapText = string.slice(prevChild.endIndex, eachSecondaryNode.startIndex);
557
- const thisChild = prevChild;
558
- handleGaps(gapText, () => ({ index: thisChild.endIndex, position: thisChild.endPosition }), node);
559
- }
560
- // eachSecondaryNode.indent = indent
561
- newChildren.push(eachSecondaryNode);
562
- prevChild = eachSecondaryNode;
563
- }
564
- // gap between last child and parent
565
- if (prevChild.endIndex != node.endIndex) {
566
- const gapText = string.slice(prevChild.endIndex, node.endIndex);
567
- const thisChild = prevChild;
568
- handleGaps(gapText, () => ({ index: thisChild.endIndex, position: thisChild.endPosition }), node);
569
- }
570
- return newChildren;
571
- }
572
- };
@@ -1,37 +0,0 @@
1
- /**
2
- * Creates and returns a new parser instance, loading a language from a WebAssembly binary or file path.
3
- * Optionally, the parser can be configured to disable soft nodes.
4
- *
5
- * @async
6
- * @param {Uint8Array|string} wasmUint8ArrayOrFilePath - The WebAssembly binary as a `Uint8Array` or a file path to load the language.
7
- * @param {Object} [options] - Optional configuration options.
8
- * @param {boolean} [options.disableSoftNodes=false] - Whether to disable soft nodes in the parser (default is `false`).
9
- * @returns {Promise<ExtendedParser>} A promise that resolves to the created parser instance.
10
- */
11
- export function createParser(wasmUint8ArrayOrFilePath: Uint8Array | string, { disableSoftNodes, moduleOptions }?: {
12
- disableSoftNodes?: boolean | undefined;
13
- }): Promise<ExtendedParser>;
14
- declare class ExtendedParser extends Parser {
15
- /**
16
- * Parse a slice of UTF8 text.
17
- *
18
- * @param {string | ParseCallback} callback - Source code to parse
19
- *
20
- * @param {Tree | null} [oldTree] - A previous syntax tree parsed from the same document. If the text of the
21
- * document has changed since `oldTree` was created, then you must edit `oldTree` to match
22
- * the new text using {@link Tree#edit}.
23
- *
24
- * @param {ParseOptions} [options] - Options for parsing the text.
25
- * This can be used to set the included ranges, or a progress callback.
26
- *
27
- * @returns {ExtendedTree | null} A {@link Tree} if parsing succeeded, or `null` if:
28
- * - The parser has not yet had a language assigned with {@link Parser#setLanguage}.
29
- * - The progress callback returned true.
30
- */
31
- parse(inputString: any, oldTree?: Tree | null, options?: ParseOptions): ExtendedTree | null;
32
- }
33
- import { Parser } from "../tree_sitter/parser.js";
34
- import { Tree } from "../tree_sitter/tree.js";
35
- import { ExtendedTree } from "./node_extended.js";
36
- export {};
37
- //# sourceMappingURL=parser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/extended/parser.js"],"names":[],"mappings":"AAiDA;;;;;;;;;GASG;AACH,uDALW,UAAU,GAAC,MAAM,wCAEzB;IAA0B,gBAAgB;CAC1C,GAAU,OAAO,CAAC,cAAc,CAAC,CA6BnC;AA5DD;IACI;;;;;;;;;;;;;;;OAeG;IACH,kCAXW,IAAI,GAAG,IAAI,YAIX,YAAY,GAGV,YAAY,GAAG,IAAI,CAK/B;CACJ;uBA3CsB,0BAA0B;qBAD5B,wBAAwB;6BAIkB,oBAAoB"}