@yalehwang/archguard 0.1.7 → 0.1.9
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/README.md +33 -23
- package/dist/cli/analyze/normalize-to-diagrams.d.ts.map +1 -1
- package/dist/cli/analyze/normalize-to-diagrams.js +61 -4
- package/dist/cli/analyze/normalize-to-diagrams.js.map +1 -1
- package/dist/cli/analyze/run-analysis.d.ts.map +1 -1
- package/dist/cli/analyze/run-analysis.js +12 -4
- package/dist/cli/analyze/run-analysis.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/commands/mcp.js +2 -6
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/cli/index.js +0 -0
- package/dist/cli/mcp/analyze-tool.d.ts +1 -5
- package/dist/cli/mcp/analyze-tool.d.ts.map +1 -1
- package/dist/cli/mcp/analyze-tool.js +48 -52
- package/dist/cli/mcp/analyze-tool.js.map +1 -1
- package/dist/cli/mcp/mcp-server.d.ts +4 -4
- package/dist/cli/mcp/mcp-server.d.ts.map +1 -1
- package/dist/cli/mcp/mcp-server.js +108 -57
- package/dist/cli/mcp/mcp-server.js.map +1 -1
- package/dist/cli/processors/arch-json-provider.d.ts +4 -1
- package/dist/cli/processors/arch-json-provider.d.ts.map +1 -1
- package/dist/cli/processors/arch-json-provider.js +87 -23
- package/dist/cli/processors/arch-json-provider.js.map +1 -1
- package/dist/cli/processors/diagram-output-router.d.ts.map +1 -1
- package/dist/cli/processors/diagram-output-router.js +1 -0
- package/dist/cli/processors/diagram-output-router.js.map +1 -1
- package/dist/cli/processors/diagram-processor.d.ts.map +1 -1
- package/dist/cli/processors/diagram-processor.js +10 -5
- package/dist/cli/processors/diagram-processor.js.map +1 -1
- package/dist/cli/query/engine-loader.js +2 -2
- package/dist/cli/query/engine-loader.js.map +1 -1
- package/dist/cli/query/query-artifacts.d.ts +5 -1
- package/dist/cli/query/query-artifacts.d.ts.map +1 -1
- package/dist/cli/query/query-artifacts.js +22 -3
- package/dist/cli/query/query-artifacts.js.map +1 -1
- package/dist/cli/query/query-manifest.d.ts +2 -0
- package/dist/cli/query/query-manifest.d.ts.map +1 -1
- package/dist/cli/utils/default-scope-planner.d.ts +22 -0
- package/dist/cli/utils/default-scope-planner.d.ts.map +1 -0
- package/dist/cli/utils/default-scope-planner.js +84 -0
- package/dist/cli/utils/default-scope-planner.js.map +1 -0
- package/dist/cli/utils/project-language-detector.d.ts +10 -0
- package/dist/cli/utils/project-language-detector.d.ts.map +1 -0
- package/dist/cli/utils/project-language-detector.js +179 -0
- package/dist/cli/utils/project-language-detector.js.map +1 -0
- package/dist/mermaid/render-worker-pool.d.ts.map +1 -1
- package/dist/mermaid/render-worker-pool.js +7 -1
- package/dist/mermaid/render-worker-pool.js.map +1 -1
- package/dist/plugins/golang/atlas/index.d.ts.map +1 -1
- package/dist/plugins/golang/atlas/index.js +3 -1
- package/dist/plugins/golang/atlas/index.js.map +1 -1
- package/dist/plugins/golang/atlas/types.d.ts +1 -0
- package/dist/plugins/golang/atlas/types.d.ts.map +1 -1
- package/dist/plugins/golang/index.d.ts.map +1 -1
- package/dist/plugins/golang/index.js +15 -6
- package/dist/plugins/golang/index.js.map +1 -1
- package/dist/plugins/golang/source-scope.d.ts +7 -0
- package/dist/plugins/golang/source-scope.d.ts.map +1 -0
- package/dist/plugins/golang/source-scope.js +83 -0
- package/dist/plugins/golang/source-scope.js.map +1 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/config.d.ts.map +1 -1
- package/node_modules/node-addon-api/LICENSE.md +9 -0
- package/node_modules/node-addon-api/README.md +95 -0
- package/node_modules/node-addon-api/common.gypi +21 -0
- package/node_modules/node-addon-api/except.gypi +25 -0
- package/node_modules/node-addon-api/index.js +14 -0
- package/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
- package/node_modules/node-addon-api/napi-inl.h +7033 -0
- package/node_modules/node-addon-api/napi.h +3309 -0
- package/node_modules/node-addon-api/node_addon_api.gyp +42 -0
- package/node_modules/node-addon-api/node_api.gyp +9 -0
- package/node_modules/node-addon-api/noexcept.gypi +26 -0
- package/node_modules/node-addon-api/nothing.c +0 -0
- package/node_modules/node-addon-api/package-support.json +21 -0
- package/node_modules/node-addon-api/package.json +480 -0
- package/node_modules/node-addon-api/tools/README.md +73 -0
- package/node_modules/node-addon-api/tools/check-napi.js +99 -0
- package/node_modules/node-addon-api/tools/clang-format.js +71 -0
- package/node_modules/node-addon-api/tools/conversion.js +301 -0
- package/node_modules/node-gyp-build/LICENSE +21 -0
- package/node_modules/node-gyp-build/README.md +58 -0
- package/node_modules/node-gyp-build/SECURITY.md +5 -0
- package/node_modules/node-gyp-build/bin.js +84 -0
- package/node_modules/node-gyp-build/build-test.js +19 -0
- package/node_modules/node-gyp-build/index.js +6 -0
- package/node_modules/node-gyp-build/node-gyp-build.js +207 -0
- package/node_modules/node-gyp-build/optional.js +7 -0
- package/node_modules/node-gyp-build/package.json +43 -0
- package/node_modules/tree-sitter/LICENSE +21 -0
- package/node_modules/tree-sitter/README.md +128 -0
- package/node_modules/tree-sitter/binding.gyp +80 -0
- package/node_modules/tree-sitter/index.js +916 -0
- package/node_modules/tree-sitter/package.json +76 -0
- package/node_modules/tree-sitter/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/node_modules/tree-sitter/src/addon_data.h +47 -0
- package/node_modules/tree-sitter/src/binding.cc +35 -0
- package/node_modules/tree-sitter/src/conversions.cc +140 -0
- package/node_modules/tree-sitter/src/conversions.h +22 -0
- package/node_modules/tree-sitter/src/language.cc +106 -0
- package/node_modules/tree-sitter/src/language.h +17 -0
- package/node_modules/tree-sitter/src/logger.cc +70 -0
- package/node_modules/tree-sitter/src/logger.h +19 -0
- package/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
- package/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
- package/node_modules/tree-sitter/src/node.cc +1088 -0
- package/node_modules/tree-sitter/src/node.h +30 -0
- package/node_modules/tree-sitter/src/parser.cc +306 -0
- package/node_modules/tree-sitter/src/parser.h +35 -0
- package/node_modules/tree-sitter/src/query.cc +397 -0
- package/node_modules/tree-sitter/src/query.h +40 -0
- package/node_modules/tree-sitter/src/tree.cc +316 -0
- package/node_modules/tree-sitter/src/tree.h +45 -0
- package/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
- package/node_modules/tree-sitter/src/tree_cursor.h +52 -0
- package/node_modules/tree-sitter/tree-sitter.d.ts +1042 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1478 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +291 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +523 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +293 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +293 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +483 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +54 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +12 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +875 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2293 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +286 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/portable/endian.h +239 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4350 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +911 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +133 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1034 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +399 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +170 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +717 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/ts_assert.h +11 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +75 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +24 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +113 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1314 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1935 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
- package/package.json +8 -2
- package/scripts/postinstall-tree-sitter.mjs +28 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tree-sitter",
|
|
3
|
+
"version": "0.25.0",
|
|
4
|
+
"description": "Node.js bindings to the Tree-sitter parsing library",
|
|
5
|
+
"repository": "http://github.com/tree-sitter/node-tree-sitter",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Max Brunsfeld",
|
|
12
|
+
"email": "maxbrunsfeld@gmail.com"
|
|
13
|
+
},
|
|
14
|
+
"maintainers": [
|
|
15
|
+
{
|
|
16
|
+
"name": "Amaan Qureshi",
|
|
17
|
+
"email": "amaanq12@gmail.com"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"contributors": [
|
|
21
|
+
{
|
|
22
|
+
"name": "Segev Finer",
|
|
23
|
+
"email": "segev208@gmail.com"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "Boris Verkhovskiy",
|
|
27
|
+
"email": "boris.verk@gmail.com"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"main": "index.js",
|
|
31
|
+
"types": "tree-sitter.d.ts",
|
|
32
|
+
"keywords": [
|
|
33
|
+
"incremental",
|
|
34
|
+
"parsing",
|
|
35
|
+
"tree-sitter"
|
|
36
|
+
],
|
|
37
|
+
"files": [
|
|
38
|
+
"binding.gyp",
|
|
39
|
+
"tree-sitter.d.ts",
|
|
40
|
+
"prebuilds/*",
|
|
41
|
+
"src/*",
|
|
42
|
+
"vendor/tree-sitter/lib/include/*",
|
|
43
|
+
"vendor/tree-sitter/lib/src/*"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"node-addon-api": "^8.3.0",
|
|
47
|
+
"node-gyp-build": "^4.8.4"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^22.10.2",
|
|
51
|
+
"@types/tmp": "^0.2.6",
|
|
52
|
+
"glob": "^11.0.0",
|
|
53
|
+
"node-gyp": "^11.0.0",
|
|
54
|
+
"prebuildify": "^6.0.1",
|
|
55
|
+
"tmp": "^0.2.3",
|
|
56
|
+
"tree-sitter-c": "^0.23.4",
|
|
57
|
+
"tree-sitter-embedded-template": "^0.23.2",
|
|
58
|
+
"tree-sitter-html": "^0.23.2",
|
|
59
|
+
"tree-sitter-java": "^0.23.5",
|
|
60
|
+
"tree-sitter-javascript": "^0.23.1",
|
|
61
|
+
"tree-sitter-json": "^0.24.8",
|
|
62
|
+
"tree-sitter-python": "^0.23.6",
|
|
63
|
+
"tree-sitter-ruby": "^0.23.1",
|
|
64
|
+
"tree-sitter-rust": "^0.23.2",
|
|
65
|
+
"typedoc": "^0.27.6",
|
|
66
|
+
"typedoc-plugin-rename-defaults": "^0.7.2",
|
|
67
|
+
"typescript": "^5.7.2"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"docs": "typedoc --out docs/api tree-sitter.d.ts --readme README.md",
|
|
71
|
+
"install": "node-gyp-build",
|
|
72
|
+
"build": "prebuildify --napi --strip",
|
|
73
|
+
"rebuild": "node-gyp rebuild",
|
|
74
|
+
"test": "node -e \"require('child_process').spawnSync('node', ['--test', ...require('glob').sync('test/**/*.js')], {stdio:'inherit'})\""
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#include "tree_sitter/api.h"
|
|
2
|
+
|
|
3
|
+
#include <napi.h>
|
|
4
|
+
|
|
5
|
+
#ifndef NODE_TREE_SITTER_ADDON_DATA_H_
|
|
6
|
+
#define NODE_TREE_SITTER_ADDON_DATA_H_
|
|
7
|
+
|
|
8
|
+
namespace node_tree_sitter {
|
|
9
|
+
|
|
10
|
+
class AddonData final {
|
|
11
|
+
public:
|
|
12
|
+
explicit AddonData(Napi::Env _env) {}
|
|
13
|
+
|
|
14
|
+
~AddonData() {
|
|
15
|
+
ts_query_cursor_delete(ts_query_cursor);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// conversions
|
|
19
|
+
uint32_t *point_transfer_buffer = nullptr;
|
|
20
|
+
|
|
21
|
+
// node
|
|
22
|
+
uint32_t *transfer_buffer = nullptr;
|
|
23
|
+
uint32_t transfer_buffer_length = 0;
|
|
24
|
+
Napi::ObjectReference module_exports;
|
|
25
|
+
TSTreeCursor scratch_cursor = {nullptr, nullptr, {0, 0}};
|
|
26
|
+
|
|
27
|
+
// parser
|
|
28
|
+
Napi::FunctionReference parser_constructor;
|
|
29
|
+
Napi::FunctionReference string_slice;
|
|
30
|
+
|
|
31
|
+
// query
|
|
32
|
+
TSQueryCursor *ts_query_cursor = nullptr;
|
|
33
|
+
Napi::FunctionReference query_constructor;
|
|
34
|
+
|
|
35
|
+
// tree_cursor
|
|
36
|
+
Napi::FunctionReference tree_cursor_constructor;
|
|
37
|
+
|
|
38
|
+
// tree
|
|
39
|
+
Napi::FunctionReference tree_constructor;
|
|
40
|
+
|
|
41
|
+
// lookaheaditerator
|
|
42
|
+
Napi::FunctionReference lookahead_iterator_constructor;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
} // namespace node_tree_sitter
|
|
46
|
+
|
|
47
|
+
#endif // NODE_TREE_SITTER_ADDON_DATA_H_
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#include "./addon_data.h"
|
|
2
|
+
#include "./conversions.h"
|
|
3
|
+
#include "./language.h"
|
|
4
|
+
#include "./lookaheaditerator.h"
|
|
5
|
+
#include "./node.h"
|
|
6
|
+
#include "./parser.h"
|
|
7
|
+
#include "./query.h"
|
|
8
|
+
#include "./tree.h"
|
|
9
|
+
#include "./tree_cursor.h"
|
|
10
|
+
|
|
11
|
+
#include <napi.h>
|
|
12
|
+
|
|
13
|
+
using namespace Napi;
|
|
14
|
+
|
|
15
|
+
namespace node_tree_sitter {
|
|
16
|
+
|
|
17
|
+
Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
|
|
18
|
+
auto* data = new AddonData(env);
|
|
19
|
+
env.SetInstanceData(data);
|
|
20
|
+
|
|
21
|
+
InitConversions(env, exports);
|
|
22
|
+
node_methods::Init(env, exports);
|
|
23
|
+
language_methods::Init(env, exports);
|
|
24
|
+
LookaheadIterator::Init(env, exports);
|
|
25
|
+
Parser::Init(env, exports);
|
|
26
|
+
Query::Init(env, exports);
|
|
27
|
+
Tree::Init(env, exports);
|
|
28
|
+
TreeCursor::Init(env, exports);
|
|
29
|
+
|
|
30
|
+
return exports;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
NODE_API_MODULE(tree_sitter_runtime_binding, InitAll)
|
|
34
|
+
|
|
35
|
+
} // namespace node_tree_sitter
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#include "./conversions.h"
|
|
2
|
+
#include "./addon_data.h"
|
|
3
|
+
#include "tree_sitter/api.h"
|
|
4
|
+
|
|
5
|
+
#include <cmath>
|
|
6
|
+
#include <napi.h>
|
|
7
|
+
|
|
8
|
+
using namespace Napi;
|
|
9
|
+
|
|
10
|
+
namespace node_tree_sitter {
|
|
11
|
+
|
|
12
|
+
static const unsigned BYTES_PER_CHARACTER = 2;
|
|
13
|
+
|
|
14
|
+
void InitConversions(Napi::Env env, Napi::Object exports) {
|
|
15
|
+
auto *data = env.GetInstanceData<AddonData>();
|
|
16
|
+
|
|
17
|
+
auto js_point_transfer_buffer = Uint32Array::New(env, 2);
|
|
18
|
+
data->point_transfer_buffer = js_point_transfer_buffer.Data();
|
|
19
|
+
|
|
20
|
+
exports["pointTransferArray"] = js_point_transfer_buffer;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void TransferPoint(Napi::Env env, const TSPoint &point) {
|
|
24
|
+
auto *data = env.GetInstanceData<AddonData>();
|
|
25
|
+
data->point_transfer_buffer[0] = point.row;
|
|
26
|
+
data->point_transfer_buffer[1] = point.column / 2;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Napi::Object RangeToJS(Napi::Env env, const TSRange &range) {
|
|
30
|
+
Object result = Object::New(env);
|
|
31
|
+
result.Set("startPosition", PointToJS(env, range.start_point));
|
|
32
|
+
result.Set("startIndex", ByteCountToJS(env, range.start_byte));
|
|
33
|
+
result.Set("endPosition", PointToJS(env, range.end_point));
|
|
34
|
+
result.Set("endIndex", ByteCountToJS(env, range.end_byte));
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Napi::Maybe<TSRange> RangeFromJS(const Napi::Value& arg) {
|
|
39
|
+
Env env = arg.Env();
|
|
40
|
+
if (!arg.IsObject()) {
|
|
41
|
+
TypeError::New(env, "Range must be a {startPosition, endPosition, startIndex, endIndex} object").ThrowAsJavaScriptException();
|
|
42
|
+
return Napi::Nothing<TSRange>();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
TSRange result;
|
|
46
|
+
|
|
47
|
+
auto js_range = arg.As<Object>();
|
|
48
|
+
|
|
49
|
+
#define INIT(field, key, Convert) { \
|
|
50
|
+
auto value = js_range.Get(key); \
|
|
51
|
+
if (value.IsEmpty()) { \
|
|
52
|
+
TypeError::New(env, "Range must be a {startPosition, endPosition, startIndex, endIndex} object").ThrowAsJavaScriptException(); \
|
|
53
|
+
return Napi::Nothing<TSRange>(); \
|
|
54
|
+
} \
|
|
55
|
+
auto field = Convert(value); \
|
|
56
|
+
if (field.IsJust()) { \
|
|
57
|
+
result.field = field.Unwrap(); \
|
|
58
|
+
} else { \
|
|
59
|
+
return Napi::Nothing<TSRange>(); \
|
|
60
|
+
} \
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
INIT(start_point, "startPosition", PointFromJS);
|
|
64
|
+
INIT(end_point, "endPosition", PointFromJS);
|
|
65
|
+
INIT(start_byte, "startIndex", ByteCountFromJS);
|
|
66
|
+
INIT(end_byte, "endIndex", ByteCountFromJS);
|
|
67
|
+
|
|
68
|
+
#undef INIT
|
|
69
|
+
|
|
70
|
+
return Napi::Just(result);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Napi::Object PointToJS(Napi::Env env, const TSPoint &point) {
|
|
74
|
+
Object result = Object::New(env);
|
|
75
|
+
result["row"] = Number::New(env, point.row);
|
|
76
|
+
result["column"] = ByteCountToJS(env, point.column);
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
Napi::Maybe<TSPoint> PointFromJS(const Napi::Value& arg) {
|
|
81
|
+
Env env = arg.Env();
|
|
82
|
+
|
|
83
|
+
if (!arg.IsObject()) {
|
|
84
|
+
TypeError::New(env, "Point must be a {row, column} object").ThrowAsJavaScriptException();
|
|
85
|
+
return Napi::Nothing<TSPoint>();
|
|
86
|
+
}
|
|
87
|
+
auto js_point = arg.As<Object>();
|
|
88
|
+
|
|
89
|
+
auto js_row = js_point.Get("row").As<Number>();
|
|
90
|
+
if (!js_row.IsNumber()) {
|
|
91
|
+
TypeError::New(env, "Point must be a {row, column} object").ThrowAsJavaScriptException();
|
|
92
|
+
return Napi::Nothing<TSPoint>();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
auto js_column = js_point.Get("column").As<Number>();
|
|
96
|
+
if (!js_column.IsNumber()) {
|
|
97
|
+
TypeError::New(env, "Point must be a {row, column} object").ThrowAsJavaScriptException();
|
|
98
|
+
return Napi::Nothing<TSPoint>();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
uint32_t row;
|
|
102
|
+
if (!std::isfinite(js_row.DoubleValue())) {
|
|
103
|
+
row = UINT32_MAX;
|
|
104
|
+
} else if (js_row.IsNumber()) {
|
|
105
|
+
row = js_row.Uint32Value();
|
|
106
|
+
} else {
|
|
107
|
+
TypeError::New(env, "Point.row must be a number").ThrowAsJavaScriptException();
|
|
108
|
+
return Napi::Nothing<TSPoint>();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
uint32_t column;
|
|
112
|
+
if (!std::isfinite(js_column.DoubleValue())) {
|
|
113
|
+
column = UINT32_MAX;
|
|
114
|
+
} else if (js_column.IsNumber()) {
|
|
115
|
+
column = js_column.Uint32Value() * BYTES_PER_CHARACTER;
|
|
116
|
+
} else {
|
|
117
|
+
TypeError::New(env, "Point.column must be a number").ThrowAsJavaScriptException();
|
|
118
|
+
return Napi::Nothing<TSPoint>();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return Napi::Just<TSPoint>({row, column});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
Napi::Number ByteCountToJS(Napi::Env env, uint32_t byte_count) {
|
|
125
|
+
return Number::New(env, byte_count / BYTES_PER_CHARACTER);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
Napi::Maybe<uint32_t> ByteCountFromJS(const Napi::Value &arg) {
|
|
129
|
+
Napi::Env env = arg.Env();
|
|
130
|
+
|
|
131
|
+
if (!arg.IsNumber()) {
|
|
132
|
+
TypeError::New(env, "Character index must be a number").ThrowAsJavaScriptException();
|
|
133
|
+
return Napi::Nothing<uint32_t>();
|
|
134
|
+
}
|
|
135
|
+
auto result = arg.As<Number>();
|
|
136
|
+
|
|
137
|
+
return Napi::Just<uint32_t>(result.Uint32Value() * BYTES_PER_CHARACTER);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
} // namespace node_tree_sitter
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#ifndef NODE_TREE_SITTER_CONVERSIONS_H_
|
|
2
|
+
#define NODE_TREE_SITTER_CONVERSIONS_H_
|
|
3
|
+
|
|
4
|
+
#include "./addon_data.h"
|
|
5
|
+
#include "tree_sitter/api.h"
|
|
6
|
+
|
|
7
|
+
#include <napi.h>
|
|
8
|
+
|
|
9
|
+
namespace node_tree_sitter {
|
|
10
|
+
|
|
11
|
+
void InitConversions(Napi::Env env, Napi::Object exports);
|
|
12
|
+
Napi::Object RangeToJS(Napi::Env env, const TSRange &);
|
|
13
|
+
Napi::Object PointToJS(Napi::Env env, const TSPoint &);
|
|
14
|
+
void TransferPoint(Napi::Env env, const TSPoint &);
|
|
15
|
+
Napi::Number ByteCountToJS(Napi::Env env, uint32_t);
|
|
16
|
+
Napi::Maybe<TSPoint> PointFromJS(const Napi::Value &);
|
|
17
|
+
Napi::Maybe<uint32_t> ByteCountFromJS(const Napi::Value &);
|
|
18
|
+
Napi::Maybe<TSRange> RangeFromJS(const Napi::Value&);
|
|
19
|
+
|
|
20
|
+
} // namespace node_tree_sitter
|
|
21
|
+
|
|
22
|
+
#endif // NODE_TREE_SITTER_CONVERSIONS_H_
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#include "./language.h"
|
|
2
|
+
#include "tree_sitter/api.h"
|
|
3
|
+
|
|
4
|
+
#include <napi.h>
|
|
5
|
+
#include <string>
|
|
6
|
+
|
|
7
|
+
using namespace Napi;
|
|
8
|
+
|
|
9
|
+
namespace node_tree_sitter::language_methods {
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
tstag() {
|
|
13
|
+
b2sum -l64 <(printf tree-sitter) <(printf "$1") | \
|
|
14
|
+
awk '{printf "0x" toupper($1) (NR == 1 ? ", " : "\n")}'
|
|
15
|
+
}
|
|
16
|
+
tstag language # => 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
|
|
17
|
+
*/
|
|
18
|
+
const napi_type_tag LANGUAGE_TYPE_TAG = {
|
|
19
|
+
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const TSLanguage *UnwrapLanguage(Napi::Value value) {
|
|
23
|
+
Napi::Env env = value.Env();
|
|
24
|
+
|
|
25
|
+
if (value.IsObject()) {
|
|
26
|
+
value = value.As<Object>()["language"];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
auto arg = value.As<External<const TSLanguage>>();
|
|
30
|
+
if (arg.IsExternal() && arg.CheckTypeTag(&LANGUAGE_TYPE_TAG)) {
|
|
31
|
+
const TSLanguage *language = arg.Data();
|
|
32
|
+
if (language != nullptr) {
|
|
33
|
+
uint16_t version = ts_language_version(language);
|
|
34
|
+
if (
|
|
35
|
+
version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION ||
|
|
36
|
+
version > TREE_SITTER_LANGUAGE_VERSION
|
|
37
|
+
) {
|
|
38
|
+
std::string message =
|
|
39
|
+
"Incompatible language version. Compatible range: " +
|
|
40
|
+
std::to_string(TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION) + " - " +
|
|
41
|
+
std::to_string(TREE_SITTER_LANGUAGE_VERSION) + ". Got: " +
|
|
42
|
+
std::to_string(ts_language_version(language));
|
|
43
|
+
RangeError::New(env, message.c_str());
|
|
44
|
+
return nullptr;
|
|
45
|
+
}
|
|
46
|
+
return language;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
throw TypeError::New(env, "Invalid language object");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
namespace {
|
|
53
|
+
|
|
54
|
+
Napi::Value GetNodeTypeNamesById(const Napi::CallbackInfo &info) {
|
|
55
|
+
Env env = info.Env();
|
|
56
|
+
|
|
57
|
+
const TSLanguage *language = UnwrapLanguage(info[0]);
|
|
58
|
+
if (language == nullptr) {
|
|
59
|
+
return env.Undefined();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
auto result = Array::New(env);
|
|
63
|
+
uint32_t length = ts_language_symbol_count(language);
|
|
64
|
+
for (uint32_t i = 0; i < length; i++) {
|
|
65
|
+
const char *name = ts_language_symbol_name(language, i);
|
|
66
|
+
TSSymbolType type = ts_language_symbol_type(language, i);
|
|
67
|
+
if (type == TSSymbolTypeRegular) {
|
|
68
|
+
result[i] = String::New(env, name);
|
|
69
|
+
} else {
|
|
70
|
+
result[i] = env.Null();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Napi::Value GetNodeFieldNamesById(const Napi::CallbackInfo &info) {
|
|
78
|
+
Env env = info.Env();
|
|
79
|
+
|
|
80
|
+
const TSLanguage *language = UnwrapLanguage(info[0]);
|
|
81
|
+
if (language == nullptr) {
|
|
82
|
+
return env.Undefined();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
auto result = Array::New(env);
|
|
86
|
+
uint32_t length = ts_language_field_count(language);
|
|
87
|
+
for (uint32_t i = 0; i < length + 1; i++) {
|
|
88
|
+
const char *name = ts_language_field_name_for_id(language, i);
|
|
89
|
+
if (name != nullptr) {
|
|
90
|
+
result[i] = String::New(env, name);
|
|
91
|
+
} else {
|
|
92
|
+
result[i] = env.Null();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
} // namespace
|
|
100
|
+
|
|
101
|
+
void Init(Napi::Env env, Napi::Object exports) {
|
|
102
|
+
exports["getNodeTypeNamesById"] = Function::New(env, GetNodeTypeNamesById);
|
|
103
|
+
exports["getNodeFieldNamesById"] = Function::New(env, GetNodeFieldNamesById);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
} // namespace node_tree_sitter::language_methods
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#ifndef NODE_TREE_SITTER_LANGUAGE_H_
|
|
2
|
+
#define NODE_TREE_SITTER_LANGUAGE_H_
|
|
3
|
+
|
|
4
|
+
#include "tree_sitter/api.h"
|
|
5
|
+
|
|
6
|
+
#include <napi.h>
|
|
7
|
+
#include <node_object_wrap.h>
|
|
8
|
+
|
|
9
|
+
namespace node_tree_sitter::language_methods {
|
|
10
|
+
|
|
11
|
+
void Init(Napi::Env env, Napi::Object);
|
|
12
|
+
|
|
13
|
+
const TSLanguage *UnwrapLanguage(Napi::Value);
|
|
14
|
+
|
|
15
|
+
} // namespace node_tree_sitter::language_methods
|
|
16
|
+
|
|
17
|
+
#endif // NODE_TREE_SITTER_LANGUAGE_H_
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#include "./logger.h"
|
|
2
|
+
#include "tree_sitter/api.h"
|
|
3
|
+
|
|
4
|
+
#include <napi.h>
|
|
5
|
+
#include <string>
|
|
6
|
+
|
|
7
|
+
using namespace Napi;
|
|
8
|
+
using std::string;
|
|
9
|
+
|
|
10
|
+
namespace node_tree_sitter {
|
|
11
|
+
|
|
12
|
+
void Logger::Log(void *payload, TSLogType type, const char *message_str) {
|
|
13
|
+
auto *debugger = static_cast<Logger *>(payload);
|
|
14
|
+
Env env = debugger->func.Env();
|
|
15
|
+
|
|
16
|
+
string message(message_str);
|
|
17
|
+
string param_sep = " ";
|
|
18
|
+
size_t param_sep_pos = message.find(param_sep, 0);
|
|
19
|
+
|
|
20
|
+
String type_name = String::New(env, (type == TSLogTypeParse) ? "parse" : "lex");;
|
|
21
|
+
String name = String::New(env, message.substr(0, param_sep_pos));
|
|
22
|
+
Object params = Object::New(env);
|
|
23
|
+
|
|
24
|
+
while (param_sep_pos != string::npos) {
|
|
25
|
+
size_t key_pos = param_sep_pos + param_sep.size();
|
|
26
|
+
size_t value_sep_pos = message.find(':', key_pos);
|
|
27
|
+
|
|
28
|
+
if (value_sep_pos == string::npos) {
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
size_t val_pos = value_sep_pos + 1;
|
|
33
|
+
param_sep = ", ";
|
|
34
|
+
param_sep_pos = message.find(param_sep, value_sep_pos);
|
|
35
|
+
|
|
36
|
+
string key = message.substr(key_pos, (value_sep_pos - key_pos));
|
|
37
|
+
string value = message.substr(val_pos, (param_sep_pos - val_pos));
|
|
38
|
+
params[key] = String::New(env, value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
debugger->func({ name, params, type_name });
|
|
43
|
+
} catch (const Error &error) {
|
|
44
|
+
Value console = env.Global()["console"];
|
|
45
|
+
if (!console.IsObject()) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Value error_fn = console.As<Object>()["error"];
|
|
50
|
+
if (!error_fn.IsFunction()) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
error_fn.As<Function>()({
|
|
55
|
+
String::New(env, "Error in debug callback:"),
|
|
56
|
+
error.Value()
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
TSLogger Logger::Make(const Napi::Function &func) {
|
|
62
|
+
TSLogger result;
|
|
63
|
+
auto *logger = new Logger();
|
|
64
|
+
logger->func = Napi::Persistent(func);
|
|
65
|
+
result.payload = static_cast<void *>(logger);
|
|
66
|
+
result.log = Log;
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
} // namespace node_tree_sitter
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#ifndef NODE_TREE_SITTER_LOGGER_H_
|
|
2
|
+
#define NODE_TREE_SITTER_LOGGER_H_
|
|
3
|
+
|
|
4
|
+
#include "tree_sitter/api.h"
|
|
5
|
+
|
|
6
|
+
#include <napi.h>
|
|
7
|
+
|
|
8
|
+
namespace node_tree_sitter {
|
|
9
|
+
|
|
10
|
+
class Logger final {
|
|
11
|
+
public:
|
|
12
|
+
static TSLogger Make(const Napi::Function &);
|
|
13
|
+
Napi::FunctionReference func;
|
|
14
|
+
static void Log(void *, TSLogType, const char *);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
} // namespace node_tree_sitter
|
|
18
|
+
|
|
19
|
+
#endif // NODE_TREE_SITTER_LOGGER_H_
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#include "./conversions.h"
|
|
2
|
+
#include "./language.h"
|
|
3
|
+
#include "./lookaheaditerator.h"
|
|
4
|
+
#include "tree_sitter/api.h"
|
|
5
|
+
|
|
6
|
+
#include <napi.h>
|
|
7
|
+
|
|
8
|
+
using namespace Napi;
|
|
9
|
+
|
|
10
|
+
namespace node_tree_sitter {
|
|
11
|
+
|
|
12
|
+
void LookaheadIterator::Init(Napi::Env env, Napi::Object exports) {
|
|
13
|
+
auto *data = env.GetInstanceData<AddonData>();
|
|
14
|
+
|
|
15
|
+
Function ctor = DefineClass(env, "LookaheadIterator", {
|
|
16
|
+
InstanceAccessor("currentTypeId", &LookaheadIterator::CurrentTypeId, nullptr, napi_default_method),
|
|
17
|
+
InstanceAccessor("currentType", &LookaheadIterator::CurrentType, nullptr, napi_default_method),
|
|
18
|
+
|
|
19
|
+
InstanceMethod("reset", &LookaheadIterator::Reset, napi_default_method),
|
|
20
|
+
InstanceMethod("resetState", &LookaheadIterator::ResetState, napi_default_method),
|
|
21
|
+
InstanceMethod("_next", &LookaheadIterator::Next, napi_default_method),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
exports["LookaheadIterator"] = ctor;
|
|
25
|
+
data->lookahead_iterator_constructor = Napi::Persistent(ctor);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
LookaheadIterator::LookaheadIterator(const Napi::CallbackInfo &info) : Napi::ObjectWrap<LookaheadIterator>(info), iterator_(nullptr) {
|
|
29
|
+
Napi::Env env = info.Env();
|
|
30
|
+
const TSLanguage *language = language_methods::UnwrapLanguage(info[0]);
|
|
31
|
+
|
|
32
|
+
if (language == nullptr) {
|
|
33
|
+
Napi::Error::New(env, "Missing language argument").ThrowAsJavaScriptException();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!info[1].IsNumber()) {
|
|
37
|
+
Napi::Error::New(env, "Missing state argument").ThrowAsJavaScriptException();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
TSStateId state = info[1].As<Napi::Number>().Uint32Value();
|
|
42
|
+
iterator_ = ts_lookahead_iterator_new(language, state);
|
|
43
|
+
if (iterator_ == nullptr) {
|
|
44
|
+
Napi::Error::New(env, "Invalid state argument").ThrowAsJavaScriptException();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
LookaheadIterator::~LookaheadIterator() {
|
|
51
|
+
ts_lookahead_iterator_delete(iterator_);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Napi::Value LookaheadIterator::NewInstance(Napi::Env env, TSLookaheadIterator *iterator) {
|
|
55
|
+
auto *data = env.GetInstanceData<AddonData>();
|
|
56
|
+
if (iterator != nullptr) {
|
|
57
|
+
Object self = data->lookahead_iterator_constructor.New({});
|
|
58
|
+
LookaheadIterator::Unwrap(self)->iterator_ = iterator;
|
|
59
|
+
return self;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return env.Null();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
LookaheadIterator *LookaheadIterator::UnwrapLookaheadIterator(const Napi::Value &value) {
|
|
66
|
+
auto *data = value.Env().GetInstanceData<AddonData>();
|
|
67
|
+
if (!value.IsObject()) {
|
|
68
|
+
return nullptr;
|
|
69
|
+
}
|
|
70
|
+
auto js_iterator = value.As<Object>();
|
|
71
|
+
if (!js_iterator.InstanceOf(data->lookahead_iterator_constructor.Value())) {
|
|
72
|
+
return nullptr;
|
|
73
|
+
}
|
|
74
|
+
return LookaheadIterator::Unwrap(js_iterator);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Napi::Value LookaheadIterator::CurrentType(const Napi::CallbackInfo &info) {
|
|
78
|
+
LookaheadIterator *iterator = UnwrapLookaheadIterator(info.This());
|
|
79
|
+
return Napi::String::New(info.Env(), ts_lookahead_iterator_current_symbol_name(iterator->iterator_));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Napi::Value LookaheadIterator::CurrentTypeId(const Napi::CallbackInfo &info) {
|
|
83
|
+
LookaheadIterator *iterator = UnwrapLookaheadIterator(info.This());
|
|
84
|
+
return Napi::Number::New(info.Env(), ts_lookahead_iterator_current_symbol(iterator->iterator_));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
Napi::Value LookaheadIterator::Reset(const Napi::CallbackInfo &info) {
|
|
88
|
+
LookaheadIterator *iterator = UnwrapLookaheadIterator(info.This());
|
|
89
|
+
const TSLanguage *language = language_methods::UnwrapLanguage(info[0]);
|
|
90
|
+
|
|
91
|
+
if (language == nullptr) {
|
|
92
|
+
Napi::Error::New(info.Env(), "Invalid language argument").ThrowAsJavaScriptException();
|
|
93
|
+
return info.Env().Undefined();
|
|
94
|
+
}
|
|
95
|
+
if (!info[1].IsNumber()) {
|
|
96
|
+
Napi::Error::New(info.Env(), "Missing state argument").ThrowAsJavaScriptException();
|
|
97
|
+
return info.Env().Undefined();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
TSStateId state = info[1].As<Napi::Number>().Uint32Value();
|
|
101
|
+
return Napi::Boolean::New(info.Env(), ts_lookahead_iterator_reset(iterator->iterator_, language, state));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
Napi::Value LookaheadIterator::ResetState(const Napi::CallbackInfo &info) {
|
|
105
|
+
Napi::Env env = info.Env();
|
|
106
|
+
LookaheadIterator *iterator = UnwrapLookaheadIterator(info.This());
|
|
107
|
+
|
|
108
|
+
if (!info[0].IsNumber()) {
|
|
109
|
+
Napi::Error::New(env, "Missing state argument").ThrowAsJavaScriptException();
|
|
110
|
+
return env.Undefined();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
TSStateId state = info[0].As<Napi::Number>().Uint32Value();
|
|
114
|
+
return Napi::Boolean::New(env, ts_lookahead_iterator_reset_state(iterator->iterator_, state));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
Napi::Value LookaheadIterator::Next(const Napi::CallbackInfo &info) {
|
|
118
|
+
LookaheadIterator *iterator = UnwrapLookaheadIterator(info.This());
|
|
119
|
+
return Napi::Boolean::New(info.Env(), ts_lookahead_iterator_next(iterator->iterator_));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
} // namespace node_tree_sitter
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#ifndef NODE_TREE_SITTER_LOOKAHEAD_ITERATOR_H_
|
|
2
|
+
#define NODE_TREE_SITTER_LOOKAHEAD_ITERATOR_H_
|
|
3
|
+
|
|
4
|
+
#include "tree_sitter/api.h"
|
|
5
|
+
|
|
6
|
+
#include <napi.h>
|
|
7
|
+
|
|
8
|
+
namespace node_tree_sitter {
|
|
9
|
+
|
|
10
|
+
class LookaheadIterator final : public Napi::ObjectWrap<LookaheadIterator> {
|
|
11
|
+
public:
|
|
12
|
+
static void Init(Napi::Env env, Napi::Object exports);
|
|
13
|
+
static Napi::Value NewInstance(Napi::Env env, TSLookaheadIterator *);
|
|
14
|
+
static LookaheadIterator *UnwrapLookaheadIterator(const Napi::Value &);
|
|
15
|
+
|
|
16
|
+
explicit LookaheadIterator(const Napi::CallbackInfo &);
|
|
17
|
+
~LookaheadIterator() final;
|
|
18
|
+
|
|
19
|
+
private:
|
|
20
|
+
TSLookaheadIterator *iterator_;
|
|
21
|
+
|
|
22
|
+
Napi::Value New(const Napi::CallbackInfo &);
|
|
23
|
+
Napi::Value Reset(const Napi::CallbackInfo &);
|
|
24
|
+
Napi::Value ResetState(const Napi::CallbackInfo &);
|
|
25
|
+
Napi::Value Next(const Napi::CallbackInfo &);
|
|
26
|
+
|
|
27
|
+
Napi::Value CurrentTypeId(const Napi::CallbackInfo &);
|
|
28
|
+
Napi::Value CurrentType(const Napi::CallbackInfo &);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
} // namespace node_tree_sitter
|
|
32
|
+
|
|
33
|
+
#endif // NODE_TREE_SITTER_LOOKAHEAD_ITERATOR_H_
|