tree-sitter-kdl 1.0.0 → 1.0.1

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/.gitattributes CHANGED
@@ -1,3 +1,6 @@
1
+ /src/** linguist-vendored
2
+ /examples/* linguist-vendored
3
+
1
4
  src/grammar.json -diff
2
5
  src/node-types.json -diff
3
6
  src/parser.c -diff
@@ -1,4 +1,4 @@
1
- name: Build/test
1
+ name: CI
2
2
 
3
3
  on:
4
4
  push:
@@ -1,4 +1,4 @@
1
- name: Fuzz parser
1
+ name: Fuzz Parser
2
2
 
3
3
  on:
4
4
  push:
@@ -1,4 +1,4 @@
1
- name: Build and Publish
1
+ name: Publish
2
2
 
3
3
  on:
4
4
  push:
package/Cargo.toml CHANGED
@@ -1,8 +1,11 @@
1
1
  [package]
2
2
  name = "tree-sitter-kdl"
3
3
  description = "kdl grammar for the tree-sitter parsing library"
4
- version = "0.0.1"
5
- authors = ["amaanq (Amaan Qureshi) <amaanq12@gmail.com>"]
4
+ version = "1.0.1"
5
+ authors = [
6
+ "Amaan Qureshi <amaanq12@gmail.com>",
7
+ "Andrew Hlynskyi <ahlincq@gmail.com>",
8
+ ]
6
9
  keywords = ["incremental", "parsing", "kdl"]
7
10
  categories = ["parsing", "text-editors"]
8
11
  repository = "https://github.com/tree-sitter/tree-sitter-kdl"
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2023 Amaan Qureshi <amaanq12@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # tree-sitter-kdl
2
2
 
3
+ [![Build Status](https://github.com/amaanq/tree-sitter-kdl/workflows/CI/badge.svg)](https://github.com/amaanq/tree-sitter-kdl/workflows/CI/badge.svg)
4
+ [![Discord](https://img.shields.io/discord/1063097320771698699?logo=discord)](https://discord.gg/w7nTvsVJhm)
5
+
3
6
  KDL grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
4
7
 
5
8
  Adapted from the [official spec](https://github.com/kdl-org/kdl/blob/main/SPEC.md)
package/binding.gyp CHANGED
@@ -10,7 +10,6 @@
10
10
  "bindings/node/binding.cc",
11
11
  "src/parser.c",
12
12
  "src/scanner.c",
13
- # If your language uses an external scanner, add it here.
14
13
  ],
15
14
  "cflags_c": [
16
15
  "-std=c99",
package/grammar.js CHANGED
@@ -1,4 +1,14 @@
1
+ /**
2
+ * @file KDL grammar for tree-sitter
3
+ * @author Amaan Qureshi <amaanq12@gmail.com>
4
+ * @license MIT
5
+ * @see {@link https://www.pathofexile.com/item-filter/about|official syntax spec}
6
+ * @see {@link https://pathofexile.fandom.com/wiki/Guide:Item_filter#Syntax|wiki guide}
7
+ * @see {@link https://www.filterblade.xyz/|filter generator}
8
+ */
9
+
1
10
  // deno-lint-ignore-file no-control-regex
11
+ /* eslint-disable arrow-parens */
2
12
  /* eslint-disable camelcase */
3
13
  /* eslint-disable-next-line spaced-comment */
4
14
  /// <reference types="tree-sitter-cli/dsl" />
