@gram-data/tree-sitter-gram 0.2.7 → 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/bindings/node/binding_test.js +28 -0
- package/editors/zed/extension.toml +2 -2
- package/editors/zed/languages/gram/highlights.scm +4 -2
- package/grammar.js +19 -4
- package/package.json +7 -4
- package/prebuilds/darwin-arm64/@gram-data+tree-sitter-gram.node +0 -0
- package/prebuilds/darwin-x64/@gram-data+tree-sitter-gram.node +0 -0
- package/prebuilds/linux-arm64/@gram-data+tree-sitter-gram.node +0 -0
- package/prebuilds/linux-x64/@gram-data+tree-sitter-gram.node +0 -0
- package/prebuilds/win32-arm64/@gram-data+tree-sitter-gram.node +0 -0
- package/prebuilds/win32-x64/@gram-data+tree-sitter-gram.node +0 -0
- package/queries/highlights.scm +4 -2
- package/src/grammar.json +78 -6
- package/src/node-types.json +113 -71
- package/src/parser.c +2052 -1815
- package/src/tree_sitter/array.h +124 -68
- package/tree-sitter-gram.wasm +0 -0
- package/tree-sitter.json +29 -0
|
@@ -7,3 +7,31 @@ test("can load grammar", () => {
|
|
|
7
7
|
const parser = new (require("tree-sitter"))();
|
|
8
8
|
assert.doesNotThrow(() => parser.setLanguage(require(".")));
|
|
9
9
|
});
|
|
10
|
+
|
|
11
|
+
test("annotation node kinds: identified_annotation and property_annotation", () => {
|
|
12
|
+
const Parser = require("tree-sitter");
|
|
13
|
+
const GramLang = require(".");
|
|
14
|
+
const parser = new Parser();
|
|
15
|
+
parser.setLanguage(GramLang);
|
|
16
|
+
|
|
17
|
+
const annotated = (root) => root.child(0) ?? null;
|
|
18
|
+
|
|
19
|
+
const withIdentified = parser.parse("@@p (a)");
|
|
20
|
+
const ap1 = annotated(withIdentified.rootNode);
|
|
21
|
+
assert(ap1?.type === "annotated_pattern", "root should have annotated_pattern child");
|
|
22
|
+
const annotations1 = ap1.childForFieldName("annotations");
|
|
23
|
+
assert(annotations1, "annotations node should exist");
|
|
24
|
+
const first1 = annotations1.child(0);
|
|
25
|
+
assert.strictEqual(first1?.type, "identified_annotation", "@@ form should be identified_annotation");
|
|
26
|
+
assert(first1?.childForFieldName("identifier"), "identified_annotation should have identifier field");
|
|
27
|
+
|
|
28
|
+
const withProperty = parser.parse("@x(1) ()");
|
|
29
|
+
const ap2 = annotated(withProperty.rootNode);
|
|
30
|
+
assert(ap2?.type === "annotated_pattern", "root should have annotated_pattern child");
|
|
31
|
+
const annotations2 = ap2.childForFieldName("annotations");
|
|
32
|
+
assert(annotations2, "annotations node should exist");
|
|
33
|
+
const first2 = annotations2.child(0);
|
|
34
|
+
assert.strictEqual(first2?.type, "property_annotation", "@ form should be property_annotation");
|
|
35
|
+
assert(first2?.childForFieldName("key"), "property_annotation should have key field");
|
|
36
|
+
assert(first2?.childForFieldName("value"), "property_annotation should have value field");
|
|
37
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
id = "gram"
|
|
2
2
|
name = "Gram Language Support"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.3"
|
|
4
4
|
schema_version = 1
|
|
5
5
|
authors = ["Gram Data Contributors"]
|
|
6
6
|
description = "Support for Gram notation - a subject-oriented notation for structured data"
|
|
@@ -8,4 +8,4 @@ description = "Support for Gram notation - a subject-oriented notation for struc
|
|
|
8
8
|
# path = "grammars/tree-sitter-gram"
|
|
9
9
|
[grammars.gram]
|
|
10
10
|
repository = "https://github.com/gram-data/tree-sitter-gram"
|
|
11
|
-
rev = "
|
|
11
|
+
rev = "78fba591ce4e3ca86ae77c871cfc9e87205c8e2b"
|
|
@@ -46,8 +46,10 @@
|
|
|
46
46
|
(map_entry key: (string_literal) @property)
|
|
47
47
|
(map_entry key: (integer) @property)
|
|
48
48
|
|
|
49
|
-
; Annotation keys
|
|
50
|
-
(
|
|
49
|
+
; Annotation keys (property-style) and headers (identified/label-style)
|
|
50
|
+
(property_annotation key: (symbol) @attribute)
|
|
51
|
+
(identified_annotation identifier: (_) @attribute)
|
|
52
|
+
(identified_annotation labels: (_) @attribute)
|
|
51
53
|
|
|
52
54
|
; Subject Pattern notation (special highlighting)
|
|
53
55
|
(subject_pattern) @type
|
package/grammar.js
CHANGED
|
@@ -13,11 +13,9 @@ module.exports = grammar({
|
|
|
13
13
|
|
|
14
14
|
annotated_pattern: ($) =>
|
|
15
15
|
seq(
|
|
16
|
-
// field("annotations", optional($.annotations)),
|
|
17
16
|
field("annotations", $.annotations),
|
|
18
17
|
field("elements", choice($.subject_pattern, $._path_pattern)),
|
|
19
18
|
),
|
|
20
|
-
// _annotated_pattern_element: ($) => choice($.subject_pattern, $._path_pattern),
|
|
21
19
|
|
|
22
20
|
subject_pattern: ($) =>
|
|
23
21
|
seq(
|
|
@@ -31,11 +29,28 @@ module.exports = grammar({
|
|
|
31
29
|
|
|
32
30
|
_subject_pattern_element: ($) => choice($.subject_pattern, $._path_pattern, $.pattern_reference),
|
|
33
31
|
|
|
34
|
-
annotations: ($) =>
|
|
32
|
+
annotations: ($) =>
|
|
33
|
+
choice(
|
|
34
|
+
seq($.identified_annotation, repeat($.property_annotation)),
|
|
35
|
+
repeat1($.property_annotation),
|
|
36
|
+
),
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
property_annotation: ($) =>
|
|
37
39
|
seq("@", field("key", $.symbol), "(", field("value", $._value), ")"),
|
|
38
40
|
|
|
41
|
+
identified_annotation: ($) =>
|
|
42
|
+
seq(
|
|
43
|
+
"@@",
|
|
44
|
+
choice(
|
|
45
|
+
field("identifier", $._identifier),
|
|
46
|
+
field("labels", $.labels),
|
|
47
|
+
seq(
|
|
48
|
+
field("identifier", $._identifier),
|
|
49
|
+
field("labels", $.labels),
|
|
50
|
+
),
|
|
51
|
+
),
|
|
52
|
+
),
|
|
53
|
+
|
|
39
54
|
_path_pattern: ($) => choice($.relationship_pattern, $.node_pattern),
|
|
40
55
|
|
|
41
56
|
node_pattern: ($) =>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gram-data/tree-sitter-gram",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "subject-oriented notation for structured data",
|
|
5
5
|
"homepage": "https://gram-data.github.io",
|
|
6
6
|
"repository": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"install": "node-gyp-build",
|
|
14
14
|
"prestart": "tree-sitter build --wasm",
|
|
15
|
+
"build": "tree-sitter build --wasm",
|
|
15
16
|
"start": "tree-sitter playground",
|
|
16
17
|
"test": "node --test bindings/node/*_test.js",
|
|
17
18
|
"zed:dev": "ZED_REPO_MODE=dev bash scripts/prepare-zed-extension.sh",
|
|
@@ -28,12 +29,14 @@
|
|
|
28
29
|
],
|
|
29
30
|
"files": [
|
|
30
31
|
"grammar.js",
|
|
32
|
+
"tree-sitter.json",
|
|
31
33
|
"binding.gyp",
|
|
32
34
|
"prebuilds/**",
|
|
33
35
|
"bindings/node/*",
|
|
34
36
|
"queries/*",
|
|
35
37
|
"src/**",
|
|
36
|
-
"editors/**"
|
|
38
|
+
"editors/**",
|
|
39
|
+
"*.wasm"
|
|
37
40
|
],
|
|
38
41
|
"author": "",
|
|
39
42
|
"license": "ISC",
|
|
@@ -51,8 +54,8 @@
|
|
|
51
54
|
},
|
|
52
55
|
"devDependencies": {
|
|
53
56
|
"eslint": "^9.37.0",
|
|
54
|
-
"node-gyp": "^11.4.2",
|
|
55
57
|
"prebuildify": "^6.0.1",
|
|
56
|
-
"tree-sitter
|
|
58
|
+
"tree-sitter": "^0.25.0",
|
|
59
|
+
"tree-sitter-cli": "^0.26.5"
|
|
57
60
|
}
|
|
58
61
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/queries/highlights.scm
CHANGED
|
@@ -46,8 +46,10 @@
|
|
|
46
46
|
(map_entry key: (string_literal) @property)
|
|
47
47
|
(map_entry key: (integer) @property)
|
|
48
48
|
|
|
49
|
-
; Annotation keys
|
|
50
|
-
(
|
|
49
|
+
; Annotation keys (property-style) and headers (identified/label-style)
|
|
50
|
+
(property_annotation key: (symbol) @attribute)
|
|
51
|
+
(identified_annotation identifier: (_) @attribute)
|
|
52
|
+
(identified_annotation labels: (_) @attribute)
|
|
51
53
|
|
|
52
54
|
; Subject Pattern notation (special highlighting)
|
|
53
55
|
(subject_pattern) @type
|
package/src/grammar.json
CHANGED
|
@@ -178,13 +178,34 @@
|
|
|
178
178
|
]
|
|
179
179
|
},
|
|
180
180
|
"annotations": {
|
|
181
|
-
"type": "
|
|
182
|
-
"
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
"type": "CHOICE",
|
|
182
|
+
"members": [
|
|
183
|
+
{
|
|
184
|
+
"type": "SEQ",
|
|
185
|
+
"members": [
|
|
186
|
+
{
|
|
187
|
+
"type": "SYMBOL",
|
|
188
|
+
"name": "identified_annotation"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"type": "REPEAT",
|
|
192
|
+
"content": {
|
|
193
|
+
"type": "SYMBOL",
|
|
194
|
+
"name": "property_annotation"
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"type": "REPEAT1",
|
|
201
|
+
"content": {
|
|
202
|
+
"type": "SYMBOL",
|
|
203
|
+
"name": "property_annotation"
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
]
|
|
186
207
|
},
|
|
187
|
-
"
|
|
208
|
+
"property_annotation": {
|
|
188
209
|
"type": "SEQ",
|
|
189
210
|
"members": [
|
|
190
211
|
{
|
|
@@ -217,6 +238,57 @@
|
|
|
217
238
|
}
|
|
218
239
|
]
|
|
219
240
|
},
|
|
241
|
+
"identified_annotation": {
|
|
242
|
+
"type": "SEQ",
|
|
243
|
+
"members": [
|
|
244
|
+
{
|
|
245
|
+
"type": "STRING",
|
|
246
|
+
"value": "@@"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"type": "CHOICE",
|
|
250
|
+
"members": [
|
|
251
|
+
{
|
|
252
|
+
"type": "FIELD",
|
|
253
|
+
"name": "identifier",
|
|
254
|
+
"content": {
|
|
255
|
+
"type": "SYMBOL",
|
|
256
|
+
"name": "_identifier"
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
"type": "FIELD",
|
|
261
|
+
"name": "labels",
|
|
262
|
+
"content": {
|
|
263
|
+
"type": "SYMBOL",
|
|
264
|
+
"name": "labels"
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"type": "SEQ",
|
|
269
|
+
"members": [
|
|
270
|
+
{
|
|
271
|
+
"type": "FIELD",
|
|
272
|
+
"name": "identifier",
|
|
273
|
+
"content": {
|
|
274
|
+
"type": "SYMBOL",
|
|
275
|
+
"name": "_identifier"
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
"type": "FIELD",
|
|
280
|
+
"name": "labels",
|
|
281
|
+
"content": {
|
|
282
|
+
"type": "SYMBOL",
|
|
283
|
+
"name": "labels"
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
}
|
|
288
|
+
]
|
|
289
|
+
}
|
|
290
|
+
]
|
|
291
|
+
},
|
|
220
292
|
"_path_pattern": {
|
|
221
293
|
"type": "CHOICE",
|
|
222
294
|
"members": [
|
package/src/node-types.json
CHANGED
|
@@ -33,76 +33,6 @@
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
|
-
{
|
|
37
|
-
"type": "annotation",
|
|
38
|
-
"named": true,
|
|
39
|
-
"fields": {
|
|
40
|
-
"key": {
|
|
41
|
-
"multiple": false,
|
|
42
|
-
"required": true,
|
|
43
|
-
"types": [
|
|
44
|
-
{
|
|
45
|
-
"type": "symbol",
|
|
46
|
-
"named": true
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
},
|
|
50
|
-
"value": {
|
|
51
|
-
"multiple": false,
|
|
52
|
-
"required": true,
|
|
53
|
-
"types": [
|
|
54
|
-
{
|
|
55
|
-
"type": "array",
|
|
56
|
-
"named": true
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"type": "boolean_literal",
|
|
60
|
-
"named": true
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"type": "decimal",
|
|
64
|
-
"named": true
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"type": "hexadecimal",
|
|
68
|
-
"named": true
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
"type": "integer",
|
|
72
|
-
"named": true
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"type": "map",
|
|
76
|
-
"named": true
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
"type": "measurement",
|
|
80
|
-
"named": true
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
"type": "octal",
|
|
84
|
-
"named": true
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"type": "range",
|
|
88
|
-
"named": true
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
"type": "string_literal",
|
|
92
|
-
"named": true
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
"type": "symbol",
|
|
96
|
-
"named": true
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"type": "tagged_string",
|
|
100
|
-
"named": true
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
36
|
{
|
|
107
37
|
"type": "annotations",
|
|
108
38
|
"named": true,
|
|
@@ -112,7 +42,11 @@
|
|
|
112
42
|
"required": true,
|
|
113
43
|
"types": [
|
|
114
44
|
{
|
|
115
|
-
"type": "
|
|
45
|
+
"type": "identified_annotation",
|
|
46
|
+
"named": true
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"type": "property_annotation",
|
|
116
50
|
"named": true
|
|
117
51
|
}
|
|
118
52
|
]
|
|
@@ -283,6 +217,40 @@
|
|
|
283
217
|
]
|
|
284
218
|
}
|
|
285
219
|
},
|
|
220
|
+
{
|
|
221
|
+
"type": "identified_annotation",
|
|
222
|
+
"named": true,
|
|
223
|
+
"fields": {
|
|
224
|
+
"identifier": {
|
|
225
|
+
"multiple": false,
|
|
226
|
+
"required": false,
|
|
227
|
+
"types": [
|
|
228
|
+
{
|
|
229
|
+
"type": "integer",
|
|
230
|
+
"named": true
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"type": "string_literal",
|
|
234
|
+
"named": true
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"type": "symbol",
|
|
238
|
+
"named": true
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
},
|
|
242
|
+
"labels": {
|
|
243
|
+
"multiple": false,
|
|
244
|
+
"required": false,
|
|
245
|
+
"types": [
|
|
246
|
+
{
|
|
247
|
+
"type": "labels",
|
|
248
|
+
"named": true
|
|
249
|
+
}
|
|
250
|
+
]
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
},
|
|
286
254
|
{
|
|
287
255
|
"type": "labels",
|
|
288
256
|
"named": true,
|
|
@@ -547,6 +515,76 @@
|
|
|
547
515
|
}
|
|
548
516
|
}
|
|
549
517
|
},
|
|
518
|
+
{
|
|
519
|
+
"type": "property_annotation",
|
|
520
|
+
"named": true,
|
|
521
|
+
"fields": {
|
|
522
|
+
"key": {
|
|
523
|
+
"multiple": false,
|
|
524
|
+
"required": true,
|
|
525
|
+
"types": [
|
|
526
|
+
{
|
|
527
|
+
"type": "symbol",
|
|
528
|
+
"named": true
|
|
529
|
+
}
|
|
530
|
+
]
|
|
531
|
+
},
|
|
532
|
+
"value": {
|
|
533
|
+
"multiple": false,
|
|
534
|
+
"required": true,
|
|
535
|
+
"types": [
|
|
536
|
+
{
|
|
537
|
+
"type": "array",
|
|
538
|
+
"named": true
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
"type": "boolean_literal",
|
|
542
|
+
"named": true
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
"type": "decimal",
|
|
546
|
+
"named": true
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
"type": "hexadecimal",
|
|
550
|
+
"named": true
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
"type": "integer",
|
|
554
|
+
"named": true
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
"type": "map",
|
|
558
|
+
"named": true
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
"type": "measurement",
|
|
562
|
+
"named": true
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
"type": "octal",
|
|
566
|
+
"named": true
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
"type": "range",
|
|
570
|
+
"named": true
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
"type": "string_literal",
|
|
574
|
+
"named": true
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
"type": "symbol",
|
|
578
|
+
"named": true
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
"type": "tagged_string",
|
|
582
|
+
"named": true
|
|
583
|
+
}
|
|
584
|
+
]
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
},
|
|
550
588
|
{
|
|
551
589
|
"type": "range",
|
|
552
590
|
"named": true,
|
|
@@ -1115,6 +1153,10 @@
|
|
|
1115
1153
|
"type": "@",
|
|
1116
1154
|
"named": false
|
|
1117
1155
|
},
|
|
1156
|
+
{
|
|
1157
|
+
"type": "@@",
|
|
1158
|
+
"named": false
|
|
1159
|
+
},
|
|
1118
1160
|
{
|
|
1119
1161
|
"type": "[",
|
|
1120
1162
|
"named": false
|