tree-sitter-kdl 0.0.1 → 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 +3 -0
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/fuzz.yml +1 -1
- package/.github/workflows/{build.yml → publish.yml} +1 -1
- package/Cargo.toml +5 -2
- package/LICENSE +7 -0
- package/README.md +3 -0
- package/binding.gyp +0 -1
- package/grammar.js +48 -40
- package/package.json +10 -2
- package/queries/folds.scm +6 -1
- package/queries/highlights.scm +1 -1
- package/queries/indents.scm +7 -0
- package/queries/injections.scm +4 -0
- package/queries/locals.scm +10 -0
package/.gitattributes
CHANGED
package/.github/workflows/ci.yml
CHANGED
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 = "1.0.
|
|
5
|
-
authors = [
|
|
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
|
+
[](https://github.com/amaanq/tree-sitter-kdl/workflows/CI/badge.svg)
|
|
4
|
+
[](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
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:
|
|
70
|
+
extras: $ => [$.multi_line_comment],
|
|
61
71
|
|
|
62
|
-
externals:
|
|
72
|
+
externals: $ => [$._eof],
|
|
63
73
|
|
|
64
|
-
word:
|
|
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:
|
|
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:
|
|
101
|
-
_node_field_comment:
|
|
102
|
-
_node_field:
|
|
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:
|
|
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:
|
|
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:
|
|
167
|
+
keyword: $ => choice($.boolean, 'null'),
|
|
159
168
|
// type annotations
|
|
160
169
|
annotation_type: () => choice(...ANNOTATION_BUILTINS),
|
|
161
170
|
// prop := identifier '=' value
|
|
162
|
-
prop:
|
|
171
|
+
prop: $ => seq($.identifier, '=', $.value),
|
|
163
172
|
// value := type? (string | number | keyword)
|
|
164
|
-
value:
|
|
173
|
+
value: $ => seq(optional($.type), choice($.string, $.number, $.keyword)),
|
|
165
174
|
// type := '(' identifier ')'
|
|
166
|
-
type:
|
|
175
|
+
type: $ => seq('(', choice($.identifier, $.annotation_type), ')'),
|
|
167
176
|
|
|
168
177
|
// String
|
|
169
178
|
// string := raw-string | escaped-string
|
|
170
|
-
string:
|
|
179
|
+
string: $ => choice($._raw_string, $._escaped_string),
|
|
171
180
|
// escaped-string := '"' character* '"'
|
|
172
|
-
_escaped_string:
|
|
181
|
+
_escaped_string: $ => seq('"', alias(repeat(choice($.escape, /[^"]/)), $.string_fragment), '"'),
|
|
173
182
|
// character := '\' escape | [^\"]
|
|
174
|
-
_character:
|
|
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:
|
|
191
|
+
// raw_string: $ => seq('r', $._raw_string_hash),
|
|
183
192
|
// // raw-string-hash := '#' raw-string-hash '#' | raw-string-quotes
|
|
184
|
-
// _raw_string_hash:
|
|
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:
|
|
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:
|
|
220
|
+
_exponent: $ => seq(choice('e', 'E'), optional($._sign), $._integer),
|
|
213
221
|
// integer := digit (digit | '_')*
|
|
214
|
-
_integer:
|
|
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:
|
|
229
|
+
_hex: $ => seq(optional($._sign), '0x', $._hex_digit, repeat(choice($._hex_digit, '_'))),
|
|
222
230
|
// octal := sign? '0o' [0-7] [0-7_]*
|
|
223
|
-
_octal:
|
|
231
|
+
_octal: $ => seq(optional($._sign), '0o', /[0-7]/, repeat(choice(/[0-7]/, '_'))),
|
|
224
232
|
// binary := sign? '0b' ('0' | '1') ('0' | '1' | '_')*
|
|
225
|
-
_binary:
|
|
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:
|
|
239
|
+
_escline: $ => seq('\\', repeat($._ws), choice($.single_line_comment, $._newline)),
|
|
232
240
|
|
|
233
241
|
// linespace := newline | ws | single-line-comment
|
|
234
|
-
_linespace:
|
|
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:
|
|
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,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tree-sitter-kdl",
|
|
3
|
-
"version": "
|
|
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
11
|
"author": "Amaan Qureshi <amaanq12@gmail.com>",
|
|
12
|
+
"contributors": [
|
|
13
|
+
"Andrew Hlynskyi <ahlincq@gmail.com>"
|
|
14
|
+
],
|
|
11
15
|
"license": "MIT",
|
|
12
16
|
"bugs": {
|
|
13
17
|
"url": "https://github.com/amaanq/tree-sitter-kdl/issues"
|
|
14
18
|
},
|
|
19
|
+
"homepage": "https://github.com/amaanq/tree-sitter-kdl#readme",
|
|
15
20
|
"dependencies": {
|
|
16
21
|
"nan": "^2.17.0"
|
|
17
22
|
},
|
|
@@ -32,6 +37,9 @@
|
|
|
32
37
|
"scope": "source.kdl",
|
|
33
38
|
"file-types": [
|
|
34
39
|
"kdl"
|
|
40
|
+
],
|
|
41
|
+
"highlights": [
|
|
42
|
+
"queries/highlights.scm"
|
|
35
43
|
]
|
|
36
44
|
}
|
|
37
45
|
]
|
package/queries/folds.scm
CHANGED
package/queries/highlights.scm
CHANGED