@@ -51,21 +61,21 @@ const ANNOTATION_BUILTINS = [
51
61
  module.exports = grammar({
52
62
  name: 'kdl',
53
63
 
54
- conflicts: ($) => [
64
+ conflicts: $ => [
55
65
  [$.document],
56
66
  [$._node_space],
57
67
  [$.node_children],
58
68
  ],
59
69
 
60
- extras: ($) => [$.multi_line_comment],
70
+ extras: $ => [$.multi_line_comment],
61
71
 
62
- externals: ($) => [$._eof],
72
+ externals: $ => [$._eof],
63
73
 
64
- word: ($) => $._normal_bare_identifier,
74
+ word: $ => $._normal_bare_identifier,
65
75
 
66
76
  rules: {
67
77
  // nodes := linespace* (node nodes?)? linespace*
68
- document: ($) =>
78
+ document: $ =>
69
79
  seq(
70
80
  repeat($._linespace),
71
81
  optional(seq(
@@ -79,7 +89,7 @@ module.exports = grammar({
79
89
  ),
80
90
 
81
91
  // node := ('/-' node-space*)? type? identifier (node-space+ node-prop-or-arg)* (node-space* node-children ws*)? node-space* node-terminator
82
- node: ($) => prec(PREC.node,
92
+ node: $ => prec(PREC.node,
83
93
  seq(
84
94
  alias(optional(seq('/-', repeat($._node_space))), $.node_comment),
85
95
  optional($.type),
@@ -92,16 +102,16 @@ module.exports = grammar({
92
102
  ),
93
103
 
94
104
  // node-prop-or-arg (field) := ('/-' node-space*)? (prop | value)
95
- // _node_prop_or_arg: ($) =>
105
+ // _node_prop_or_arg: $ =>
96
106
  // seq(
97
107
  // alias(optional(seq('/-', repeat($._node_space))), $.node_prop_or_arg_slash_dash),
98
108
  // field('node_prop_or_arg', choice($.prop, $.value)),
99
109
  // ),
100
- node_field: ($) => choice($._node_field_comment, $._node_field),
101
- _node_field_comment: ($) => alias(seq('/-', repeat($._node_space), $._node_field), $.node_field_comment),
102
- _node_field: ($) => choice($.prop, $.value),
110
+ node_field: $ => choice($._node_field_comment, $._node_field),
111
+ _node_field_comment: $ => alias(seq('/-', repeat($._node_space), $._node_field), $.node_field_comment),
112
+ _node_field: $ => choice($.prop, $.value),
103
113
  // node-children := ('/-' node-space*)? '{' nodes '}'
104
- node_children: ($) =>
114
+ node_children: $ =>
105
115
  seq(
106
116
  optional(seq(alias('/-', $.node_children_comment), repeat($._node_space))),
107
117
  '{',
@@ -113,26 +123,25 @@ module.exports = grammar({
113
123
  '}',
114
124
  ),
115
125
  // node-space := ws* escline ws* | ws+
116
- _node_space: ($) =>
126
+ _node_space: $ =>
117
127
  choice(
118
128
  seq(repeat($._ws), $._escline, repeat($._ws)),
119
129
  repeat1($._ws),
120
130
  ),
121
131
  // node-terminator := single-line-comment | newline | ';' | eof
122
- _node_terminator: ($) =>
132
+ _node_terminator: $ =>
123
133
  choice($.single_line_comment, $._newline, ';', $._eof),
124
134
 
125
-
126
135
  // identifier := string | bare-identifier
127
- identifier: ($) => choice($.string, $._bare_identifier),
136
+ identifier: $ => choice($.string, $._bare_identifier),
128
137
  // bare-identifier := ((identifier-char - digit - sign) identifier-char* | sign ((identifier-char - digit) identifier-char*)?) - keyword
129
- _bare_identifier: ($) =>
138
+ _bare_identifier: $ =>
130
139
  choice(
131
140
  $._normal_bare_identifier,
132
141
  seq($._sign, optional(seq($.__identifier_char_no_digit, repeat($._identifier_char)))),
133
142
  ),
134
143
 
135
- // _normal_bare_identifier: ($) => $.__identifier_char_no_digit_sign,
144
+ // _normal_bare_identifier: $ => $.__identifier_char_no_digit_sign,
136
145
  _normal_bare_identifier: () => token(
137
146
  seq(
138
147
  /[\u4E00-\u9FFF\p{L}\p{M}\p{N}\p{Emoji}_~!@#\$%\^&\*.:'\|\?&&[^\s\d\/(){}<>;\[\]=,"]]/,
@@ -155,23 +164,23 @@ module.exports = grammar({
155
164
  ),
156
165
 
157
166
  // keyword := boolean | 'null'
158
- keyword: ($) => choice($.boolean, 'null'),
167
+ keyword: $ => choice($.boolean, 'null'),
159
168
  // type annotations
160
169
  annotation_type: () => choice(...ANNOTATION_BUILTINS),
161
170
  // prop := identifier '=' value
162
- prop: ($) => seq($.identifier, '=', $.value),
171
+ prop: $ => seq($.identifier, '=', $.value),
163
172
  // value := type? (string | number | keyword)
164
- value: ($) => seq(optional($.type), choice($.string, $.number, $.keyword)),
173
+ value: $ => seq(optional($.type), choice($.string, $.number, $.keyword)),
165
174
  // type := '(' identifier ')'
166
- type: ($) => seq('(', choice($.identifier, $.annotation_type), ')'),
175
+ type: $ => seq('(', choice($.identifier, $.annotation_type), ')'),
167
176
 
168
177
  // String
169
178
  // string := raw-string | escaped-string
170
- string: ($) => choice($._raw_string, $._escaped_string),
179
+ string: $ => choice($._raw_string, $._escaped_string),
171
180
  // escaped-string := '"' character* '"'
172
- _escaped_string: ($) => seq('"', alias(repeat(choice($.escape, /[^"]/)), $.string_fragment), '"'),
181
+ _escaped_string: $ => seq('"', alias(repeat(choice($.escape, /[^"]/)), $.string_fragment), '"'),
173
182
  // character := '\' escape | [^\"]
174
- _character: ($) => choice($.escape, /[^"]/),
183
+ _character: $ => choice($.escape, /[^"]/),
175
184
  // escape := ["\\/bfnrt] | 'u{' hex-digit{1, 6} '}'
176
185
  escape: () =>
177
186
  token.immediate(/\\\\|\\"|\\\/|\\b|\\f|\\n|\\r|\\t|\\u\{[0-9a-fA-F]{1,6}\}/),
@@ -179,9 +188,9 @@ module.exports = grammar({
179
188
  _hex_digit: () => /[0-9a-fA-F]/,
180
189
 
181
190
  // // raw-string := 'r' raw-string-hash
182
- // raw_string: ($) => seq('r', $._raw_string_hash),
191
+ // raw_string: $ => seq('r', $._raw_string_hash),
183
192
  // // raw-string-hash := '#' raw-string-hash '#' | raw-string-quotes
184
- // _raw_string_hash: ($) => choice(seq('#', $._raw_string_hash, '#'), $._raw_string_quotes),
193
+ // _raw_string_hash: $ => choice(seq('#', $._raw_string_hash, '#'), $._raw_string_quotes),
185
194
  // // raw-string-quotes := '"' .* '"'
186
195
  // _raw_string_quotes: () => seq('"', /.*/, '"'),
187
196
  _raw_string: () =>
@@ -195,12 +204,11 @@ module.exports = grammar({
195
204
  ),
196
205
  ),
197
206
 
198
-
199
207
  // number := decimal | hex | octal | binary
200
- number: ($) => choice($._decimal, $._hex, $._octal, $._binary),
208
+ number: $ => choice($._decimal, $._hex, $._octal, $._binary),
201
209
 
202
210
  // decimal := sign? integer ('.' integer)? exponent?
203
- _decimal: ($) =>
211
+ _decimal: $ =>
204
212
  seq(
205
213
  optional($._sign),
206
214
  $._integer,
@@ -209,29 +217,29 @@ module.exports = grammar({
209
217
  ),
210
218
 
211
219
  // exponent := ('e' | 'E') sign? integer
212
- _exponent: ($) => seq(choice('e', 'E'), optional($._sign), $._integer),
220
+ _exponent: $ => seq(choice('e', 'E'), optional($._sign), $._integer),
213
221
  // integer := digit (digit | '_')*
214
- _integer: ($) => seq($._digit, repeat(choice($._digit, '_'))),
222
+ _integer: $ => seq($._digit, repeat(choice($._digit, '_'))),
215
223
  // digit := [0-9]
216
224
  _digit: () => /[0-9]/,
217
225
  // sign := '+' | '-'
218
226
  _sign: () => choice('+', '-'),
219
227
 
220
228
  // hex := sign? '0x' hex-digit (hex-digit | '_')*
221
- _hex: ($) => seq(optional($._sign), '0x', $._hex_digit, repeat(choice($._hex_digit, '_'))),
229
+ _hex: $ => seq(optional($._sign), '0x', $._hex_digit, repeat(choice($._hex_digit, '_'))),
222
230
  // octal := sign? '0o' [0-7] [0-7_]*
223
- _octal: ($) => seq(optional($._sign), '0o', /[0-7]/, repeat(choice(/[0-7]/, '_'))),
231
+ _octal: $ => seq(optional($._sign), '0o', /[0-7]/, repeat(choice(/[0-7]/, '_'))),
224
232
  // binary := sign? '0b' ('0' | '1') ('0' | '1' | '_')*
225
- _binary: ($) => seq(optional($._sign), '0b', choice('0', '1'), repeat(choice('0', '1', '_'))),
233
+ _binary: $ => seq(optional($._sign), '0b', choice('0', '1'), repeat(choice('0', '1', '_'))),
226
234
 
227
235
  // boolean := 'true' | 'false'
228
236
  boolean: () => choice('true', 'false'),
229
237
 
230
238
  // escline := '\\' ws* (single-line-comment | newline)
231
- _escline: ($) => seq('\\', repeat($._ws), choice($.single_line_comment, $._newline)),
239
+ _escline: $ => seq('\\', repeat($._ws), choice($.single_line_comment, $._newline)),
232
240
 
233
241
  // linespace := newline | ws | single-line-comment
234
- _linespace: ($) => choice($._newline, $._ws, $.single_line_comment),
242
+ _linespace: $ => choice($._newline, $._ws, $.single_line_comment),
235
243
 
236
244
  // newline := See Table (All line-break white_space)
237
245
  // Newline
@@ -251,7 +259,7 @@ module.exports = grammar({
251
259
  _newline: () => choice(/\r'/, /\n/, /\r\n/, /\u0085/, /\u000C/, /\u2028/, /\u2029/),
252
260
 
253
261
  // ws := bom | unicode-space | multi-line-comment
254
- _ws: ($) => choice($._bom, $._unicode_space, $.multi_line_comment),
262
+ _ws: $ => choice($._bom, $._unicode_space, $.multi_line_comment),
255
263
 
256
264
  // bom := '\u{FEFF}'
257
265
  _bom: () => /\u{FEFF}/,
@@ -285,17 +293,17 @@ module.exports = grammar({
285
293
  /[\u0009\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000]/,
286
294
 
287
295
  // single-line-comment := '//' ^newline+ (newline | eof)
288
- single_line_comment: ($) =>
296
+ single_line_comment: $ =>
289
297
  seq(
290
298
  '//',
291
299
  repeat1(/[^\r\n\u0085\u000C\u2028\u2029]/),
292
300
  choice($._newline, $._eof),
293
301
  ),
294
302
  // multi-line-comment := '/*' commented-block
295
- multi_line_comment: ($) =>
303
+ multi_line_comment: $ =>
296
304
  seq('/*', repeat(prec.right(2, choice($.commented_block, /[^*\/]/))), '*/'),
297
305
  // commented-block := '*/' | (multi-line-comment | '*' | '/' | [^*/]+) commented-block
298
- commented_block: ($) =>
306
+ commented_block: $ =>
299
307
  prec.right(1, seq(
300
308
  /[^*\/]/,
301
309
  repeat(choice($.multi_line_comment, /[^*\/]/)),
package/package.json CHANGED
@@ -1,21 +1,18 @@
1
1
  {
2
2
  "name": "tree-sitter-kdl",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "KDL grammar for tree-sitter",
5
5
  "main": "bindings/node",
6
6
  "keywords": [
7
7
  "parser",
8
- "lexer"
8
+ "lexer",
9
+ "kdl"
9
10
  ],
10
- "author": "Amaan Qureshi",
11
- "scripts": {
12
- "test": "echo \"Error: no test specified\" && exit 1"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/amaanq/tree-sitter-kdl.git"
17
- },
18
- "license": "ISC",
11
+ "author": "Amaan Qureshi <amaanq12@gmail.com>",
12
+ "contributors": [
13
+ "Andrew Hlynskyi <ahlincq@gmail.com>"
14
+ ],
15
+ "license": "MIT",
19
16
  "bugs": {
20
17
  "url": "https://github.com/amaanq/tree-sitter-kdl/issues"
21
18
  },
@@ -24,9 +21,26 @@
24
21
  "nan": "^2.17.0"
25
22
  },
26
23
  "devDependencies": {
27
- "@types/node": "^18.11.18",
28
24
  "eslint": "^8.32.0",
29
25
  "eslint-config-google": "^0.14.0",
30
26
  "tree-sitter-cli": "^0.20.7"
31
- }
27
+ },
28
+ "repository": "https://github.com/amaanq/tree-sitter-kdl",
29
+ "scripts": {
30
+ "build": "tree-sitter generate && node-gyp build",
31
+ "test": "tree-sitter test && script/parse-examples",
32
+ "parse": "tree-sitter parse",
33
+ "test-windows": "tree-sitter test"
34
+ },
35
+ "tree-sitter": [
36
+ {
37
+ "scope": "source.kdl",
38
+ "file-types": [
39
+ "kdl"
40
+ ],
41
+ "highlights": [
42
+ "queries/highlights.scm"
43
+ ]
44
+ }
45
+ ]
32
46
  }
package/queries/folds.scm CHANGED
@@ -1,3 +1,8 @@
1
1
  ; Folds
2
2
 
3
- (node_children) @fold
3
+ [
4
+ (node)
5
+ (node_children)
6
+ (string)
7
+ (multi_line_comment)
8
+ ] @fold
@@ -48,7 +48,7 @@
48
48
  [
49
49
  (single_line_comment)
50
50
  (multi_line_comment)
51
- ] @comment
51
+ ] @comment @spell
52
52
 
53
53
  (node (node_comment) (#set! "priority" 105)) @comment
54
54
  (node (node_field (node_field_comment) (#set! "priority" 105)) @comment)
@@ -0,0 +1,7 @@
1
+ (node (node_children) @indent)
2
+
3
+ "}" @indent_end
4
+
5
+ [ "{" "}" ] @branch
6
+
7
+ [ "(" ")" ] @branch
@@ -0,0 +1,4 @@
1
+ [
2
+ (single_line_comment)
3
+ (multi_line_comment)
4
+ ] @comment
@@ -0,0 +1,10 @@
1
+ (document) @scope
2
+ (node (node_children) @scope)
3
+ (node_children (node) @scope)
4
+
5
+ (identifier) @reference
6
+
7
+ (node_field) @definition.field
8
+
9
+ (node (identifier) @definition.type)
10
+ (type) @definition.type