@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 @@
|
|
|
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"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Node } from "../tree_sitter/node.js";
|
|
2
|
+
import { Tree } from "../tree_sitter/tree.js";
|
|
3
|
+
import { Parser } from "../tree_sitter/parser.js";
|
|
4
|
+
import { Language } from "../tree_sitter/language.js";
|
|
5
|
+
import "./node_extended.js"; // note: redundant but might not be redundant in the future
|
|
6
|
+
import { HardNode, ExtendedTree, _childrenWithSoftNodes } from "./node_extended.js";
|
|
7
|
+
const realParseFunction = Parser.prototype.parse;
|
|
8
|
+
Parser.prototype.parse = function (code, oldTree, options) {
|
|
9
|
+
if (typeof code == "function") {
|
|
10
|
+
console.warn("When calling .parse() the source code was a function instead of a string. The original tree sitter supports giving a function as a means of supporting edits (see: https://github.com/tree-sitter/tree-sitter/discussions/2553 ).\nHowever, this library supports edits directly (use node.replaceInnards(``))\nThe downside of making edits easy is that .parse() doesn't really accept a function argument. I'm just going to evaluate that function to grab the string once at the beginning. Use tree.codeString if you want to get the full string after a .replaceInnards() call.");
|
|
11
|
+
code = code(0);
|
|
12
|
+
}
|
|
13
|
+
let tree;
|
|
14
|
+
tree = realParseFunction.apply(this, [
|
|
15
|
+
(index) => (tree?.codeString ?? code).slice(index),
|
|
16
|
+
oldTree,
|
|
17
|
+
options
|
|
18
|
+
]);
|
|
19
|
+
tree.codeString = code;
|
|
20
|
+
code = null;
|
|
21
|
+
tree._enableSoftNodes = !this.disableSoftNodes;
|
|
22
|
+
return tree;
|
|
23
|
+
};
|
|
24
|
+
// this only exists to help with type hints
|
|
25
|
+
class ExtendedParser extends Parser {
|
|
26
|
+
/**
|
|
27
|
+
* Parse a slice of UTF8 text.
|
|
28
|
+
*
|
|
29
|
+
* @param {string | ParseCallback} callback - Source code to parse
|
|
30
|
+
*
|
|
31
|
+
* @param {Tree | null} [oldTree] - A previous syntax tree parsed from the same document. If the text of the
|
|
32
|
+
* document has changed since `oldTree` was created, then you must edit `oldTree` to match
|
|
33
|
+
* the new text using {@link Tree#edit}.
|
|
34
|
+
*
|
|
35
|
+
* @param {ParseOptions} [options] - Options for parsing the text.
|
|
36
|
+
* This can be used to set the included ranges, or a progress callback.
|
|
37
|
+
*
|
|
38
|
+
* @returns {ExtendedTree | null} A {@link Tree} if parsing succeeded, or `null` if:
|
|
39
|
+
* - The parser has not yet had a language assigned with {@link Parser#setLanguage}.
|
|
40
|
+
* - The progress callback returned true.
|
|
41
|
+
*/
|
|
42
|
+
parse(inputString, oldTree, options) {
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const langCache = new Map();
|
|
46
|
+
let hasBeenLoaded = false;
|
|
47
|
+
/**
|
|
48
|
+
* Creates and returns a new parser instance, loading a language from a WebAssembly binary or file path.
|
|
49
|
+
* Optionally, the parser can be configured to disable soft nodes.
|
|
50
|
+
*
|
|
51
|
+
* @async
|
|
52
|
+
* @param {Uint8Array|string} wasmUint8ArrayOrFilePath - The WebAssembly binary as a `Uint8Array` or a file path to load the language.
|
|
53
|
+
* @param {Object} [options] - Optional configuration options.
|
|
54
|
+
* @param {boolean} [options.disableSoftNodes=false] - Whether to disable soft nodes in the parser (default is `false`).
|
|
55
|
+
* @returns {Promise<ExtendedParser>} A promise that resolves to the created parser instance.
|
|
56
|
+
*/
|
|
57
|
+
export async function createParser(wasmUint8ArrayOrFilePath, { disableSoftNodes = false, moduleOptions } = {}) {
|
|
58
|
+
// download if given a url
|
|
59
|
+
if (typeof wasmUint8ArrayOrFilePath == "string" && wasmUint8ArrayOrFilePath.match(/^https?:\/\//)) {
|
|
60
|
+
wasmUint8ArrayOrFilePath = await fetch(wasmUint8ArrayOrFilePath).then(async (r) => new Uint8Array(await r.arrayBuffer()));
|
|
61
|
+
}
|
|
62
|
+
if (!hasBeenLoaded) {
|
|
63
|
+
hasBeenLoaded = true;
|
|
64
|
+
await Parser.init(moduleOptions);
|
|
65
|
+
}
|
|
66
|
+
// this is a workaround for the a bug in the loader where loading the same language twice causes a freeze
|
|
67
|
+
// see: "WebAssembly.instantiate(binary, info).then" inside wasm_loader.js
|
|
68
|
+
let language;
|
|
69
|
+
if (wasmUint8ArrayOrFilePath instanceof Uint8Array) {
|
|
70
|
+
const hashString = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", wasmUint8ArrayOrFilePath))).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
71
|
+
if (langCache.has(hashString)) {
|
|
72
|
+
language = langCache.get(hashString);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
language = await Language.load(wasmUint8ArrayOrFilePath);
|
|
76
|
+
langCache.set(hashString, language);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
language = await Language.load(wasmUint8ArrayOrFilePath);
|
|
81
|
+
}
|
|
82
|
+
const parser = new Parser();
|
|
83
|
+
parser.setLanguage(language);
|
|
84
|
+
parser.disableSoftNodes = disableSoftNodes;
|
|
85
|
+
return parser;
|
|
86
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class SoftNode extends BaseNode {
|
|
2
|
+
children: any[];
|
|
3
|
+
get startIndex(): any;
|
|
4
|
+
get startPosition(): {
|
|
5
|
+
row: any;
|
|
6
|
+
column: any;
|
|
7
|
+
};
|
|
8
|
+
get endIndex(): any;
|
|
9
|
+
get endPosition(): {
|
|
10
|
+
row: any;
|
|
11
|
+
column: any;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
import { BaseNode } from "./base_node.js";
|
|
15
|
+
//# sourceMappingURL=soft_node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"soft_node.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/extended/soft_node.js"],"names":[],"mappings":"AAGA;IACI,gBAAa;IAMb,sBAEC;IAED;;;MAKC;IAED,oBAEC;IAED;;;MAKC;CACJ;yBA/BwB,gBAAgB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseNode } from "./base_node.js";
|
|
2
|
+
// HardNode extends BaseNode as well (indirectly)
|
|
3
|
+
export class SoftNode extends BaseNode {
|
|
4
|
+
constructor(data) {
|
|
5
|
+
super(data);
|
|
6
|
+
Object.defineProperty(this, "children", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: []
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
// these are getters because when calling .replaceInnards() on a node the indices of hardNodes shift, these getters piggyback on that shift (otherwise they'd be wrong)
|
|
14
|
+
get startIndex() {
|
|
15
|
+
return this._startIndexOffset + this.getReferencePoint().index;
|
|
16
|
+
}
|
|
17
|
+
get startPosition() {
|
|
18
|
+
return {
|
|
19
|
+
row: this._startRowOffset + this.getReferencePoint().position.row,
|
|
20
|
+
column: this._startColOffset + this.getReferencePoint().position.column,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
get endIndex() {
|
|
24
|
+
return this._endIndexOffset + this.getReferencePoint().index;
|
|
25
|
+
}
|
|
26
|
+
get endPosition() {
|
|
27
|
+
return {
|
|
28
|
+
row: this._endRowOffset + this.getReferencePoint().position.row,
|
|
29
|
+
column: this._endColOffset + this.getReferencePoint().position.column,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"soft_text_node.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/extended/soft_text_node.js"],"names":[],"mappings":"AAEA;IACI;;;OAGC;IADG,aAAqB;IAEzB,kBAEC;CACJ;yBAVwB,gBAAgB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whitespace_node.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/extended/whitespace_node.js"],"names":[],"mappings":"AAEA;IACI;;;OAGC;IADG,aAAqB;IAEzB,kBAEC;CACJ;yBAVwB,gBAAgB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/extras/misc.js"],"names":[],"mappings":"AAAA,+DAWC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function _getQueryCaptureTargets(queryString) {
|
|
2
|
+
if (!queryString.includes("@")) {
|
|
3
|
+
return [];
|
|
4
|
+
}
|
|
5
|
+
else { // need a rigorous check
|
|
6
|
+
// remove all strings from within the query (the only place a false capture target could appear)
|
|
7
|
+
// NOTE: this is based exactly on the language spec, its not a hack: https://github.com/tree-sitter-grammars/tree-sitter-query/blob/3a9808b22742d5bd906ef5d1a562f2f1ae57406d/src/grammar.json#L140
|
|
8
|
+
const safeSearchableQuery = queryString.replace(/"(?:\\(?:[^xu0-7]|[0-7]{1,3}|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|u{[0-9a-fA-F]+})|[^\"\\])*"/g, "");
|
|
9
|
+
// now check if there is a capture target
|
|
10
|
+
// NOTE: also based on the language spec: https://github.com/tree-sitter-grammars/tree-sitter-query/blob/3a9808b22742d5bd906ef5d1a562f2f1ae57406d/src/grammar.json#L204
|
|
11
|
+
return safeSearchableQuery.match(/(?<=@)([a-zA-Z0-9.\-_\$]+)/g);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*
|
|
4
|
+
* Initialize the Tree-sitter Wasm module. This should only be called by the {@link Parser} class via {@link Parser.init}.
|
|
5
|
+
*/
|
|
6
|
+
export function initializeBinding(moduleOptions: any): Promise<null>;
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*
|
|
10
|
+
* Checks if the Tree-sitter Wasm module has been initialized.
|
|
11
|
+
*/
|
|
12
|
+
export function checkModule(): boolean;
|
|
13
|
+
export let Module: null;
|
|
14
|
+
//# sourceMappingURL=bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/tree_sitter/bindings.js"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,qEAKC;AAED;;;;GAIG;AACH,uCAEC;AArBD,wBAAwB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import createModule from "../wasm_loader_with_defaults.js";
|
|
2
|
+
export let Module = null;
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*
|
|
6
|
+
* Initialize the Tree-sitter Wasm module. This should only be called by the {@link Parser} class via {@link Parser.init}.
|
|
7
|
+
*/
|
|
8
|
+
export async function initializeBinding(moduleOptions) {
|
|
9
|
+
if (!Module) {
|
|
10
|
+
Module = await createModule(moduleOptions);
|
|
11
|
+
}
|
|
12
|
+
return Module;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*
|
|
17
|
+
* Checks if the Tree-sitter Wasm module has been initialized.
|
|
18
|
+
*/
|
|
19
|
+
export function checkModule() {
|
|
20
|
+
return !!Module;
|
|
21
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
/** @internal */
|
|
3
|
+
export function assertInternal(x: any): void;
|
|
4
|
+
/** @internal */
|
|
5
|
+
export function isPoint(point: any): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*
|
|
9
|
+
* Sets the Tree-sitter Wasm module. This should only be called by the {@link Parser} class via {@link Parser.init}.
|
|
10
|
+
*/
|
|
11
|
+
export function setModule(module: any): void;
|
|
12
|
+
/**
|
|
13
|
+
* A position in a multi-line text document, in terms of rows and columns.
|
|
14
|
+
*
|
|
15
|
+
* Rows and columns are zero-based.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* A range of positions in a multi-line text document, both in terms of bytes
|
|
19
|
+
* and of rows and columns.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* A summary of a change to a text document.
|
|
23
|
+
*/
|
|
24
|
+
/** @internal */
|
|
25
|
+
export const SIZE_OF_SHORT: 2;
|
|
26
|
+
/** @internal */
|
|
27
|
+
export const SIZE_OF_INT: 4;
|
|
28
|
+
/** @internal */
|
|
29
|
+
export const SIZE_OF_CURSOR: number;
|
|
30
|
+
/** @internal */
|
|
31
|
+
export const SIZE_OF_NODE: number;
|
|
32
|
+
/** @internal */
|
|
33
|
+
export const SIZE_OF_POINT: number;
|
|
34
|
+
/** @internal */
|
|
35
|
+
export const SIZE_OF_RANGE: number;
|
|
36
|
+
export namespace ZERO_POINT {
|
|
37
|
+
let row: number;
|
|
38
|
+
let column: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A callback for parsing that takes an index and point, and should return a string.
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* A callback that receives the parse state during parsing.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* A callback for logging messages.
|
|
48
|
+
*
|
|
49
|
+
* If `isLex` is `true`, the message is from the lexer, otherwise it's from the parser.
|
|
50
|
+
*/
|
|
51
|
+
/** @internal */
|
|
52
|
+
export const INTERNAL: unique symbol;
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*
|
|
56
|
+
* `C` is a convenient shorthand for the Tree-sitter Wasm module,
|
|
57
|
+
* which allows us to call all of the exported functions.
|
|
58
|
+
*/
|
|
59
|
+
export let C: any;
|
|
60
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/tree_sitter/constants.js"],"names":[],"mappings":"AAmDA,gBAAgB;AAEhB,gBAAgB;AAChB,6CAEC;AAED,gBAAgB;AAChB,6CAEC;AAED;;;;GAIG;AACH,6CAEC;AAlED;;;;GAIG;AACH;;;GAGG;AACH;;GAEG;AACH,gBAAgB;AAChB,4BAA6B,CAAC,CAAA;AAE9B,gBAAgB;AAChB,0BAA2B,CAAC,CAAA;AAE5B,gBAAgB;AAChB,oCAA6C;AAE7C,gBAAgB;AAChB,kCAA2C;AAE3C,gBAAgB;AAChB,mCAA4C;AAE5C,gBAAgB;AAChB,mCAAgE;;;;;AAKhE;;GAEG;AACH;;GAEG;AACH;;;;GAIG;AAEH,gBAAgB;AAChB,qCAA0C;AAsB1C;;;;;GAKG;AACH,kBAAY"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A position in a multi-line text document, in terms of rows and columns.
|
|
3
|
+
*
|
|
4
|
+
* Rows and columns are zero-based.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A range of positions in a multi-line text document, both in terms of bytes
|
|
8
|
+
* and of rows and columns.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* A summary of a change to a text document.
|
|
12
|
+
*/
|
|
13
|
+
/** @internal */
|
|
14
|
+
export const SIZE_OF_SHORT = 2;
|
|
15
|
+
/** @internal */
|
|
16
|
+
export const SIZE_OF_INT = 4;
|
|
17
|
+
/** @internal */
|
|
18
|
+
export const SIZE_OF_CURSOR = 4 * SIZE_OF_INT;
|
|
19
|
+
/** @internal */
|
|
20
|
+
export const SIZE_OF_NODE = 5 * SIZE_OF_INT;
|
|
21
|
+
/** @internal */
|
|
22
|
+
export const SIZE_OF_POINT = 2 * SIZE_OF_INT;
|
|
23
|
+
/** @internal */
|
|
24
|
+
export const SIZE_OF_RANGE = 2 * SIZE_OF_INT + 2 * SIZE_OF_POINT;
|
|
25
|
+
/** @internal */
|
|
26
|
+
export const ZERO_POINT = { row: 0, column: 0 };
|
|
27
|
+
/**
|
|
28
|
+
* A callback for parsing that takes an index and point, and should return a string.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* A callback that receives the parse state during parsing.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* A callback for logging messages.
|
|
35
|
+
*
|
|
36
|
+
* If `isLex` is `true`, the message is from the lexer, otherwise it's from the parser.
|
|
37
|
+
*/
|
|
38
|
+
// Helper type for internal use
|
|
39
|
+
/** @internal */
|
|
40
|
+
export const INTERNAL = Symbol("INTERNAL");
|
|
41
|
+
/** @internal */
|
|
42
|
+
// Helper functions for type checking
|
|
43
|
+
/** @internal */
|
|
44
|
+
export function assertInternal(x) {
|
|
45
|
+
if (x !== INTERNAL)
|
|
46
|
+
throw new Error("Illegal constructor");
|
|
47
|
+
}
|
|
48
|
+
/** @internal */
|
|
49
|
+
export function isPoint(point) {
|
|
50
|
+
return !!point && typeof point.row === "number" && typeof point.column === "number";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*
|
|
55
|
+
* Sets the Tree-sitter Wasm module. This should only be called by the {@link Parser} class via {@link Parser.init}.
|
|
56
|
+
*/
|
|
57
|
+
export function setModule(module) {
|
|
58
|
+
C = module;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*
|
|
63
|
+
* `C` is a convenient shorthand for the Tree-sitter Wasm module,
|
|
64
|
+
* which allows us to call all of the exported functions.
|
|
65
|
+
*/
|
|
66
|
+
export let C;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export class LanguageMetadata {
|
|
2
|
+
major_version: any;
|
|
3
|
+
minor_version: any;
|
|
4
|
+
patch_version: any;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* An opaque object that defines how to parse a particular language.
|
|
8
|
+
* The code for each `Language` is generated by the Tree-sitter CLI.
|
|
9
|
+
*/
|
|
10
|
+
export class Language {
|
|
11
|
+
/**
|
|
12
|
+
* Load a language from a WebAssembly module.
|
|
13
|
+
* The module can be provided as a path to a file or as a buffer.
|
|
14
|
+
*/
|
|
15
|
+
static load(input: any): Promise<Language>;
|
|
16
|
+
/** @internal */
|
|
17
|
+
constructor(internal: any, address: any);
|
|
18
|
+
/** @internal */
|
|
19
|
+
0: number;
|
|
20
|
+
/**
|
|
21
|
+
* A list of all node types in the language. The index of each type in this
|
|
22
|
+
* array is its node type id.
|
|
23
|
+
*/
|
|
24
|
+
types: any[];
|
|
25
|
+
/**
|
|
26
|
+
* A list of all field names in the language. The index of each field name in
|
|
27
|
+
* this array is its field id.
|
|
28
|
+
*/
|
|
29
|
+
fields: any[];
|
|
30
|
+
/**
|
|
31
|
+
* Gets the name of the language.
|
|
32
|
+
*/
|
|
33
|
+
get name(): any;
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated since version 0.25.0, use {@link Language#abiVersion} instead
|
|
36
|
+
* Gets the version of the language.
|
|
37
|
+
*/
|
|
38
|
+
get version(): any;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the ABI version of the language.
|
|
41
|
+
*/
|
|
42
|
+
get abiVersion(): any;
|
|
43
|
+
/**
|
|
44
|
+
* Get the metadata for this language. This information is generated by the
|
|
45
|
+
* CLI, and relies on the language author providing the correct metadata in
|
|
46
|
+
* the language's `tree-sitter.json` file.
|
|
47
|
+
*/
|
|
48
|
+
get metadata(): {
|
|
49
|
+
major_version: any;
|
|
50
|
+
minor_version: any;
|
|
51
|
+
field_count: any;
|
|
52
|
+
} | null;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the number of fields in the language.
|
|
55
|
+
*/
|
|
56
|
+
get fieldCount(): number;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the number of states in the language.
|
|
59
|
+
*/
|
|
60
|
+
get stateCount(): any;
|
|
61
|
+
/**
|
|
62
|
+
* Get the field id for a field name.
|
|
63
|
+
*/
|
|
64
|
+
fieldIdForName(fieldName: any): number | null;
|
|
65
|
+
/**
|
|
66
|
+
* Get the field name for a field id.
|
|
67
|
+
*/
|
|
68
|
+
fieldNameForId(fieldId: any): any;
|
|
69
|
+
/**
|
|
70
|
+
* Get the node type id for a node type name.
|
|
71
|
+
*/
|
|
72
|
+
idForNodeType(type: any, named: any): any;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the number of node types in the language.
|
|
75
|
+
*/
|
|
76
|
+
get nodeTypeCount(): any;
|
|
77
|
+
/**
|
|
78
|
+
* Get the node type name for a node type id.
|
|
79
|
+
*/
|
|
80
|
+
nodeTypeForId(typeId: any): any;
|
|
81
|
+
/**
|
|
82
|
+
* Check if a node type is named.
|
|
83
|
+
*
|
|
84
|
+
* @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers/2-basic-parsing.html#named-vs-anonymous-nodes}
|
|
85
|
+
*/
|
|
86
|
+
nodeTypeIsNamed(typeId: any): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Check if a node type is visible.
|
|
89
|
+
*/
|
|
90
|
+
nodeTypeIsVisible(typeId: any): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Get the supertypes ids of this language.
|
|
93
|
+
*
|
|
94
|
+
* @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types.html?highlight=supertype#supertype-nodes}
|
|
95
|
+
*/
|
|
96
|
+
get supertypes(): any[];
|
|
97
|
+
/**
|
|
98
|
+
* Get the subtype ids for a given supertype node id.
|
|
99
|
+
*/
|
|
100
|
+
subtypes(supertype: any): any[];
|
|
101
|
+
/**
|
|
102
|
+
* Get the next state id for a given state id and node type id.
|
|
103
|
+
*/
|
|
104
|
+
nextState(stateId: any, typeId: any): any;
|
|
105
|
+
/**
|
|
106
|
+
* Create a new lookahead iterator for this language and parse state.
|
|
107
|
+
*
|
|
108
|
+
* This returns `null` if state is invalid for this language.
|
|
109
|
+
*
|
|
110
|
+
* Iterating {@link LookaheadIterator} will yield valid symbols in the given
|
|
111
|
+
* parse state. Newly created lookahead iterators will return the `ERROR`
|
|
112
|
+
* symbol from {@link LookaheadIterator#currentType}.
|
|
113
|
+
*
|
|
114
|
+
* Lookahead iterators can be useful for generating suggestions and improving
|
|
115
|
+
* syntax error diagnostics. To get symbols valid in an `ERROR` node, use the
|
|
116
|
+
* lookahead iterator on its first leaf node state. For `MISSING` nodes, a
|
|
117
|
+
* lookahead iterator created on the previous non-extra leaf node may be
|
|
118
|
+
* appropriate.
|
|
119
|
+
*/
|
|
120
|
+
lookaheadIterator(stateId: any): LookaheadIterator | null;
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated since version 0.25.0, call `new` on a {@link Query} instead
|
|
123
|
+
*
|
|
124
|
+
* Create a new query from a string containing one or more S-expression
|
|
125
|
+
* patterns.
|
|
126
|
+
*
|
|
127
|
+
* The query is associated with a particular language, and can only be run
|
|
128
|
+
* on syntax nodes parsed with that language. References to Queries can be
|
|
129
|
+
* shared between multiple threads.
|
|
130
|
+
*
|
|
131
|
+
* @link {@see https://tree-sitter.github.io/tree-sitter/using-parsers/queries}
|
|
132
|
+
*/
|
|
133
|
+
query(source: any): Query;
|
|
134
|
+
}
|
|
135
|
+
import { LookaheadIterator } from "./lookahead_iterator.js";
|
|
136
|
+
import { Query } from "./query.js";
|
|
137
|
+
//# sourceMappingURL=language.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/tree_sitter/language.js"],"names":[],"mappings":"AAQA;IACI,mBAAa;IACb,mBAAa;IACb,mBAAa;CAChB;AAED;;;GAGG;AACH;IAyOI;;;OAGG;IACH,2CAgCC;IA7PD,gBAAgB;IAChB,yCAkBC;IAlCD,gBAAgB;IAChB,UAAO;IAEP;;;OAGG;IACH,aAAK;IAEL;;;OAGG;IACH,cAAM;IAuBN;;OAEG;IACH,gBAIC;IAED;;;OAGG;IACH,mBAEC;IAED;;OAEG;IACH,sBAEC;IAED;;;;OAIG;IACH;;;;aAMC;IAED;;OAEG;IACH,yBAEC;IAED;;OAEG;IACH,sBAEC;IAED;;OAEG;IACH,8CAGC;IAED;;OAEG;IACH,kCAEC;IAED;;OAEG;IACH,0CAOC;IAED;;OAEG;IACH,yBAEC;IAED;;OAEG;IACH,gCAGC;IAED;;;;OAIG;IACH,sCAEC;IAED;;OAEG;IACH,wCAEC;IAED;;;;OAIG;IACH,wBAeC;IAED;;OAEG;IACH,gCAeC;IAED;;OAEG;IACH,0CAEC;IAED;;;;;;;;;;;;;;OAcG;IACH,0DAIC;IAED;;;;;;;;;;;OAWG;IACH,0BAGC;CAuCJ;kCA/RiC,yBAAyB;sBAGrC,YAAY"}
|