@tbela99/css-parser 0.7.1 → 0.9.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.
Files changed (90) hide show
  1. package/.editorconfig +484 -0
  2. package/README.md +140 -84
  3. package/dist/index-umd-web.js +8461 -51655
  4. package/dist/index.cjs +8437 -51636
  5. package/dist/index.d.ts +220 -68
  6. package/dist/lib/ast/expand.js +46 -9
  7. package/dist/lib/ast/features/calc.js +76 -12
  8. package/dist/lib/ast/features/inlinecssvariables.js +6 -1
  9. package/dist/lib/ast/features/prefix.js +17 -9
  10. package/dist/lib/ast/features/shorthand.js +1 -0
  11. package/dist/lib/ast/math/expression.js +299 -11
  12. package/dist/lib/ast/math/math.js +7 -1
  13. package/dist/lib/ast/minify.js +30 -16
  14. package/dist/lib/ast/types.js +59 -49
  15. package/dist/lib/ast/walk.js +92 -18
  16. package/dist/lib/parser/declaration/list.js +1 -0
  17. package/dist/lib/parser/declaration/map.js +60 -52
  18. package/dist/lib/parser/declaration/set.js +1 -12
  19. package/dist/lib/parser/parse.js +371 -119
  20. package/dist/lib/parser/tokenize.js +31 -6
  21. package/dist/lib/parser/utils/declaration.js +2 -2
  22. package/dist/lib/parser/utils/type.js +6 -6
  23. package/dist/lib/renderer/color/a98rgb.js +1 -0
  24. package/dist/lib/renderer/color/color.js +1 -0
  25. package/dist/lib/renderer/color/colormix.js +1 -0
  26. package/dist/lib/renderer/color/hex.js +2 -1
  27. package/dist/lib/renderer/color/hsl.js +2 -1
  28. package/dist/lib/renderer/color/hwb.js +3 -2
  29. package/dist/lib/renderer/color/lab.js +2 -1
  30. package/dist/lib/renderer/color/lch.js +2 -1
  31. package/dist/lib/renderer/color/oklab.js +3 -2
  32. package/dist/lib/renderer/color/oklch.js +2 -1
  33. package/dist/lib/renderer/color/p3.js +2 -1
  34. package/dist/lib/renderer/color/prophotoRgb.js +56 -0
  35. package/dist/lib/renderer/color/prophotorgb.js +1 -1
  36. package/dist/lib/renderer/color/rec2020.js +1 -0
  37. package/dist/lib/renderer/color/relativecolor.js +52 -28
  38. package/dist/lib/renderer/color/rgb.js +2 -1
  39. package/dist/lib/renderer/color/srgb.js +3 -2
  40. package/dist/lib/renderer/color/utils/components.js +1 -0
  41. package/dist/lib/renderer/color/utils/constants.js +2 -1
  42. package/dist/lib/renderer/color/xyz.js +2 -1
  43. package/dist/lib/renderer/color/xyzd50.js +1 -0
  44. package/dist/lib/renderer/render.js +62 -12
  45. package/dist/lib/syntax/syntax.js +362 -4
  46. package/dist/lib/validation/at-rules/container.js +353 -0
  47. package/dist/lib/validation/at-rules/counter-style.js +78 -0
  48. package/dist/lib/validation/at-rules/custom-media.js +52 -0
  49. package/dist/lib/validation/at-rules/document.js +114 -0
  50. package/dist/lib/validation/at-rules/else.js +5 -0
  51. package/dist/lib/validation/at-rules/font-feature-values.js +52 -0
  52. package/dist/lib/validation/at-rules/import.js +199 -0
  53. package/dist/lib/validation/at-rules/keyframes.js +70 -0
  54. package/dist/lib/validation/at-rules/layer.js +30 -0
  55. package/dist/lib/validation/at-rules/media.js +254 -0
  56. package/dist/lib/validation/at-rules/namespace.js +85 -0
  57. package/dist/lib/validation/at-rules/page-margin-box.js +56 -0
  58. package/dist/lib/validation/at-rules/page.js +88 -0
  59. package/dist/lib/validation/at-rules/supports.js +262 -0
  60. package/dist/lib/validation/at-rules/when.js +178 -0
  61. package/dist/lib/validation/atrule.js +187 -0
  62. package/dist/lib/validation/config.js +35 -2
  63. package/dist/lib/validation/config.json.js +1683 -50905
  64. package/dist/lib/validation/declaration.js +102 -0
  65. package/dist/lib/validation/parser/parse.js +1137 -7
  66. package/dist/lib/validation/parser/types.js +28 -12
  67. package/dist/lib/validation/selector.js +26 -444
  68. package/dist/lib/validation/syntax.js +1475 -0
  69. package/dist/lib/validation/syntaxes/complex-selector-list.js +45 -0
  70. package/dist/lib/validation/syntaxes/complex-selector.js +53 -0
  71. package/dist/lib/validation/syntaxes/compound-selector.js +226 -0
  72. package/dist/lib/validation/syntaxes/family-name.js +91 -0
  73. package/dist/lib/validation/syntaxes/image.js +29 -0
  74. package/dist/lib/validation/syntaxes/keyframe-block-list.js +27 -0
  75. package/dist/lib/validation/syntaxes/keyframe-selector.js +137 -0
  76. package/dist/lib/validation/syntaxes/layer-name.js +67 -0
  77. package/dist/lib/validation/syntaxes/relative-selector-list.js +57 -0
  78. package/dist/lib/validation/syntaxes/relative-selector.js +36 -0
  79. package/dist/lib/validation/syntaxes/selector-list.js +5 -0
  80. package/dist/lib/validation/syntaxes/selector.js +5 -0
  81. package/dist/lib/validation/syntaxes/url.js +75 -0
  82. package/dist/lib/validation/utils/list.js +24 -0
  83. package/dist/lib/validation/utils/whitespace.js +22 -0
  84. package/dist/node/index.js +5 -5
  85. package/dist/web/index.js +5 -1
  86. package/dist/web/load.js +1 -0
  87. package/package.json +16 -14
  88. package/dist/lib/ast/utils/minifyfeature.js +0 -9
  89. package/dist/lib/iterable/weakset.js +0 -58
  90. package/dist/lib/parser/utils/syntax.js +0 -450
@@ -1,12 +1,21 @@
1
1
  import { ValidationTokenEnum } from './types.js';
2
- import '../../ast/types.js';
3
- import '../../ast/minify.js';
4
- import '../../parser/parse.js';
5
- import '../../parser/utils/config.js';
6
- import '../../renderer/color/utils/constants.js';
7
- import '../../renderer/sourcemap/lib/encode.js';
2
+ import { isIdent, isPseudo } from '../../syntax/syntax.js';
8
3
 
9
- [
4
+ var WalkValidationTokenEnum;
5
+ (function (WalkValidationTokenEnum) {
6
+ WalkValidationTokenEnum[WalkValidationTokenEnum["IgnoreChildren"] = 0] = "IgnoreChildren";
7
+ WalkValidationTokenEnum[WalkValidationTokenEnum["IgnoreNode"] = 1] = "IgnoreNode";
8
+ WalkValidationTokenEnum[WalkValidationTokenEnum["IgnoreAll"] = 2] = "IgnoreAll";
9
+ })(WalkValidationTokenEnum || (WalkValidationTokenEnum = {}));
10
+ var WalkValidationTokenKeyTypeEnum;
11
+ (function (WalkValidationTokenKeyTypeEnum) {
12
+ WalkValidationTokenKeyTypeEnum["Array"] = "array";
13
+ WalkValidationTokenKeyTypeEnum["Children"] = "chi";
14
+ WalkValidationTokenKeyTypeEnum["Left"] = "l";
15
+ WalkValidationTokenKeyTypeEnum["Right"] = "r";
16
+ WalkValidationTokenKeyTypeEnum["Prelude"] = "prelude";
17
+ })(WalkValidationTokenKeyTypeEnum || (WalkValidationTokenKeyTypeEnum = {}));
18
+ const skipped = [
10
19
  ValidationTokenEnum.Star,
11
20
  ValidationTokenEnum.HashMark,
12
21
  ValidationTokenEnum.AtLeastOnce,
@@ -14,3 +23,1124 @@ import '../../renderer/sourcemap/lib/encode.js';
14
23
  ValidationTokenEnum.QuestionMark,
15
24
  ValidationTokenEnum.OpenCurlyBrace
16
25
  ];
26
+ const objectProperties = {
27
+ enumerable: false,
28
+ writable: true,
29
+ configurable: true
30
+ };
31
+ // syntaxes: keyword | <'property'> | <function>
32
+ // "none | [ [<dashed-ident> || <try-tactic>] | inset-area( <'inset-area'> ) ]#"
33
+ // ""
34
+ // : "<outline-radius>{1,4} [ / <outline-radius>{1,4} ]?
35
+ // ""
36
+ // false | true
37
+ // [ <mask-reference> || <position> [ / <bg-size> ]? || <repeat-style> || [ <box> | border | padding | content | text ] || [ <box> | border | padding | content ] ]#
38
+ // false | true | green | pipe
39
+ // keyword | <'property'> | <function>
40
+ // [<dashed-ident> || <try-tactic>]
41
+ // [ <mask-reference> || <position> [ / <bg-size> ]? || <repeat-style> || [ <box> | border | padding | content | text ] || [ <box> | border | padding | content ] ]#
42
+ // none | [ [<dashed-ident> || <try-tactic>] | inset-area( <'inset-area'> ) ]
43
+ function* tokenize(syntax, position = { ind: 0, lin: 1, col: 0 }, currentPosition = {
44
+ ind: -1,
45
+ lin: 1,
46
+ col: 0
47
+ }) {
48
+ let i = -1;
49
+ let buffer = '';
50
+ while (++i < syntax.length) {
51
+ let chr = syntax.charAt(i);
52
+ move(currentPosition, chr);
53
+ switch (chr) {
54
+ case '\\':
55
+ if (buffer.length > 0) {
56
+ yield getTokenType(buffer, position, currentPosition);
57
+ buffer = '';
58
+ }
59
+ buffer += chr;
60
+ chr = syntax.charAt(++i);
61
+ buffer += chr;
62
+ move(currentPosition, chr);
63
+ break;
64
+ case ';':
65
+ if (buffer.length > 0) {
66
+ yield getTokenType(buffer, position, currentPosition);
67
+ buffer = '';
68
+ }
69
+ yield getTokenType(chr, position, currentPosition);
70
+ buffer = '';
71
+ break;
72
+ case ':':
73
+ if (isIdent(buffer)) {
74
+ yield Object.defineProperty({
75
+ typ: ValidationTokenEnum.DeclarationNameToken,
76
+ val: buffer
77
+ }, 'pos', { ...objectProperties, value: { ...position } });
78
+ buffer = '';
79
+ move(currentPosition, chr);
80
+ break;
81
+ }
82
+ buffer += chr;
83
+ break;
84
+ case '"':
85
+ case "'":
86
+ if (buffer.length > 0) {
87
+ yield getTokenType(buffer, position, currentPosition);
88
+ buffer = '';
89
+ }
90
+ buffer += chr;
91
+ while (i + 1 < syntax.length) {
92
+ chr = syntax.charAt(++i);
93
+ buffer += chr;
94
+ move(currentPosition, chr);
95
+ if (chr == '\\') {
96
+ chr = syntax.charAt(++i);
97
+ buffer += chr;
98
+ move(currentPosition, chr);
99
+ continue;
100
+ }
101
+ if (chr == buffer.charAt(0)) {
102
+ break;
103
+ }
104
+ }
105
+ // check for type "<property>" or "<'property'>"
106
+ if (buffer.at(1) == '<' && buffer.at(-2) == '>') {
107
+ yield Object.defineProperty({
108
+ typ: ValidationTokenEnum.Character,
109
+ val: chr
110
+ }, 'pos', { ...objectProperties, value: { ...position } });
111
+ position = { ...currentPosition };
112
+ move(currentPosition, chr);
113
+ buffer = buffer.slice(1, -1);
114
+ yield* tokenize(buffer, position, currentPosition);
115
+ yield Object.defineProperty({
116
+ typ: ValidationTokenEnum.Character,
117
+ val: chr
118
+ }, 'pos', { ...objectProperties, value: { ...position } });
119
+ position = { ...currentPosition };
120
+ move(currentPosition, chr);
121
+ buffer = '';
122
+ break;
123
+ }
124
+ yield getTokenType(buffer, position, currentPosition);
125
+ buffer = '';
126
+ break;
127
+ case '<':
128
+ buffer += chr;
129
+ while (i + 1 < syntax.length) {
130
+ chr = syntax.charAt(++i);
131
+ buffer += chr;
132
+ move(currentPosition, chr);
133
+ if (chr == '>') {
134
+ break;
135
+ }
136
+ }
137
+ yield getTokenType(buffer, position, currentPosition);
138
+ buffer = '';
139
+ break;
140
+ case ' ':
141
+ case '\t':
142
+ case '\n':
143
+ case '\r':
144
+ case '\f':
145
+ case '|':
146
+ case '#':
147
+ case '+':
148
+ case ',':
149
+ case '[':
150
+ case ']':
151
+ case '(':
152
+ case ')':
153
+ case '*':
154
+ case '{':
155
+ case '}':
156
+ case '?':
157
+ case '!':
158
+ case '&':
159
+ if (buffer.length > 0) {
160
+ yield getTokenType(buffer, position, currentPosition);
161
+ }
162
+ if (chr == '|' || chr == '&') {
163
+ if (syntax.charAt(i + 1) == chr) {
164
+ move(currentPosition, chr);
165
+ yield getTokenType(chr + chr, position, currentPosition);
166
+ i++;
167
+ buffer = '';
168
+ continue;
169
+ }
170
+ }
171
+ Object.assign(position, currentPosition);
172
+ yield getTokenType(chr, position, currentPosition);
173
+ buffer = '';
174
+ break;
175
+ default:
176
+ buffer += chr;
177
+ break;
178
+ }
179
+ }
180
+ if (buffer.length > 0) {
181
+ yield getTokenType(buffer, position, currentPosition);
182
+ }
183
+ }
184
+ function columnCallback(token, parent, key) {
185
+ if (key == WalkValidationTokenKeyTypeEnum.Prelude) {
186
+ return WalkValidationTokenEnum.IgnoreAll;
187
+ }
188
+ if (token.typ == ValidationTokenEnum.ColumnToken || token.typ == ValidationTokenEnum.Whitespace) {
189
+ return WalkValidationTokenEnum.IgnoreNode;
190
+ }
191
+ return WalkValidationTokenEnum.IgnoreChildren;
192
+ }
193
+ function toColumnArray(ast, parent) {
194
+ const result = new Map;
195
+ // @ts-ignore
196
+ for (const { token } of walkValidationToken(ast, null, columnCallback)) {
197
+ result.set(JSON.stringify(token), token);
198
+ }
199
+ const node = {
200
+ typ: ValidationTokenEnum.ColumnArrayToken,
201
+ chi: [...result.values()]
202
+ };
203
+ if (parent != null) {
204
+ replaceNode(parent, ast, node);
205
+ }
206
+ return node;
207
+ }
208
+ function replaceNode(parent, target, node) {
209
+ if ('l' in parent && parent.l == target) {
210
+ parent.l = node;
211
+ }
212
+ if ('r' in parent && parent.r == target) {
213
+ parent.r = node;
214
+ }
215
+ if ('chi' in parent) {
216
+ // @ts-ignore
217
+ for (let i = 0; i < parent.chi.length; i++) {
218
+ // @ts-ignore
219
+ if (parent.chi[i] == target) {
220
+ // @ts-ignore
221
+ parent.chi[i] = node;
222
+ break;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ function transform(context) {
228
+ for (const { token, parent } of walkValidationToken(context)) {
229
+ switch (token.typ) {
230
+ case ValidationTokenEnum.ColumnToken:
231
+ toColumnArray(token, parent);
232
+ break;
233
+ }
234
+ }
235
+ return context;
236
+ }
237
+ function parseSyntax(syntax) {
238
+ const root = Object.defineProperty({
239
+ typ: ValidationTokenEnum.Root,
240
+ chi: []
241
+ }, 'pos', { ...objectProperties, value: { ind: 0, lin: 1, col: 0 } });
242
+ // return minify(doParseSyntax(syntaxes, tokenize(syntaxes), root)) as ValidationRootToken;
243
+ return minify(transform(doParseSyntax(syntax, tokenize(syntax), root)));
244
+ }
245
+ function matchParens(syntax, iterator) {
246
+ let item;
247
+ let func = null;
248
+ let items = [];
249
+ let match = 0;
250
+ while ((item = iterator.next()) && !item.done) {
251
+ switch (item.value.typ) {
252
+ case ValidationTokenEnum.OpenParenthesis:
253
+ if (match > 0) {
254
+ func.chi.push(item.value);
255
+ }
256
+ else if (match == 0) {
257
+ func = items.at(-1);
258
+ if (func == null) {
259
+ func = Object.defineProperty({
260
+ typ: ValidationTokenEnum.Parens,
261
+ val: '',
262
+ chi: []
263
+ }, 'pos', { ...objectProperties, value: item.value.pos });
264
+ items.push(func);
265
+ }
266
+ else {
267
+ // @ts-ignore
268
+ func.typ = func.typ == ValidationTokenEnum.PseudoClassToken ? ValidationTokenEnum.PseudoClassFunctionToken : ValidationTokenEnum.Function;
269
+ func.chi = [];
270
+ }
271
+ }
272
+ match++;
273
+ break;
274
+ case ValidationTokenEnum.CloseParenthesis:
275
+ match--;
276
+ if (match > 0) {
277
+ func.chi.push(item.value);
278
+ }
279
+ break;
280
+ default:
281
+ if (match > 0) {
282
+ func.chi.push(item.value);
283
+ }
284
+ else {
285
+ items.push(item.value);
286
+ }
287
+ break;
288
+ }
289
+ }
290
+ for (const item of items) {
291
+ if ('chi' in item) {
292
+ // @ts-ignore
293
+ item.chi = matchParens(syntax, item.chi[Symbol.iterator]());
294
+ }
295
+ }
296
+ return items;
297
+ }
298
+ function matchBrackets(syntax, iterator) {
299
+ let item;
300
+ let bracket = null;
301
+ let items = [];
302
+ let match = 0;
303
+ while ((item = iterator.next()) && !item.done) {
304
+ switch (item.value.typ) {
305
+ case ValidationTokenEnum.OpenBracket:
306
+ if (match > 0) {
307
+ bracket.chi.push(item.value);
308
+ }
309
+ else if (match == 0) {
310
+ bracket = Object.defineProperty({
311
+ typ: ValidationTokenEnum.Bracket,
312
+ chi: []
313
+ }, 'pos', { ...objectProperties, value: item.value.pos });
314
+ items.push(bracket);
315
+ }
316
+ match++;
317
+ break;
318
+ case ValidationTokenEnum.CloseBracket:
319
+ match--;
320
+ if (match > 0) {
321
+ bracket.chi.push(item.value);
322
+ }
323
+ break;
324
+ default:
325
+ if (match > 0) {
326
+ bracket.chi.push(item.value);
327
+ }
328
+ else {
329
+ items.push(item.value);
330
+ }
331
+ break;
332
+ }
333
+ }
334
+ for (const item of items) {
335
+ if ('chi' in item) {
336
+ // @ts-ignore
337
+ item.chi = matchBrackets(syntax, item.chi[Symbol.iterator]());
338
+ }
339
+ }
340
+ return items;
341
+ }
342
+ function matchCurlBraces(syntax, iterator) {
343
+ let item;
344
+ let block = null;
345
+ let items = [];
346
+ let match = 0;
347
+ while ((item = iterator.next()) && !item.done) {
348
+ switch (item.value.typ) {
349
+ case ValidationTokenEnum.OpenCurlyBrace:
350
+ if (match > 0) {
351
+ block.chi.push(item.value);
352
+ }
353
+ else if (match == 0) {
354
+ block = Object.defineProperty({
355
+ typ: ValidationTokenEnum.Block,
356
+ chi: []
357
+ }, 'pos', { ...objectProperties, value: item.value.pos });
358
+ items.push(block);
359
+ }
360
+ match++;
361
+ break;
362
+ case ValidationTokenEnum.CloseCurlyBrace:
363
+ match--;
364
+ if (match > 0) {
365
+ block.chi.push(item.value);
366
+ }
367
+ break;
368
+ default:
369
+ if (match > 0) {
370
+ block.chi.push(item.value);
371
+ }
372
+ else {
373
+ items.push(item.value);
374
+ }
375
+ break;
376
+ }
377
+ }
378
+ let it;
379
+ let i = 0;
380
+ for (; i < items.length; i++) {
381
+ it = items[i];
382
+ if (i > 0 && it.typ == ValidationTokenEnum.Block && it.chi[0]?.typ == ValidationTokenEnum.Number) {
383
+ items[i - 1].occurence = {
384
+ min: +it.chi[0].val,
385
+ max: +(it.chi[2] ?? it.chi[0]).val
386
+ };
387
+ items.splice(i--, 1);
388
+ continue;
389
+ }
390
+ if ('chi' in it) {
391
+ // @ts-ignore
392
+ it.chi = matchBrackets(syntax, it.chi[Symbol.iterator]());
393
+ }
394
+ }
395
+ return items;
396
+ }
397
+ function matchAtRule(syntax, iterator) {
398
+ const children = [];
399
+ let item;
400
+ let token = null;
401
+ while ((item = iterator.next()) && !item.done) {
402
+ if (item.value.typ == ValidationTokenEnum.AtRule || item.value.typ == ValidationTokenEnum.AtRuleDefinition) {
403
+ token = Object.defineProperty({
404
+ ...item.value,
405
+ typ: ValidationTokenEnum.AtRuleDefinition
406
+ }, 'pos', { ...objectProperties, value: item.value.pos });
407
+ children.push(token);
408
+ item = iterator.next();
409
+ if (item.done) {
410
+ // @ts-ignore
411
+ token.typ = ValidationTokenEnum.AtRule;
412
+ break;
413
+ }
414
+ if (item.value.typ != ValidationTokenEnum.Whitespace) {
415
+ console.error('unexpected token', item.value);
416
+ }
417
+ item = iterator.next();
418
+ if (item.done) {
419
+ break;
420
+ }
421
+ if (item.value.typ == ValidationTokenEnum.Pipe) {
422
+ // @ts-ignore
423
+ token.typ = ValidationTokenEnum.AtRule;
424
+ children.push(item.value);
425
+ continue;
426
+ }
427
+ if (item.value.typ != ValidationTokenEnum.OpenCurlyBrace) {
428
+ if (!('prelude' in token)) {
429
+ token.prelude = [];
430
+ }
431
+ token.prelude.push(item.value);
432
+ }
433
+ let braces = 0;
434
+ let previousItem = item.value;
435
+ while ((item = iterator.next()) && !item.done) {
436
+ if (item.value.typ == ValidationTokenEnum.DeclarationNameToken) {
437
+ iterator.next();
438
+ const t = Object.defineProperty({
439
+ typ: ValidationTokenEnum.DeclarationDefinitionToken,
440
+ nam: item.value.val,
441
+ val: iterator.next().value
442
+ }, 'pos', {
443
+ ...objectProperties,
444
+ value: item.value.pos
445
+ });
446
+ if (braces > 0) {
447
+ token.chi.push(t);
448
+ }
449
+ else {
450
+ token.prelude.push(t);
451
+ }
452
+ previousItem = t;
453
+ continue;
454
+ }
455
+ if (item.value.typ == ValidationTokenEnum.OpenCurlyBrace) {
456
+ previousItem = item.value;
457
+ continue;
458
+ }
459
+ if (item.value.typ == ValidationTokenEnum.Whitespace && previousItem?.typ == ValidationTokenEnum.OpenCurlyBrace) {
460
+ braces++;
461
+ if (braces == 1) {
462
+ previousItem = item.value;
463
+ continue;
464
+ }
465
+ }
466
+ if (previousItem?.typ == ValidationTokenEnum.Whitespace && item.value.typ == ValidationTokenEnum.CloseCurlyBrace) {
467
+ braces--;
468
+ if (braces == 0) {
469
+ break;
470
+ }
471
+ }
472
+ if (braces == 0) {
473
+ if (!('prelude' in token)) {
474
+ token.prelude = [];
475
+ }
476
+ token.prelude.push(item.value);
477
+ }
478
+ else {
479
+ if (!('chi' in token)) {
480
+ token.chi = [];
481
+ }
482
+ token.chi.push(item.value);
483
+ }
484
+ previousItem = item.value;
485
+ }
486
+ if ('prelude' in token) {
487
+ if (token?.prelude?.length == 1 && token.prelude[0].typ == ValidationTokenEnum.Whitespace) {
488
+ delete token.prelude;
489
+ }
490
+ else {
491
+ const t = { typ: ValidationTokenEnum.Root, chi: token.prelude };
492
+ doParseSyntax(syntax, t.chi[Symbol.iterator](), t);
493
+ token.prelude = t.chi;
494
+ minify(token.prelude);
495
+ }
496
+ }
497
+ // @ts-ignore
498
+ if (token?.chi?.length > 0) {
499
+ minify(doParseSyntax(syntax, token.chi[Symbol.iterator](), token));
500
+ }
501
+ }
502
+ else {
503
+ children.push(item.value);
504
+ }
505
+ }
506
+ return children;
507
+ }
508
+ function matchToken(syntax, iterator, validationToken) {
509
+ let children = [];
510
+ let item;
511
+ let token = null;
512
+ let i;
513
+ if (validationToken == ValidationTokenEnum.Ampersand) {
514
+ // @ts-ignore
515
+ children = [...iterator];
516
+ let offsetL;
517
+ let offsetR;
518
+ for (i = 0; i < children.length; i++) {
519
+ if (children[i].typ == ValidationTokenEnum.Ampersand) {
520
+ offsetR = i + 1;
521
+ offsetL = i - 1;
522
+ while (offsetR < children.length - 1 && children[offsetR].typ == ValidationTokenEnum.Whitespace) {
523
+ offsetR++;
524
+ }
525
+ while (offsetR + 1 < children.length && skipped.includes(children[offsetR + 1].typ)) {
526
+ offsetR++;
527
+ }
528
+ while (offsetL > 0 && (children[offsetL].typ == ValidationTokenEnum.Whitespace || skipped.includes(children[offsetL].typ))) {
529
+ offsetL--;
530
+ }
531
+ token = Object.defineProperty({
532
+ typ: ValidationTokenEnum.AmpersandToken,
533
+ l: children.slice(offsetL, i),
534
+ r: children.slice(i + 1, offsetR + 1)
535
+ }, 'pos', { ...objectProperties, value: children[i].pos });
536
+ i = offsetL;
537
+ children.splice(offsetL, offsetR - offsetL + 1, token);
538
+ }
539
+ else if ('chi' in children[i]) {
540
+ // @ts-ignore
541
+ children[i].chi = matchToken(syntax, children[i].chi[Symbol.iterator](), validationToken);
542
+ }
543
+ else if ('l' in children[i]) {
544
+ // @ts-ignore
545
+ children[i].l = matchToken(syntax, children[i].l[Symbol.iterator](), validationToken);
546
+ // @ts-ignore
547
+ children[i].r = matchToken(syntax, children[i].r[Symbol.iterator](), validationToken);
548
+ }
549
+ }
550
+ return children;
551
+ }
552
+ while ((item = iterator.next()) && !item.done) {
553
+ if (item.value.typ == validationToken) {
554
+ if (item.value.typ == ValidationTokenEnum.Pipe) {
555
+ token = Object.defineProperty({
556
+ typ: ValidationTokenEnum.PipeToken,
557
+ chi: [matchToken(syntax, children.slice()[Symbol.iterator](), validationToken)], //.concat(matchToken(syntaxes, children.slice()[Symbol.iterator]() as Iterator<ValidationTokenIteratorValue>, validationToken), matchToken(syntaxes, iterator, validationToken)),
558
+ // @ts-ignore
559
+ // l: matchToken(syntaxes, children.slice()[Symbol.iterator](), validationToken),
560
+ // r: matchToken(syntaxes, iterator, validationToken)
561
+ }, 'pos', {
562
+ ...objectProperties,
563
+ value: item.value.pos
564
+ });
565
+ children.length = 0;
566
+ while ((item = iterator.next()) && !item.done) {
567
+ if (item.value.typ == ValidationTokenEnum.Pipe) {
568
+ token.chi.push(matchToken(syntax, children.slice()[Symbol.iterator](), validationToken));
569
+ children.length = 0;
570
+ }
571
+ else {
572
+ children.push(item.value);
573
+ }
574
+ }
575
+ if (children.length > 0) {
576
+ token.chi.push(matchToken(syntax, children.slice()[Symbol.iterator](), validationToken));
577
+ }
578
+ token.chi.sort((a, b) => {
579
+ if (a.some((t) => t.isList)) {
580
+ return -1;
581
+ }
582
+ if (b.some((t) => t.isList)) {
583
+ return 1;
584
+ }
585
+ if (a.some((t) => t.occurence != null)) {
586
+ return -1;
587
+ }
588
+ if (b.some((t) => t.occurence != null)) {
589
+ return -1;
590
+ }
591
+ if (a.some((t) => t.isRepeatableGroup)) {
592
+ return -1;
593
+ }
594
+ if (b.some((t) => t.isRepeatableGroup)) {
595
+ return 1;
596
+ }
597
+ if (a.some((t) => t.isRepeatable)) {
598
+ return -1;
599
+ }
600
+ if (b.some((t) => t.isRepeatable)) {
601
+ return 1;
602
+ }
603
+ if (a.some((t) => t.isOptional)) {
604
+ return 1;
605
+ }
606
+ if (b.some((t) => t.isOptional)) {
607
+ return -1;
608
+ }
609
+ return 0;
610
+ });
611
+ children = [token];
612
+ }
613
+ else {
614
+ token = Object.defineProperty({
615
+ typ: ValidationTokenEnum.ColumnToken,
616
+ l: matchToken(syntax, children.slice()[Symbol.iterator](), validationToken),
617
+ r: matchToken(syntax, iterator, validationToken)
618
+ }, 'pos', {
619
+ ...objectProperties,
620
+ value: item.value.pos
621
+ });
622
+ }
623
+ children.length = 0;
624
+ children.push(token);
625
+ while ((item = iterator.next()) && !item.done) {
626
+ children.push(item.value);
627
+ if ('chi' in item.value) {
628
+ // @ts-ignore
629
+ item.value.chi = matchToken(syntax, item.value.chi[Symbol.iterator](), validationToken);
630
+ }
631
+ else if ('l' in item.value) {
632
+ // @ts-ignore
633
+ item.value.l = matchToken(syntax, item.value.l[Symbol.iterator](), validationToken);
634
+ // @ts-ignore
635
+ item.value.r = matchToken(syntax, item.value.r[Symbol.iterator](), validationToken);
636
+ }
637
+ }
638
+ // @ts-ignore
639
+ return children;
640
+ }
641
+ else {
642
+ children.push(item.value);
643
+ if ('chi' in item.value) {
644
+ // @ts-ignore
645
+ item.value.chi = matchToken(syntax, item.value.chi[Symbol.iterator](), validationToken);
646
+ }
647
+ else if ('l' in item.value) {
648
+ // @ts-ignore
649
+ item.value.l = matchToken(syntax, item.value.l[Symbol.iterator](), validationToken);
650
+ // @ts-ignore
651
+ item.value.r = matchToken(syntax, item.value.r[Symbol.iterator](), validationToken);
652
+ }
653
+ }
654
+ }
655
+ return children;
656
+ }
657
+ function parseTokens(syntax, iterator) {
658
+ const items = [];
659
+ let item;
660
+ let i;
661
+ while ((item = iterator.next()) && !item.done) {
662
+ if (Array.isArray(item.value)) {
663
+ // @ts-ignore
664
+ item.value = parseTokens(syntax, item.value[Symbol.iterator]());
665
+ }
666
+ switch (item.value.typ) {
667
+ case ValidationTokenEnum.Star:
668
+ case ValidationTokenEnum.HashMark:
669
+ case ValidationTokenEnum.AtLeastOnce:
670
+ case ValidationTokenEnum.Exclamation:
671
+ case ValidationTokenEnum.QuestionMark:
672
+ case ValidationTokenEnum.OpenCurlyBrace:
673
+ i = items.length;
674
+ while (i--) {
675
+ if (items[i].typ != ValidationTokenEnum.Whitespace) {
676
+ break;
677
+ }
678
+ }
679
+ if (item.value.typ == ValidationTokenEnum.Exclamation) {
680
+ items[i].isRepeatableGroup = true;
681
+ }
682
+ else if (item.value.typ == ValidationTokenEnum.QuestionMark) {
683
+ items[i].isOptional = true;
684
+ }
685
+ else if (item.value.typ == ValidationTokenEnum.Star) {
686
+ items[i].isRepeatable = true;
687
+ }
688
+ else if (item.value.typ == ValidationTokenEnum.AtLeastOnce) {
689
+ items[i].atLeastOnce = true;
690
+ }
691
+ else if (item.value.typ == ValidationTokenEnum.HashMark) {
692
+ items[i].isList = true;
693
+ }
694
+ else if (item.value.typ == ValidationTokenEnum.OpenCurlyBrace) {
695
+ items[i].occurence = {
696
+ min: 0,
697
+ max: 0
698
+ };
699
+ while ((item = iterator.next()) && !item.done) {
700
+ if (item.value.typ == ValidationTokenEnum.Number) {
701
+ // @ts-ignore
702
+ if (items[i].occurence.min == 0) {
703
+ // @ts-ignore
704
+ items[i].occurence.min = +item.value.val;
705
+ }
706
+ else {
707
+ // @ts-ignore
708
+ items[i].occurence.max = +item.value.val;
709
+ }
710
+ }
711
+ if (item.value.typ == ValidationTokenEnum.CloseCurlyBrace) {
712
+ break;
713
+ }
714
+ }
715
+ }
716
+ break;
717
+ case ValidationTokenEnum.Pipe:
718
+ item.value.chi = item.value.chi.map((t) => parseTokens(syntax, t[Symbol.iterator]()));
719
+ items.push(item.value);
720
+ break;
721
+ default:
722
+ items.push(item.value);
723
+ break;
724
+ }
725
+ }
726
+ for (i = 0; i < items.length; i++) {
727
+ if ('chi' in items[i]) {
728
+ // @ts-ignore
729
+ items[i].chi = parseTokens(syntax, items[i].chi[Symbol.iterator]());
730
+ }
731
+ else if ('l' in items[i]) {
732
+ // @ts-ignore
733
+ items[i].l = parseTokens(syntax, items[i].l[Symbol.iterator]());
734
+ // @ts-ignore
735
+ items[i].r = parseTokens(syntax, items[i].r[Symbol.iterator]());
736
+ }
737
+ if (items[i].isOptional || items[i].isRepeatable) {
738
+ if (i <= 1) {
739
+ let k = i;
740
+ while (++k < items.length) {
741
+ if (items[k].typ == ValidationTokenEnum.Whitespace) {
742
+ continue;
743
+ }
744
+ if (items[k].typ == ValidationTokenEnum.Comma) {
745
+ items.splice(i, k - i + 1, Object.defineProperty({
746
+ typ: ValidationTokenEnum.Bracket,
747
+ chi: items.slice(i, k + 1)
748
+ }, 'pos', { ...objectProperties, value: items[i].pos }));
749
+ }
750
+ break;
751
+ }
752
+ }
753
+ else {
754
+ let k = i;
755
+ while (--k > 0) {
756
+ if (items[k].typ == ValidationTokenEnum.Whitespace) {
757
+ continue;
758
+ }
759
+ if (items[k].typ == ValidationTokenEnum.Comma) {
760
+ items.splice(k, i - k + 1, Object.defineProperty({
761
+ typ: ValidationTokenEnum.Bracket,
762
+ chi: items.slice(k, i + 1)
763
+ }, 'pos', { ...objectProperties, value: items[k].pos }));
764
+ i = k - 1;
765
+ }
766
+ break;
767
+ }
768
+ }
769
+ }
770
+ }
771
+ return items;
772
+ }
773
+ function doParseSyntax(syntax, iterator, context) {
774
+ context.chi = matchParens(syntax, iterator);
775
+ // @ts-ignore
776
+ context.chi = matchAtRule(syntax, context.chi[Symbol.iterator]());
777
+ // @ts-ignore
778
+ context.chi = matchBrackets(syntax, context.chi[Symbol.iterator]());
779
+ // @ts-ignore
780
+ context.chi = matchCurlBraces(syntax, context.chi[Symbol.iterator]());
781
+ // @ts-ignore
782
+ context.chi = matchToken(syntax, context.chi[Symbol.iterator](), ValidationTokenEnum.Column);
783
+ // @ts-ignore
784
+ context.chi = matchToken(syntax, context.chi[Symbol.iterator](), ValidationTokenEnum.Pipe);
785
+ // @ts-ignore
786
+ context.chi = parseTokens(syntax, context.chi[Symbol.iterator]());
787
+ // @ts-ignore
788
+ context.chi = matchToken(syntax, context.chi[Symbol.iterator](), ValidationTokenEnum.Ampersand);
789
+ return context;
790
+ }
791
+ function getTokenType(token, position, currentPosition) {
792
+ const pos = { ...position };
793
+ Object.assign(position, currentPosition);
794
+ if (token.charAt(0) == '"' || token.charAt(0) == "'") {
795
+ return Object.defineProperty({
796
+ typ: ValidationTokenEnum.StringToken,
797
+ val: token
798
+ }, 'pos', { ...objectProperties, value: pos });
799
+ }
800
+ if (token == ';') {
801
+ return Object.defineProperty({
802
+ typ: ValidationTokenEnum.SemiColon
803
+ }, 'pos', { ...objectProperties, value: pos });
804
+ }
805
+ if (token.match(/^\s+$/)) {
806
+ return Object.defineProperty({
807
+ typ: ValidationTokenEnum.Whitespace,
808
+ }, 'pos', { ...objectProperties, value: pos });
809
+ }
810
+ if (token.match(/^\d+$/)) {
811
+ return Object.defineProperty({
812
+ typ: ValidationTokenEnum.Number,
813
+ val: Number(token)
814
+ }, 'pos', { ...objectProperties, value: pos });
815
+ }
816
+ if (isPseudo(token)) {
817
+ return Object.defineProperty({
818
+ typ: ValidationTokenEnum.PseudoClassToken,
819
+ val: token
820
+ }, 'pos', { ...objectProperties, value: pos });
821
+ }
822
+ if (token == '!') {
823
+ return Object.defineProperty({
824
+ typ: ValidationTokenEnum.Exclamation
825
+ }, 'pos', { ...objectProperties, value: pos });
826
+ }
827
+ if (token == '#') {
828
+ return Object.defineProperty({
829
+ typ: ValidationTokenEnum.HashMark
830
+ }, 'pos', { ...objectProperties, value: pos });
831
+ }
832
+ if (token == '/') {
833
+ return Object.defineProperty({
834
+ typ: ValidationTokenEnum.Separator
835
+ }, 'pos', { ...objectProperties, value: pos });
836
+ }
837
+ if (token == '+') {
838
+ return Object.defineProperty({
839
+ typ: ValidationTokenEnum.AtLeastOnce
840
+ }, 'pos', { ...objectProperties, value: pos });
841
+ }
842
+ if (token == '|') {
843
+ return Object.defineProperty({
844
+ typ: ValidationTokenEnum.Pipe
845
+ }, 'pos', { ...objectProperties, value: pos });
846
+ }
847
+ if (token == '&&') {
848
+ return Object.defineProperty({
849
+ typ: ValidationTokenEnum.Ampersand
850
+ }, 'pos', { ...objectProperties, value: pos });
851
+ }
852
+ if (token == '||') {
853
+ return Object.defineProperty({
854
+ typ: ValidationTokenEnum.Column
855
+ }, 'pos', { ...objectProperties, value: pos });
856
+ }
857
+ if (token == ',') {
858
+ return Object.defineProperty({
859
+ typ: ValidationTokenEnum.Comma
860
+ }, 'pos', { ...objectProperties, value: pos });
861
+ }
862
+ if (token == '[') {
863
+ return Object.defineProperty({
864
+ typ: ValidationTokenEnum.OpenBracket
865
+ }, 'pos', { ...objectProperties, value: pos });
866
+ }
867
+ if (token == ']') {
868
+ return Object.defineProperty({
869
+ typ: ValidationTokenEnum.CloseBracket
870
+ }, 'pos', { ...objectProperties, value: pos });
871
+ }
872
+ if (token == '(') {
873
+ return Object.defineProperty({
874
+ typ: ValidationTokenEnum.OpenParenthesis
875
+ }, 'pos', { ...objectProperties, value: pos });
876
+ }
877
+ if (token == ')') {
878
+ return Object.defineProperty({
879
+ typ: ValidationTokenEnum.CloseParenthesis
880
+ }, 'pos', { ...objectProperties, value: pos });
881
+ }
882
+ if (token == '{') {
883
+ return Object.defineProperty({
884
+ typ: ValidationTokenEnum.OpenCurlyBrace
885
+ }, 'pos', { ...objectProperties, value: pos });
886
+ }
887
+ if (token == '}') {
888
+ return Object.defineProperty({
889
+ typ: ValidationTokenEnum.CloseCurlyBrace
890
+ }, 'pos', { ...objectProperties, value: pos });
891
+ }
892
+ if (token == '*') {
893
+ return Object.defineProperty({
894
+ typ: ValidationTokenEnum.Star
895
+ }, 'pos', { ...objectProperties, value: pos });
896
+ }
897
+ if (token == '?') {
898
+ return Object.defineProperty({
899
+ typ: ValidationTokenEnum.QuestionMark
900
+ }, 'pos', { ...objectProperties, value: pos });
901
+ }
902
+ if (token.startsWith("<'")) {
903
+ return Object.defineProperty({
904
+ typ: ValidationTokenEnum.DeclarationType,
905
+ val: token.slice(2, -2)
906
+ }, 'pos', { ...objectProperties, value: pos });
907
+ }
908
+ if (token.startsWith('<')) {
909
+ // <number [1,1000]>
910
+ // <length [0,∞]>
911
+ let match = token.match(/<([a-z0-9-]+)(\s+\[([0-9]+),(([0-9]+)|∞)\])?>/);
912
+ if (match == null) {
913
+ let match = token.match(/<([a-zA-Z0-9-]+)\(\)>/);
914
+ if (match != null) {
915
+ return Object.defineProperty({
916
+ typ: ValidationTokenEnum.ValidationFunctionDefinition,
917
+ val: match[1]
918
+ }, 'pos', { ...objectProperties, value: pos });
919
+ }
920
+ throw new Error('invalid token at position: ' + position.lin + ':' + position.col + ' ' + token);
921
+ }
922
+ if (match[2] != null) {
923
+ return Object.defineProperty({
924
+ typ: ValidationTokenEnum.PropertyType,
925
+ val: match[1],
926
+ range: [+match[3], match[4] == '∞' ? Infinity : +match[4]]
927
+ }, 'pos', { ...objectProperties, value: pos });
928
+ }
929
+ return Object.defineProperty({
930
+ typ: ValidationTokenEnum.PropertyType,
931
+ val: token.slice(1, -1)
932
+ }, 'pos', { ...objectProperties, value: pos });
933
+ }
934
+ if (token.startsWith('@') && isIdent(token.slice(1))) {
935
+ return Object.defineProperty({
936
+ typ: ValidationTokenEnum.AtRule,
937
+ val: token.slice(1)
938
+ }, 'pos', { ...objectProperties, value: pos });
939
+ }
940
+ return Object.defineProperty({
941
+ typ: ValidationTokenEnum.Keyword,
942
+ val: token
943
+ }, 'pos', { ...objectProperties, value: pos });
944
+ }
945
+ function move(position, chr) {
946
+ for (const c of chr) {
947
+ position.col++;
948
+ position.ind += c.length;
949
+ }
950
+ return position;
951
+ }
952
+ function renderSyntax(token, parent) {
953
+ let glue;
954
+ switch (token.typ) {
955
+ case ValidationTokenEnum.Root:
956
+ return token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '');
957
+ case ValidationTokenEnum.Whitespace:
958
+ return ' ';
959
+ case ValidationTokenEnum.ValidationFunctionDefinition:
960
+ return '<' + token.val + '()>';
961
+ case ValidationTokenEnum.HashMark:
962
+ return '#';
963
+ case ValidationTokenEnum.Pipe:
964
+ return '|';
965
+ case ValidationTokenEnum.Column:
966
+ return '||';
967
+ case ValidationTokenEnum.PipeToken:
968
+ return token.chi.reduce((acc, curr) => acc + (acc.trim().length > 0 ? '|' : '') + curr.reduce((acc, curr) => acc + renderSyntax(curr), ''), '');
969
+ case ValidationTokenEnum.ColumnToken:
970
+ case ValidationTokenEnum.AmpersandToken:
971
+ glue = token.typ == ValidationTokenEnum.ColumnToken ? '||' : '&&';
972
+ return token.l.reduce((acc, curr) => acc + renderSyntax(curr), '') +
973
+ glue +
974
+ token.r.reduce((acc, curr) => acc + renderSyntax(curr), '');
975
+ case ValidationTokenEnum.Function:
976
+ case ValidationTokenEnum.PseudoClassFunctionToken:
977
+ case ValidationTokenEnum.Parens:
978
+ return token.val + '(' + token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '') + ')' + renderAttributes(token);
979
+ case ValidationTokenEnum.Comma:
980
+ return ',';
981
+ case ValidationTokenEnum.Keyword:
982
+ return token.val + renderAttributes(token);
983
+ case ValidationTokenEnum.OpenBracket:
984
+ return '[';
985
+ case ValidationTokenEnum.Ampersand:
986
+ return '&&';
987
+ case ValidationTokenEnum.QuestionMark:
988
+ return '?';
989
+ case ValidationTokenEnum.Separator:
990
+ return '/';
991
+ case ValidationTokenEnum.Bracket:
992
+ return '[' + token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '') + ']' + renderAttributes(token);
993
+ case ValidationTokenEnum.PropertyType:
994
+ return '<' + token.val + '>' + renderAttributes(token);
995
+ case ValidationTokenEnum.DeclarationType:
996
+ return "<'" + token.val + "'>" + renderAttributes(token);
997
+ case ValidationTokenEnum.Number:
998
+ case ValidationTokenEnum.PseudoClassToken:
999
+ case ValidationTokenEnum.StringToken:
1000
+ return token.val + '';
1001
+ case ValidationTokenEnum.SemiColon:
1002
+ return ';';
1003
+ case ValidationTokenEnum.AtRule:
1004
+ return '@' + token.val;
1005
+ case ValidationTokenEnum.AtRuleDefinition:
1006
+ return '@' + token.val +
1007
+ (token.prelude == null ? '' : ' ' + token.prelude.reduce((acc, curr) => acc + renderSyntax(curr), '')) +
1008
+ (token.chi == null ? '' : ' {\n' + token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '')).slice(1, -1) + '\n}';
1009
+ case ValidationTokenEnum.Block:
1010
+ return '{' + token.chi.reduce((acc, t) => acc + renderSyntax(t), '') + '}';
1011
+ case ValidationTokenEnum.DeclarationDefinitionToken:
1012
+ return token.nam + ': ' + renderSyntax(token.val);
1013
+ case ValidationTokenEnum.ColumnArrayToken:
1014
+ return token.chi.reduce((acc, curr) => acc + (acc.trim().length > 0 ? '||' : '') + renderSyntax(curr), '');
1015
+ default:
1016
+ throw new Error('Unhandled token: ' + JSON.stringify({ token }));
1017
+ }
1018
+ }
1019
+ function renderAttributes(token) {
1020
+ let result = '';
1021
+ if (token.isList) {
1022
+ result += '#';
1023
+ }
1024
+ if (token.isOptional) {
1025
+ result += '?';
1026
+ }
1027
+ if (token.isRepeatableGroup) {
1028
+ result += '!';
1029
+ }
1030
+ if (token.isRepeatable) {
1031
+ result += '*';
1032
+ }
1033
+ if (token.atLeastOnce) {
1034
+ result += '+';
1035
+ }
1036
+ if (token.occurence != null) {
1037
+ if (token.occurence.max == 0 || token.occurence.max == token.occurence.min || Number.isNaN(token.occurence.max)) {
1038
+ result += '{' + token.occurence.min + '}';
1039
+ }
1040
+ else {
1041
+ result += '{' + token.occurence.min + ',' + token.occurence.max + '}';
1042
+ }
1043
+ }
1044
+ return result;
1045
+ }
1046
+ function minify(ast) {
1047
+ if (Array.isArray(ast)) {
1048
+ // @ts-ignore
1049
+ while (ast.length > 0 && ast[0].typ == ValidationTokenEnum.Whitespace) {
1050
+ // @ts-ignore
1051
+ ast.shift();
1052
+ }
1053
+ while (ast.length > 0 && ast.at(-1).typ == ValidationTokenEnum.Whitespace) {
1054
+ ast.pop();
1055
+ }
1056
+ for (let i = 0; i < ast.length; i++) {
1057
+ // if ([ValidationTokenEnum.ColumnToken, ValidationTokenEnum.PipeToken, ValidationTokenEnum.AmpersandToken].includes(ast[i].typ)) {
1058
+ // for (const j of (ast[i] as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).l) {
1059
+ minify(ast[i]);
1060
+ // }
1061
+ // for (const j of (ast[i] as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).r) {
1062
+ //
1063
+ // minify(j);
1064
+ // }
1065
+ // } else
1066
+ // if ('chi' in ast[i]) {
1067
+ //
1068
+ // minify((ast[i] as ValidationFunctionToken | ValidationBracketToken).chi as ValidationToken[]);
1069
+ //
1070
+ // } else
1071
+ if (ast[i].typ == ValidationTokenEnum.Whitespace && ast[i + 1]?.typ == ValidationTokenEnum.Whitespace) {
1072
+ ast.splice(i + 1, 1);
1073
+ i--;
1074
+ continue;
1075
+ }
1076
+ if (ast[i].typ == ValidationTokenEnum.Separator) {
1077
+ if (ast[i + 1]?.typ == ValidationTokenEnum.Whitespace) {
1078
+ ast.splice(i + 1, 1);
1079
+ }
1080
+ if (ast[i - 1]?.typ == ValidationTokenEnum.Whitespace) {
1081
+ ast.splice(--i, 1);
1082
+ }
1083
+ }
1084
+ }
1085
+ return ast;
1086
+ }
1087
+ // else {
1088
+ // if ([ValidationTokenEnum.ColumnToken, ValidationTokenEnum.PipeToken, ValidationTokenEnum.AmpersandToken].includes(ast.typ)) {
1089
+ // for (const j of (ast as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).l) {
1090
+ if ('l' in ast) {
1091
+ minify(ast.l);
1092
+ }
1093
+ // }
1094
+ // for (const j of (ast as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).r) {
1095
+ if ('r' in ast) {
1096
+ minify(ast.r);
1097
+ }
1098
+ if ('chi' in ast) {
1099
+ minify(ast.chi);
1100
+ }
1101
+ if ('prelude' in ast) {
1102
+ minify(ast.prelude);
1103
+ }
1104
+ return ast;
1105
+ }
1106
+ function* walkValidationToken(token, parent, callback, key) {
1107
+ if (Array.isArray(token)) {
1108
+ for (const child of token) {
1109
+ yield* walkValidationToken(child, parent, callback, WalkValidationTokenKeyTypeEnum.Array);
1110
+ }
1111
+ return;
1112
+ }
1113
+ let action = null;
1114
+ if (callback != null) {
1115
+ // @ts-ignore
1116
+ action = callback(token, parent, key);
1117
+ }
1118
+ if (action != WalkValidationTokenEnum.IgnoreNode && action != WalkValidationTokenEnum.IgnoreAll) {
1119
+ yield { token, parent };
1120
+ }
1121
+ if (action != WalkValidationTokenEnum.IgnoreChildren && action != WalkValidationTokenEnum.IgnoreAll && 'prelude' in token) {
1122
+ for (const child of token.prelude) {
1123
+ yield* walkValidationToken(child, token, callback, WalkValidationTokenKeyTypeEnum.Prelude);
1124
+ }
1125
+ }
1126
+ if (action != WalkValidationTokenEnum.IgnoreChildren && 'chi' in token) {
1127
+ // @ts-ignore
1128
+ for (const child of token.chi) {
1129
+ yield* walkValidationToken(child, token, callback, WalkValidationTokenKeyTypeEnum.Children);
1130
+ }
1131
+ }
1132
+ if (action != WalkValidationTokenEnum.IgnoreChildren && action != WalkValidationTokenEnum.IgnoreAll && 'l' in token) {
1133
+ // @ts-ignore
1134
+ for (const child of token.l) {
1135
+ yield* walkValidationToken(child, token, callback, WalkValidationTokenKeyTypeEnum.Left);
1136
+ }
1137
+ }
1138
+ if (action != WalkValidationTokenEnum.IgnoreChildren && action != WalkValidationTokenEnum.IgnoreAll && 'r' in token) {
1139
+ // @ts-ignore
1140
+ for (const child of token.r) {
1141
+ yield* walkValidationToken(child, token, callback, WalkValidationTokenKeyTypeEnum.Right);
1142
+ }
1143
+ }
1144
+ }
1145
+
1146
+ export { WalkValidationTokenEnum, WalkValidationTokenKeyTypeEnum, parseSyntax, renderSyntax, walkValidationToken };