@konomanoasa/tree-sitter-gitattributes 0.5.0 → 0.6.0
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/Cargo.toml +1 -1
- package/grammar.js +166 -60
- package/package.json +1 -1
- package/pyproject.toml +1 -1
- package/src/grammar.json +1343 -224
- package/src/node-types.json +258 -9
- package/src/parser.c +5031 -1247
- package/src/scanner.c +155 -53
- package/tree-sitter.json +1 -1
package/Cargo.toml
CHANGED
package/grammar.js
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
+
const missingKinds = (name) => [
|
|
2
|
+
[`missing_${name}`, "invalid_syntax", `missing_${name}`],
|
|
3
|
+
[`incomplete_${name}`, "incomplete_syntax", `missing_${name}`],
|
|
4
|
+
];
|
|
5
|
+
const issueKinds = [
|
|
6
|
+
...missingKinds("set_close"),
|
|
7
|
+
["invalid_encoding", "invalid_syntax", "invalid_encoding"],
|
|
8
|
+
["negative_pattern", "invalid_syntax", "negative_pattern"],
|
|
9
|
+
["ended_escape", "invalid_syntax", "incomplete_escape"],
|
|
10
|
+
["incomplete_escape", "incomplete_syntax", "incomplete_escape"],
|
|
11
|
+
["invalid_quoted_escape", "invalid_syntax", "invalid_quoted_escape"],
|
|
12
|
+
["ended_quoted_escape", "invalid_syntax", "incomplete_quoted_escape"],
|
|
13
|
+
["incomplete_quoted_escape", "incomplete_syntax", "incomplete_quoted_escape"],
|
|
14
|
+
...missingKinds("quote_close"),
|
|
15
|
+
[
|
|
16
|
+
"missing_attribute_separator",
|
|
17
|
+
"invalid_syntax",
|
|
18
|
+
"missing_attribute_separator",
|
|
19
|
+
],
|
|
20
|
+
...missingKinds("attribute_name"),
|
|
21
|
+
["invalid_name_character", "invalid_syntax", "invalid_name_character"],
|
|
22
|
+
["incomplete_name_character", "incomplete_syntax", "invalid_name_character"],
|
|
23
|
+
[
|
|
24
|
+
"invalid_name_escape",
|
|
25
|
+
"invalid_syntax",
|
|
26
|
+
"invalid_name_character",
|
|
27
|
+
"quoted_escape",
|
|
28
|
+
],
|
|
29
|
+
];
|
|
30
|
+
const quotedEscapeIssues = [
|
|
31
|
+
"invalid_quoted_escape",
|
|
32
|
+
"ended_quoted_escape",
|
|
33
|
+
"incomplete_quoted_escape",
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const issueRules = Object.fromEntries(
|
|
37
|
+
issueKinds.flatMap(([token, outcome, reason, child]) => [
|
|
38
|
+
...(child
|
|
39
|
+
? [[`_${token}_reason`, ($) => alias($[`_${token}`], $[child])]]
|
|
40
|
+
: []),
|
|
41
|
+
[
|
|
42
|
+
`_${token}_outcome`,
|
|
43
|
+
($) => alias($[child ? `_${token}_reason` : `_${token}`], $[reason]),
|
|
44
|
+
],
|
|
45
|
+
[`_${token}_issue`, ($) => alias($[`_${token}_outcome`], $[outcome])],
|
|
46
|
+
]),
|
|
47
|
+
);
|
|
48
|
+
const issue = ($, name) =>
|
|
49
|
+
field("issue", alias($[`_${name}_issue`], $.syntax_issue));
|
|
50
|
+
const issues = ($, ...names) => names.map((name) => issue($, name));
|
|
51
|
+
const missing = ($, name) =>
|
|
52
|
+
choice(issue($, `missing_${name}`), issue($, `incomplete_${name}`));
|
|
53
|
+
const heldPrefix = ($, ...names) =>
|
|
54
|
+
seq($._escape_prefix, choice(...issues($, ...names)));
|
|
55
|
+
const quoteClose = ($) =>
|
|
56
|
+
optional(choice(field("closing", $.quote_close), missing($, "quote_close")));
|
|
57
|
+
const attributeName = ($) =>
|
|
58
|
+
choice(field("name", $.attribute_name), missing($, "attribute_name"));
|
|
59
|
+
const globIssues = ($) => [
|
|
60
|
+
...issues(
|
|
61
|
+
$,
|
|
62
|
+
"invalid_encoding",
|
|
63
|
+
"ended_escape",
|
|
64
|
+
"incomplete_escape",
|
|
65
|
+
...quotedEscapeIssues,
|
|
66
|
+
),
|
|
67
|
+
heldPrefix($, "invalid_encoding", ...quotedEscapeIssues),
|
|
68
|
+
];
|
|
69
|
+
|
|
1
70
|
export default grammar({
|
|
2
71
|
name: "gitattributes",
|
|
3
72
|
externals: ($) => [
|
|
@@ -7,6 +76,7 @@ export default grammar({
|
|
|
7
76
|
$._rule_start,
|
|
8
77
|
$._macro_start,
|
|
9
78
|
$._eof,
|
|
79
|
+
$.line_ending,
|
|
10
80
|
$._layout,
|
|
11
81
|
$._separator,
|
|
12
82
|
$._attribute_start,
|
|
@@ -35,6 +105,7 @@ export default grammar({
|
|
|
35
105
|
$.path_separator,
|
|
36
106
|
$.escape,
|
|
37
107
|
$.quoted_escape,
|
|
108
|
+
$._escape_prefix,
|
|
38
109
|
$.set_open,
|
|
39
110
|
$.set_negation,
|
|
40
111
|
$.set_text,
|
|
@@ -47,52 +118,59 @@ export default grammar({
|
|
|
47
118
|
$._class_open,
|
|
48
119
|
$.class_name,
|
|
49
120
|
$._class_close,
|
|
121
|
+
...issueKinds.map(([name]) => $[`_${name}`]),
|
|
50
122
|
$._error_sentinel,
|
|
51
123
|
],
|
|
52
|
-
extras: () => [],
|
|
124
|
+
extras: ($) => [$._unmatchable],
|
|
53
125
|
rules: {
|
|
54
|
-
document: ($) =>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
126
|
+
document: ($) =>
|
|
127
|
+
repeat(
|
|
128
|
+
seq(
|
|
129
|
+
$._line_start,
|
|
130
|
+
choice($.blank_line, $.comment, $.attribute_rule, $.macro_definition),
|
|
131
|
+
),
|
|
59
132
|
),
|
|
60
|
-
|
|
133
|
+
_unmatchable: () => token(seq(/[\s\S]/, /[^\s\S]/)),
|
|
61
134
|
_end: ($) => seq(optional($._layout), choice($.line_ending, $._eof)),
|
|
62
135
|
blank_line: ($) => seq($._blank_start, $._end),
|
|
63
136
|
comment: ($) =>
|
|
64
|
-
seq(
|
|
137
|
+
seq(
|
|
138
|
+
$._comment_start,
|
|
139
|
+
$.comment_marker,
|
|
140
|
+
repeat(choice($.comment_text, issue($, "invalid_encoding"))),
|
|
141
|
+
$._end,
|
|
142
|
+
),
|
|
65
143
|
attribute_rule: ($) =>
|
|
66
144
|
seq(
|
|
67
145
|
$._rule_start,
|
|
68
146
|
field("pattern", $.pattern),
|
|
69
|
-
|
|
147
|
+
optional($._attributes),
|
|
70
148
|
$._end,
|
|
71
149
|
),
|
|
72
150
|
macro_definition: ($) =>
|
|
73
151
|
seq(
|
|
74
152
|
$._macro_start,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
field("closing", $.quote_close),
|
|
81
|
-
),
|
|
82
|
-
),
|
|
83
|
-
repeat($._attribute),
|
|
153
|
+
optional(field("opening", $.quote_open)),
|
|
154
|
+
field("marker", $.macro_marker),
|
|
155
|
+
attributeName($),
|
|
156
|
+
quoteClose($),
|
|
157
|
+
optional($._attributes),
|
|
84
158
|
$._end,
|
|
85
159
|
),
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
160
|
+
_attributes: ($) =>
|
|
161
|
+
repeat1(
|
|
162
|
+
seq(
|
|
163
|
+
choice($._separator, issue($, "missing_attribute_separator")),
|
|
164
|
+
$.attribute,
|
|
165
|
+
),
|
|
166
|
+
),
|
|
89
167
|
attribute: ($) =>
|
|
90
168
|
seq(
|
|
91
169
|
$._attribute_start,
|
|
92
170
|
optional(
|
|
93
171
|
field("modifier", choice($.unset_marker, $.unspecified_marker)),
|
|
94
172
|
),
|
|
95
|
-
|
|
173
|
+
attributeName($),
|
|
96
174
|
optional(
|
|
97
175
|
seq(
|
|
98
176
|
field("operator", $.assignment_operator),
|
|
@@ -104,56 +182,73 @@ export default grammar({
|
|
|
104
182
|
attribute_name: ($) =>
|
|
105
183
|
seq(
|
|
106
184
|
$._name_start,
|
|
107
|
-
repeat1(
|
|
185
|
+
repeat1(
|
|
186
|
+
choice(
|
|
187
|
+
$.name_text,
|
|
188
|
+
$.quoted_escape,
|
|
189
|
+
...issues(
|
|
190
|
+
$,
|
|
191
|
+
"invalid_encoding",
|
|
192
|
+
"invalid_name_character",
|
|
193
|
+
"incomplete_name_character",
|
|
194
|
+
"invalid_name_escape",
|
|
195
|
+
...quotedEscapeIssues,
|
|
196
|
+
),
|
|
197
|
+
heldPrefix($, "invalid_encoding"),
|
|
198
|
+
),
|
|
199
|
+
),
|
|
108
200
|
$._name_end,
|
|
109
201
|
),
|
|
110
|
-
attribute_value: ($) =>
|
|
111
|
-
pattern: ($) =>
|
|
202
|
+
attribute_value: ($) =>
|
|
112
203
|
seq(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
field("opening", $.quote_open),
|
|
117
|
-
repeat($._glob),
|
|
118
|
-
field("closing", $.quote_close),
|
|
119
|
-
),
|
|
120
|
-
),
|
|
121
|
-
$._pattern_end,
|
|
204
|
+
$._value_start,
|
|
205
|
+
repeat1(choice($.value_text, issue($, "invalid_encoding"))),
|
|
206
|
+
$._value_end,
|
|
122
207
|
),
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
$.
|
|
126
|
-
|
|
127
|
-
$._glob_start,
|
|
208
|
+
pattern: ($) =>
|
|
209
|
+
seq(
|
|
210
|
+
optional(field("opening", $.quote_open)),
|
|
211
|
+
repeat(
|
|
128
212
|
choice(
|
|
129
|
-
$.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
213
|
+
$.glob_literal,
|
|
214
|
+
seq(
|
|
215
|
+
$._glob_start,
|
|
216
|
+
choice(
|
|
217
|
+
$.wildcard,
|
|
218
|
+
$.recursive_wildcard,
|
|
219
|
+
$.single_character,
|
|
220
|
+
$.path_separator,
|
|
221
|
+
$.escape,
|
|
222
|
+
$.quoted_escape,
|
|
223
|
+
$.character_set,
|
|
224
|
+
issue($, "negative_pattern"),
|
|
225
|
+
...globIssues($),
|
|
226
|
+
),
|
|
227
|
+
),
|
|
136
228
|
),
|
|
137
229
|
),
|
|
230
|
+
quoteClose($),
|
|
231
|
+
$._pattern_end,
|
|
138
232
|
),
|
|
139
233
|
glob_literal: ($) => $._literal,
|
|
140
234
|
character_set: ($) =>
|
|
141
235
|
seq(
|
|
142
236
|
field("opening", $.set_open),
|
|
143
237
|
optional(field("negation", $.set_negation)),
|
|
144
|
-
repeat(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
238
|
+
repeat(
|
|
239
|
+
seq(
|
|
240
|
+
$._set_item_start,
|
|
241
|
+
choice(
|
|
242
|
+
$.set_text,
|
|
243
|
+
$.escape,
|
|
244
|
+
$.quoted_escape,
|
|
245
|
+
$.character_range,
|
|
246
|
+
$.character_class,
|
|
247
|
+
...globIssues($),
|
|
248
|
+
),
|
|
249
|
+
),
|
|
156
250
|
),
|
|
251
|
+
choice(field("closing", $.set_close), missing($, "set_close")),
|
|
157
252
|
),
|
|
158
253
|
character_range: ($) =>
|
|
159
254
|
seq(
|
|
@@ -167,10 +262,21 @@ export default grammar({
|
|
|
167
262
|
seq(
|
|
168
263
|
alias($._compound_open, "["),
|
|
169
264
|
alias($._class_open, ":"),
|
|
170
|
-
repeat(
|
|
265
|
+
repeat(
|
|
266
|
+
choice(
|
|
267
|
+
field("name", choice($.class_name, $.quoted_escape)),
|
|
268
|
+
...issues(
|
|
269
|
+
$,
|
|
270
|
+
"invalid_encoding",
|
|
271
|
+
"invalid_quoted_escape",
|
|
272
|
+
"ended_quoted_escape",
|
|
273
|
+
),
|
|
274
|
+
heldPrefix($, "invalid_encoding"),
|
|
275
|
+
),
|
|
276
|
+
),
|
|
171
277
|
alias($._class_close, ":"),
|
|
172
278
|
alias($._compound_close, "]"),
|
|
173
279
|
),
|
|
174
|
-
|
|
280
|
+
...issueRules,
|
|
175
281
|
},
|
|
176
282
|
});
|
package/package.json
CHANGED