@prisma-next/psl-parser 0.13.0 → 0.14.0-dev.10

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 (54) hide show
  1. package/README.md +28 -10
  2. package/dist/declarations-D9h_ihD3.mjs +820 -0
  3. package/dist/declarations-D9h_ihD3.mjs.map +1 -0
  4. package/dist/format.d.mts +19 -0
  5. package/dist/format.d.mts.map +1 -0
  6. package/dist/format.mjs +470 -0
  7. package/dist/format.mjs.map +1 -0
  8. package/dist/index.d.mts +136 -3
  9. package/dist/index.d.mts.map +1 -1
  10. package/dist/index.mjs +472 -2
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/parse-BjZ1LPe6.d.mts +349 -0
  13. package/dist/parse-BjZ1LPe6.d.mts.map +1 -0
  14. package/dist/parse-DhEV6av6.mjs +605 -0
  15. package/dist/parse-DhEV6av6.mjs.map +1 -0
  16. package/dist/syntax.d.mts +3 -272
  17. package/dist/syntax.d.mts.map +1 -1
  18. package/dist/syntax.mjs +3 -708
  19. package/dist/tokenizer-1hAHZzmp.mjs +228 -0
  20. package/dist/tokenizer-1hAHZzmp.mjs.map +1 -0
  21. package/dist/tokenizer.mjs +1 -190
  22. package/package.json +6 -6
  23. package/src/block-reconstruction.ts +139 -0
  24. package/src/exports/format.ts +3 -0
  25. package/src/exports/index.ts +40 -5
  26. package/src/exports/syntax.ts +9 -4
  27. package/src/extension-block.ts +107 -0
  28. package/src/format/emit.ts +603 -0
  29. package/src/format/error.ts +13 -0
  30. package/src/format/format.ts +13 -0
  31. package/src/format/options.ts +28 -0
  32. package/src/parse.ts +751 -0
  33. package/src/resolve.ts +120 -0
  34. package/src/source-file.ts +89 -0
  35. package/src/symbol-table.ts +446 -0
  36. package/src/syntax/ast/attributes.ts +5 -24
  37. package/src/syntax/ast/declarations.ts +14 -67
  38. package/src/syntax/ast/expressions.ts +187 -19
  39. package/src/syntax/ast/identifier.ts +4 -0
  40. package/src/syntax/ast/qualified-name.ts +87 -0
  41. package/src/syntax/ast/type-annotation.ts +11 -41
  42. package/src/syntax/ast-helpers.ts +12 -0
  43. package/src/syntax/syntax-kind.ts +8 -4
  44. package/src/tokenizer.ts +47 -7
  45. package/dist/parser-Cw_zV0M5.mjs +0 -1176
  46. package/dist/parser-Cw_zV0M5.mjs.map +0 -1
  47. package/dist/parser-Dfi3Wfdq.d.mts +0 -7
  48. package/dist/parser-Dfi3Wfdq.d.mts.map +0 -1
  49. package/dist/parser.d.mts +0 -2
  50. package/dist/parser.mjs +0 -2
  51. package/dist/syntax.mjs.map +0 -1
  52. package/dist/tokenizer.mjs.map +0 -1
  53. package/src/exports/parser.ts +0 -1
  54. package/src/parser.ts +0 -1713
