tree-sitter-syscript 0.1.1 → 1.0.1
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/bindings/node/binding.cc +19 -0
- package/bindings/node/binding_test.js +9 -0
- package/bindings/node/index.d.ts +27 -0
- package/bindings/node/index.js +11 -0
- package/grammar.js +3 -3
- package/package.json +1 -1
- package/src/grammar.json +22 -6
- package/src/node-types.json +34 -17
- package/src/parser.c +3464 -3384
- package/tree-sitter-syscript.wasm +0 -0
- package/tree-sitter.json +2 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include <napi.h>
|
|
2
|
+
|
|
3
|
+
typedef struct TSLanguage TSLanguage;
|
|
4
|
+
|
|
5
|
+
extern "C" TSLanguage *tree_sitter_syscript();
|
|
6
|
+
|
|
7
|
+
// "tree-sitter", "language" hashed with BLAKE2
|
|
8
|
+
const napi_type_tag LANGUAGE_TYPE_TAG = {
|
|
9
|
+
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
13
|
+
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_syscript());
|
|
14
|
+
language.TypeTag(&LANGUAGE_TYPE_TAG);
|
|
15
|
+
exports["language"] = language;
|
|
16
|
+
return exports;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
NODE_API_MODULE(tree_sitter_syscript_binding, Init)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type BaseNode = {
|
|
2
|
+
type: string;
|
|
3
|
+
named: boolean;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
type ChildNode = {
|
|
7
|
+
multiple: boolean;
|
|
8
|
+
required: boolean;
|
|
9
|
+
types: BaseNode[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type NodeInfo =
|
|
13
|
+
| (BaseNode & {
|
|
14
|
+
subtypes: BaseNode[];
|
|
15
|
+
})
|
|
16
|
+
| (BaseNode & {
|
|
17
|
+
fields: { [name: string]: ChildNode };
|
|
18
|
+
children: ChildNode[];
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
type Language = {
|
|
22
|
+
language: unknown;
|
|
23
|
+
nodeTypeInfo: NodeInfo[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
declare const language: Language;
|
|
27
|
+
export = language;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const root = require("path").join(__dirname, "..", "..");
|
|
2
|
+
|
|
3
|
+
module.exports =
|
|
4
|
+
typeof process.versions.bun === "string"
|
|
5
|
+
// Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
|
|
6
|
+
? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-syscript.node`)
|
|
7
|
+
: require("node-gyp-build")(root);
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
|
11
|
+
} catch (_) {}
|
package/grammar.js
CHANGED
|
@@ -42,20 +42,20 @@ module.exports = grammar({
|
|
|
42
42
|
function: $ => seq("fn", $.method),
|
|
43
43
|
method: $ => seq(field("name", $.identifier), $.param_list, optional(seq(":", choice($.type_signature, "noreturn"))), $.code_block),
|
|
44
44
|
param_list: $ => seq("(", optional(seq($.parameter, optional(seq(",", $.parameter)))), ")"),
|
|
45
|
-
parameter: $ => seq(optional("..."), $.identifier, ":", $.type_signature),
|
|
45
|
+
parameter: $ => seq(optional("..."), field("name", $.identifier), ":", $.type_signature),
|
|
46
46
|
code_block: $ => seq("{", repeat($.statement), "}"),
|
|
47
47
|
|
|
48
48
|
declaration: $ => seq(choice($.let_declaration, $.const_declaration), ";"),
|
|
49
49
|
let_declaration: $ => seq("let", field("name", $.identifier), ":", field("type", $.type_signature), optional(seq("=", field("value", $.value)))),
|
|
50
50
|
const_declaration: $ => seq("const", field("name", $.identifier), ":", field("type", $.type_signature), "=", field("value", $.value)),
|
|
51
51
|
|
|
52
|
-
statement: $ => choice($.if_statement, $.while_loop, $.for_loop, $.declaration, seq(choice($.return_statement, $.control_flow, $.value), ";")),
|
|
52
|
+
statement: $ => choice($.if_statement, $.while_loop, $.for_loop, $.declaration, seq(choice($.return_statement, $.control_flow, $.value), ";"), ";"),
|
|
53
53
|
|
|
54
54
|
return_statement: $ => seq("return", optional($.value)),
|
|
55
55
|
control_flow: $ => choice("break", "continue"),
|
|
56
56
|
|
|
57
57
|
routine: $ => choice($.code_block, $.statement),
|
|
58
|
-
if_statement: $ => prec.right(1, seq("if", field("condition", $.parenthesis_enclosed), $.routine, optional(seq("else", $.routine)))),
|
|
58
|
+
if_statement: $ => prec.right(1, seq("if", field("condition", $.parenthesis_enclosed), field("branch", $.routine), optional(seq("else", field("else_branch", $.routine))))),
|
|
59
59
|
while_loop: $ => seq("while", field("condition", $.parenthesis_enclosed), $.routine),
|
|
60
60
|
|
|
61
61
|
for_loop: $ => seq("for", $.for_loop_def, $.routine),
|
package/package.json
CHANGED
package/src/grammar.json
CHANGED
|
@@ -479,8 +479,12 @@
|
|
|
479
479
|
]
|
|
480
480
|
},
|
|
481
481
|
{
|
|
482
|
-
"type": "
|
|
483
|
-
"name": "
|
|
482
|
+
"type": "FIELD",
|
|
483
|
+
"name": "name",
|
|
484
|
+
"content": {
|
|
485
|
+
"type": "SYMBOL",
|
|
486
|
+
"name": "identifier"
|
|
487
|
+
}
|
|
484
488
|
},
|
|
485
489
|
{
|
|
486
490
|
"type": "STRING",
|
|
@@ -673,6 +677,10 @@
|
|
|
673
677
|
"value": ";"
|
|
674
678
|
}
|
|
675
679
|
]
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
"type": "STRING",
|
|
683
|
+
"value": ";"
|
|
676
684
|
}
|
|
677
685
|
]
|
|
678
686
|
},
|
|
@@ -742,8 +750,12 @@
|
|
|
742
750
|
}
|
|
743
751
|
},
|
|
744
752
|
{
|
|
745
|
-
"type": "
|
|
746
|
-
"name": "
|
|
753
|
+
"type": "FIELD",
|
|
754
|
+
"name": "branch",
|
|
755
|
+
"content": {
|
|
756
|
+
"type": "SYMBOL",
|
|
757
|
+
"name": "routine"
|
|
758
|
+
}
|
|
747
759
|
},
|
|
748
760
|
{
|
|
749
761
|
"type": "CHOICE",
|
|
@@ -756,8 +768,12 @@
|
|
|
756
768
|
"value": "else"
|
|
757
769
|
},
|
|
758
770
|
{
|
|
759
|
-
"type": "
|
|
760
|
-
"name": "
|
|
771
|
+
"type": "FIELD",
|
|
772
|
+
"name": "else_branch",
|
|
773
|
+
"content": {
|
|
774
|
+
"type": "SYMBOL",
|
|
775
|
+
"name": "routine"
|
|
776
|
+
}
|
|
761
777
|
}
|
|
762
778
|
]
|
|
763
779
|
},
|
package/src/node-types.json
CHANGED
|
@@ -331,6 +331,16 @@
|
|
|
331
331
|
"type": "if_statement",
|
|
332
332
|
"named": true,
|
|
333
333
|
"fields": {
|
|
334
|
+
"branch": {
|
|
335
|
+
"multiple": false,
|
|
336
|
+
"required": true,
|
|
337
|
+
"types": [
|
|
338
|
+
{
|
|
339
|
+
"type": "routine",
|
|
340
|
+
"named": true
|
|
341
|
+
}
|
|
342
|
+
]
|
|
343
|
+
},
|
|
334
344
|
"condition": {
|
|
335
345
|
"multiple": false,
|
|
336
346
|
"required": true,
|
|
@@ -340,17 +350,17 @@
|
|
|
340
350
|
"named": true
|
|
341
351
|
}
|
|
342
352
|
]
|
|
353
|
+
},
|
|
354
|
+
"else_branch": {
|
|
355
|
+
"multiple": false,
|
|
356
|
+
"required": false,
|
|
357
|
+
"types": [
|
|
358
|
+
{
|
|
359
|
+
"type": "routine",
|
|
360
|
+
"named": true
|
|
361
|
+
}
|
|
362
|
+
]
|
|
343
363
|
}
|
|
344
|
-
},
|
|
345
|
-
"children": {
|
|
346
|
-
"multiple": true,
|
|
347
|
-
"required": true,
|
|
348
|
-
"types": [
|
|
349
|
-
{
|
|
350
|
-
"type": "routine",
|
|
351
|
-
"named": true
|
|
352
|
-
}
|
|
353
|
-
]
|
|
354
364
|
}
|
|
355
365
|
},
|
|
356
366
|
{
|
|
@@ -500,15 +510,22 @@
|
|
|
500
510
|
{
|
|
501
511
|
"type": "parameter",
|
|
502
512
|
"named": true,
|
|
503
|
-
"fields": {
|
|
513
|
+
"fields": {
|
|
514
|
+
"name": {
|
|
515
|
+
"multiple": false,
|
|
516
|
+
"required": true,
|
|
517
|
+
"types": [
|
|
518
|
+
{
|
|
519
|
+
"type": "identifier",
|
|
520
|
+
"named": true
|
|
521
|
+
}
|
|
522
|
+
]
|
|
523
|
+
}
|
|
524
|
+
},
|
|
504
525
|
"children": {
|
|
505
|
-
"multiple":
|
|
526
|
+
"multiple": false,
|
|
506
527
|
"required": true,
|
|
507
528
|
"types": [
|
|
508
|
-
{
|
|
509
|
-
"type": "identifier",
|
|
510
|
-
"named": true
|
|
511
|
-
},
|
|
512
529
|
{
|
|
513
530
|
"type": "type_signature",
|
|
514
531
|
"named": true
|
|
@@ -797,7 +814,7 @@
|
|
|
797
814
|
"fields": {},
|
|
798
815
|
"children": {
|
|
799
816
|
"multiple": false,
|
|
800
|
-
"required":
|
|
817
|
+
"required": false,
|
|
801
818
|
"types": [
|
|
802
819
|
{
|
|
803
820
|
"type": "control_flow",
|