@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "konomanoasa-tree-sitter-gitattributes"
3
- version = "0.5.0"
3
+ version = "0.6.0"
4
4
  description = "Tree-sitter grammar for gitattributes."
5
5
  readme = "README.md"
6
6
  license = "MIT"
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: ($) => repeat($._line),
55
- _line: ($) =>
56
- seq(
57
- $._line_start,
58
- choice($.blank_line, $.comment, $.attribute_rule, $.macro_definition),
126
+ document: ($) =>
127
+ repeat(
128
+ seq(
129
+ $._line_start,
130
+ choice($.blank_line, $.comment, $.attribute_rule, $.macro_definition),
131
+ ),
59
132
  ),
60
- line_ending: () => /\r?\n/,
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($._comment_start, $.comment_marker, optional($.comment_text), $._end),
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
- repeat($._attribute),
147
+ optional($._attributes),
70
148
  $._end,
71
149
  ),
72
150
  macro_definition: ($) =>
73
151
  seq(
74
152
  $._macro_start,
75
- choice(
76
- $._macro_name,
77
- seq(
78
- field("opening", $.quote_open),
79
- $._macro_name,
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
- _macro_name: ($) =>
87
- seq(field("marker", $.macro_marker), field("name", $.attribute_name)),
88
- _attribute: ($) => seq($._separator, $.attribute),
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
- field("name", $.attribute_name),
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(choice($.name_text, $.quoted_escape)),
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: ($) => seq($._value_start, $.value_text, $._value_end),
111
- pattern: ($) =>
202
+ attribute_value: ($) =>
112
203
  seq(
113
- choice(
114
- repeat1($._glob),
115
- seq(
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
- _glob: ($) =>
124
- choice(
125
- $.glob_literal,
126
- seq(
127
- $._glob_start,
208
+ pattern: ($) =>
209
+ seq(
210
+ optional(field("opening", $.quote_open)),
211
+ repeat(
128
212
  choice(
129
- $.wildcard,
130
- $.recursive_wildcard,
131
- $.single_character,
132
- $.path_separator,
133
- $.escape,
134
- $.quoted_escape,
135
- $.character_set,
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($._set_item),
145
- field("closing", $.set_close),
146
- ),
147
- _set_item: ($) =>
148
- seq(
149
- $._set_item_start,
150
- choice(
151
- $.set_text,
152
- $.escape,
153
- $.quoted_escape,
154
- $.character_range,
155
- $.character_class,
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($._class_piece),
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
- _class_piece: ($) => field("name", choice($.class_name, $.quoted_escape)),
280
+ ...issueRules,
175
281
  },
176
282
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konomanoasa/tree-sitter-gitattributes",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Tree-sitter grammar for gitattributes.",
5
5
  "license": "MIT",
6
6
  "repository": "git+https://github.com/konomanoasa/tree-sitter-gitattributes.git",
package/pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "konomanoasa-tree-sitter-gitattributes"
3
- version = "0.5.0"
3
+ version = "0.6.0"
4
4
  description = "Tree-sitter grammar for gitattributes."
5
5
  readme = "README.md"
6
6
  license = "MIT"