tree-sitter-gosum-orchard 0.3.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Amaan Qureshi <amaanq12@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # tree-sitter-gosum-orchard
2
+
3
+ [![crates][crates]](https://crates.io/crates/tree-sitter-gosum-orchard)
4
+ [![pypi][pypi]](https://pypi.org/project/tree-sitter-gosum-orchard)
5
+ [![npm][npm]](https://www.npmjs.com/package/tree-sitter-gosum-orchard)
6
+
7
+ This is a tree-sitter grammar for go.sum.
8
+
9
+ ### Using it
10
+
11
+ You can obtain this parser in various formats:
12
+ * as an archive from [the Releases page](/grammar-orchard/tree-sitter-gosum-orchard/releases), which contains all the generated files (bindings, parser code)
13
+ * as a Rust crate: `cargo add tree-sitter-gosum-orchard`
14
+ * as a Python package: `pip install tree-sitter-gosum-orchard`
15
+ * as an NPM package: `npm install tree-sitter-gosum-orchard`
16
+
17
+ ### Contributing
18
+
19
+ Contributions are welcome, so are co-maintainers.
20
+
21
+ Unlike many grammar repositories, this one does not track generated files.
22
+ After cloning this repository, you'll need to run `tree-sitter generate` to obtain the parser.
23
+ If you want to use it via bindings, you'll also need to run `tree-sitter init`.
24
+
25
+ ### Origin
26
+
27
+ This project was forked from https://github.com/tree-sitter-grammars/tree-sitter-go-sum, to [ease the use of and collaboration on this grammar](https://codeberg.org/grammar-orchard#for-contributors).
28
+
29
+ [crates]: https://img.shields.io/crates/v/tree-sitter-gosum-orchard?logo=rust
30
+ [pypi]: https://img.shields.io/pypi/v/tree-sitter-gosum-orchard?logo=pypi&logoColor=ffd242
31
+ [npm]: https://img.shields.io/npm/v/tree-sitter-gosum-orchard?logo=npm
package/binding.gyp ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "tree_sitter_gosum_orchard_binding",
5
+ "dependencies": [
6
+ "<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
7
+ ],
8
+ "include_dirs": [
9
+ "src",
10
+ ],
11
+ "sources": [
12
+ "bindings/node/binding.cc",
13
+ "src/parser.c",
14
+ ],
15
+ "variables": {
16
+ "has_scanner": "<!(node -p \"fs.existsSync('src/scanner.c')\")"
17
+ },
18
+ "conditions": [
19
+ ["has_scanner=='true'", {
20
+ "sources+": ["src/scanner.c"],
21
+ }],
22
+ ["OS!='win'", {
23
+ "cflags_c": [
24
+ "-std=c11",
25
+ ],
26
+ }, { # OS == "win"
27
+ "cflags_c": [
28
+ "/std:c11",
29
+ "/utf-8",
30
+ ],
31
+ }],
32
+ ],
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1,19 @@
1
+ #include <napi.h>
2
+
3
+ typedef struct TSLanguage TSLanguage;
4
+
5
+ extern "C" TSLanguage *tree_sitter_gosum_orchard();
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_gosum_orchard());
14
+ language.TypeTag(&LANGUAGE_TYPE_TAG);
15
+ exports["language"] = language;
16
+ return exports;
17
+ }
18
+
19
+ NODE_API_MODULE(tree_sitter_gosum_orchard_binding, Init)
@@ -0,0 +1,11 @@
1
+ import assert from "node:assert";
2
+ import { test } from "node:test";
3
+ import Parser from "tree-sitter";
4
+
5
+ test("can load grammar", () => {
6
+ const parser = new Parser();
7
+ assert.doesNotReject(async () => {
8
+ const { default: language } = await import("./index.js");
9
+ parser.setLanguage(language);
10
+ });
11
+ });
@@ -0,0 +1,60 @@
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
+ /**
22
+ * The tree-sitter language object for this grammar.
23
+ *
24
+ * @see {@linkcode https://tree-sitter.github.io/node-tree-sitter/interfaces/Parser.Language.html Parser.Language}
25
+ *
26
+ * @example
27
+ * import Parser from "tree-sitter";
28
+ * import GoSumOrchard from "tree-sitter-gosum-orchard";
29
+ *
30
+ * const parser = new Parser();
31
+ * parser.setLanguage(GoSumOrchard);
32
+ */
33
+ declare const binding: {
34
+ /**
35
+ * The inner language object.
36
+ * @private
37
+ */
38
+ language: unknown;
39
+
40
+ /**
41
+ * The content of the `node-types.json` file for this grammar.
42
+ *
43
+ * @see {@linkplain https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types Static Node Types}
44
+ */
45
+ nodeTypeInfo: NodeInfo[];
46
+
47
+ /** The syntax highlighting query for this grammar. */
48
+ HIGHLIGHTS_QUERY?: string;
49
+
50
+ /** The language injection query for this grammar. */
51
+ INJECTIONS_QUERY?: string;
52
+
53
+ /** The local variable query for this grammar. */
54
+ LOCALS_QUERY?: string;
55
+
56
+ /** The symbol tagging query for this grammar. */
57
+ TAGS_QUERY?: string;
58
+ };
59
+
60
+ export default binding;
@@ -0,0 +1,37 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ const root = fileURLToPath(new URL("../..", import.meta.url));
5
+
6
+ const binding = typeof process.versions.bun === "string"
7
+ // Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
8
+ ? await import(`${root}/prebuilds/${process.platform}-${process.arch}/tree-sitter-gosum-orchard.node`)
9
+ : (await import("node-gyp-build")).default(root);
10
+
11
+ try {
12
+ const nodeTypes = await import(`${root}/src/node-types.json`, { with: { type: "json" } });
13
+ binding.nodeTypeInfo = nodeTypes.default;
14
+ } catch { }
15
+
16
+ const queries = [
17
+ ["HIGHLIGHTS_QUERY", `${root}/queries/highlights.scm`],
18
+ ["INJECTIONS_QUERY", `${root}/queries/injections.scm`],
19
+ ["LOCALS_QUERY", `${root}/queries/locals.scm`],
20
+ ["TAGS_QUERY", `${root}/queries/tags.scm`],
21
+ ];
22
+
23
+ for (const [prop, path] of queries) {
24
+ Object.defineProperty(binding, prop, {
25
+ configurable: true,
26
+ enumerable: true,
27
+ get() {
28
+ delete binding[prop];
29
+ try {
30
+ binding[prop] = readFileSync(path, "utf8");
31
+ } catch { }
32
+ return binding[prop];
33
+ }
34
+ });
35
+ }
36
+
37
+ export default binding;
package/grammar.js ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @file gosum grammar for tree-sitter
3
+ * @author Amaan Qureshi <amaanq12@gmail.com>
4
+ * @license MIT
5
+ * @see {@link https://go.dev/ref/mod#go-sum-files|official syntax spec}
6
+ */
7
+
8
+ /* eslint-disable arrow-parens */
9
+ /* eslint-disable camelcase */
10
+ /* eslint-disable-next-line spaced-comment */
11
+ /// <reference types="tree-sitter-cli/dsl" />
12
+ // @ts-check
13
+
14
+ export default grammar({
15
+ name: 'gosum_orchard',
16
+
17
+ rules: {
18
+ checksum_database: $ => repeat1($.checksum),
19
+
20
+ checksum: $ => seq(
21
+ field('path', $.module_path),
22
+ field('version', $.version),
23
+ optional(seq('/', field('go_mod', $.go_mod))),
24
+ field('checksum', $.checksum_value),
25
+ ),
26
+
27
+ go_mod: $ => 'go.mod',
28
+
29
+ module_path: _ => /[a-zA-Z0-9\-_\./]+/,
30
+ version: $ => seq(
31
+ alias(seq(
32
+ 'v',
33
+ field('major', $.number),
34
+ '.',
35
+ field('minor', $.number),
36
+ '.',
37
+ field('patch', $.number)), $.module_version),
38
+ optional(seq(
39
+ '-',
40
+ field(
41
+ 'pre_release',
42
+ choice(
43
+ $.number_with_decimal, // YYYYMMDDHHMMSS
44
+ seq(
45
+ choice('alpha', 'beta', 'dev', 'pre', 'rc'),
46
+ optional('.'),
47
+ $.number,
48
+ optional(seq('.', $.number_with_decimal)),
49
+ ),
50
+ ),
51
+ ),
52
+ optional(seq('-', field('build', $.hex_number))),
53
+ )),
54
+ optional('+incompatible'),
55
+ ),
56
+
57
+ checksum_value: $ => seq(
58
+ $.hash_version,
59
+ ':',
60
+ $.hash,
61
+ ),
62
+
63
+ // currently only h1 is supported
64
+ hash_version: _ => 'h1',
65
+
66
+ hash: _ => /[a-zA-Z0-9+/]+={0,2}/,
67
+
68
+ number: _ => /\d+/,
69
+ number_with_decimal: _ => /[\d\.]+/,
70
+ hex_number: _ => /[0-9a-fA-F]+/,
71
+ },
72
+ });
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "tree-sitter-gosum-orchard",
3
+ "version": "0.3.3",
4
+ "description": "Parser for go.sum lock files",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://codeberg.org/grammar-orchard/tree-sitter-gosum-orchard.git"
9
+ },
10
+ "license": "MIT",
11
+ "author": {
12
+ "name": "Amaan Qureshi",
13
+ "email": "amaanq12@gmail.com",
14
+ "url": "https://github.com/amaanq"
15
+ },
16
+ "main": "bindings/node",
17
+ "types": "bindings/node",
18
+ "keywords": [
19
+ "incremental",
20
+ "parsing",
21
+ "tree-sitter",
22
+ "gosum_orchard"
23
+ ],
24
+ "files": [
25
+ "grammar.js",
26
+ "tree-sitter.json",
27
+ "binding.gyp",
28
+ "prebuilds/**",
29
+ "bindings/node/*",
30
+ "queries/*",
31
+ "src/**",
32
+ "*.wasm"
33
+ ],
34
+ "dependencies": {
35
+ "node-addon-api": "^8.5.0",
36
+ "node-gyp-build": "^4.8.4"
37
+ },
38
+ "devDependencies": {
39
+ "prebuildify": "^6.0.1",
40
+ "tree-sitter": "^0.25.0",
41
+ "tree-sitter-cli": "^0.26.11"
42
+ },
43
+ "peerDependencies": {
44
+ "tree-sitter": "^0.25.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "tree-sitter": {
48
+ "optional": true
49
+ }
50
+ },
51
+ "scripts": {
52
+ "install": "node-gyp-build",
53
+ "prestart": "tree-sitter build --wasm",
54
+ "start": "tree-sitter playground",
55
+ "test": "node --test bindings/node/*_test.js"
56
+ }
57
+ }
@@ -0,0 +1,31 @@
1
+ [
2
+ "alpha"
3
+ "beta"
4
+ "dev"
5
+ "pre"
6
+ "rc"
7
+ "+incompatible"
8
+ ] @keyword
9
+
10
+
11
+ (module_path) @string @text.uri
12
+ (module_version) @string.special
13
+
14
+ (hash_version) @attribute
15
+ (hash) @symbol
16
+
17
+ [
18
+ (number)
19
+ (number_with_decimal)
20
+ (hex_number)
21
+ ] @number
22
+
23
+ (checksum
24
+ (go_mod) @string)
25
+
26
+ [
27
+ ":"
28
+ "."
29
+ "-"
30
+ "/"
31
+ ] @punctuation.delimiter
@@ -0,0 +1,309 @@
1
+ {
2
+ "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
3
+ "name": "gosum_orchard",
4
+ "rules": {
5
+ "checksum_database": {
6
+ "type": "REPEAT1",
7
+ "content": {
8
+ "type": "SYMBOL",
9
+ "name": "checksum"
10
+ }
11
+ },
12
+ "checksum": {
13
+ "type": "SEQ",
14
+ "members": [
15
+ {
16
+ "type": "FIELD",
17
+ "name": "path",
18
+ "content": {
19
+ "type": "SYMBOL",
20
+ "name": "module_path"
21
+ }
22
+ },
23
+ {
24
+ "type": "FIELD",
25
+ "name": "version",
26
+ "content": {
27
+ "type": "SYMBOL",
28
+ "name": "version"
29
+ }
30
+ },
31
+ {
32
+ "type": "CHOICE",
33
+ "members": [
34
+ {
35
+ "type": "SEQ",
36
+ "members": [
37
+ {
38
+ "type": "STRING",
39
+ "value": "/"
40
+ },
41
+ {
42
+ "type": "FIELD",
43
+ "name": "go_mod",
44
+ "content": {
45
+ "type": "SYMBOL",
46
+ "name": "go_mod"
47
+ }
48
+ }
49
+ ]
50
+ },
51
+ {
52
+ "type": "BLANK"
53
+ }
54
+ ]
55
+ },
56
+ {
57
+ "type": "FIELD",
58
+ "name": "checksum",
59
+ "content": {
60
+ "type": "SYMBOL",
61
+ "name": "checksum_value"
62
+ }
63
+ }
64
+ ]
65
+ },
66
+ "go_mod": {
67
+ "type": "STRING",
68
+ "value": "go.mod"
69
+ },
70
+ "module_path": {
71
+ "type": "PATTERN",
72
+ "value": "[a-zA-Z0-9\\-_\\./]+"
73
+ },
74
+ "version": {
75
+ "type": "SEQ",
76
+ "members": [
77
+ {
78
+ "type": "ALIAS",
79
+ "content": {
80
+ "type": "SEQ",
81
+ "members": [
82
+ {
83
+ "type": "STRING",
84
+ "value": "v"
85
+ },
86
+ {
87
+ "type": "FIELD",
88
+ "name": "major",
89
+ "content": {
90
+ "type": "SYMBOL",
91
+ "name": "number"
92
+ }
93
+ },
94
+ {
95
+ "type": "STRING",
96
+ "value": "."
97
+ },
98
+ {
99
+ "type": "FIELD",
100
+ "name": "minor",
101
+ "content": {
102
+ "type": "SYMBOL",
103
+ "name": "number"
104
+ }
105
+ },
106
+ {
107
+ "type": "STRING",
108
+ "value": "."
109
+ },
110
+ {
111
+ "type": "FIELD",
112
+ "name": "patch",
113
+ "content": {
114
+ "type": "SYMBOL",
115
+ "name": "number"
116
+ }
117
+ }
118
+ ]
119
+ },
120
+ "named": true,
121
+ "value": "module_version"
122
+ },
123
+ {
124
+ "type": "CHOICE",
125
+ "members": [
126
+ {
127
+ "type": "SEQ",
128
+ "members": [
129
+ {
130
+ "type": "STRING",
131
+ "value": "-"
132
+ },
133
+ {
134
+ "type": "FIELD",
135
+ "name": "pre_release",
136
+ "content": {
137
+ "type": "CHOICE",
138
+ "members": [
139
+ {
140
+ "type": "SYMBOL",
141
+ "name": "number_with_decimal"
142
+ },
143
+ {
144
+ "type": "SEQ",
145
+ "members": [
146
+ {
147
+ "type": "CHOICE",
148
+ "members": [
149
+ {
150
+ "type": "STRING",
151
+ "value": "alpha"
152
+ },
153
+ {
154
+ "type": "STRING",
155
+ "value": "beta"
156
+ },
157
+ {
158
+ "type": "STRING",
159
+ "value": "dev"
160
+ },
161
+ {
162
+ "type": "STRING",
163
+ "value": "pre"
164
+ },
165
+ {
166
+ "type": "STRING",
167
+ "value": "rc"
168
+ }
169
+ ]
170
+ },
171
+ {
172
+ "type": "CHOICE",
173
+ "members": [
174
+ {
175
+ "type": "STRING",
176
+ "value": "."
177
+ },
178
+ {
179
+ "type": "BLANK"
180
+ }
181
+ ]
182
+ },
183
+ {
184
+ "type": "SYMBOL",
185
+ "name": "number"
186
+ },
187
+ {
188
+ "type": "CHOICE",
189
+ "members": [
190
+ {
191
+ "type": "SEQ",
192
+ "members": [
193
+ {
194
+ "type": "STRING",
195
+ "value": "."
196
+ },
197
+ {
198
+ "type": "SYMBOL",
199
+ "name": "number_with_decimal"
200
+ }
201
+ ]
202
+ },
203
+ {
204
+ "type": "BLANK"
205
+ }
206
+ ]
207
+ }
208
+ ]
209
+ }
210
+ ]
211
+ }
212
+ },
213
+ {
214
+ "type": "CHOICE",
215
+ "members": [
216
+ {
217
+ "type": "SEQ",
218
+ "members": [
219
+ {
220
+ "type": "STRING",
221
+ "value": "-"
222
+ },
223
+ {
224
+ "type": "FIELD",
225
+ "name": "build",
226
+ "content": {
227
+ "type": "SYMBOL",
228
+ "name": "hex_number"
229
+ }
230
+ }
231
+ ]
232
+ },
233
+ {
234
+ "type": "BLANK"
235
+ }
236
+ ]
237
+ }
238
+ ]
239
+ },
240
+ {
241
+ "type": "BLANK"
242
+ }
243
+ ]
244
+ },
245
+ {
246
+ "type": "CHOICE",
247
+ "members": [
248
+ {
249
+ "type": "STRING",
250
+ "value": "+incompatible"
251
+ },
252
+ {
253
+ "type": "BLANK"
254
+ }
255
+ ]
256
+ }
257
+ ]
258
+ },
259
+ "checksum_value": {
260
+ "type": "SEQ",
261
+ "members": [
262
+ {
263
+ "type": "SYMBOL",
264
+ "name": "hash_version"
265
+ },
266
+ {
267
+ "type": "STRING",
268
+ "value": ":"
269
+ },
270
+ {
271
+ "type": "SYMBOL",
272
+ "name": "hash"
273
+ }
274
+ ]
275
+ },
276
+ "hash_version": {
277
+ "type": "STRING",
278
+ "value": "h1"
279
+ },
280
+ "hash": {
281
+ "type": "PATTERN",
282
+ "value": "[a-zA-Z0-9+/]+={0,2}"
283
+ },
284
+ "number": {
285
+ "type": "PATTERN",
286
+ "value": "\\d+"
287
+ },
288
+ "number_with_decimal": {
289
+ "type": "PATTERN",
290
+ "value": "[\\d\\.]+"
291
+ },
292
+ "hex_number": {
293
+ "type": "PATTERN",
294
+ "value": "[0-9a-fA-F]+"
295
+ }
296
+ },
297
+ "extras": [
298
+ {
299
+ "type": "PATTERN",
300
+ "value": "\\s"
301
+ }
302
+ ],
303
+ "conflicts": [],
304
+ "precedences": [],
305
+ "externals": [],
306
+ "inline": [],
307
+ "supertypes": [],
308
+ "reserved": {}
309
+ }