@gram-data/tree-sitter-gram 0.1.7 → 0.1.9

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
@@ -3,7 +3,7 @@
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
+ Gram is a subject-based notation for structured data.
7
7
 
8
8
  If this is an object:
9
9
  ```
@@ -13,15 +13,15 @@ If this is an object:
13
13
  }
14
14
  ```
15
15
 
16
- Implicitly it is about a person. To become a subject, the implicit
16
+ Implicitly the object is a person. To become a subject, the implicit
17
17
  information can be explicit.
18
18
 
19
19
  As a subject:
20
20
  ```
21
- [:Person {
21
+ (:Person {
22
22
  name: "Andreas",
23
23
  roles: ["author"]
24
- }]
24
+ })
25
25
  ```
26
26
 
27
27
  Learn more about `gram` at the [gram-data github org](https://github.com/gram-data) notation.
package/grammar.js CHANGED
@@ -8,54 +8,46 @@ 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,
30
37
  $.node
31
38
  ),
32
39
 
33
- node: $ => seq("(", optional($._attributes),")"),
40
+ node: $ => seq(token("("), optional($._attributes), token(")")),
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@gram-data/tree-sitter-gram",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "subject-oriented notation for structured data",
5
5
  "homepage": "https://gram-data.github.io",
6
6
  "repository": "github:gram-data/tree-sitter-gram",
@@ -12,7 +12,12 @@
12
12
  "start": "tree-sitter playground",
13
13
  "test": "node --test bindings/node/*_test.js"
14
14
  },
15
- "keywords": [],
15
+ "keywords": [
16
+ "tree-sitter",
17
+ "parser",
18
+ "gram",
19
+ "json"
20
+ ],
16
21
  "files": [
17
22
  "grammar.js",
18
23
  "binding.gyp",
@@ -24,8 +29,8 @@
24
29
  "author": "",
25
30
  "license": "ISC",
26
31
  "dependencies": {
27
- "node-gyp-build": "^4.8.2",
28
- "node-addon-api": "^8.1.0"
32
+ "node-gyp-build": "^4.8.4",
33
+ "node-addon-api": "^8.3.0"
29
34
  },
30
35
  "peerDependencies": {
31
36
  "tree-sitter": "^0.21.0"
@@ -36,17 +41,9 @@
36
41
  }
37
42
  },
38
43
  "devDependencies": {
39
- "eslint": "^9.12.0",
40
- "node-gyp": "^10.2.0",
44
+ "eslint": "^9.17.0",
45
+ "node-gyp": "^11.0.0",
41
46
  "prebuildify": "^6.0.1",
42
- "tree-sitter-cli": "^0.24.2"
43
- },
44
- "tree-sitter": [
45
- {
46
- "scope": "source.gram",
47
- "file-types": [
48
- "gram"
49
- ]
50
- }
51
- ]
52
- }
47
+ "tree-sitter-cli": "^0.24.5"
48
+ }
49
+ }