@prisma-next/psl-parser 0.14.0-dev.4 → 0.14.0-dev.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -10
- package/dist/declarations-CPDuQm7x.mjs +1055 -0
- package/dist/declarations-CPDuQm7x.mjs.map +1 -0
- package/dist/format.d.mts +1 -1
- package/dist/format.mjs +2 -1
- package/dist/format.mjs.map +1 -1
- package/dist/index.d.mts +137 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +474 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{parse-BjZ1LPe6.d.mts → parse-BKN_-hW8.d.mts} +126 -51
- package/dist/parse-BKN_-hW8.d.mts.map +1 -0
- package/dist/parse-Du30Ca0-.mjs +626 -0
- package/dist/parse-Du30Ca0-.mjs.map +1 -0
- package/dist/syntax.d.mts +20 -2
- package/dist/syntax.d.mts.map +1 -1
- package/dist/syntax.mjs +43 -2
- package/dist/syntax.mjs.map +1 -0
- package/package.json +5 -6
- package/src/block-reconstruction.ts +139 -0
- package/src/exports/index.ts +27 -3
- package/src/exports/syntax.ts +25 -5
- package/src/extension-block.ts +107 -0
- package/src/parse.ts +23 -5
- package/src/resolve.ts +123 -0
- package/src/source-file.ts +25 -0
- package/src/symbol-table.ts +446 -0
- package/src/syntax/ast/attributes.ts +5 -6
- package/src/syntax/ast/declarations.ts +51 -26
- package/src/syntax/ast/expressions.ts +12 -13
- package/src/syntax/ast/identifier.ts +2 -3
- package/src/syntax/ast/qualified-name.ts +22 -19
- package/src/syntax/ast/type-annotation.ts +4 -5
- package/src/syntax/ast-helpers.ts +27 -3
- package/src/syntax/navigation.ts +55 -0
- package/src/syntax/red.ts +317 -42
- package/dist/parse-B_3gIEFd.mjs +0 -1421
- package/dist/parse-B_3gIEFd.mjs.map +0 -1
- package/dist/parse-BjZ1LPe6.d.mts.map +0 -1
- package/dist/parser-CaplKvRs.mjs +0 -1145
- package/dist/parser-CaplKvRs.mjs.map +0 -1
- package/dist/parser-Dfi3Wfdq.d.mts +0 -7
- package/dist/parser-Dfi3Wfdq.d.mts.map +0 -1
- package/dist/parser.d.mts +0 -2
- package/dist/parser.mjs +0 -2
- package/src/exports/parser.ts +0 -1
- package/src/parser.ts +0 -1642
|
@@ -0,0 +1,1055 @@
|
|
|
1
|
+
//#region src/syntax/red.ts
|
|
2
|
+
/**
|
|
3
|
+
* A token in the red tree. Unlike the green-layer {@link Token} (kind + text
|
|
4
|
+
* only), a red token also carries its absolute `offset` within the source and a
|
|
5
|
+
* link back to its `parent` {@link SyntaxNode}, so a cursor anchored on a token
|
|
6
|
+
* can walk outward (parent, previous/next token, siblings) without re-scanning
|
|
7
|
+
* from the document root.
|
|
8
|
+
*/
|
|
9
|
+
var SyntaxToken = class {
|
|
10
|
+
green;
|
|
11
|
+
kind;
|
|
12
|
+
text;
|
|
13
|
+
offset;
|
|
14
|
+
parent;
|
|
15
|
+
/** Position within the parent's children, enabling O(1) sibling navigation without rescanning the green layer. */
|
|
16
|
+
index;
|
|
17
|
+
constructor(green, offset, parent, index) {
|
|
18
|
+
this.green = green;
|
|
19
|
+
this.kind = green.kind;
|
|
20
|
+
this.text = green.text;
|
|
21
|
+
this.offset = offset;
|
|
22
|
+
this.parent = parent;
|
|
23
|
+
this.index = index;
|
|
24
|
+
}
|
|
25
|
+
get textLength() {
|
|
26
|
+
return this.text.length;
|
|
27
|
+
}
|
|
28
|
+
get endOffset() {
|
|
29
|
+
return this.offset + this.textLength;
|
|
30
|
+
}
|
|
31
|
+
/** Whether `offset` falls within this token, inclusive of both ends. */
|
|
32
|
+
isInside(offset) {
|
|
33
|
+
return offset >= this.offset && offset <= this.endOffset;
|
|
34
|
+
}
|
|
35
|
+
isOutside(offset) {
|
|
36
|
+
return !this.isInside(offset);
|
|
37
|
+
}
|
|
38
|
+
/** The sibling element immediately after this token within its parent. */
|
|
39
|
+
get nextSiblingOrToken() {
|
|
40
|
+
return childAt(this.parent, this.index + 1);
|
|
41
|
+
}
|
|
42
|
+
/** The sibling element immediately before this token within its parent. */
|
|
43
|
+
get prevSiblingOrToken() {
|
|
44
|
+
return childAt(this.parent, this.index - 1);
|
|
45
|
+
}
|
|
46
|
+
/** The next token in document order, crossing node boundaries. */
|
|
47
|
+
get nextToken() {
|
|
48
|
+
for (let el = climbingNext(this); el !== void 0; el = climbingNext(el)) {
|
|
49
|
+
const token = firstToken(el);
|
|
50
|
+
if (token !== void 0) return token;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** The previous token in document order, crossing node boundaries. */
|
|
54
|
+
get prevToken() {
|
|
55
|
+
for (let el = climbingPrev(this); el !== void 0; el = climbingPrev(el)) {
|
|
56
|
+
const token = lastToken(el);
|
|
57
|
+
if (token !== void 0) return token;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var TokenAtOffset = class TokenAtOffset {
|
|
62
|
+
#state;
|
|
63
|
+
constructor(state) {
|
|
64
|
+
this.#state = state;
|
|
65
|
+
}
|
|
66
|
+
static none() {
|
|
67
|
+
return new TokenAtOffset({ kind: "none" });
|
|
68
|
+
}
|
|
69
|
+
static single(token) {
|
|
70
|
+
return new TokenAtOffset({
|
|
71
|
+
kind: "single",
|
|
72
|
+
token
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
static between(left, right) {
|
|
76
|
+
return new TokenAtOffset({
|
|
77
|
+
kind: "between",
|
|
78
|
+
left,
|
|
79
|
+
right
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
get isEmpty() {
|
|
83
|
+
return this.#state.kind === "none";
|
|
84
|
+
}
|
|
85
|
+
get isBetween() {
|
|
86
|
+
return this.#state.kind === "between";
|
|
87
|
+
}
|
|
88
|
+
leftBiased() {
|
|
89
|
+
switch (this.#state.kind) {
|
|
90
|
+
case "none": return;
|
|
91
|
+
case "single": return this.#state.token;
|
|
92
|
+
case "between": return this.#state.left;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
rightBiased() {
|
|
96
|
+
switch (this.#state.kind) {
|
|
97
|
+
case "none": return;
|
|
98
|
+
case "single": return this.#state.token;
|
|
99
|
+
case "between": return this.#state.right;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var SyntaxNode = class SyntaxNode {
|
|
104
|
+
green;
|
|
105
|
+
offset;
|
|
106
|
+
parent;
|
|
107
|
+
/** Position within the parent's children, enabling O(1) sibling navigation without rescanning the green layer. */
|
|
108
|
+
index;
|
|
109
|
+
constructor(green, offset, parent, index) {
|
|
110
|
+
this.green = green;
|
|
111
|
+
this.offset = offset;
|
|
112
|
+
this.parent = parent;
|
|
113
|
+
this.index = index;
|
|
114
|
+
}
|
|
115
|
+
get kind() {
|
|
116
|
+
return this.green.kind;
|
|
117
|
+
}
|
|
118
|
+
get textLength() {
|
|
119
|
+
return this.green.textLength;
|
|
120
|
+
}
|
|
121
|
+
get endOffset() {
|
|
122
|
+
return this.offset + this.textLength;
|
|
123
|
+
}
|
|
124
|
+
/** Whether `offset` falls within this node, inclusive of both ends. */
|
|
125
|
+
isInside(offset) {
|
|
126
|
+
return offset >= this.offset && offset <= this.endOffset;
|
|
127
|
+
}
|
|
128
|
+
isOutside(offset) {
|
|
129
|
+
return !this.isInside(offset);
|
|
130
|
+
}
|
|
131
|
+
get firstChild() {
|
|
132
|
+
return childAt(this, 0);
|
|
133
|
+
}
|
|
134
|
+
get lastChild() {
|
|
135
|
+
const len = this.green.children.length;
|
|
136
|
+
if (len === 0) return void 0;
|
|
137
|
+
return childAt(this, len - 1);
|
|
138
|
+
}
|
|
139
|
+
get nextSibling() {
|
|
140
|
+
return this.parent === void 0 ? void 0 : childAt(this.parent, this.index + 1);
|
|
141
|
+
}
|
|
142
|
+
get prevSibling() {
|
|
143
|
+
return this.parent === void 0 ? void 0 : childAt(this.parent, this.index - 1);
|
|
144
|
+
}
|
|
145
|
+
/** The sibling element immediately after this node within its parent. */
|
|
146
|
+
get nextSiblingOrToken() {
|
|
147
|
+
return this.nextSibling;
|
|
148
|
+
}
|
|
149
|
+
/** The sibling element immediately before this node within its parent. */
|
|
150
|
+
get prevSiblingOrToken() {
|
|
151
|
+
return this.prevSibling;
|
|
152
|
+
}
|
|
153
|
+
/** The first token in this subtree (depth-first), or `undefined` if empty. */
|
|
154
|
+
get firstToken() {
|
|
155
|
+
return firstToken(this);
|
|
156
|
+
}
|
|
157
|
+
/** The last token in this subtree (depth-first), or `undefined` if empty. */
|
|
158
|
+
get lastToken() {
|
|
159
|
+
return lastToken(this);
|
|
160
|
+
}
|
|
161
|
+
*children() {
|
|
162
|
+
let offset = this.offset;
|
|
163
|
+
let index = 0;
|
|
164
|
+
for (const child of this.green.children) {
|
|
165
|
+
yield wrapElement(child, offset, this, index);
|
|
166
|
+
offset += elementTextLength(child);
|
|
167
|
+
index++;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
*childNodes() {
|
|
171
|
+
for (const child of this.children()) if (child instanceof SyntaxNode) yield child;
|
|
172
|
+
}
|
|
173
|
+
*ancestors() {
|
|
174
|
+
let current = this.parent;
|
|
175
|
+
while (current) {
|
|
176
|
+
yield current;
|
|
177
|
+
current = current.parent;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** The nearest match, testing this node itself before walking its ancestors. */
|
|
181
|
+
findAncestor(cast) {
|
|
182
|
+
const self = cast(this);
|
|
183
|
+
if (self !== void 0) return self;
|
|
184
|
+
for (const ancestor of this.ancestors()) {
|
|
185
|
+
const result = cast(ancestor);
|
|
186
|
+
if (result !== void 0) return result;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
*descendants() {
|
|
190
|
+
const stack = [this];
|
|
191
|
+
for (let el = stack.pop(); el !== void 0; el = stack.pop()) {
|
|
192
|
+
yield el;
|
|
193
|
+
if (el instanceof SyntaxNode) {
|
|
194
|
+
const children = Array.from(el.children());
|
|
195
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
196
|
+
const child = children[i];
|
|
197
|
+
if (child !== void 0) stack.push(child);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
*tokens() {
|
|
203
|
+
for (const el of this.descendants()) if (el instanceof SyntaxToken) yield el;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The token(s) at `offset`. The between-two-tokens case (offset exactly on a
|
|
207
|
+
* token seam) is represented explicitly so callers can left/right bias.
|
|
208
|
+
*/
|
|
209
|
+
tokenAtOffset(offset) {
|
|
210
|
+
return tokenAtOffsetOf(this, offset);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The smallest element fully containing the range `[start, end]`. At a seam
|
|
214
|
+
* (and for empty ranges) the left-hand element is preferred, matching
|
|
215
|
+
* {@link containsOffset}'s inclusive span.
|
|
216
|
+
*/
|
|
217
|
+
coveringElement(start, end) {
|
|
218
|
+
let result = this;
|
|
219
|
+
for (;;) {
|
|
220
|
+
if (result instanceof SyntaxToken) return result;
|
|
221
|
+
let next;
|
|
222
|
+
for (const child of result.children()) if (containsRange(child, start, end)) {
|
|
223
|
+
next = child;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (next === void 0) return result;
|
|
227
|
+
result = next;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
function elementTextLength(el) {
|
|
232
|
+
return el.type === "token" ? el.text.length : el.textLength;
|
|
233
|
+
}
|
|
234
|
+
function elementLength(el) {
|
|
235
|
+
return el instanceof SyntaxToken ? el.text.length : el.textLength;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Whether `el` contains `offset`. The span is inclusive on both ends so a seam
|
|
239
|
+
* offset touches both neighbours.
|
|
240
|
+
*/
|
|
241
|
+
function containsOffset(el, offset) {
|
|
242
|
+
const start = el.offset;
|
|
243
|
+
const len = elementLength(el);
|
|
244
|
+
return offset >= start && offset <= start + len;
|
|
245
|
+
}
|
|
246
|
+
function containsRange(el, start, end) {
|
|
247
|
+
const elStart = el.offset;
|
|
248
|
+
const len = elementLength(el);
|
|
249
|
+
return elStart <= start && end <= elStart + len;
|
|
250
|
+
}
|
|
251
|
+
function tokenAtOffsetOf(el, offset) {
|
|
252
|
+
if (el instanceof SyntaxToken) return TokenAtOffset.single(el);
|
|
253
|
+
let left;
|
|
254
|
+
let right;
|
|
255
|
+
for (const child of el.children()) {
|
|
256
|
+
if (!containsOffset(child, offset)) continue;
|
|
257
|
+
if (left === void 0) left = child;
|
|
258
|
+
else {
|
|
259
|
+
right = child;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (left === void 0) return TokenAtOffset.none();
|
|
264
|
+
if (right === void 0) return tokenAtOffsetOf(left, offset);
|
|
265
|
+
const leftToken = tokenAtOffsetOf(left, offset).rightBiased();
|
|
266
|
+
const rightToken = tokenAtOffsetOf(right, offset).leftBiased();
|
|
267
|
+
if (leftToken !== void 0 && rightToken !== void 0) return TokenAtOffset.between(leftToken, rightToken);
|
|
268
|
+
if (leftToken !== void 0) return TokenAtOffset.single(leftToken);
|
|
269
|
+
if (rightToken !== void 0) return TokenAtOffset.single(rightToken);
|
|
270
|
+
return TokenAtOffset.none();
|
|
271
|
+
}
|
|
272
|
+
function firstToken(el) {
|
|
273
|
+
if (el instanceof SyntaxToken) return el;
|
|
274
|
+
for (const child of el.children()) {
|
|
275
|
+
const token = firstToken(child);
|
|
276
|
+
if (token !== void 0) return token;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function lastToken(el) {
|
|
280
|
+
if (el instanceof SyntaxToken) return el;
|
|
281
|
+
const children = Array.from(el.children());
|
|
282
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
283
|
+
const child = children[i];
|
|
284
|
+
if (child !== void 0) {
|
|
285
|
+
const token = lastToken(child);
|
|
286
|
+
if (token !== void 0) return token;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function climbingNext(el) {
|
|
291
|
+
let current = el;
|
|
292
|
+
for (;;) {
|
|
293
|
+
const parent = current.parent;
|
|
294
|
+
if (parent === void 0) return void 0;
|
|
295
|
+
const sibling = childAt(parent, current.index + 1);
|
|
296
|
+
if (sibling !== void 0) return sibling;
|
|
297
|
+
current = parent;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function climbingPrev(el) {
|
|
301
|
+
let current = el;
|
|
302
|
+
for (;;) {
|
|
303
|
+
const parent = current.parent;
|
|
304
|
+
if (parent === void 0) return void 0;
|
|
305
|
+
const sibling = childAt(parent, current.index - 1);
|
|
306
|
+
if (sibling !== void 0) return sibling;
|
|
307
|
+
current = parent;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function wrapElement(green, offset, parent, index) {
|
|
311
|
+
if (green.type === "token") return new SyntaxToken(green, offset, parent, index);
|
|
312
|
+
return new SyntaxNode(green, offset, parent, index);
|
|
313
|
+
}
|
|
314
|
+
function childAt(node, index) {
|
|
315
|
+
const children = node.green.children;
|
|
316
|
+
const target = children[index];
|
|
317
|
+
if (target === void 0) return void 0;
|
|
318
|
+
let offset = node.offset;
|
|
319
|
+
for (let i = 0; i < index; i++) {
|
|
320
|
+
const child = children[i];
|
|
321
|
+
if (child !== void 0) offset += elementTextLength(child);
|
|
322
|
+
}
|
|
323
|
+
return wrapElement(target, offset, node, index);
|
|
324
|
+
}
|
|
325
|
+
function createSyntaxTree(green) {
|
|
326
|
+
return new SyntaxNode(green, 0, void 0, 0);
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/syntax/ast-helpers.ts
|
|
330
|
+
function findChildToken(node, kind) {
|
|
331
|
+
for (const child of node.children()) if (!(child instanceof SyntaxNode) && child.kind === kind) return child;
|
|
332
|
+
}
|
|
333
|
+
function findFirstChild(node, cast) {
|
|
334
|
+
for (const child of node.childNodes()) {
|
|
335
|
+
const result = cast(child);
|
|
336
|
+
if (result !== void 0) return result;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function* filterChildren(node, cast) {
|
|
340
|
+
for (const child of node.childNodes()) {
|
|
341
|
+
const result = cast(child);
|
|
342
|
+
if (result !== void 0) yield result;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function any(...casts) {
|
|
346
|
+
return (node) => {
|
|
347
|
+
for (const cast of casts) {
|
|
348
|
+
const result = cast(node);
|
|
349
|
+
if (result !== void 0) return result;
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Raw source text of a CST node, verbatim (quotes and brackets preserved). For
|
|
355
|
+
* the decoded value of a string literal, decode it instead.
|
|
356
|
+
*/
|
|
357
|
+
function printSyntax(node) {
|
|
358
|
+
let text = "";
|
|
359
|
+
for (const token of node.tokens()) text += token.text;
|
|
360
|
+
return text;
|
|
361
|
+
}
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region src/syntax/ast/identifier.ts
|
|
364
|
+
var IdentifierAst = class IdentifierAst {
|
|
365
|
+
syntax;
|
|
366
|
+
constructor(syntax) {
|
|
367
|
+
this.syntax = syntax;
|
|
368
|
+
}
|
|
369
|
+
token() {
|
|
370
|
+
return findChildToken(this.syntax, "Ident");
|
|
371
|
+
}
|
|
372
|
+
name() {
|
|
373
|
+
return this.token()?.text;
|
|
374
|
+
}
|
|
375
|
+
static cast(node) {
|
|
376
|
+
return node.kind === "Identifier" ? new IdentifierAst(node) : void 0;
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/syntax/ast/qualified-name.ts
|
|
381
|
+
/** A namespace-qualified name, e.g. `pgvector.Vector` or `supabase:auth.User`. */
|
|
382
|
+
var QualifiedNameAst = class QualifiedNameAst {
|
|
383
|
+
syntax;
|
|
384
|
+
constructor(syntax) {
|
|
385
|
+
this.syntax = syntax;
|
|
386
|
+
}
|
|
387
|
+
#segmentBefore(boundary) {
|
|
388
|
+
let found;
|
|
389
|
+
for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) {
|
|
390
|
+
if (segment.syntax.offset >= boundary) break;
|
|
391
|
+
found = segment;
|
|
392
|
+
}
|
|
393
|
+
return found;
|
|
394
|
+
}
|
|
395
|
+
#segmentAfter(boundary) {
|
|
396
|
+
for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) if (segment.syntax.offset > boundary) return segment;
|
|
397
|
+
}
|
|
398
|
+
#separatorCount(kind) {
|
|
399
|
+
let count = 0;
|
|
400
|
+
for (const child of this.syntax.children()) if (!(child instanceof SyntaxNode) && child.kind === kind) count++;
|
|
401
|
+
return count;
|
|
402
|
+
}
|
|
403
|
+
colon() {
|
|
404
|
+
return findChildToken(this.syntax, "Colon");
|
|
405
|
+
}
|
|
406
|
+
dot() {
|
|
407
|
+
return findChildToken(this.syntax, "Dot");
|
|
408
|
+
}
|
|
409
|
+
space() {
|
|
410
|
+
const colon = this.colon();
|
|
411
|
+
if (!colon) return void 0;
|
|
412
|
+
return this.#segmentBefore(colon.offset);
|
|
413
|
+
}
|
|
414
|
+
namespace() {
|
|
415
|
+
const dot = this.dot();
|
|
416
|
+
if (!dot) return void 0;
|
|
417
|
+
return this.#segmentBefore(dot.offset);
|
|
418
|
+
}
|
|
419
|
+
identifier() {
|
|
420
|
+
const dot = this.dot();
|
|
421
|
+
if (dot) return this.#segmentAfter(dot.offset);
|
|
422
|
+
const colon = this.colon();
|
|
423
|
+
if (colon) return this.#segmentAfter(colon.offset);
|
|
424
|
+
return findFirstChild(this.syntax, IdentifierAst.cast);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Every identifier segment, in source order. A bare `Vector` yields
|
|
428
|
+
* `['Vector']`; a qualified `pgvector.Vector` yields `['pgvector', 'Vector']`.
|
|
429
|
+
*/
|
|
430
|
+
path() {
|
|
431
|
+
const segments = [];
|
|
432
|
+
for (const segment of filterChildren(this.syntax, IdentifierAst.cast)) {
|
|
433
|
+
const text = segment.token()?.text;
|
|
434
|
+
if (text !== void 0) segments.push(text);
|
|
435
|
+
}
|
|
436
|
+
return segments;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Flags a malformed name with more qualifier segments than allowed (a second
|
|
440
|
+
* `:`-space or a second `.`-namespace).
|
|
441
|
+
*/
|
|
442
|
+
isOverQualified() {
|
|
443
|
+
return this.#separatorCount("Dot") > 1 || this.#separatorCount("Colon") > 1;
|
|
444
|
+
}
|
|
445
|
+
static cast(node) {
|
|
446
|
+
return node.kind === "QualifiedName" ? new QualifiedNameAst(node) : void 0;
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/syntax/ast/expressions.ts
|
|
451
|
+
var FunctionCallAst = class FunctionCallAst {
|
|
452
|
+
syntax;
|
|
453
|
+
constructor(syntax) {
|
|
454
|
+
this.syntax = syntax;
|
|
455
|
+
}
|
|
456
|
+
/** The qualified-name callee, or `undefined` when identifier segments sit directly under the node. */
|
|
457
|
+
name() {
|
|
458
|
+
return findFirstChild(this.syntax, QualifiedNameAst.cast);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* The dotted call path, in source order. A bare `Vector(…)` yields
|
|
462
|
+
* `['Vector']`; a namespace-qualified `pgvector.Vector(…)` yields
|
|
463
|
+
* `['pgvector', 'Vector']`. Empty when the call carries no identifier.
|
|
464
|
+
*/
|
|
465
|
+
path() {
|
|
466
|
+
const qualified = this.name();
|
|
467
|
+
const segments = [];
|
|
468
|
+
for (const segment of filterChildren(qualified?.syntax ?? this.syntax, IdentifierAst.cast)) {
|
|
469
|
+
const text = segment.token()?.text;
|
|
470
|
+
if (text !== void 0) segments.push(text);
|
|
471
|
+
}
|
|
472
|
+
return segments;
|
|
473
|
+
}
|
|
474
|
+
lparen() {
|
|
475
|
+
return findChildToken(this.syntax, "LParen");
|
|
476
|
+
}
|
|
477
|
+
rparen() {
|
|
478
|
+
return findChildToken(this.syntax, "RParen");
|
|
479
|
+
}
|
|
480
|
+
*args() {
|
|
481
|
+
yield* filterChildren(this.syntax, AttributeArgAst.cast);
|
|
482
|
+
}
|
|
483
|
+
static cast(node) {
|
|
484
|
+
return node.kind === "FunctionCall" ? new FunctionCallAst(node) : void 0;
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
var ArrayLiteralAst = class ArrayLiteralAst {
|
|
488
|
+
syntax;
|
|
489
|
+
constructor(syntax) {
|
|
490
|
+
this.syntax = syntax;
|
|
491
|
+
}
|
|
492
|
+
lbracket() {
|
|
493
|
+
return findChildToken(this.syntax, "LBracket");
|
|
494
|
+
}
|
|
495
|
+
rbracket() {
|
|
496
|
+
return findChildToken(this.syntax, "RBracket");
|
|
497
|
+
}
|
|
498
|
+
*elements() {
|
|
499
|
+
yield* filterChildren(this.syntax, castExpression);
|
|
500
|
+
}
|
|
501
|
+
static cast(node) {
|
|
502
|
+
return node.kind === "ArrayLiteral" ? new ArrayLiteralAst(node) : void 0;
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
const HEX = /^[0-9a-fA-F]+$/;
|
|
506
|
+
function decodeFixedHex(raw, start, width) {
|
|
507
|
+
if (start + width > raw.length) return void 0;
|
|
508
|
+
const hex = raw.slice(start, start + width);
|
|
509
|
+
if (!HEX.test(hex)) return void 0;
|
|
510
|
+
return String.fromCharCode(Number.parseInt(hex, 16));
|
|
511
|
+
}
|
|
512
|
+
function decodeStringLiteral(raw) {
|
|
513
|
+
let out = "";
|
|
514
|
+
let i = 0;
|
|
515
|
+
while (i < raw.length) {
|
|
516
|
+
const ch = raw.charAt(i);
|
|
517
|
+
if (ch !== "\\" || i + 1 >= raw.length) {
|
|
518
|
+
out += ch;
|
|
519
|
+
i++;
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
const next = raw.charAt(i + 1);
|
|
523
|
+
switch (next) {
|
|
524
|
+
case "n":
|
|
525
|
+
out += "\n";
|
|
526
|
+
i += 2;
|
|
527
|
+
continue;
|
|
528
|
+
case "r":
|
|
529
|
+
out += "\r";
|
|
530
|
+
i += 2;
|
|
531
|
+
continue;
|
|
532
|
+
case "t":
|
|
533
|
+
out += " ";
|
|
534
|
+
i += 2;
|
|
535
|
+
continue;
|
|
536
|
+
case "\"":
|
|
537
|
+
out += "\"";
|
|
538
|
+
i += 2;
|
|
539
|
+
continue;
|
|
540
|
+
case "'":
|
|
541
|
+
out += "'";
|
|
542
|
+
i += 2;
|
|
543
|
+
continue;
|
|
544
|
+
case "\\":
|
|
545
|
+
out += "\\";
|
|
546
|
+
i += 2;
|
|
547
|
+
continue;
|
|
548
|
+
case "x": {
|
|
549
|
+
const decoded = decodeFixedHex(raw, i + 2, 2);
|
|
550
|
+
if (decoded === void 0) {
|
|
551
|
+
out += "\\x";
|
|
552
|
+
i += 2;
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
out += decoded;
|
|
556
|
+
i += 4;
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
case "u": {
|
|
560
|
+
const decoded = decodeFixedHex(raw, i + 2, 4);
|
|
561
|
+
if (decoded === void 0) {
|
|
562
|
+
out += "\\u";
|
|
563
|
+
i += 2;
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
out += decoded;
|
|
567
|
+
i += 6;
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
default:
|
|
571
|
+
out += `\\${next}`;
|
|
572
|
+
i += 2;
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
return out;
|
|
577
|
+
}
|
|
578
|
+
var StringLiteralExprAst = class StringLiteralExprAst {
|
|
579
|
+
syntax;
|
|
580
|
+
constructor(syntax) {
|
|
581
|
+
this.syntax = syntax;
|
|
582
|
+
}
|
|
583
|
+
token() {
|
|
584
|
+
return findChildToken(this.syntax, "StringLiteral");
|
|
585
|
+
}
|
|
586
|
+
value() {
|
|
587
|
+
const tok = this.token();
|
|
588
|
+
if (!tok) return void 0;
|
|
589
|
+
return decodeStringLiteral(tok.text.slice(1, -1));
|
|
590
|
+
}
|
|
591
|
+
static cast(node) {
|
|
592
|
+
return node.kind === "StringLiteralExpr" ? new StringLiteralExprAst(node) : void 0;
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
var NumberLiteralExprAst = class NumberLiteralExprAst {
|
|
596
|
+
syntax;
|
|
597
|
+
constructor(syntax) {
|
|
598
|
+
this.syntax = syntax;
|
|
599
|
+
}
|
|
600
|
+
token() {
|
|
601
|
+
return findChildToken(this.syntax, "NumberLiteral");
|
|
602
|
+
}
|
|
603
|
+
value() {
|
|
604
|
+
const tok = this.token();
|
|
605
|
+
if (!tok) return void 0;
|
|
606
|
+
return Number(tok.text);
|
|
607
|
+
}
|
|
608
|
+
static cast(node) {
|
|
609
|
+
return node.kind === "NumberLiteralExpr" ? new NumberLiteralExprAst(node) : void 0;
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
var BooleanLiteralExprAst = class BooleanLiteralExprAst {
|
|
613
|
+
syntax;
|
|
614
|
+
constructor(syntax) {
|
|
615
|
+
this.syntax = syntax;
|
|
616
|
+
}
|
|
617
|
+
token() {
|
|
618
|
+
return findChildToken(this.syntax, "Ident");
|
|
619
|
+
}
|
|
620
|
+
value() {
|
|
621
|
+
const tok = this.token();
|
|
622
|
+
if (!tok) return void 0;
|
|
623
|
+
if (tok.text === "true") return true;
|
|
624
|
+
if (tok.text === "false") return false;
|
|
625
|
+
}
|
|
626
|
+
static cast(node) {
|
|
627
|
+
return node.kind === "BooleanLiteralExpr" ? new BooleanLiteralExprAst(node) : void 0;
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
var ObjectLiteralExprAst = class ObjectLiteralExprAst {
|
|
631
|
+
syntax;
|
|
632
|
+
constructor(syntax) {
|
|
633
|
+
this.syntax = syntax;
|
|
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, ObjectFieldAst.cast);
|
|
643
|
+
}
|
|
644
|
+
static cast(node) {
|
|
645
|
+
return node.kind === "ObjectLiteralExpr" ? new ObjectLiteralExprAst(node) : void 0;
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
var ObjectFieldAst = class ObjectFieldAst {
|
|
649
|
+
syntax;
|
|
650
|
+
constructor(syntax) {
|
|
651
|
+
this.syntax = syntax;
|
|
652
|
+
}
|
|
653
|
+
key() {
|
|
654
|
+
for (const child of this.syntax.children()) {
|
|
655
|
+
if (!(child instanceof SyntaxNode)) {
|
|
656
|
+
if (child.kind === "Colon") break;
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
return IdentifierAst.cast(child);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* The field's logical key name, unquoted. An identifier key (`length:`) yields
|
|
664
|
+
* its text; a string-literal key (`"length":`) yields the decoded string.
|
|
665
|
+
* `undefined` when the field carries no key node.
|
|
666
|
+
*/
|
|
667
|
+
keyName() {
|
|
668
|
+
for (const child of this.syntax.children()) {
|
|
669
|
+
if (!(child instanceof SyntaxNode)) {
|
|
670
|
+
if (child.kind === "Colon") break;
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const identifier = IdentifierAst.cast(child);
|
|
674
|
+
if (identifier) return identifier.token()?.text;
|
|
675
|
+
const stringKey = StringLiteralExprAst.cast(child);
|
|
676
|
+
if (stringKey) return stringKey.value();
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
colon() {
|
|
681
|
+
return findChildToken(this.syntax, "Colon");
|
|
682
|
+
}
|
|
683
|
+
value() {
|
|
684
|
+
if (this.colon()) {
|
|
685
|
+
let pastColon = false;
|
|
686
|
+
for (const child of this.syntax.children()) {
|
|
687
|
+
if (!(child instanceof SyntaxNode)) {
|
|
688
|
+
if (child.kind === "Colon") pastColon = true;
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
if (pastColon) {
|
|
692
|
+
const expr = castExpression(child);
|
|
693
|
+
if (expr) return expr;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
return findFirstChild(this.syntax, castExpression);
|
|
699
|
+
}
|
|
700
|
+
static cast(node) {
|
|
701
|
+
return node.kind === "ObjectField" ? new ObjectFieldAst(node) : void 0;
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
function castExpression(node) {
|
|
705
|
+
return FunctionCallAst.cast(node) ?? ArrayLiteralAst.cast(node) ?? StringLiteralExprAst.cast(node) ?? NumberLiteralExprAst.cast(node) ?? BooleanLiteralExprAst.cast(node) ?? ObjectLiteralExprAst.cast(node) ?? IdentifierAst.cast(node);
|
|
706
|
+
}
|
|
707
|
+
var AttributeArgAst = class AttributeArgAst {
|
|
708
|
+
syntax;
|
|
709
|
+
constructor(syntax) {
|
|
710
|
+
this.syntax = syntax;
|
|
711
|
+
}
|
|
712
|
+
name() {
|
|
713
|
+
if (!this.colon()) return void 0;
|
|
714
|
+
return findFirstChild(this.syntax, IdentifierAst.cast);
|
|
715
|
+
}
|
|
716
|
+
colon() {
|
|
717
|
+
return findChildToken(this.syntax, "Colon");
|
|
718
|
+
}
|
|
719
|
+
value() {
|
|
720
|
+
if (this.colon()) {
|
|
721
|
+
let pastColon = false;
|
|
722
|
+
for (const child of this.syntax.children()) {
|
|
723
|
+
if (!(child instanceof SyntaxNode)) {
|
|
724
|
+
if (child.kind === "Colon") pastColon = true;
|
|
725
|
+
continue;
|
|
726
|
+
}
|
|
727
|
+
if (pastColon) {
|
|
728
|
+
const expr = castExpression(child);
|
|
729
|
+
if (expr) return expr;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
return findFirstChild(this.syntax, castExpression);
|
|
735
|
+
}
|
|
736
|
+
static cast(node) {
|
|
737
|
+
return node.kind === "AttributeArg" ? new AttributeArgAst(node) : void 0;
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
//#endregion
|
|
741
|
+
//#region src/syntax/ast/attributes.ts
|
|
742
|
+
var AttributeArgListAst = class AttributeArgListAst {
|
|
743
|
+
syntax;
|
|
744
|
+
constructor(syntax) {
|
|
745
|
+
this.syntax = syntax;
|
|
746
|
+
}
|
|
747
|
+
lparen() {
|
|
748
|
+
return findChildToken(this.syntax, "LParen");
|
|
749
|
+
}
|
|
750
|
+
rparen() {
|
|
751
|
+
return findChildToken(this.syntax, "RParen");
|
|
752
|
+
}
|
|
753
|
+
*args() {
|
|
754
|
+
yield* filterChildren(this.syntax, AttributeArgAst.cast);
|
|
755
|
+
}
|
|
756
|
+
static cast(node) {
|
|
757
|
+
return node.kind === "AttributeArgList" ? new AttributeArgListAst(node) : void 0;
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
var FieldAttributeAst = class FieldAttributeAst {
|
|
761
|
+
syntax;
|
|
762
|
+
constructor(syntax) {
|
|
763
|
+
this.syntax = syntax;
|
|
764
|
+
}
|
|
765
|
+
at() {
|
|
766
|
+
return findChildToken(this.syntax, "At");
|
|
767
|
+
}
|
|
768
|
+
name() {
|
|
769
|
+
return findFirstChild(this.syntax, QualifiedNameAst.cast);
|
|
770
|
+
}
|
|
771
|
+
argList() {
|
|
772
|
+
return findFirstChild(this.syntax, AttributeArgListAst.cast);
|
|
773
|
+
}
|
|
774
|
+
static cast(node) {
|
|
775
|
+
return node.kind === "FieldAttribute" ? new FieldAttributeAst(node) : void 0;
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
var ModelAttributeAst = class ModelAttributeAst {
|
|
779
|
+
syntax;
|
|
780
|
+
constructor(syntax) {
|
|
781
|
+
this.syntax = syntax;
|
|
782
|
+
}
|
|
783
|
+
doubleAt() {
|
|
784
|
+
return findChildToken(this.syntax, "DoubleAt");
|
|
785
|
+
}
|
|
786
|
+
name() {
|
|
787
|
+
return findFirstChild(this.syntax, QualifiedNameAst.cast);
|
|
788
|
+
}
|
|
789
|
+
argList() {
|
|
790
|
+
return findFirstChild(this.syntax, AttributeArgListAst.cast);
|
|
791
|
+
}
|
|
792
|
+
static cast(node) {
|
|
793
|
+
return node.kind === "ModelAttribute" ? new ModelAttributeAst(node) : void 0;
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
//#endregion
|
|
797
|
+
//#region src/syntax/ast/type-annotation.ts
|
|
798
|
+
var TypeAnnotationAst = class TypeAnnotationAst {
|
|
799
|
+
syntax;
|
|
800
|
+
constructor(syntax) {
|
|
801
|
+
this.syntax = syntax;
|
|
802
|
+
}
|
|
803
|
+
/** The annotation's reference, doubling as the constructor callee when an {@link argList} follows. */
|
|
804
|
+
name() {
|
|
805
|
+
return findFirstChild(this.syntax, QualifiedNameAst.cast);
|
|
806
|
+
}
|
|
807
|
+
/** Present when the annotation is a constructor (`Vector(1536)`) rather than a plain reference. */
|
|
808
|
+
argList() {
|
|
809
|
+
return findFirstChild(this.syntax, AttributeArgListAst.cast);
|
|
810
|
+
}
|
|
811
|
+
isConstructor() {
|
|
812
|
+
return this.argList() !== void 0;
|
|
813
|
+
}
|
|
814
|
+
lbracket() {
|
|
815
|
+
return findChildToken(this.syntax, "LBracket");
|
|
816
|
+
}
|
|
817
|
+
rbracket() {
|
|
818
|
+
return findChildToken(this.syntax, "RBracket");
|
|
819
|
+
}
|
|
820
|
+
questionMark() {
|
|
821
|
+
return findChildToken(this.syntax, "Question");
|
|
822
|
+
}
|
|
823
|
+
isList() {
|
|
824
|
+
return this.lbracket() !== void 0;
|
|
825
|
+
}
|
|
826
|
+
isOptional() {
|
|
827
|
+
return this.questionMark() !== void 0;
|
|
828
|
+
}
|
|
829
|
+
static cast(node) {
|
|
830
|
+
return node.kind === "TypeAnnotation" ? new TypeAnnotationAst(node) : void 0;
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
//#endregion
|
|
834
|
+
//#region src/syntax/ast/declarations.ts
|
|
835
|
+
function castNamespaceMember(node) {
|
|
836
|
+
return ModelDeclarationAst.cast(node) ?? CompositeTypeDeclarationAst.cast(node) ?? GenericBlockDeclarationAst.cast(node);
|
|
837
|
+
}
|
|
838
|
+
var DocumentAst = class DocumentAst {
|
|
839
|
+
syntax;
|
|
840
|
+
constructor(syntax) {
|
|
841
|
+
this.syntax = syntax;
|
|
842
|
+
}
|
|
843
|
+
*declarations() {
|
|
844
|
+
yield* filterChildren(this.syntax, (node) => castNamespaceMember(node) ?? TypesBlockAst.cast(node) ?? NamespaceDeclarationAst.cast(node));
|
|
845
|
+
}
|
|
846
|
+
static cast(node) {
|
|
847
|
+
return node.kind === "Document" ? new DocumentAst(node) : void 0;
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
var ModelDeclarationAst = class ModelDeclarationAst {
|
|
851
|
+
syntax;
|
|
852
|
+
constructor(syntax) {
|
|
853
|
+
this.syntax = syntax;
|
|
854
|
+
}
|
|
855
|
+
keyword() {
|
|
856
|
+
return findChildToken(this.syntax, "Ident");
|
|
857
|
+
}
|
|
858
|
+
name() {
|
|
859
|
+
return findFirstChild(this.syntax, IdentifierAst.cast);
|
|
860
|
+
}
|
|
861
|
+
lbrace() {
|
|
862
|
+
return findChildToken(this.syntax, "LBrace");
|
|
863
|
+
}
|
|
864
|
+
rbrace() {
|
|
865
|
+
return findChildToken(this.syntax, "RBrace");
|
|
866
|
+
}
|
|
867
|
+
*fields() {
|
|
868
|
+
yield* filterChildren(this.syntax, FieldDeclarationAst.cast);
|
|
869
|
+
}
|
|
870
|
+
*attributes() {
|
|
871
|
+
yield* filterChildren(this.syntax, ModelAttributeAst.cast);
|
|
872
|
+
}
|
|
873
|
+
*members() {
|
|
874
|
+
yield* filterChildren(this.syntax, (node) => FieldDeclarationAst.cast(node) ?? ModelAttributeAst.cast(node));
|
|
875
|
+
}
|
|
876
|
+
static cast(node) {
|
|
877
|
+
return node.kind === "ModelDeclaration" ? new ModelDeclarationAst(node) : void 0;
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
var CompositeTypeDeclarationAst = class CompositeTypeDeclarationAst {
|
|
881
|
+
syntax;
|
|
882
|
+
constructor(syntax) {
|
|
883
|
+
this.syntax = syntax;
|
|
884
|
+
}
|
|
885
|
+
keyword() {
|
|
886
|
+
return findChildToken(this.syntax, "Ident");
|
|
887
|
+
}
|
|
888
|
+
name() {
|
|
889
|
+
return findFirstChild(this.syntax, IdentifierAst.cast);
|
|
890
|
+
}
|
|
891
|
+
lbrace() {
|
|
892
|
+
return findChildToken(this.syntax, "LBrace");
|
|
893
|
+
}
|
|
894
|
+
rbrace() {
|
|
895
|
+
return findChildToken(this.syntax, "RBrace");
|
|
896
|
+
}
|
|
897
|
+
*fields() {
|
|
898
|
+
yield* filterChildren(this.syntax, FieldDeclarationAst.cast);
|
|
899
|
+
}
|
|
900
|
+
*attributes() {
|
|
901
|
+
yield* filterChildren(this.syntax, ModelAttributeAst.cast);
|
|
902
|
+
}
|
|
903
|
+
*members() {
|
|
904
|
+
yield* filterChildren(this.syntax, (node) => FieldDeclarationAst.cast(node) ?? ModelAttributeAst.cast(node));
|
|
905
|
+
}
|
|
906
|
+
static cast(node) {
|
|
907
|
+
return node.kind === "CompositeTypeDeclaration" ? new CompositeTypeDeclarationAst(node) : void 0;
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
var NamespaceDeclarationAst = class NamespaceDeclarationAst {
|
|
911
|
+
syntax;
|
|
912
|
+
constructor(syntax) {
|
|
913
|
+
this.syntax = syntax;
|
|
914
|
+
}
|
|
915
|
+
keyword() {
|
|
916
|
+
return findChildToken(this.syntax, "Ident");
|
|
917
|
+
}
|
|
918
|
+
name() {
|
|
919
|
+
return findFirstChild(this.syntax, IdentifierAst.cast);
|
|
920
|
+
}
|
|
921
|
+
lbrace() {
|
|
922
|
+
return findChildToken(this.syntax, "LBrace");
|
|
923
|
+
}
|
|
924
|
+
rbrace() {
|
|
925
|
+
return findChildToken(this.syntax, "RBrace");
|
|
926
|
+
}
|
|
927
|
+
*declarations() {
|
|
928
|
+
yield* filterChildren(this.syntax, castNamespaceMember);
|
|
929
|
+
}
|
|
930
|
+
static cast(node) {
|
|
931
|
+
return node.kind === "Namespace" ? new NamespaceDeclarationAst(node) : void 0;
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
var TypesBlockAst = class TypesBlockAst {
|
|
935
|
+
syntax;
|
|
936
|
+
constructor(syntax) {
|
|
937
|
+
this.syntax = syntax;
|
|
938
|
+
}
|
|
939
|
+
keyword() {
|
|
940
|
+
return findChildToken(this.syntax, "Ident");
|
|
941
|
+
}
|
|
942
|
+
lbrace() {
|
|
943
|
+
return findChildToken(this.syntax, "LBrace");
|
|
944
|
+
}
|
|
945
|
+
rbrace() {
|
|
946
|
+
return findChildToken(this.syntax, "RBrace");
|
|
947
|
+
}
|
|
948
|
+
*declarations() {
|
|
949
|
+
yield* filterChildren(this.syntax, NamedTypeDeclarationAst.cast);
|
|
950
|
+
}
|
|
951
|
+
static cast(node) {
|
|
952
|
+
return node.kind === "TypesBlock" ? new TypesBlockAst(node) : void 0;
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
var GenericBlockDeclarationAst = class GenericBlockDeclarationAst {
|
|
956
|
+
syntax;
|
|
957
|
+
constructor(syntax) {
|
|
958
|
+
this.syntax = syntax;
|
|
959
|
+
}
|
|
960
|
+
keyword() {
|
|
961
|
+
return findChildToken(this.syntax, "Ident");
|
|
962
|
+
}
|
|
963
|
+
name() {
|
|
964
|
+
return findFirstChild(this.syntax, IdentifierAst.cast);
|
|
965
|
+
}
|
|
966
|
+
lbrace() {
|
|
967
|
+
return findChildToken(this.syntax, "LBrace");
|
|
968
|
+
}
|
|
969
|
+
rbrace() {
|
|
970
|
+
return findChildToken(this.syntax, "RBrace");
|
|
971
|
+
}
|
|
972
|
+
*entries() {
|
|
973
|
+
yield* filterChildren(this.syntax, KeyValuePairAst.cast);
|
|
974
|
+
}
|
|
975
|
+
*attributes() {
|
|
976
|
+
yield* filterChildren(this.syntax, ModelAttributeAst.cast);
|
|
977
|
+
}
|
|
978
|
+
*members() {
|
|
979
|
+
yield* filterChildren(this.syntax, (node) => KeyValuePairAst.cast(node) ?? ModelAttributeAst.cast(node));
|
|
980
|
+
}
|
|
981
|
+
static cast(node) {
|
|
982
|
+
return node.kind === "GenericBlockDeclaration" ? new GenericBlockDeclarationAst(node) : void 0;
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
var KeyValuePairAst = class KeyValuePairAst {
|
|
986
|
+
syntax;
|
|
987
|
+
constructor(syntax) {
|
|
988
|
+
this.syntax = syntax;
|
|
989
|
+
}
|
|
990
|
+
key() {
|
|
991
|
+
return findFirstChild(this.syntax, IdentifierAst.cast);
|
|
992
|
+
}
|
|
993
|
+
equals() {
|
|
994
|
+
return findChildToken(this.syntax, "Equals");
|
|
995
|
+
}
|
|
996
|
+
value() {
|
|
997
|
+
let pastEquals = false;
|
|
998
|
+
for (const child of this.syntax.children()) {
|
|
999
|
+
if (!(child instanceof SyntaxNode)) {
|
|
1000
|
+
if (child.kind === "Equals") pastEquals = true;
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
if (pastEquals) {
|
|
1004
|
+
const expr = castExpression(child);
|
|
1005
|
+
if (expr) return expr;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
static cast(node) {
|
|
1010
|
+
return node.kind === "KeyValuePair" ? new KeyValuePairAst(node) : void 0;
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
var FieldDeclarationAst = class FieldDeclarationAst {
|
|
1014
|
+
syntax;
|
|
1015
|
+
constructor(syntax) {
|
|
1016
|
+
this.syntax = syntax;
|
|
1017
|
+
}
|
|
1018
|
+
name() {
|
|
1019
|
+
return findFirstChild(this.syntax, IdentifierAst.cast);
|
|
1020
|
+
}
|
|
1021
|
+
typeAnnotation() {
|
|
1022
|
+
return findFirstChild(this.syntax, TypeAnnotationAst.cast);
|
|
1023
|
+
}
|
|
1024
|
+
*attributes() {
|
|
1025
|
+
yield* filterChildren(this.syntax, FieldAttributeAst.cast);
|
|
1026
|
+
}
|
|
1027
|
+
static cast(node) {
|
|
1028
|
+
return node.kind === "FieldDeclaration" ? new FieldDeclarationAst(node) : void 0;
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
var NamedTypeDeclarationAst = class NamedTypeDeclarationAst {
|
|
1032
|
+
syntax;
|
|
1033
|
+
constructor(syntax) {
|
|
1034
|
+
this.syntax = syntax;
|
|
1035
|
+
}
|
|
1036
|
+
name() {
|
|
1037
|
+
return findFirstChild(this.syntax, IdentifierAst.cast);
|
|
1038
|
+
}
|
|
1039
|
+
equals() {
|
|
1040
|
+
return findChildToken(this.syntax, "Equals");
|
|
1041
|
+
}
|
|
1042
|
+
typeAnnotation() {
|
|
1043
|
+
return findFirstChild(this.syntax, TypeAnnotationAst.cast);
|
|
1044
|
+
}
|
|
1045
|
+
*attributes() {
|
|
1046
|
+
yield* filterChildren(this.syntax, FieldAttributeAst.cast);
|
|
1047
|
+
}
|
|
1048
|
+
static cast(node) {
|
|
1049
|
+
return node.kind === "NamedTypeDeclaration" ? new NamedTypeDeclarationAst(node) : void 0;
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
//#endregion
|
|
1053
|
+
export { SyntaxNode as A, QualifiedNameAst as C, findChildToken as D, filterChildren as E, TokenAtOffset as M, createSyntaxTree as N, findFirstChild as O, castExpression as S, any 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, SyntaxToken as j, printSyntax 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 };
|
|
1054
|
+
|
|
1055
|
+
//# sourceMappingURL=declarations-CPDuQm7x.mjs.map
|