tree-sitter
Advanced tools
Comparing version 0.20.3 to 0.20.4
50
index.js
@@ -255,3 +255,3 @@ let binding; | ||
const {parse, parseTextBuffer, parseTextBufferSync, setLanguage} = Parser.prototype; | ||
const {parse, setLanguage} = Parser.prototype; | ||
const languageSymbol = Symbol('parser.language'); | ||
@@ -296,46 +296,2 @@ | ||
Parser.prototype.parseTextBuffer = function( | ||
buffer, oldTree, | ||
{syncTimeoutMicros, includedRanges} = {} | ||
) { | ||
let tree | ||
let resolveTreePromise | ||
const treePromise = new Promise(resolve => { resolveTreePromise = resolve }) | ||
const snapshot = buffer.getSnapshot(); | ||
parseTextBuffer.call( | ||
this, | ||
result => { | ||
tree = result | ||
snapshot.destroy(); | ||
if (tree) { | ||
tree.input = buffer | ||
tree.getText = getTextFromTextBuffer | ||
tree.language = this.getLanguage() | ||
} | ||
resolveTreePromise(tree); | ||
}, | ||
snapshot, | ||
oldTree, | ||
includedRanges, | ||
syncTimeoutMicros | ||
); | ||
// If the parse finished synchronously within the time specified by the | ||
// `syncTimeoutMicros` parameter, then return the tree immediately | ||
// so that callers have the option of continuing synchronously. | ||
return tree || treePromise | ||
}; | ||
Parser.prototype.parseTextBufferSync = function(buffer, oldTree, {includedRanges}={}) { | ||
const snapshot = buffer.getSnapshot(); | ||
const tree = parseTextBufferSync.call(this, snapshot, oldTree, includedRanges); | ||
if (tree) { | ||
tree.input = buffer; | ||
tree.getText = getTextFromTextBuffer; | ||
tree.language = this.getLanguage() | ||
} | ||
snapshot.destroy(); | ||
return tree; | ||
}; | ||
/* | ||
@@ -612,6 +568,2 @@ * TreeCursor | ||
function getTextFromTextBuffer ({startPosition, endPosition}) { | ||
return this.input.getTextInRange({start: startPosition, end: endPosition}); | ||
} | ||
const {pointTransferArray} = binding; | ||
@@ -618,0 +570,0 @@ |
{ | ||
"name": "tree-sitter", | ||
"version": "0.20.3", | ||
"version": "0.20.4", | ||
"description": "Incremental parsers for node", | ||
@@ -27,3 +27,2 @@ "author": "Max Brunsfeld", | ||
"prebuild": "^11.0.4", | ||
"superstring": "^2.4.2", | ||
"tree-sitter-javascript": "https://github.com/tree-sitter/tree-sitter-javascript.git#master" | ||
@@ -30,0 +29,0 @@ }, |
@@ -91,25 +91,1 @@ node tree-sitter | ||
``` | ||
### Asynchronous Parsing | ||
If you have source code stored in a [superstring](https://github.com/atom/superstring) `TextBuffer`, you can parse that source code on a background thread with a `Promise`-based interface: | ||
```javascript | ||
const {TextBuffer} = require('superstring'); | ||
async function test() { | ||
const buffer = new TextBuffer('const x= 1; console.log(x);'); | ||
const newTree = await parser.parseTextBuffer(buffer, oldTree); | ||
} | ||
``` | ||
Using a background thread can introduce a slight delay, so you may want to allow *some* work to be done on the main thread, in the hopes that parsing will complete so quickly that you won't even *need* a background thread: | ||
```javascript | ||
async function test2() { | ||
const buffer = new TextBuffer('const x= 1; console.log(x);'); | ||
const newTree = await parser.parseTextBuffer(buffer, oldTree, { | ||
syncOperationCount: 1000 | ||
}); | ||
} | ||
``` |
declare module "tree-sitter" { | ||
class Parser { | ||
parse(input: string | Parser.Input | Parser.InputReader, oldTree?: Parser.Tree, options?: { bufferSize?: number, includedRanges?: Parser.Range[] }): Parser.Tree; | ||
parseTextBuffer(buffer: Parser.TextBuffer, oldTree?: Parser.Tree, options?: { syncTimeoutMicros?: number, includedRanges?: Parser.Range[] }): Parser.Tree | Promise<Parser.Tree>; | ||
parseTextBufferSync(buffer: Parser.TextBuffer, oldTree?: Parser.Tree, options?: { includedRanges?: Parser.Range[] }): Parser.Tree; | ||
getLanguage(): any; | ||
@@ -41,4 +39,2 @@ setLanguage(language: any): void; | ||
export type TextBuffer = Buffer; | ||
export interface InputReader { | ||
@@ -104,2 +100,3 @@ (index: any, position: Point): string; | ||
nodeIsNamed: boolean; | ||
nodeIsMissing: boolean; | ||
startPosition: Point; | ||
@@ -106,0 +103,0 @@ endPosition: Point; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6
620040
70
728
91