tree-sitter-syscript 0.1.0 → 1.0.0

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.
@@ -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,9 @@
1
+ const assert = require("node:assert");
2
+ const { test } = require("node:test");
3
+
4
+ const Parser = require("tree-sitter");
5
+
6
+ test("can load grammar", () => {
7
+ const parser = new Parser();
8
+ assert.doesNotThrow(() => parser.setLanguage(require(".")));
9
+ });
@@ -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
@@ -7,10 +7,12 @@
7
7
  /// <reference types="tree-sitter-cli/dsl" />
8
8
  // @ts-check
9
9
 
10
+ const MULTILINE_COMMENT_REGEX = /[^*]*\*+([^\/*][^*]*\*+)*/;
11
+
10
12
  module.exports = grammar({
11
13
  name: "syscript",
12
14
 
13
- extras: $ => [/\s/, $.comment],
15
+ extras: $ => [/\s/, $.comment],
14
16
 
15
17
  conflicts: $ => [
16
18
  [$.code_block, $.struct_literal]
@@ -21,11 +23,12 @@ module.exports = grammar({
21
23
 
22
24
  shebang: $ => seq("#!", /.*/),
23
25
 
24
- comment: $ => choice($.single_line_comment, $.documentation_comment, $.multi_line_comment, $.unclosed_multi_line_comment),
26
+ comment: $ => choice($.single_line_comment, $.multi_line_comment, $.doc_comment),
25
27
  single_line_comment: $ => token(seq("//", /.*/)),
26
- documentation_comment: $ => prec.left(1, token(seq("/**", /(.*)*(\n.*)*/, "*/"))),
27
- multi_line_comment: $ => prec.left(1, token(seq("/*", /(.*)*(\n.*)*/, "*/"))),
28
-
28
+ doc_comment: $ => token(seq("/**", MULTILINE_COMMENT_REGEX, "/")),
29
+ multi_line_comment: $ => token(seq("/*", MULTILINE_COMMENT_REGEX, "/")),
30
+
31
+
29
32
  classes: $ =>
30
33
  seq("class", field("name", $.identifier), optional(seq("extends", $.identifier)), "{", field("fields", repeat(choice($.field, $.method))), "}"),
31
34
  structs: $ => seq("struct", field("name", $.identifier), optional(seq("extends", $.identifier)), "{", field("fields", repeat($.field)), "}"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-syscript",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "Syscript grammar for tree-sitter",
5
5
  "repository": "https://github.com/tree-sitter/tree-sitter-syscript",
6
6
  "license": "MIT",
@@ -41,7 +41,7 @@
41
41
  (identifier) @variable
42
42
 
43
43
  (comment) @comment
44
- (documentation_comment) @comment.doc
44
+ (doc_comment) @comment.doc
45
45
 
46
46
  (const_declaration
47
47
  (identifier) @constant)
package/src/grammar.json CHANGED
@@ -71,17 +71,13 @@
71
71
  "type": "SYMBOL",
72
72
  "name": "single_line_comment"
73
73
  },
74
- {
75
- "type": "SYMBOL",
76
- "name": "documentation_comment"
77
- },
78
74
  {
79
75
  "type": "SYMBOL",
80
76
  "name": "multi_line_comment"
81
77
  },
82
78
  {
83
79
  "type": "SYMBOL",
84
- "name": "unclosed_multi_line_comment"
80
+ "name": "doc_comment"
85
81
  }
86
82
  ]
87
83
  },
@@ -101,55 +97,27 @@
101
97
  ]
102
98
  }
103
99
  },
104
- "documentation_comment": {
105
- "type": "PREC_LEFT",
106
- "value": 1,
100
+ "doc_comment": {
101
+ "type": "TOKEN",
107
102
  "content": {
108
- "type": "TOKEN",
109
- "content": {
110
- "type": "SEQ",
111
- "members": [
112
- {
113
- "type": "STRING",
114
- "value": "/**"
115
- },
116
- {
117
- "type": "PATTERN",
118
- "value": "(.*)*(\\n.*)*"
119
- },
120
- {
121
- "type": "STRING",
122
- "value": "*/"
123
- }
124
- ]
125
- }
103
+ "type": "SEQ",
104
+ "members": [
105
+ {
106
+ "type": "STRING",
107
+ "value": "/**"
108
+ },
109
+ {
110
+ "type": "PATTERN",
111
+ "value": "[^*]*\\*+([^\\/*][^*]*\\*+)*"
112
+ },
113
+ {
114
+ "type": "STRING",
115
+ "value": "/"
116
+ }
117
+ ]
126
118
  }
127
119
  },
128
120
  "multi_line_comment": {
129
- "type": "PREC_LEFT",
130
- "value": 1,
131
- "content": {
132
- "type": "TOKEN",
133
- "content": {
134
- "type": "SEQ",
135
- "members": [
136
- {
137
- "type": "STRING",
138
- "value": "/*"
139
- },
140
- {
141
- "type": "PATTERN",
142
- "value": "(.*)*(\\n.*)*"
143
- },
144
- {
145
- "type": "STRING",
146
- "value": "*/"
147
- }
148
- ]
149
- }
150
- }
151
- },
152
- "unclosed_multi_line_comment": {
153
121
  "type": "TOKEN",
154
122
  "content": {
155
123
  "type": "SEQ",
@@ -160,7 +128,11 @@
160
128
  },
161
129
  {
162
130
  "type": "PATTERN",
163
- "value": "(.*)*(\\n.*)*$"
131
+ "value": "[^*]*\\*+([^\\/*][^*]*\\*+)*"
132
+ },
133
+ {
134
+ "type": "STRING",
135
+ "value": "/"
164
136
  }
165
137
  ]
166
138
  }
@@ -129,7 +129,7 @@
129
129
  "required": true,
130
130
  "types": [
131
131
  {
132
- "type": "documentation_comment",
132
+ "type": "doc_comment",
133
133
  "named": true
134
134
  },
135
135
  {
@@ -1201,7 +1201,7 @@
1201
1201
  "named": false
1202
1202
  },
1203
1203
  {
1204
- "type": "documentation_comment",
1204
+ "type": "doc_comment",
1205
1205
  "named": true
1206
1206
  },
1207
1207
  {