package/dist/syntax.mjs CHANGED
@@ -1,708 +1,3 @@
1
- //#region src/syntax/red.ts
2
- var SyntaxNode = class SyntaxNode {
3
- green;
4
- offset;
5
- parent;
6
- constructor(green, offset, parent) {
7
- this.green = green;
8
- this.offset = offset;
9
- this.parent = parent;
10
- }
11
- get kind() {
12
- return this.green.kind;
13
- }
14
- get textLength() {
15
- return this.green.textLength;
16
- }
17
- get firstChild() {
18
- return childAt(this, 0);
19
- }
20
- get lastChild() {
21
- const len = this.green.children.length;
22
- if (len === 0) return void 0;
23
- return childAt(this, len - 1);
24
- }
25
- get nextSibling() {
26
- if (!this.parent) return void 0;
27
- const siblings = this.parent.green.children;
28
- let offset = this.parent.offset;
29
- let found = false;
30
- for (const child of siblings) {
31
- if (found) return wrapElement(child, offset, this.parent);
32
- const childLen = elementTextLength(child);
33
- if (child.type === "node" && offset === this.offset && child === this.green) found = true;
34
- offset += childLen;
35
- }
36
- }
37
- get prevSibling() {
38
- if (!this.parent) return void 0;
39
- const siblings = this.parent.green.children;
40
- let offset = this.parent.offset;
41
- let prev;
42
- for (const child of siblings) {
43
- if (child.type === "node" && offset === this.offset && child === this.green) {
44
- if (!prev) return void 0;
45
- return wrapElement(prev.green, prev.offset, this.parent);
46
- }
47
- prev = {
48
- green: child,
49
- offset
50
- };
51
- offset += elementTextLength(child);
52
- }
53
- }
54
- *children() {
55
- let offset = this.offset;
56
- for (const child of this.green.children) {
57
- yield wrapElement(child, offset, this);
58
- offset += elementTextLength(child);
59
- }
60
- }
61
- *childNodes() {
62
- for (const child of this.children()) if (child instanceof SyntaxNode) yield child;
63
- }
64
- *ancestors() {
65
- let current = this.parent;
66
- while (current) {
67
- yield current;
68
- current = current.parent;
69
- }
70
- }
71
- *descendants() {
72
- const stack = [this];
73
- for (let el = stack.pop(); el !== void 0; el = stack.pop()) {
74
- yield el;
75
- if (el instanceof SyntaxNode) {
76
- const children = Array.from(el.children());
77
- for (let i = children.length - 1; i >= 0; i--) {
78
- const child = children[i];
79
- if (child !== void 0) stack.push(child);
80
- }
81
- }
82
- }
83
- }
84
- *tokens() {
85
- for (const el of this.descendants()) if (!(el instanceof SyntaxNode)) yield el;
86
- }
87
- };
88
- function elementTextLength(el) {
89
- return el.type === "token" ? el.text.length : el.textLength;
90
- }
91
- function wrapElement(green, offset, parent) {
92
- if (green.type === "token") return {
93
- kind: green.kind,
94
- text: green.text,
95
- offset
96
- };
97
- return new SyntaxNode(green, offset, parent);
98
- }
99
- function childAt(node, index) {
100
- const children = node.green.children;
101
- const target = children[index];
102
- if (target === void 0) return void 0;
103
- let offset = node.offset;
104
- for (let i = 0; i < index; i++) {
105
- const child = children[i];
106
- if (child !== void 0) offset += elementTextLength(child);
107
- }
108
- return wrapElement(target, offset, node);
109
- }
110
- function createSyntaxTree(green) {
111
- return new SyntaxNode(green, 0, void 0);
112
- }
113
- //#endregion
114
- //#region src/syntax/ast-helpers.ts
115
- function findChildToken(node, kind) {
116
- for (const child of node.children()) if (!(child instanceof SyntaxNode) && child.kind === kind) return child;
117
- }
118
- function findFirstChild(node, cast) {
119
- for (const child of node.childNodes()) {
120
- const result = cast(child);
121
- if (result !== void 0) return result;
122
- }
123
- }
124
- function* filterChildren(node, cast) {
125
- for (const child of node.childNodes()) {
126
- const result = cast(child);
127
- if (result !== void 0) yield result;
128
- }
129
- }
130
- //#endregion
131
- //#region src/syntax/ast/identifier.ts
132
- var IdentifierAst = class IdentifierAst {
133
- syntax;
134
- constructor(syntax) {
135
- this.syntax = syntax;
136
- }
137
- token() {
138
- return findChildToken(this.syntax, "Ident");
139
- }
140
- static cast(node) {
141
- return node.kind === "Identifier" ? new IdentifierAst(node) : void 0;
142
- }
143
- };
144
- //#endregion
145
- //#region src/syntax/ast/expressions.ts
146
- var FunctionCallAst = class FunctionCallAst {
147
- syntax;
148
- constructor(syntax) {
149
- this.syntax = syntax;
150
- }
151
- name() {
152
- return findFirstChild(this.syntax, IdentifierAst.cast);
153
- }
154
- lparen() {
155
- return findChildToken(this.syntax, "LParen");
156
- }
157
- rparen() {
158
- return findChildToken(this.syntax, "RParen");
159
- }
160
- *args() {
161
- yield* filterChildren(this.syntax, AttributeArgAst.cast);
162
- }
163
- static cast(node) {
164
- return node.kind === "FunctionCall" ? new FunctionCallAst(node) : void 0;
165
- }
166
- };
167
- var ArrayLiteralAst = class ArrayLiteralAst {
168
- syntax;
169
- constructor(syntax) {
170
- this.syntax = syntax;
171
- }
172
- lbracket() {
173
- return findChildToken(this.syntax, "LBracket");
174
- }
175
- rbracket() {
176
- return findChildToken(this.syntax, "RBracket");
177
- }
178
- *elements() {
179
- yield* filterChildren(this.syntax, castExpression);
180
- }
181
- static cast(node) {
182
- return node.kind === "ArrayLiteral" ? new ArrayLiteralAst(node) : void 0;
183
- }
184
- };
185
- var StringLiteralExprAst = class StringLiteralExprAst {
186
- syntax;
187
- constructor(syntax) {
188
- this.syntax = syntax;
189
- }
190
- token() {
191
- return findChildToken(this.syntax, "StringLiteral");
192
- }
193
- value() {
194
- const tok = this.token();
195
- if (!tok) return void 0;
196
- return tok.text.slice(1, -1).replace(/\\(.)/g, (_match, char) => {
197
- switch (char) {
198
- case "n": return "\n";
199
- case "r": return "\r";
200
- case "t": return " ";
201
- case "\"": return "\"";
202
- case "\\": return "\\";
203
- default: return `\\${char}`;
204
- }
205
- });
206
- }
207
- static cast(node) {
208
- return node.kind === "StringLiteralExpr" ? new StringLiteralExprAst(node) : void 0;
209
- }
210
- };
211
- var NumberLiteralExprAst = class NumberLiteralExprAst {
212
- syntax;
213
- constructor(syntax) {
214
- this.syntax = syntax;
215
- }
216
- token() {
217
- return findChildToken(this.syntax, "NumberLiteral");
218
- }
219
- value() {
220
- const tok = this.token();
221
- if (!tok) return void 0;
222
- return Number(tok.text);
223
- }
224
- static cast(node) {
225
- return node.kind === "NumberLiteralExpr" ? new NumberLiteralExprAst(node) : void 0;
226
- }
227
- };
228
- var BooleanLiteralExprAst = class BooleanLiteralExprAst {
229
- syntax;
230
- constructor(syntax) {
231
- this.syntax = syntax;
232
- }
233
- token() {
234
- return findChildToken(this.syntax, "Ident");
235
- }
236
- value() {
237
- const tok = this.token();
238
- if (!tok) return void 0;
239
- if (tok.text === "true") return true;
240
- if (tok.text === "false") return false;
241
- }
242
- static cast(node) {
243
- return node.kind === "BooleanLiteralExpr" ? new BooleanLiteralExprAst(node) : void 0;
244
- }
245
- };
246
- function castExpression(node) {
247
- return FunctionCallAst.cast(node) ?? ArrayLiteralAst.cast(node) ?? StringLiteralExprAst.cast(node) ?? NumberLiteralExprAst.cast(node) ?? BooleanLiteralExprAst.cast(node) ?? IdentifierAst.cast(node);
248
- }
249
- var AttributeArgAst = class AttributeArgAst {
250
- syntax;
251
- constructor(syntax) {
252
- this.syntax = syntax;
253
- }
254
- name() {
255
- if (!this.colon()) return void 0;
256
- return findFirstChild(this.syntax, IdentifierAst.cast);
257
- }
258
- colon() {
259
- return findChildToken(this.syntax, "Colon");
260
- }
261
- value() {
262
- if (this.colon()) {
263
- let pastColon = false;
264
- for (const child of this.syntax.children()) {
265
- if (!(child instanceof SyntaxNode)) {
266
- if (child.kind === "Colon") pastColon = true;
267
- continue;
268
- }
269
- if (pastColon) {
270
- const expr = castExpression(child);
271
- if (expr) return expr;
272
- }
273
- }
274
- return;
275
- }
276
- return findFirstChild(this.syntax, castExpression);
277
- }
278
- static cast(node) {
279
- return node.kind === "AttributeArg" ? new AttributeArgAst(node) : void 0;
280
- }
281
- };
282
- //#endregion
283
- //#region src/syntax/ast/attributes.ts
284
- var AttributeArgListAst = class AttributeArgListAst {
285
- syntax;
286
- constructor(syntax) {
287
- this.syntax = syntax;
288
- }
289
- lparen() {
290
- return findChildToken(this.syntax, "LParen");
291
- }
292
- rparen() {
293
- return findChildToken(this.syntax, "RParen");
294
- }
295
- *args() {
296
- yield* filterChildren(this.syntax, AttributeArgAst.cast);
297
- }
298
- static cast(node) {
299
- return node.kind === "AttributeArgList" ? new AttributeArgListAst(node) : void 0;
300
- }
301
- };
302
- var FieldAttributeAst = class FieldAttributeAst {
303
- syntax;
304
- constructor(syntax) {
305
- this.syntax = syntax;
306
- }
307
- at() {
308
- return findChildToken(this.syntax, "At");
309
- }
310
- name() {
311
- if (this.dot()) {
312
- let count = 0;
313
- for (const child of this.syntax.childNodes()) if (child.kind === "Identifier") {
314
- count++;
315
- if (count === 2) return new IdentifierAst(child);
316
- }
317
- return;
318
- }
319
- return findFirstChild(this.syntax, IdentifierAst.cast);
320
- }
321
- dot() {
322
- return findChildToken(this.syntax, "Dot");
323
- }
324
- namespaceName() {
325
- if (!this.dot()) return void 0;
326
- return findFirstChild(this.syntax, IdentifierAst.cast);
327
- }
328
- argList() {
329
- return findFirstChild(this.syntax, AttributeArgListAst.cast);
330
- }
331
- static cast(node) {
332
- return node.kind === "FieldAttribute" ? new FieldAttributeAst(node) : void 0;
333
- }
334
- };
335
- var ModelAttributeAst = class ModelAttributeAst {
336
- syntax;
337
- constructor(syntax) {
338
- this.syntax = syntax;
339
- }
340
- doubleAt() {
341
- return findChildToken(this.syntax, "DoubleAt");
342
- }
343
- name() {
344
- return findFirstChild(this.syntax, IdentifierAst.cast);
345
- }
346
- argList() {
347
- return findFirstChild(this.syntax, AttributeArgListAst.cast);
348
- }
349
- static cast(node) {
350
- return node.kind === "ModelAttribute" ? new ModelAttributeAst(node) : void 0;
351
- }
352
- };
353
- //#endregion
354
- //#region src/syntax/ast/type-annotation.ts
355
- var TypeAnnotationAst = class TypeAnnotationAst {
356
- syntax;
357
- constructor(syntax) {
358
- this.syntax = syntax;
359
- }
360
- #lastSegment() {
361
- let last;
362
- for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) last = segment;
363
- return last;
364
- }
365
- #penultimateSegment() {
366
- let last;
367
- let penultimate;
368
- for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) {
369
- penultimate = last;
370
- last = segment;
371
- }
372
- return penultimate;
373
- }
374
- name() {
375
- return this.#lastSegment();
376
- }
377
- colon() {
378
- return findChildToken(this.syntax, "Colon");
379
- }
380
- dot() {
381
- return findChildToken(this.syntax, "Dot");
382
- }
383
- spaceName() {
384
- if (!this.colon()) return void 0;
385
- return findFirstChild(this.syntax, IdentifierAst.cast);
386
- }
387
- namespaceName() {
388
- if (!this.dot()) return void 0;
389
- return this.#penultimateSegment();
390
- }
391
- constructorCall() {
392
- return findFirstChild(this.syntax, FunctionCallAst.cast);
393
- }
394
- lbracket() {
395
- return findChildToken(this.syntax, "LBracket");
396
- }
397
- rbracket() {
398
- return findChildToken(this.syntax, "RBracket");
399
- }
400
- questionMark() {
401
- return findChildToken(this.syntax, "Question");
402
- }
403
- isList() {
404
- return this.lbracket() !== void 0;
405
- }
406
- isOptional() {
407
- return this.questionMark() !== void 0;
408
- }
409
- static cast(node) {
410
- return node.kind === "TypeAnnotation" ? new TypeAnnotationAst(node) : void 0;
411
- }
412
- };
413
- //#endregion
414
- //#region src/syntax/ast/declarations.ts
415
- function castNamespaceMember(node) {
416
- return ModelDeclarationAst.cast(node) ?? EnumDeclarationAst.cast(node) ?? CompositeTypeDeclarationAst.cast(node) ?? BlockDeclarationAst.cast(node);
417
- }
418
- var DocumentAst = class DocumentAst {
419
- syntax;
420
- constructor(syntax) {
421
- this.syntax = syntax;
422
- }
423
- *declarations() {
424
- yield* filterChildren(this.syntax, (node) => castNamespaceMember(node) ?? TypesBlockAst.cast(node) ?? NamespaceDeclarationAst.cast(node));
425
- }
426
- static cast(node) {
427
- return node.kind === "Document" ? new DocumentAst(node) : void 0;
428
- }
429
- };
430
- var ModelDeclarationAst = class ModelDeclarationAst {
431
- syntax;
432
- constructor(syntax) {
433
- this.syntax = syntax;
434
- }
435
- keyword() {
436
- return findChildToken(this.syntax, "Ident");
437
- }
438
- name() {
439
- return findFirstChild(this.syntax, IdentifierAst.cast);
440
- }
441
- lbrace() {
442
- return findChildToken(this.syntax, "LBrace");
443
- }
444
- rbrace() {
445
- return findChildToken(this.syntax, "RBrace");
446
- }
447
- *fields() {
448
- yield* filterChildren(this.syntax, FieldDeclarationAst.cast);
449
- }
450
- *attributes() {
451
- yield* filterChildren(this.syntax, ModelAttributeAst.cast);
452
- }
453
- static cast(node) {
454
- return node.kind === "ModelDeclaration" ? new ModelDeclarationAst(node) : void 0;
455
- }
456
- };
457
- var EnumDeclarationAst = class EnumDeclarationAst {
458
- syntax;
459
- constructor(syntax) {
460
- this.syntax = syntax;
461
- }
462
- keyword() {
463
- return findChildToken(this.syntax, "Ident");
464
- }
465
- name() {
466
- return findFirstChild(this.syntax, IdentifierAst.cast);
467
- }
468
- lbrace() {
469
- return findChildToken(this.syntax, "LBrace");
470
- }
471
- rbrace() {
472
- return findChildToken(this.syntax, "RBrace");
473
- }
474
- *values() {
475
- yield* filterChildren(this.syntax, EnumValueDeclarationAst.cast);
476
- }
477
- *attributes() {
478
- yield* filterChildren(this.syntax, ModelAttributeAst.cast);
479
- }
480
- static cast(node) {
481
- return node.kind === "EnumDeclaration" ? new EnumDeclarationAst(node) : void 0;
482
- }
483
- };
484
- var CompositeTypeDeclarationAst = class CompositeTypeDeclarationAst {
485
- syntax;
486
- constructor(syntax) {
487
- this.syntax = syntax;
488
- }
489
- keyword() {
490
- return findChildToken(this.syntax, "Ident");
491
- }
492
- name() {
493
- return findFirstChild(this.syntax, IdentifierAst.cast);
494
- }
495
- lbrace() {
496
- return findChildToken(this.syntax, "LBrace");
497
- }
498
- rbrace() {
499
- return findChildToken(this.syntax, "RBrace");
500
- }
501
- *fields() {
502
- yield* filterChildren(this.syntax, FieldDeclarationAst.cast);
503
- }
504
- *attributes() {
505
- yield* filterChildren(this.syntax, ModelAttributeAst.cast);
506
- }
507
- static cast(node) {
508
- return node.kind === "CompositeTypeDeclaration" ? new CompositeTypeDeclarationAst(node) : void 0;
509
- }
510
- };
511
- var NamespaceDeclarationAst = class NamespaceDeclarationAst {
512
- syntax;
513
- constructor(syntax) {
514
- this.syntax = syntax;
515
- }
516
- keyword() {
517
- return findChildToken(this.syntax, "Ident");
518
- }
519
- name() {
520
- return findFirstChild(this.syntax, IdentifierAst.cast);
521
- }
522
- lbrace() {
523
- return findChildToken(this.syntax, "LBrace");
524
- }
525
- rbrace() {
526
- return findChildToken(this.syntax, "RBrace");
527
- }
528
- *declarations() {
529
- yield* filterChildren(this.syntax, castNamespaceMember);
530
- }
531
- static cast(node) {
532
- return node.kind === "Namespace" ? new NamespaceDeclarationAst(node) : void 0;
533
- }
534
- };
535
- var TypesBlockAst = class TypesBlockAst {
536
- syntax;
537
- constructor(syntax) {
538
- this.syntax = syntax;
539
- }
540
- keyword() {
541
- return findChildToken(this.syntax, "Ident");
542
- }
543
- lbrace() {
544
- return findChildToken(this.syntax, "LBrace");
545
- }
546
- rbrace() {
547
- return findChildToken(this.syntax, "RBrace");
548
- }
549
- *declarations() {
550
- yield* filterChildren(this.syntax, NamedTypeDeclarationAst.cast);
551
- }
552
- static cast(node) {
553
- return node.kind === "TypesBlock" ? new TypesBlockAst(node) : void 0;
554
- }
555
- };
556
- var BlockDeclarationAst = class BlockDeclarationAst {
557
- syntax;
558
- constructor(syntax) {
559
- this.syntax = syntax;
560
- }
561
- keyword() {
562
- return findChildToken(this.syntax, "Ident");
563
- }
564
- name() {
565
- return findFirstChild(this.syntax, IdentifierAst.cast);
566
- }
567
- lbrace() {
568
- return findChildToken(this.syntax, "LBrace");
569
- }
570
- rbrace() {
571
- return findChildToken(this.syntax, "RBrace");
572
- }
573
- *entries() {
574
- yield* filterChildren(this.syntax, KeyValuePairAst.cast);
575
- }
576
- static cast(node) {
577
- return node.kind === "BlockDeclaration" ? new BlockDeclarationAst(node) : void 0;
578
- }
579
- };
580
- var KeyValuePairAst = class KeyValuePairAst {
581
- syntax;
582
- constructor(syntax) {
583
- this.syntax = syntax;
584
- }
585
- key() {
586
- return findFirstChild(this.syntax, IdentifierAst.cast);
587
- }
588
- equals() {
589
- return findChildToken(this.syntax, "Equals");
590
- }
591
- value() {
592
- let pastEquals = false;
593
- for (const child of this.syntax.children()) {
594
- if (!(child instanceof SyntaxNode)) {
595
- if (child.kind === "Equals") pastEquals = true;
596
- continue;
597
- }
598
- if (pastEquals) {
599
- const expr = castExpression(child);
600
- if (expr) return expr;
601
- }
602
- }
603
- }
604
- static cast(node) {
605
- return node.kind === "KeyValuePair" ? new KeyValuePairAst(node) : void 0;
606
- }
607
- };
608
- var FieldDeclarationAst = class FieldDeclarationAst {
609
- syntax;
610
- constructor(syntax) {
611
- this.syntax = syntax;
612
- }
613
- name() {
614
- return findFirstChild(this.syntax, IdentifierAst.cast);
615
- }
616
- typeAnnotation() {
617
- return findFirstChild(this.syntax, TypeAnnotationAst.cast);
618
- }
619
- *attributes() {
620
- yield* filterChildren(this.syntax, FieldAttributeAst.cast);
621
- }
622
- static cast(node) {
623
- return node.kind === "FieldDeclaration" ? new FieldDeclarationAst(node) : void 0;
624
- }
625
- };
626
- var EnumValueDeclarationAst = class EnumValueDeclarationAst {
627
- syntax;
628
- constructor(syntax) {
629
- this.syntax = syntax;
630
- }
631
- name() {
632
- return findFirstChild(this.syntax, IdentifierAst.cast);
633
- }
634
- *attributes() {
635
- yield* filterChildren(this.syntax, FieldAttributeAst.cast);
636
- }
637
- static cast(node) {
638
- return node.kind === "EnumValueDeclaration" ? new EnumValueDeclarationAst(node) : void 0;
639
- }
640
- };
641
- var NamedTypeDeclarationAst = class NamedTypeDeclarationAst {
642
- syntax;
643
- constructor(syntax) {
644
- this.syntax = syntax;
645
- }
646
- name() {
647
- return findFirstChild(this.syntax, IdentifierAst.cast);
648
- }
649
- equals() {
650
- return findChildToken(this.syntax, "Equals");
651
- }
652
- typeAnnotation() {
653
- return findFirstChild(this.syntax, TypeAnnotationAst.cast);
654
- }
655
- *attributes() {
656
- yield* filterChildren(this.syntax, FieldAttributeAst.cast);
657
- }
658
- static cast(node) {
659
- return node.kind === "NamedTypeDeclaration" ? new NamedTypeDeclarationAst(node) : void 0;
660
- }
661
- };
662
- //#endregion
663
- //#region src/syntax/green.ts
664
- function greenToken(kind, text) {
665
- return {
666
- type: "token",
667
- kind,
668
- text
669
- };
670
- }
671
- function greenNode(kind, children) {
672
- let textLength = 0;
673
- for (const child of children) textLength += child.type === "token" ? child.text.length : child.textLength;
674
- return {
675
- type: "node",
676
- kind,
677
- children,
678
- textLength
679
- };
680
- }
681
- //#endregion
682
- //#region src/syntax/green-builder.ts
683
- var GreenNodeBuilder = class {
684
- #stack = [];
685
- startNode(kind) {
686
- this.#stack.push({
687
- kind,
688
- children: []
689
- });
690
- }
691
- token(kind, text) {
692
- const current = this.#stack.at(-1);
693
- if (!current) throw new Error("GreenNodeBuilder: token() called with no open node");
694
- current.children.push(greenToken(kind, text));
695
- }
696
- finishNode() {
697
- const completed = this.#stack.pop();
698
- if (!completed) throw new Error("GreenNodeBuilder: finishNode() called with no open node");
699
- const node = greenNode(completed.kind, completed.children);
700
- const parent = this.#stack.at(-1);
701
- if (parent) parent.children.push(node);
702
- return node;
703
- }
704
- };
705
- //#endregion
706
- export { ArrayLiteralAst, AttributeArgAst, AttributeArgListAst, BlockDeclarationAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, DocumentAst, EnumDeclarationAst, EnumValueDeclarationAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GreenNodeBuilder, IdentifierAst, KeyValuePairAst, ModelAttributeAst, ModelDeclarationAst, NamedTypeDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, StringLiteralExprAst, SyntaxNode, TypeAnnotationAst, TypesBlockAst, castExpression, createSyntaxTree, filterChildren, findChildToken, findFirstChild, greenNode, greenToken };
707
-
708
- //# sourceMappingURL=syntax.mjs.map
1
+ import { A as createSyntaxTree, C as QualifiedNameAst, D as findFirstChild, E as findChildToken, O as printSyntax, S as castExpression, T as filterChildren, _ as FunctionCallAst, a as KeyValuePairAst, b as ObjectLiteralExprAst, c as NamespaceDeclarationAst, d as AttributeArgListAst, f as FieldAttributeAst, g as BooleanLiteralExprAst, h as AttributeArgAst, i as GenericBlockDeclarationAst, k as SyntaxNode, l as TypesBlockAst, m as ArrayLiteralAst, n as DocumentAst, o as ModelDeclarationAst, p as ModelAttributeAst, r as FieldDeclarationAst, s as NamedTypeDeclarationAst, t as CompositeTypeDeclarationAst, u as TypeAnnotationAst, v as NumberLiteralExprAst, w as IdentifierAst, x as StringLiteralExprAst, y as ObjectFieldAst } from "./declarations-D9h_ihD3.mjs";
2
+ import { a as SourceFile, i as greenToken, n as GreenNodeBuilder, r as greenNode, t as parse } from "./parse-DhEV6av6.mjs";
3
+ export { ArrayLiteralAst, AttributeArgAst, AttributeArgListAst, BooleanLiteralExprAst, CompositeTypeDeclarationAst, DocumentAst, FieldAttributeAst, FieldDeclarationAst, FunctionCallAst, GenericBlockDeclarationAst, GreenNodeBuilder, IdentifierAst, KeyValuePairAst, ModelAttributeAst, ModelDeclarationAst, NamedTypeDeclarationAst, NamespaceDeclarationAst, NumberLiteralExprAst, ObjectFieldAst, ObjectLiteralExprAst, QualifiedNameAst, SourceFile, StringLiteralExprAst, SyntaxNode, TypeAnnotationAst, TypesBlockAst, castExpression, createSyntaxTree, filterChildren, findChildToken, findFirstChild, greenNode, greenToken, parse, printSyntax };