Tweak query interface
* Rename TSQueryContext -> TSQueryCursor * Remove the permanent association between the cursor and its query. The cursor can now be used again for a different query.
This commit is contained in:
parent
c8c75782e3
commit
c71de5bd81
9 changed files with 142 additions and 147 deletions
|
|
@ -677,7 +677,6 @@ class Language {
|
|||
TRANSFER_BUFFER + SIZE_OF_INT
|
||||
);
|
||||
if (address) {
|
||||
const contextAddress = C._ts_query_context_new(address);
|
||||
const captureCount = C._ts_query_capture_count(address);
|
||||
const captureNames = new Array(captureCount);
|
||||
for (let i = 0; i < captureCount; i++) {
|
||||
|
|
@ -689,7 +688,7 @@ class Language {
|
|||
const nameLength = getValue(TRANSFER_BUFFER, 'i32');
|
||||
captureNames[i] = UTF8ToString(nameAddress, nameLength);
|
||||
}
|
||||
return new Query(INTERNAL, address, contextAddress, captureNames);
|
||||
return new Query(INTERNAL, address, captureNames);
|
||||
} else {
|
||||
const errorId = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
|
||||
const utf8ErrorOffset = getValue(TRANSFER_BUFFER, 'i32');
|
||||
|
|
@ -743,22 +742,20 @@ class Language {
|
|||
}
|
||||
|
||||
class Query {
|
||||
constructor(internal, address, contextAddress, captureNames) {
|
||||
constructor(internal, address, captureNames) {
|
||||
assertInternal(internal);
|
||||
this[0] = address;
|
||||
this[1] = contextAddress;
|
||||
this.captureNames = captureNames;
|
||||
}
|
||||
|
||||
delete() {
|
||||
C._ts_query_delete(this[0]);
|
||||
C._ts_query_context_delete(this[0]);
|
||||
}
|
||||
|
||||
exec(queryNode) {
|
||||
marshalNode(queryNode);
|
||||
|
||||
C._ts_query_exec_wasm(this[0], this[1], queryNode.tree[0]);
|
||||
C._ts_query_exec_wasm(this[0], queryNode.tree[0]);
|
||||
|
||||
const matchCount = getValue(TRANSFER_BUFFER, 'i32');
|
||||
const nodesAddress = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue