@gram-data/tree-sitter-gram 0.1.6 → 0.1.8

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
+ MIT License
2
+
3
+ Copyright (c) 2024 Andreas Kollegger
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 CHANGED
@@ -1,61 +1,27 @@
1
- # Gram - a lightweight, flexible graph notation
1
+ # tree-sitter-gram
2
2
 
3
- Gram describes the structure and content of graphs, without semantics.
3
+ A [tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar
4
+ for [gram](https://gram-data.github.io) notation.
4
5
 
5
- A graph is composed from a sequence of patterns, where each pattern
6
- is a sequence of graph elements.
7
-
8
- ## Graph elements - nodes
9
-
10
- The smallest graph pattern is an empty node.
11
- ```
12
- ()
13
- ```
14
-
15
- Nodes may include properties using classic curly-braces-styled notation. This expression
16
- is like an anonymous object that appears inside some other data structure, perhaps a list
17
- like `const people = [{name:ABK}]`:
6
+ Gram is a subject-based notation for structured data.
18
7
 
8
+ If this is an object:
19
9
  ```
20
- ({name:"ABK"})
10
+ {
11
+ "name":"Andreas",
12
+ "roles":["author"]
13
+ }
21
14
  ```
22
15
 
23
- Nodes may self-identify themselves. This is like an object that is aware of the variable
24
- name you've given it in a programming language -- `const abk = {name:"ABK"}`
25
- ```
26
- (abk {name:"ABK"})
27
- ```
28
-
29
- Or, the identity could be considered the representative value of the node as in these examples:
30
- ```
31
- (1), (true), (`heir to the Iron Throne`)
32
- ```
16
+ Implicitly the object is a person. To become a subject, the implicit
17
+ information can be explicit.
33
18
 
34
- Nodes may also provide labels to associate with other nodes. This is like having an
35
- introspectable object in a programming language -- `const abk:Person = {name:"ABK"}`:
19
+ As a subject:
36
20
  ```
37
- (abk:Person {name:"ABK"}), (michael:Person {name:"Michael"})
21
+ (:Person {
22
+ name: "Andreas",
23
+ roles: ["author"]
24
+ })
38
25
  ```
39
26
 
40
- It's ok to use multiple labels, which could be subsets, singletons, or intersections:
41
- ```
42
- (abk:Person:Author {name:"ABK"}), (one:Person:King:Fictional {name: "John Snow"}),
43
- (drogon:Dragon:Fictional {name:"Drogon"})
44
- ```
45
-
46
-
47
- ## FAQ
48
-
49
- - Annotation vs self-loop?
50
-
51
- Q: What is the difference between an annotation and a self-loop?
52
- A: An annotation provides extra information about a single target, while a self-loop provides
53
- information about a source,target pair where either the source or target may have been different,
54
- but happen to be the same.
55
-
56
- For example, `@physics("rigid")(a:Player)` annotates a player entity with information for the physics subsystem.
57
- The information is particular to the player and not about how the player relates to itself.
58
-
59
- As a self-loop, `(a:Player)-[:MESSAGE]->(a:Player)` is a message a player sent to themselves that could've
60
- been sent to another player. The message has a specific source and target, which happen to be the same.
61
-
27
+ Learn more about `gram` at the [gram-data github org](https://github.com/gram-data) notation.
package/grammar.js CHANGED
@@ -8,22 +8,29 @@ module.exports = grammar({
8
8
  repeat($.pattern)
9
9
  ),
10
10
 
11
- pattern: $ => seq(optional(repeat($.annotation)), commaSep1($._patternComponent)),
11
+ pattern: $ => commaSep1($.pattern_element),
12
12
 
13
- _patternComponent: $ => choice(
14
- $.subject,
15
- $._path
13
+ pattern_element: $ => seq(
14
+ optional(repeat($.annotation)),
15
+ choice(
16
+ $.subject,
17
+ $._path,
18
+ $._reference
19
+ )
16
20
  ),
17
21
 
18
- subject: $ => seq("[", optional($._attributes), optional(field("association", $._association)),"]"),
22
+ // ABKNOTE -- consider the naming of the two parts of a subject
23
+ // attributes & association
24
+ // information & association
25
+ subject: $ => seq("[", optional(field("attributes", $._attributes)), optional(field("association", $._association)),"]"),
19
26
 
20
- annotation: $ => prec(9999,seq(
21
- "@",
27
+ annotation: $ => seq(
28
+ "@",
22
29
  field('key', $.symbol),
23
30
  "(",
24
31
  field('value', $._value),
25
32
  ")"
26
- )),
33
+ ),
27
34
 
28
35
  _path: $ => choice(
29
36
  $.relationship,
@@ -33,29 +40,14 @@ module.exports = grammar({
33
40
  node: $ => seq("(", optional($._attributes),")"),
34
41
 
35
42
  relationship: $ => seq(field("left", $.node), field("value", $._relationship_value), field("right", $._path)),
36
-
37
- _association: $ => choice($.membership, $.ordering),
38
43
 
39
- membership: $ => seq(
40
- "|",
41
- optional(seq(optional(field("labels", $.labels)), optional(field("record", $.record)), "|")),
42
- commaSep1($.member)),
43
-
44
- ordering: $ => seq(
45
- "-",
46
- optional(seq("[", optional(field("labels", $.labels)), optional(field("record", $.record)), "]-")), ">",
47
- commaSep1($.member)),
44
+ _association: $ => seq(
45
+ token("|"),
46
+ $.pattern
47
+ ),
48
48
 
49
49
  _reference: $ => $._value,
50
50
 
51
- member: $ => seq(
52
- optional(repeat($.annotation)),
53
- choice(
54
- $._reference,
55
- $._patternComponent
56
- ),
57
- ),
58
-
59
51
  _attributes: $ => choice(
60
52
  choice(field("identifier", $._value), field("labels", $.labels), field("record", $.record)),
61
53
  seq(field("identifier", $._value), field("labels", $.labels)),
@@ -65,10 +57,10 @@ module.exports = grammar({
65
57
  ),
66
58
 
67
59
  _value: $ => choice(
60
+ prec.right(2, $.range),
61
+ prec.right(1, $._numeric_literal),
68
62
  $.symbol,
69
- $._numeric_literal,
70
63
  $._string_literal,
71
- $.range,
72
64
  $.math_symbol,
73
65
  $.greek,
74
66
  $.pictograph
@@ -78,18 +70,25 @@ module.exports = grammar({
78
70
 
79
71
  label: $ => seq(field("binder", $.binder), $.symbol),
80
72
 
81
- binder: $ => choice(token(":"), token("::"), token("@")),
73
+ binder: $ => choice(token(":"), token("::")),
82
74
 
83
75
  record: $ => seq("{", commaSep($.property), "}"),
84
76
 
85
77
  property: $ => seq(
86
- field('key', $.symbol),
78
+ field('key', $._key),
87
79
  field('binder', $.binder),
88
80
  field('value', $._value),
89
81
  optional(field('cardinality', choice('!', '?', '*', '+')))
90
82
  ),
91
83
 
92
- symbol: $ => token(/[a-zA-Z_][0-9a-zA-Z_.\-]*/),
84
+
85
+ _key: $ => choice(
86
+ $.symbol,
87
+ $._string_literal
88
+ ),
89
+
90
+ symbol: $ => token(/[a-zA-Z_][0-9a-zA-Z_.\-@]*/),
91
+
93
92
 
94
93
  greek: $ => token(/[\u03B1-\u03C9\u0391-\u03A9]/),
95
94
  math_symbol: $ => token(/\p{Other_Math}/),
@@ -159,7 +158,7 @@ module.exports = grammar({
159
158
  },
160
159
 
161
160
  tagged_string: $ => {
162
- const tagged = /[a-zA-Z][0-9a-zA-Z_.@]*`[^`\n]*`/;
161
+ const tagged = /[a-zA-Z@][0-9a-zA-Z_.@]*`[^`\n]*`/;
163
162
  return token(tagged);
164
163
  },
165
164
 
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@gram-data/tree-sitter-gram",
3
- "private": false,
4
- "version": "0.1.6",
3
+ "version": "0.1.8",
5
4
  "description": "subject-oriented notation for structured data",
5
+ "homepage": "https://gram-data.github.io",
6
+ "repository": "github:gram-data/tree-sitter-gram",
6
7
  "main": "bindings/node",
7
8
  "types": "bindings/node",
8
9
  "scripts": {
@@ -11,7 +12,12 @@
11
12
  "start": "tree-sitter playground",
12
13
  "test": "node --test bindings/node/*_test.js"
13
14
  },
14
- "keywords": [],
15
+ "keywords": [
16
+ "tree-sitter",
17
+ "parser",
18
+ "gram",
19
+ "json"
20
+ ],
15
21
  "files": [
16
22
  "grammar.js",
17
23
  "binding.gyp",
@@ -23,8 +29,8 @@
23
29
  "author": "",
24
30
  "license": "ISC",
25
31
  "dependencies": {
26
- "node-gyp-build": "^4.8.2",
27
- "node-addon-api": "^8.1.0"
32
+ "node-gyp-build": "^4.8.4",
33
+ "node-addon-api": "^8.2.2"
28
34
  },
29
35
  "peerDependencies": {
30
36
  "tree-sitter": "^0.21.0"
@@ -35,17 +41,9 @@
35
41
  }
36
42
  },
37
43
  "devDependencies": {
38
- "eslint": "^9.12.0",
44
+ "eslint": "^9.15.0",
39
45
  "node-gyp": "^10.2.0",
40
46
  "prebuildify": "^6.0.1",
41
- "tree-sitter-cli": "^0.24.2"
42
- },
43
- "tree-sitter": [
44
- {
45
- "scope": "source.gram",
46
- "file-types": [
47
- "gram"
48
- ]
49
- }
50
- ]
51
- }
47
+ "tree-sitter-cli": "^0.24.4"
48
+ }
49
+ }