@prisma-next/psl-parser 0.14.0-dev.5 → 0.14.0-dev.7

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.
@@ -0,0 +1,820 @@
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
+ /**
131
+ * Raw source text of a CST node, verbatim (quotes and brackets preserved). For
132
+ * the decoded value of a string literal, decode it instead.
133
+ */
134
+ function printSyntax(node) {
135
+ let text = "";
136
+ for (const token of node.tokens()) text += token.text;
137
+ return text;
138
+ }
139
+ //#endregion
140
+ //#region src/syntax/ast/identifier.ts
141
+ var IdentifierAst = class IdentifierAst {
142
+ syntax;
143
+ constructor(syntax) {
144
+ this.syntax = syntax;
145
+ }
146
+ token() {
147
+ return findChildToken(this.syntax, "Ident");
148
+ }
149
+ name() {
150
+ return this.token()?.text;
151
+ }
152
+ static cast(node) {
153
+ return node.kind === "Identifier" ? new IdentifierAst(node) : void 0;
154
+ }
155
+ };
156
+ //#endregion
157
+ //#region src/syntax/ast/qualified-name.ts
158
+ /** A namespace-qualified name, e.g. `pgvector.Vector` or `supabase:auth.User`. */
159
+ var QualifiedNameAst = class QualifiedNameAst {
160
+ syntax;
161
+ constructor(syntax) {
162
+ this.syntax = syntax;
163
+ }
164
+ #lastSegment() {
165
+ let last;
166
+ for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) last = segment;
167
+ return last;
168
+ }
169
+ #penultimateSegment() {
170
+ let last;
171
+ let penultimate;
172
+ for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) {
173
+ penultimate = last;
174
+ last = segment;
175
+ }
176
+ return penultimate;
177
+ }
178
+ #separatorCount(kind) {
179
+ let count = 0;
180
+ for (const child of this.syntax.children()) if (!(child instanceof SyntaxNode) && child.kind === kind) count++;
181
+ return count;
182
+ }
183
+ colon() {
184
+ return findChildToken(this.syntax, "Colon");
185
+ }
186
+ dot() {
187
+ return findChildToken(this.syntax, "Dot");
188
+ }
189
+ space() {
190
+ if (!this.colon()) return void 0;
191
+ return findFirstChild(this.syntax, IdentifierAst.cast);
192
+ }
193
+ namespace() {
194
+ if (!this.dot()) return void 0;
195
+ return this.#penultimateSegment();
196
+ }
197
+ identifier() {
198
+ return this.#lastSegment();
199
+ }
200
+ /**
201
+ * Every identifier segment, in source order. A bare `Vector` yields
202
+ * `['Vector']`; a qualified `pgvector.Vector` yields `['pgvector', 'Vector']`.
203
+ */
204
+ path() {
205
+ const segments = [];
206
+ for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) {
207
+ const text = segment.token()?.text;
208
+ if (text !== void 0) segments.push(text);
209
+ }
210
+ return segments;
211
+ }
212
+ /**
213
+ * Flags a malformed name with more qualifier segments than allowed (a second
214
+ * `:`-space or a second `.`-namespace).
215
+ */
216
+ isOverQualified() {
217
+ return this.#separatorCount("Dot") > 1 || this.#separatorCount("Colon") > 1;
218
+ }
219
+ static cast(node) {
220
+ return node.kind === "QualifiedName" ? new QualifiedNameAst(node) : void 0;
221
+ }
222
+ };
223
+ //#endregion
224
+ //#region src/syntax/ast/expressions.ts
225
+ var FunctionCallAst = class FunctionCallAst {
226
+ syntax;
227
+ constructor(syntax) {
228
+ this.syntax = syntax;
229
+ }
230
+ /** The qualified-name callee, or `undefined` when identifier segments sit directly under the node. */
231
+ name() {
232
+ return findFirstChild(this.syntax, QualifiedNameAst.cast);
233
+ }
234
+ /**
235
+ * The dotted call path, in source order. A bare `Vector(…)` yields
236
+ * `['Vector']`; a namespace-qualified `pgvector.Vector(…)` yields
237
+ * `['pgvector', 'Vector']`. Empty when the call carries no identifier.
238
+ */
239
+ path() {
240
+ const qualified = this.name();
241
+ const segments = [];
242
+ for (const segment of filterChildren(qualified?.syntax ?? this.syntax, IdentifierAst.cast)) {
243
+ const text = segment.token()?.text;
244
+ if (text !== void 0) segments.push(text);
245
+ }
246
+ return segments;
247
+ }
248
+ lparen() {
249
+ return findChildToken(this.syntax, "LParen");
250
+ }
251
+ rparen() {
252
+ return findChildToken(this.syntax, "RParen");
253
+ }
254
+ *args() {
255
+ yield* filterChildren(this.syntax, AttributeArgAst.cast);
256
+ }
257
+ static cast(node) {
258
+ return node.kind === "FunctionCall" ? new FunctionCallAst(node) : void 0;
259
+ }
260
+ };
261
+ var ArrayLiteralAst = class ArrayLiteralAst {
262
+ syntax;
263
+ constructor(syntax) {
264
+ this.syntax = syntax;
265
+ }
266
+ lbracket() {
267
+ return findChildToken(this.syntax, "LBracket");
268
+ }
269
+ rbracket() {
270
+ return findChildToken(this.syntax, "RBracket");
271
+ }
272
+ *elements() {
273
+ yield* filterChildren(this.syntax, castExpression);
274
+ }
275
+ static cast(node) {
276
+ return node.kind === "ArrayLiteral" ? new ArrayLiteralAst(node) : void 0;
277
+ }
278
+ };
279
+ const HEX = /^[0-9a-fA-F]+$/;
280
+ function decodeFixedHex(raw, start, width) {
281
+ if (start + width > raw.length) return void 0;
282
+ const hex = raw.slice(start, start + width);
283
+ if (!HEX.test(hex)) return void 0;
284
+ return String.fromCharCode(Number.parseInt(hex, 16));
285
+ }
286
+ function decodeStringLiteral(raw) {
287
+ let out = "";
288
+ let i = 0;
289
+ while (i < raw.length) {
290
+ const ch = raw.charAt(i);
291
+ if (ch !== "\\" || i + 1 >= raw.length) {
292
+ out += ch;
293
+ i++;
294
+ continue;
295
+ }
296
+ const next = raw.charAt(i + 1);
297
+ switch (next) {
298
+ case "n":
299
+ out += "\n";
300
+ i += 2;
301
+ continue;
302
+ case "r":
303
+ out += "\r";
304
+ i += 2;
305
+ continue;
306
+ case "t":
307
+ out += " ";
308
+ i += 2;
309
+ continue;
310
+ case "\"":
311
+ out += "\"";
312
+ i += 2;
313
+ continue;
314
+ case "'":
315
+ out += "'";
316
+ i += 2;
317
+ continue;
318
+ case "\\":
319
+ out += "\\";
320
+ i += 2;
321
+ continue;
322
+ case "x": {
323
+ const decoded = decodeFixedHex(raw, i + 2, 2);
324
+ if (decoded === void 0) {
325
+ out += "\\x";
326
+ i += 2;
327
+ continue;
328
+ }
329
+ out += decoded;
330
+ i += 4;
331
+ continue;
332
+ }
333
+ case "u": {
334
+ const decoded = decodeFixedHex(raw, i + 2, 4);
335
+ if (decoded === void 0) {
336
+ out += "\\u";
337
+ i += 2;
338
+ continue;
339
+ }
340
+ out += decoded;
341
+ i += 6;
342
+ continue;
343
+ }
344
+ default:
345
+ out += `\\${next}`;
346
+ i += 2;
347
+ continue;
348
+ }
349
+ }
350
+ return out;
351
+ }
352
+ var StringLiteralExprAst = class StringLiteralExprAst {
353
+ syntax;
354
+ constructor(syntax) {
355
+ this.syntax = syntax;
356
+ }
357
+ token() {
358
+ return findChildToken(this.syntax, "StringLiteral");
359
+ }
360
+ value() {
361
+ const tok = this.token();
362
+ if (!tok) return void 0;
363
+ return decodeStringLiteral(tok.text.slice(1, -1));
364
+ }
365
+ static cast(node) {
366
+ return node.kind === "StringLiteralExpr" ? new StringLiteralExprAst(node) : void 0;
367
+ }
368
+ };
369
+ var NumberLiteralExprAst = class NumberLiteralExprAst {
370
+ syntax;
371
+ constructor(syntax) {
372
+ this.syntax = syntax;
373
+ }
374
+ token() {
375
+ return findChildToken(this.syntax, "NumberLiteral");
376
+ }
377
+ value() {
378
+ const tok = this.token();
379
+ if (!tok) return void 0;
380
+ return Number(tok.text);
381
+ }
382
+ static cast(node) {
383
+ return node.kind === "NumberLiteralExpr" ? new NumberLiteralExprAst(node) : void 0;
384
+ }
385
+ };
386
+ var BooleanLiteralExprAst = class BooleanLiteralExprAst {
387
+ syntax;
388
+ constructor(syntax) {
389
+ this.syntax = syntax;
390
+ }
391
+ token() {
392
+ return findChildToken(this.syntax, "Ident");
393
+ }
394
+ value() {
395
+ const tok = this.token();
396
+ if (!tok) return void 0;
397
+ if (tok.text === "true") return true;
398
+ if (tok.text === "false") return false;
399
+ }
400
+ static cast(node) {
401
+ return node.kind === "BooleanLiteralExpr" ? new BooleanLiteralExprAst(node) : void 0;
402
+ }
403
+ };
404
+ var ObjectLiteralExprAst = class ObjectLiteralExprAst {
405
+ syntax;
406
+ constructor(syntax) {
407
+ this.syntax = syntax;
408
+ }
409
+ lbrace() {
410
+ return findChildToken(this.syntax, "LBrace");
411
+ }
412
+ rbrace() {
413
+ return findChildToken(this.syntax, "RBrace");
414
+ }
415
+ *fields() {
416
+ yield* filterChildren(this.syntax, ObjectFieldAst.cast);
417
+ }
418
+ static cast(node) {
419
+ return node.kind === "ObjectLiteralExpr" ? new ObjectLiteralExprAst(node) : void 0;
420
+ }
421
+ };
422
+ var ObjectFieldAst = class ObjectFieldAst {
423
+ syntax;
424
+ constructor(syntax) {
425
+ this.syntax = syntax;
426
+ }
427
+ key() {
428
+ for (const child of this.syntax.children()) {
429
+ if (!(child instanceof SyntaxNode)) {
430
+ if (child.kind === "Colon") break;
431
+ continue;
432
+ }
433
+ return IdentifierAst.cast(child);
434
+ }
435
+ }
436
+ /**
437
+ * The field's logical key name, unquoted. An identifier key (`length:`) yields
438
+ * its text; a string-literal key (`"length":`) yields the decoded string.
439
+ * `undefined` when the field carries no key node.
440
+ */
441
+ keyName() {
442
+ for (const child of this.syntax.children()) {
443
+ if (!(child instanceof SyntaxNode)) {
444
+ if (child.kind === "Colon") break;
445
+ continue;
446
+ }
447
+ const identifier = IdentifierAst.cast(child);
448
+ if (identifier) return identifier.token()?.text;
449
+ const stringKey = StringLiteralExprAst.cast(child);
450
+ if (stringKey) return stringKey.value();
451
+ return;
452
+ }
453
+ }
454
+ colon() {
455
+ return findChildToken(this.syntax, "Colon");
456
+ }
457
+ value() {
458
+ if (this.colon()) {
459
+ let pastColon = false;
460
+ for (const child of this.syntax.children()) {
461
+ if (!(child instanceof SyntaxNode)) {
462
+ if (child.kind === "Colon") pastColon = true;
463
+ continue;
464
+ }
465
+ if (pastColon) {
466
+ const expr = castExpression(child);
467
+ if (expr) return expr;
468
+ }
469
+ }
470
+ return;
471
+ }
472
+ return findFirstChild(this.syntax, castExpression);
473
+ }
474
+ static cast(node) {
475
+ return node.kind === "ObjectField" ? new ObjectFieldAst(node) : void 0;
476
+ }
477
+ };
478
+ function castExpression(node) {
479
+ return FunctionCallAst.cast(node) ?? ArrayLiteralAst.cast(node) ?? StringLiteralExprAst.cast(node) ?? NumberLiteralExprAst.cast(node) ?? BooleanLiteralExprAst.cast(node) ?? ObjectLiteralExprAst.cast(node) ?? IdentifierAst.cast(node);
480
+ }
481
+ var AttributeArgAst = class AttributeArgAst {
482
+ syntax;
483
+ constructor(syntax) {
484
+ this.syntax = syntax;
485
+ }
486
+ name() {
487
+ if (!this.colon()) return void 0;
488
+ return findFirstChild(this.syntax, IdentifierAst.cast);
489
+ }
490
+ colon() {
491
+ return findChildToken(this.syntax, "Colon");
492
+ }
493
+ value() {
494
+ if (this.colon()) {
495
+ let pastColon = false;
496
+ for (const child of this.syntax.children()) {
497
+ if (!(child instanceof SyntaxNode)) {
498
+ if (child.kind === "Colon") pastColon = true;
499
+ continue;
500
+ }
501
+ if (pastColon) {
502
+ const expr = castExpression(child);
503
+ if (expr) return expr;
504
+ }
505
+ }
506
+ return;
507
+ }
508
+ return findFirstChild(this.syntax, castExpression);
509
+ }
510
+ static cast(node) {
511
+ return node.kind === "AttributeArg" ? new AttributeArgAst(node) : void 0;
512
+ }
513
+ };
514
+ //#endregion
515
+ //#region src/syntax/ast/attributes.ts
516
+ var AttributeArgListAst = class AttributeArgListAst {
517
+ syntax;
518
+ constructor(syntax) {
519
+ this.syntax = syntax;
520
+ }
521
+ lparen() {
522
+ return findChildToken(this.syntax, "LParen");
523
+ }
524
+ rparen() {
525
+ return findChildToken(this.syntax, "RParen");
526
+ }
527
+ *args() {
528
+ yield* filterChildren(this.syntax, AttributeArgAst.cast);
529
+ }
530
+ static cast(node) {
531
+ return node.kind === "AttributeArgList" ? new AttributeArgListAst(node) : void 0;
532
+ }
533
+ };
534
+ var FieldAttributeAst = class FieldAttributeAst {
535
+ syntax;
536
+ constructor(syntax) {
537
+ this.syntax = syntax;
538
+ }
539
+ at() {
540
+ return findChildToken(this.syntax, "At");
541
+ }
542
+ name() {
543
+ return findFirstChild(this.syntax, QualifiedNameAst.cast);
544
+ }
545
+ argList() {
546
+ return findFirstChild(this.syntax, AttributeArgListAst.cast);
547
+ }
548
+ static cast(node) {
549
+ return node.kind === "FieldAttribute" ? new FieldAttributeAst(node) : void 0;
550
+ }
551
+ };
552
+ var ModelAttributeAst = class ModelAttributeAst {
553
+ syntax;
554
+ constructor(syntax) {
555
+ this.syntax = syntax;
556
+ }
557
+ doubleAt() {
558
+ return findChildToken(this.syntax, "DoubleAt");
559
+ }
560
+ name() {
561
+ return findFirstChild(this.syntax, QualifiedNameAst.cast);
562
+ }
563
+ argList() {
564
+ return findFirstChild(this.syntax, AttributeArgListAst.cast);
565
+ }
566
+ static cast(node) {
567
+ return node.kind === "ModelAttribute" ? new ModelAttributeAst(node) : void 0;
568
+ }
569
+ };
570
+ //#endregion
571
+ //#region src/syntax/ast/type-annotation.ts
572
+ var TypeAnnotationAst = class TypeAnnotationAst {
573
+ syntax;
574
+ constructor(syntax) {
575
+ this.syntax = syntax;
576
+ }
577
+ /** The annotation's reference, doubling as the constructor callee when an {@link argList} follows. */
578
+ name() {
579
+ return findFirstChild(this.syntax, QualifiedNameAst.cast);
580
+ }
581
+ /** Present when the annotation is a constructor (`Vector(1536)`) rather than a plain reference. */
582
+ argList() {
583
+ return findFirstChild(this.syntax, AttributeArgListAst.cast);
584
+ }
585
+ isConstructor() {
586
+ return this.argList() !== void 0;
587
+ }
588
+ lbracket() {
589
+ return findChildToken(this.syntax, "LBracket");
590
+ }
591
+ rbracket() {
592
+ return findChildToken(this.syntax, "RBracket");
593
+ }
594
+ questionMark() {
595
+ return findChildToken(this.syntax, "Question");
596
+ }
597
+ isList() {
598
+ return this.lbracket() !== void 0;
599
+ }
600
+ isOptional() {
601
+ return this.questionMark() !== void 0;
602
+ }
603
+ static cast(node) {
604
+ return node.kind === "TypeAnnotation" ? new TypeAnnotationAst(node) : void 0;
605
+ }
606
+ };
607
+ //#endregion
608
+ //#region src/syntax/ast/declarations.ts
609
+ function castNamespaceMember(node) {
610
+ return ModelDeclarationAst.cast(node) ?? CompositeTypeDeclarationAst.cast(node) ?? GenericBlockDeclarationAst.cast(node);
611
+ }
612
+ var DocumentAst = class DocumentAst {
613
+ syntax;
614
+ constructor(syntax) {
615
+ this.syntax = syntax;
616
+ }
617
+ *declarations() {
618
+ yield* filterChildren(this.syntax, (node) => castNamespaceMember(node) ?? TypesBlockAst.cast(node) ?? NamespaceDeclarationAst.cast(node));
619
+ }
620
+ static cast(node) {
621
+ return node.kind === "Document" ? new DocumentAst(node) : void 0;
622
+ }
623
+ };
624
+ var ModelDeclarationAst = class ModelDeclarationAst {
625
+ syntax;
626
+ constructor(syntax) {
627
+ this.syntax = syntax;
628
+ }
629
+ keyword() {
630
+ return findChildToken(this.syntax, "Ident");
631
+ }
632
+ name() {
633
+ return findFirstChild(this.syntax, IdentifierAst.cast);
634
+ }
635
+ lbrace() {
636
+ return findChildToken(this.syntax, "LBrace");
637
+ }
638
+ rbrace() {
639
+ return findChildToken(this.syntax, "RBrace");
640
+ }
641
+ *fields() {
642
+ yield* filterChildren(this.syntax, FieldDeclarationAst.cast);
643
+ }
644
+ *attributes() {
645
+ yield* filterChildren(this.syntax, ModelAttributeAst.cast);
646
+ }
647
+ static cast(node) {
648
+ return node.kind === "ModelDeclaration" ? new ModelDeclarationAst(node) : void 0;
649
+ }
650
+ };
651
+ var CompositeTypeDeclarationAst = class CompositeTypeDeclarationAst {
652
+ syntax;
653
+ constructor(syntax) {
654
+ this.syntax = syntax;
655
+ }
656
+ keyword() {
657
+ return findChildToken(this.syntax, "Ident");
658
+ }
659
+ name() {
660
+ return findFirstChild(this.syntax, IdentifierAst.cast);
661
+ }
662
+ lbrace() {
663
+ return findChildToken(this.syntax, "LBrace");
664
+ }
665
+ rbrace() {
666
+ return findChildToken(this.syntax, "RBrace");
667
+ }
668
+ *fields() {
669
+ yield* filterChildren(this.syntax, FieldDeclarationAst.cast);
670
+ }
671
+ *attributes() {
672
+ yield* filterChildren(this.syntax, ModelAttributeAst.cast);
673
+ }
674
+ static cast(node) {
675
+ return node.kind === "CompositeTypeDeclaration" ? new CompositeTypeDeclarationAst(node) : void 0;
676
+ }
677
+ };
678
+ var NamespaceDeclarationAst = class NamespaceDeclarationAst {
679
+ syntax;
680
+ constructor(syntax) {
681
+ this.syntax = syntax;
682
+ }
683
+ keyword() {
684
+ return findChildToken(this.syntax, "Ident");
685
+ }
686
+ name() {
687
+ return findFirstChild(this.syntax, IdentifierAst.cast);
688
+ }
689
+ lbrace() {
690
+ return findChildToken(this.syntax, "LBrace");
691
+ }
692
+ rbrace() {
693
+ return findChildToken(this.syntax, "RBrace");
694
+ }
695
+ *declarations() {
696
+ yield* filterChildren(this.syntax, castNamespaceMember);
697
+ }
698
+ static cast(node) {
699
+ return node.kind === "Namespace" ? new NamespaceDeclarationAst(node) : void 0;
700
+ }
701
+ };
702
+ var TypesBlockAst = class TypesBlockAst {
703
+ syntax;
704
+ constructor(syntax) {
705
+ this.syntax = syntax;
706
+ }
707
+ keyword() {
708
+ return findChildToken(this.syntax, "Ident");
709
+ }
710
+ lbrace() {
711
+ return findChildToken(this.syntax, "LBrace");
712
+ }
713
+ rbrace() {
714
+ return findChildToken(this.syntax, "RBrace");
715
+ }
716
+ *declarations() {
717
+ yield* filterChildren(this.syntax, NamedTypeDeclarationAst.cast);
718
+ }
719
+ static cast(node) {
720
+ return node.kind === "TypesBlock" ? new TypesBlockAst(node) : void 0;
721
+ }
722
+ };
723
+ var GenericBlockDeclarationAst = class GenericBlockDeclarationAst {
724
+ syntax;
725
+ constructor(syntax) {
726
+ this.syntax = syntax;
727
+ }
728
+ keyword() {
729
+ return findChildToken(this.syntax, "Ident");
730
+ }
731
+ name() {
732
+ return findFirstChild(this.syntax, IdentifierAst.cast);
733
+ }
734
+ lbrace() {
735
+ return findChildToken(this.syntax, "LBrace");
736
+ }
737
+ rbrace() {
738
+ return findChildToken(this.syntax, "RBrace");
739
+ }
740
+ *entries() {
741
+ yield* filterChildren(this.syntax, KeyValuePairAst.cast);
742
+ }
743
+ *attributes() {
744
+ yield* filterChildren(this.syntax, ModelAttributeAst.cast);
745
+ }
746
+ static cast(node) {
747
+ return node.kind === "GenericBlockDeclaration" ? new GenericBlockDeclarationAst(node) : void 0;
748
+ }
749
+ };
750
+ var KeyValuePairAst = class KeyValuePairAst {
751
+ syntax;
752
+ constructor(syntax) {
753
+ this.syntax = syntax;
754
+ }
755
+ key() {
756
+ return findFirstChild(this.syntax, IdentifierAst.cast);
757
+ }
758
+ equals() {
759
+ return findChildToken(this.syntax, "Equals");
760
+ }
761
+ value() {
762
+ let pastEquals = false;
763
+ for (const child of this.syntax.children()) {
764
+ if (!(child instanceof SyntaxNode)) {
765
+ if (child.kind === "Equals") pastEquals = true;
766
+ continue;
767
+ }
768
+ if (pastEquals) {
769
+ const expr = castExpression(child);
770
+ if (expr) return expr;
771
+ }
772
+ }
773
+ }
774
+ static cast(node) {
775
+ return node.kind === "KeyValuePair" ? new KeyValuePairAst(node) : void 0;
776
+ }
777
+ };
778
+ var FieldDeclarationAst = class FieldDeclarationAst {
779
+ syntax;
780
+ constructor(syntax) {
781
+ this.syntax = syntax;
782
+ }
783
+ name() {
784
+ return findFirstChild(this.syntax, IdentifierAst.cast);
785
+ }
786
+ typeAnnotation() {
787
+ return findFirstChild(this.syntax, TypeAnnotationAst.cast);
788
+ }
789
+ *attributes() {
790
+ yield* filterChildren(this.syntax, FieldAttributeAst.cast);
791
+ }
792
+ static cast(node) {
793
+ return node.kind === "FieldDeclaration" ? new FieldDeclarationAst(node) : void 0;
794
+ }
795
+ };
796
+ var NamedTypeDeclarationAst = class NamedTypeDeclarationAst {
797
+ syntax;
798
+ constructor(syntax) {
799
+ this.syntax = syntax;
800
+ }
801
+ name() {
802
+ return findFirstChild(this.syntax, IdentifierAst.cast);
803
+ }
804
+ equals() {
805
+ return findChildToken(this.syntax, "Equals");
806
+ }
807
+ typeAnnotation() {
808
+ return findFirstChild(this.syntax, TypeAnnotationAst.cast);
809
+ }
810
+ *attributes() {
811
+ yield* filterChildren(this.syntax, FieldAttributeAst.cast);
812
+ }
813
+ static cast(node) {
814
+ return node.kind === "NamedTypeDeclaration" ? new NamedTypeDeclarationAst(node) : void 0;
815
+ }
816
+ };
817
+ //#endregion
818
+ export { createSyntaxTree as A, QualifiedNameAst as C, findFirstChild as D, findChildToken as E, printSyntax as O, castExpression as S, filterChildren as T, FunctionCallAst as _, KeyValuePairAst as a, ObjectLiteralExprAst as b, NamespaceDeclarationAst as c, AttributeArgListAst as d, FieldAttributeAst as f, BooleanLiteralExprAst as g, AttributeArgAst as h, GenericBlockDeclarationAst as i, SyntaxNode as k, TypesBlockAst as l, ArrayLiteralAst as m, DocumentAst as n, ModelDeclarationAst as o, ModelAttributeAst as p, FieldDeclarationAst as r, NamedTypeDeclarationAst as s, CompositeTypeDeclarationAst as t, TypeAnnotationAst as u, NumberLiteralExprAst as v, IdentifierAst as w, StringLiteralExprAst as x, ObjectFieldAst as y };
819
+
820
+ //# sourceMappingURL=declarations-D9h_ihD3.mjs.map