@gram-data/tree-sitter-gram 0.2.5 → 0.2.7

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 CHANGED
@@ -3,34 +3,93 @@
3
3
  A [tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar
4
4
  for [gram](https://gram-data.github.io) notation.
5
5
 
6
- Gram is a subject-based notation for structured data.
6
+ ## About Gram
7
7
 
8
- If this is an object:
9
- ```
10
- {
11
- "name":"Andreas",
12
- "roles":["author"]
8
+ Gram is a pattern-based notation for structured data.
9
+
10
+ ### Patterns and Subjects
11
+
12
+ A **pattern** is a generic data structure with a value and nested elements:
13
+
14
+ ```ts
15
+ interface Pattern<V> {
16
+ value: V;
17
+ elements: Pattern<V>[];
13
18
  }
14
19
  ```
15
20
 
16
- Implicitly the object is a person. To become a subject, the implicit
17
- information can be explicit.
21
+ Gram patterns are always `Pattern<Subject>` patterns where values are **subjects**.
22
+ A **subject** is content combining an optional identifier, labels, and/or a record of properties.
23
+
24
+ ### Pattern Elements
25
+
26
+ The `gram_pattern` (top-level structure) consists of a sequence of patterns. Syntactically, `subject_pattern`, `node_pattern`, `relationship_pattern`, and `annotated_pattern` are peers.
18
27
 
19
- As a subject:
28
+ They correlate to the underlying data structure based on the number of elements:
29
+
30
+ - **Node Pattern** `()`: A pattern with **0 elements**.
31
+ - **Annotated Pattern** `@a (b)`: A pattern with **1 element**.
32
+ - **Relationship Pattern** `(a)-->(b)`: A pattern with **2 elements**.
33
+ - **Subject Pattern** `[ s | ... ]`: A pattern with an **arbitrary number of elements**.
34
+
35
+ #### Path Flattening
36
+
37
+ A path is a flattened tree of relationships. For example:
38
+
39
+ ```gram
40
+ (a)-[r1]->(b)-[r2]->(c)
41
+ // is equivalent to:
42
+ [ | [r1 | (a), (b)], [r2 | (b),(c)] ]
20
43
  ```
21
- (:Person {
22
- name: "Andreas",
23
- roles: ["author"]
24
- })
44
+
45
+ #### Subject Pattern Notation
46
+
47
+ The subject pattern notation uses `[ subject | elements ]` to explicitly show pattern structure:
48
+
49
+ ```gram
50
+ // A team with members as elements
51
+ [devrel:Team {name: "Developer Relations"} | abk, adam, alex]
52
+
53
+ // A simple atomic pattern (no elements)
54
+ [:Person {name: "Andreas", roles: ["author"]}]
25
55
  ```
26
56
 
27
- Gram files support comments using `//` syntax for line-based and end-of-line comments:
57
+ #### Node Notation (Syntactic Sugar)
58
+
59
+ Parentheses `( subject )` provide familiar graph node syntax:
60
+
61
+ ```gram
62
+ () // Empty node
63
+ (a) // Node with identifier
64
+ (a:Person) // Node with identifier and label
65
+ (a:Person {name: "Alice"}) // Node with identifier, label, and properties
28
66
  ```
67
+
68
+ #### Relationship Notation (Syntactic Sugar)
69
+
70
+ Arrows connect nodes to express graph relationships:
71
+
72
+ ```gram
73
+ // Path notation for graph relationships
74
+ (a:Person)-[:KNOWS]->(b:Person)
75
+
76
+ // Subject Pattern notation can contain path patterns
77
+ [social:Graph |
78
+ (a:Person {name: "Alice"}),
79
+ (b:Person {name: "Bob"}),
80
+ (a)-[:KNOWS]->(b)
81
+ ]
82
+ ```
83
+
84
+ ### Comments
85
+
86
+ Gram files support comments using `//` syntax:
87
+ ```gram
29
88
  // This is a line comment
30
89
  (hello)-->(world) // End-of-line comment
31
90
  ```
32
91
 
33
- Learn more about `gram` at the [gram-data github org](https://github.com/gram-data) notation.
92
+ Learn more about `gram` at the [gram-data github org](https://github.com/gram-data).
34
93
 
35
94
  ## Editor Support
36
95
 
package/editors/README.md CHANGED
@@ -25,7 +25,7 @@ The Zed integration provides full syntax highlighting and language support for G
25
25
 
26
26
  **Features:**
27
27
  - Syntax highlighting for all Gram constructs
28
- - Bracket matching for `()`, `[]`, and `{}`
28
+ - Subject Pattern matching for `()`, `[]`, and `{}`
29
29
  - Automatic file type detection for `.gram` files
30
30
  - Proper indentation handling
31
31
 
@@ -5,7 +5,7 @@ A [Zed](https://zed.dev) extension providing syntax highlighting and language su
5
5
  ## Features
6
6
 
7
7
  - **Syntax Highlighting**: Full syntax highlighting for all Gram constructs including subjects, nodes, relationships, and data types
8
- - **Bracket Matching**: Automatic matching for `()`, `[]`, and `{}`
8
+ - **Subject Pattern Matching**: Automatic matching for `()`, `[]`, and `{}`
9
9
  - **File Type Detection**: Automatic recognition of `.gram` files
10
10
  - **Smart Indentation**: Proper indentation handling for nested structures
11
11
 
@@ -53,7 +53,7 @@ Once installed, the extension automatically provides syntax highlighting for any
53
53
  })
54
54
 
55
55
  // Relationships between nodes
56
- (alice:Person {name: "Alice"})->(bob:Person {name: "Bob"})
56
+ (alice:Person {name: "Alice"})-->(bob:Person {name: "Bob"})
57
57
 
58
58
  // Complex subject with annotations
59
59
  @type("Employee")
@@ -80,7 +80,7 @@ Once installed, the extension automatically provides syntax highlighting for any
80
80
 
81
81
  The extension provides highlighting for:
82
82
 
83
- - **Brackets**: `[...]` and `[:type ...]` bracket notation (containing subjects)
83
+ - **Subject Patterns**: `[...]` and `[:type ...]` subject pattern notation (containing subjects)
84
84
  - **Nodes**: `(...)` parentheses
85
85
  - **Relationships**: `->`, `--`, `<-`, `<-->`, etc.
86
86
  - **Strings**: Single, double, and backtick quoted strings
@@ -1,6 +1,6 @@
1
1
  id = "gram"
2
2
  name = "Gram Language Support"
3
- version = "0.2.5"
3
+ version = "0.2.7"
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 = "84ec592d27a13267097d83e94932de3e024ea808"
11
+ rev = "a702c249d589daca07380db66c54bcf497d71a38"
@@ -23,7 +23,7 @@
23
23
  "::"
24
24
  ] @operator
25
25
 
26
- ; Brackets and delimiters
26
+ ; Subject Patterns and delimiters
27
27
  [
28
28
  "["
29
29
  "]"
@@ -49,15 +49,7 @@
49
49
  ; Annotation keys
50
50
  (annotation key: (symbol) @attribute)
51
51
 
52
- ; Annotations inside relationship arrows
53
- [
54
- (right_arrow annotations: (annotations) @attribute)
55
- (left_arrow annotations: (annotations) @attribute)
56
- (undirected_arrow annotations: (annotations) @attribute)
57
- (bidirectional_arrow annotations: (annotations) @attribute)
58
- ]
59
-
60
- ; Bracket notation (special highlighting)
52
+ ; Subject Pattern notation (special highlighting)
61
53
  (subject_pattern) @type
62
54
 
63
55
  ; Node with labels
package/grammar.js CHANGED
@@ -7,16 +7,17 @@ module.exports = grammar({
7
7
  ],
8
8
 
9
9
  rules: {
10
- // top-level rule, forming an outer pattern shaped like `[ record | sequence-of-top-level-elements ]`
11
- gram: ($) => seq(field("root", optional($.record)), repeat($.annotated_pattern)),
10
+ gram_pattern: ($) => seq(field("root", optional($.record)), repeat($._top_level_pattern)),
11
+
12
+ _top_level_pattern: ($) => choice($.annotated_pattern, $.subject_pattern,$.node_pattern, $.relationship_pattern),
12
13
 
13
- // top-level elements are annotated patterns shaped like `[annotation-record | pattern-elements]`
14
14
  annotated_pattern: ($) =>
15
15
  seq(
16
- field("annotations", optional($.annotations)),
17
- field("elements", commaSep1($._annotated_pattern_element)),
16
+ // field("annotations", optional($.annotations)),
17
+ field("annotations", $.annotations),
18
+ field("elements", choice($.subject_pattern, $._path_pattern)),
18
19
  ),
19
- _annotated_pattern_element: ($) => choice($.subject_pattern, $._path_pattern),
20
+ // _annotated_pattern_element: ($) => choice($.subject_pattern, $._path_pattern),
20
21
 
21
22
  subject_pattern: ($) =>
22
23
  seq(
@@ -230,7 +231,6 @@ module.exports = grammar({
230
231
  optional(
231
232
  seq(
232
233
  "[",
233
- field("annotations", optional($.annotations)),
234
234
  field("subject", optional($._subject)),
235
235
  "]",
236
236
  ),
@@ -242,7 +242,6 @@ module.exports = grammar({
242
242
  optional(
243
243
  seq(
244
244
  "[",
245
- field("annotations", optional($.annotations)),
246
245
  field("subject", optional($._subject)),
247
246
  "]",
248
247
  ),
@@ -254,7 +253,6 @@ module.exports = grammar({
254
253
  optional(
255
254
  seq(
256
255
  "[",
257
- field("annotations", optional($.annotations)),
258
256
  field("subject", optional($._subject)),
259
257
  "]",
260
258
  ),
@@ -270,7 +268,6 @@ module.exports = grammar({
270
268
  optional(
271
269
  seq(
272
270
  "[",
273
- field("annotations", optional($.annotations)),
274
271
  field("subject", optional($._subject)),
275
272
  "]",
276
273
  ),
@@ -282,7 +279,6 @@ module.exports = grammar({
282
279
  optional(
283
280
  seq(
284
281
  "[",
285
- field("annotations", optional($.annotations)),
286
282
  field("subject", optional($._subject)),
287
283
  "]",
288
284
  ),
@@ -294,7 +290,6 @@ module.exports = grammar({
294
290
  optional(
295
291
  seq(
296
292
  "[",
297
- field("annotations", optional($.annotations)),
298
293
  field("subject", optional($._subject)),
299
294
  "]",
300
295
  ),
@@ -310,7 +305,6 @@ module.exports = grammar({
310
305
  optional(
311
306
  seq(
312
307
  "[",
313
- field("annotations", optional($.annotations)),
314
308
  field("subject", optional($._subject)),
315
309
  "]",
316
310
  ),
@@ -322,7 +316,6 @@ module.exports = grammar({
322
316
  optional(
323
317
  seq(
324
318
  "[",
325
- field("annotations", optional($.annotations)),
326
319
  field("subject", optional($._subject)),
327
320
  "]",
328
321
  ),
@@ -334,7 +327,6 @@ module.exports = grammar({
334
327
  optional(
335
328
  seq(
336
329
  "[",
337
- field("annotations", optional($.annotations)),
338
330
  field("subject", optional($._subject)),
339
331
  "]",
340
332
  ),
@@ -350,7 +342,6 @@ module.exports = grammar({
350
342
  optional(
351
343
  seq(
352
344
  "[",
353
- field("annotations", optional($.annotations)),
354
345
  field("subject", optional($._subject)),
355
346
  "]",
356
347
  ),
@@ -362,7 +353,6 @@ module.exports = grammar({
362
353
  optional(
363
354
  seq(
364
355
  "[",
365
- field("annotations", optional($.annotations)),
366
356
  field("subject", optional($._subject)),
367
357
  "]",
368
358
  ),
@@ -374,7 +364,6 @@ module.exports = grammar({
374
364
  optional(
375
365
  seq(
376
366
  "[",
377
- field("annotations", optional($.annotations)),
378
367
  field("subject", optional($._subject)),
379
368
  "]",
380
369
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gram-data/tree-sitter-gram",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "subject-oriented notation for structured data",
5
5
  "homepage": "https://gram-data.github.io",
6
6
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "::"
24
24
  ] @operator
25
25
 
26
- ; Brackets and delimiters
26
+ ; Subject Patterns and delimiters
27
27
  [
28
28
  "["
29
29
  "]"
@@ -49,15 +49,7 @@
49
49
  ; Annotation keys
50
50
  (annotation key: (symbol) @attribute)
51
51
 
52
- ; Annotations inside relationship arrows
53
- [
54
- (right_arrow annotations: (annotations) @attribute)
55
- (left_arrow annotations: (annotations) @attribute)
56
- (undirected_arrow annotations: (annotations) @attribute)
57
- (bidirectional_arrow annotations: (annotations) @attribute)
58
- ]
59
-
60
- ; Bracket notation (special highlighting)
52
+ ; Subject Pattern notation (special highlighting)
61
53
  (subject_pattern) @type
62
54
 
63
55
  ; Node with labels