tree-sitter-kdl 1.0.2 → 1.0.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.
@@ -3,7 +3,7 @@ name: CI
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - "master"
6
+ - master
7
7
  pull_request:
8
8
  branches:
9
9
  - "**"
@@ -0,0 +1,19 @@
1
+ name: Lint
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - "**"
10
+
11
+ jobs:
12
+ lint:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - name: Install modules
17
+ run: npm install
18
+ - name: Run ESLint
19
+ run: npm run lint
@@ -3,7 +3,7 @@ name: Publish
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - main
6
+ - master
7
7
  tags:
8
8
  - "v*"
9
9
  workflow_dispatch:
@@ -46,6 +46,6 @@ jobs:
46
46
  profile: minimal
47
47
  toolchain: stable
48
48
  override: true
49
- - uses: katyo/publish-crates@v1
49
+ - uses: katyo/publish-crates@v2
50
50
  with:
51
51
  registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
package/Cargo.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  name = "tree-sitter-kdl"
3
3
  description = "KDL grammar for tree-sitter"
4
- version = "1.0.2"
4
+ version = "1.0.3"
5
5
  authors = [
6
6
  "Amaan Qureshi <amaanq12@gmail.com>",
7
7
  "Andrew Hlynskyi <ahlincq@gmail.com>",
@@ -11,7 +11,7 @@
11
11
  //! ```
12
12
  //! let code = "";
13
13
  //! let mut parser = tree_sitter::Parser::new();
14
- //! parser.set_language(tree_sitter_kdl::language()).expect("Error loading kdl grammar");
14
+ //! parser.set_language(tree_sitter_kdl::language()).expect("Error loading KDL grammar");
15
15
  //! let tree = parser.parse(code, None).unwrap();
16
16
  //! ```
17
17
  //!
@@ -36,17 +36,21 @@ pub fn language() -> Language {
36
36
  /// The source of the Rust tree-sitter grammar description.
37
37
  pub const GRAMMAR: &str = include_str!("../../grammar.js");
38
38
 
39
+ /// The folds query for this language.
40
+ pub const FOLDS_QUERY: &str = include_str!("../../queries/folds.scm");
41
+
39
42
  /// The syntax highlighting query for this language.
40
43
  pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
41
44
 
45
+ /// The indents query for this language.
46
+ pub const INDENTS_QUERY: &str = include_str!("../../queries/indents.scm");
47
+
42
48
  /// The injection query for this language.
43
49
  pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
44
50
 
45
51
  /// The symbol tagging query for this language.
46
52
  pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
47
53
 
48
- // pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
49
-
50
54
  /// The content of the [`node-types.json`][] file for this grammar.
51
55
  ///
52
56
  /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
package/grammar.js CHANGED
@@ -13,10 +13,6 @@
13
13
  /// <reference types="tree-sitter-cli/dsl" />
14
14
  // @ts-check
15
15
 
16
- const PREC = {
17
- node: 1,
18
- };
19
-
20
16
  const ANNOTATION_BUILTINS = [
21
17
  'i8',
22
18
  'i16',
@@ -66,9 +62,9 @@ module.exports = grammar({
66
62
  [$.node_children],
67
63
  ],
68
64
 
69
- extras: $ => [$.multi_line_comment],
65
+ externals: $ => [$._eof, $.multi_line_comment],
70
66
 
71
- externals: $ => [$._eof],
67
+ extras: $ => [$.multi_line_comment],
72
68
 
73
69
  word: $ => $._normal_bare_identifier,
74
70
 
@@ -88,7 +84,7 @@ module.exports = grammar({
88
84
  ),
89
85
 
90
86
  // node := ('/-' node-space*)? type? identifier (node-space+ node-prop-or-arg)* (node-space* node-children ws*)? node-space* node-terminator
91
- node: $ => prec(PREC.node,
87
+ node: $ => prec(1,
92
88
  seq(
93
89
  alias(optional(seq('/-', repeat($._node_space))), $.node_comment),
94
90
  optional($.type),
@@ -141,31 +137,31 @@ module.exports = grammar({
141
137
  ),
142
138
 
143
139
  // _normal_bare_identifier: $ => $.__identifier_char_no_digit_sign,
144
- _normal_bare_identifier: () => token(
140
+ _normal_bare_identifier: _ => token(
145
141
  seq(
146
142
  /[\u4E00-\u9FFF\p{L}\p{M}\p{N}\p{Emoji}_~!@#\$%\^&\*.:'\|\?&&[^\s\d\/(){}<>;\[\]=,"]]/,
147
143
  /[\u4E00-\u9FFF\p{L}\p{M}\p{N}\p{Emoji}\-_~!@#\$%\^&\*.:'\|\?+&&[^\s\/(){}<>;\[\]=,"]]*/,
148
144
  ),
149
145
  ),
150
146
  // identifier-char := unicode - linespace - [\/(){}<>;[]=,"]
151
- _identifier_char: () => token(
147
+ _identifier_char: _ => token(
152
148
  /[\u4E00-\u9FFF\p{L}\p{M}\p{N}\-_~!@#\$%\^&\*.:'\|\?+&&[^\s\/(){}<>;\[\]=,"]]/,
153
149
  ),
154
150
 
155
151
  // can't start with a digit
156
- __identifier_char_no_digit: () => token(
152
+ __identifier_char_no_digit: _ => token(
157
153
  /[\u4E00-\u9FFF\p{L}\p{M}\p{N}\-_~!@#\$%\^&\*.:'\|\?+&&[^\s\d\/(){}<>;\[\]=,"]]/,
158
154
  ),
159
155
 
160
156
  // can't start with a digit or sign
161
- __identifier_char_no_digit_sign: () => token(
157
+ __identifier_char_no_digit_sign: _ => token(
162
158
  /[\u4E00-\u9FFF\p{L}\p{M}\p{N}\-_~!@#\$%\^&\*.:'\|\?&&[^\s\d\+\-\/(){}<>;\[\]=,"]]/,
163
159
  ),
164
160
 
165
161
  // keyword := boolean | 'null'
166
162
  keyword: $ => choice($.boolean, 'null'),
167
163
  // type annotations
168
- annotation_type: () => choice(...ANNOTATION_BUILTINS),
164
+ annotation_type: _ => choice(...ANNOTATION_BUILTINS),
169
165
  // prop := identifier '=' value
170
166
  prop: $ => seq($.identifier, '=', $.value),
171
167
  // value := type? (string | number | keyword)
@@ -181,18 +177,18 @@ module.exports = grammar({
181
177
  // character := '\' escape | [^\"]
182
178
  _character: $ => choice($.escape, /[^"]/),
183
179
  // escape := ["\\/bfnrt] | 'u{' hex-digit{1, 6} '}'
184
- escape: () =>
180
+ escape: _ =>
185
181
  token.immediate(/\\\\|\\"|\\\/|\\b|\\f|\\n|\\r|\\t|\\u\{[0-9a-fA-F]{1,6}\}/),
186
182
  // hex-digit := [0-9a-fA-F]
187
- _hex_digit: () => /[0-9a-fA-F]/,
183
+ _hex_digit: _ => /[0-9a-fA-F]/,
188
184
 
189
185
  // // raw-string := 'r' raw-string-hash
190
186
  // raw_string: $ => seq('r', $._raw_string_hash),
191
187
  // // raw-string-hash := '#' raw-string-hash '#' | raw-string-quotes
192
188
  // _raw_string_hash: $ => choice(seq('#', $._raw_string_hash, '#'), $._raw_string_quotes),
193
189
  // // raw-string-quotes := '"' .* '"'
194
- // _raw_string_quotes: () => seq('"', /.*/, '"'),
195
- _raw_string: () =>
190
+ // _raw_string_quotes: _ => seq('"', /.*/, '"'),
191
+ _raw_string: _ =>
196
192
  seq(
197
193
  choice(
198
194
  // raw-string-hash := '#' raw-string-hash '#' | raw-string-quotes
@@ -220,9 +216,9 @@ module.exports = grammar({
220
216
  // integer := digit (digit | '_')*
221
217
  _integer: $ => seq($._digit, repeat(choice($._digit, '_'))),
222
218
  // digit := [0-9]
223
- _digit: () => /[0-9]/,
219
+ _digit: _ => /[0-9]/,
224
220
  // sign := '+' | '-'
225
- _sign: () => choice('+', '-'),
221
+ _sign: _ => choice('+', '-'),
226
222
 
227
223
  // hex := sign? '0x' hex-digit (hex-digit | '_')*
228
224
  _hex: $ => seq(optional($._sign), '0x', $._hex_digit, repeat(choice($._hex_digit, '_'))),
@@ -232,7 +228,7 @@ module.exports = grammar({
232
228
  _binary: $ => seq(optional($._sign), '0b', choice('0', '1'), repeat(choice('0', '1', '_'))),
233
229
 
234
230
  // boolean := 'true' | 'false'
235
- boolean: () => choice('true', 'false'),
231
+ boolean: _ => choice('true', 'false'),
236
232
 
237
233
  // escline := '\\' ws* (single-line-comment | newline)
238
234
  _escline: $ => seq('\\', repeat($._ws), choice($.single_line_comment, $._newline)),
@@ -255,13 +251,13 @@ module.exports = grammar({
255
251
  // │ PS Paragraph Separator U+2029 │
256
252
  // ╰──────────────────────────────────────────────────────────╯
257
253
  // Note that for the purpose of new lines, CRLF is considered a single newline.
258
- _newline: () => choice(/\r'/, /\n/, /\r\n/, /\u0085/, /\u000C/, /\u2028/, /\u2029/),
254
+ _newline: _ => choice(/\r'/, /\n/, /\r\n/, /\u0085/, /\u000C/, /\u2028/, /\u2029/),
259
255
 
260
256
  // ws := bom | unicode-space | multi-line-comment
261
257
  _ws: $ => choice($._bom, $._unicode_space, $.multi_line_comment),
262
258
 
263
259
  // bom := '\u{FEFF}'
264
- _bom: () => /\u{FEFF}/,
260
+ _bom: _ => /\u{FEFF}/,
265
261
 
266
262
  // unicode-space := See Table (All White_Space unicode characters which are not `newline`)
267
263
  // Whitespace
@@ -288,24 +284,15 @@ module.exports = grammar({
288
284
  // │ Medium Mathematical Space U+205F │
289
285
  // │ Ideographic Space U+3000 │
290
286
  // ╰────────────────────────────────────╯
291
- _unicode_space: () =>
287
+ _unicode_space: _ =>
292
288
  /[\u0009\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000]/,
293
289
 
294
290
  // single-line-comment := '//' ^newline+ (newline | eof)
295
291
  single_line_comment: $ =>
296
292
  seq(
297
293
  '//',
298
- repeat1(/[^\r\n\u0085\u000C\u2028\u2029]/),
294
+ repeat(/[^\r\n\u0085\u000C\u2028\u2029]/),
299
295
  choice($._newline, $._eof),
300
296
  ),
301
- // multi-line-comment := '/*' commented-block
302
- multi_line_comment: $ =>
303
- seq('/*', repeat(prec.right(2, choice($.commented_block, /[^*\/]/))), '*/'),
304
- // commented-block := '*/' | (multi-line-comment | '*' | '/' | [^*/]+) commented-block
305
- commented_block: $ =>
306
- prec.right(1, seq(
307
- /[^*\/]/,
308
- repeat(choice($.multi_line_comment, /[^*\/]/)),
309
- )),
310
297
  },
311
298
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-kdl",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "KDL grammar for tree-sitter",
5
5
  "main": "bindings/node",
6
6
  "keywords": [
@@ -31,18 +31,21 @@
31
31
 
32
32
  (number (decimal) @float)
33
33
  (number (exponent) @float)
34
- (number (decimal) (exponent) @float)
35
34
 
36
35
  (boolean) @boolean
37
36
 
38
- ; Misc
39
-
40
37
  "null" @constant.builtin
41
38
 
39
+ ; Punctuation
40
+
42
41
  ["{" "}"] @punctuation.bracket
43
42
 
44
43
  ["(" ")"] @punctuation.bracket
45
44
 
45
+ [
46
+ ";"
47
+ ] @punctuation.delimiter
48
+
46
49
  ; Comments
47
50
 
48
51
  [
package/src/grammar.json CHANGED
@@ -1282,7 +1282,7 @@
1282
1282
  "value": "//"
1283
1283
  },
1284
1284
  {
1285
- "type": "REPEAT1",
1285
+ "type": "REPEAT",
1286
1286
  "content": {
1287
1287
  "type": "PATTERN",
1288
1288
  "value": "[^\\r\\n\\u0085\\u000C\\u2028\\u2029]"
@@ -1302,68 +1302,6 @@
1302
1302
  ]
1303
1303
  }
1304
1304
  ]
1305
- },
1306
- "multi_line_comment": {
1307
- "type": "SEQ",
1308
- "members": [
1309
- {
1310
- "type": "STRING",
1311
- "value": "/*"
1312
- },
1313
- {
1314
- "type": "REPEAT",
1315
- "content": {
1316
- "type": "PREC_RIGHT",
1317
- "value": 2,
1318
- "content": {
1319
- "type": "CHOICE",
1320
- "members": [
1321
- {
1322
- "type": "SYMBOL",
1323
- "name": "commented_block"
1324
- },
1325
- {
1326
- "type": "PATTERN",
1327
- "value": "[^*\\/]"
1328
- }
1329
- ]
1330
- }
1331
- }
1332
- },
1333
- {
1334
- "type": "STRING",
1335
- "value": "*/"
1336
- }
1337
- ]
1338
- },
1339
- "commented_block": {
1340
- "type": "PREC_RIGHT",
1341
- "value": 1,
1342
- "content": {
1343
- "type": "SEQ",
1344
- "members": [
1345
- {
1346
- "type": "PATTERN",
1347
- "value": "[^*\\/]"
1348
- },
1349
- {
1350
- "type": "REPEAT",
1351
- "content": {
1352
- "type": "CHOICE",
1353
- "members": [
1354
- {
1355
- "type": "SYMBOL",
1356
- "name": "multi_line_comment"
1357
- },
1358
- {
1359
- "type": "PATTERN",
1360
- "value": "[^*\\/]"
1361
- }
1362
- ]
1363
- }
1364
- }
1365
- ]
1366
- }
1367
1305
  }
1368
1306
  },
1369
1307
  "extras": [
@@ -1388,6 +1326,10 @@
1388
1326
  {
1389
1327
  "type": "SYMBOL",
1390
1328
  "name": "_eof"
1329
+ },
1330
+ {
1331
+ "type": "SYMBOL",
1332
+ "name": "multi_line_comment"
1391
1333
  }
1392
1334
  ],
1393
1335
  "inline": [],
@@ -9,21 +9,6 @@
9
9
  "named": true,
10
10
  "fields": {}
11
11
  },
12
- {
13
- "type": "commented_block",
14
- "named": true,
15
- "fields": {},
16
- "children": {
17
- "multiple": true,
18
- "required": false,
19
- "types": [
20
- {
21
- "type": "multi_line_comment",
22
- "named": true
23
- }
24
- ]
25
- }
26
- },
27
12
  {
28
13
  "type": "decimal",
29
14
  "named": true,
@@ -87,21 +72,6 @@
87
72
  ]
88
73
  }
89
74
  },
90
- {
91
- "type": "multi_line_comment",
92
- "named": true,
93
- "fields": {},
94
- "children": {
95
- "multiple": true,
96
- "required": false,
97
- "types": [
98
- {
99
- "type": "commented_block",
100
- "named": true
101
- }
102
- ]
103
- }
104
- },
105
75
  {
106
76
  "type": "node",
107
77
  "named": true,
@@ -379,10 +349,6 @@
379
349
  "type": ")",
380
350
  "named": false
381
351
  },
382
- {
383
- "type": "*/",
384
- "named": false
385
- },
386
352
  {
387
353
  "type": "+",
388
354
  "named": false
@@ -395,10 +361,6 @@
395
361
  "type": ".",
396
362
  "named": false
397
363
  },
398
- {
399
- "type": "/*",
400
- "named": false
401
- },
402
364
  {
403
365
  "type": "//",
404
366
  "named": false
@@ -559,6 +521,10 @@
559
521
  "type": "isize",
560
522
  "named": false
561
523
  },
524
+ {
525
+ "type": "multi_line_comment",
526
+ "named": true
527
+ },
562
528
  {
563
529
  "type": "node_children_comment",
564
530
  "named": true