@prisma-next/psl-parser 0.14.0-dev.2 → 0.14.0-dev.4

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,19 @@
1
+ import { t as ParseDiagnostic } from "./parse-BjZ1LPe6.mjs";
2
+
3
+ //#region src/format/error.d.ts
4
+ declare class PslFormatError extends Error {
5
+ readonly diagnostics: readonly ParseDiagnostic[];
6
+ constructor(diagnostics: readonly ParseDiagnostic[]);
7
+ }
8
+ //#endregion
9
+ //#region src/format/options.d.ts
10
+ interface FormatOptions {
11
+ readonly indent?: number | 'tab';
12
+ readonly newline?: 'LF' | 'CRLF';
13
+ }
14
+ //#endregion
15
+ //#region src/format/format.d.ts
16
+ declare function format(source: string, options?: FormatOptions): string;
17
+ //#endregion
18
+ export { type FormatOptions, PslFormatError, format };
19
+ //# sourceMappingURL=format.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.mts","names":[],"sources":["../src/format/error.ts","../src/format/options.ts","../src/format/format.ts"],"mappings":";;;cAEa,cAAA,SAAuB,KAAA;EAAA,SACzB,WAAA,WAAsB,eAAA;cAEnB,WAAA,WAAsB,eAAA;AAAA;;;UCLnB,aAAA;EAAA,SACN,MAAA;EAAA,SACA,OAAO;AAAA;;;iBCGF,MAAA,CAAO,MAAA,UAAgB,OAAA,GAAU,aAAa"}
@@ -0,0 +1,469 @@
1
+ import { N as SyntaxNode, _ as ModelAttributeAst, a as CompositeTypeDeclarationAst, c as GenericBlockDeclarationAst, d as NamedTypeDeclarationAst, f as NamespaceDeclarationAst, l as KeyValuePairAst, p as TypesBlockAst, s as FieldDeclarationAst, t as parse, u as ModelDeclarationAst } from "./parse-B_3gIEFd.mjs";
2
+ //#region src/format/error.ts
3
+ var PslFormatError = class extends Error {
4
+ diagnostics;
5
+ constructor(diagnostics) {
6
+ const summary = diagnostics[0]?.message ?? "unknown parse error";
7
+ const more = diagnostics.length > 1 ? ` (and ${diagnostics.length - 1} more)` : "";
8
+ super(`Cannot format PSL with parse errors: ${summary}${more}`);
9
+ this.name = "PslFormatError";
10
+ this.diagnostics = diagnostics;
11
+ }
12
+ };
13
+ //#endregion
14
+ //#region src/format/emit.ts
15
+ function emitDocument(document, indentUnit, newline) {
16
+ const writer = new LineWriter(indentUnit, newline);
17
+ emitTopLevel(writer, document);
18
+ return writer.finish();
19
+ }
20
+ var LineWriter = class {
21
+ #indentUnit;
22
+ #newline;
23
+ #out = [];
24
+ #depth = 0;
25
+ #line = "";
26
+ #lineOpen = false;
27
+ #prevKind;
28
+ #lastWasBlank = false;
29
+ #hasContent = false;
30
+ constructor(indentUnit, newline) {
31
+ this.#indentUnit = indentUnit;
32
+ this.#newline = newline;
33
+ }
34
+ indent() {
35
+ this.#depth += 1;
36
+ }
37
+ unindent() {
38
+ this.#depth = Math.max(0, this.#depth - 1);
39
+ }
40
+ lastIsBlank() {
41
+ return this.#lastWasBlank;
42
+ }
43
+ lineOpen() {
44
+ return this.#lineOpen;
45
+ }
46
+ prevKind() {
47
+ return this.#prevKind;
48
+ }
49
+ newline() {
50
+ if (!this.#lineOpen) return;
51
+ this.#out.push(`${this.#indentUnit.repeat(this.#depth)}${this.#line}`);
52
+ this.#line = "";
53
+ this.#lineOpen = false;
54
+ this.#prevKind = void 0;
55
+ this.#lastWasBlank = false;
56
+ this.#hasContent = true;
57
+ }
58
+ blank() {
59
+ this.newline();
60
+ if (!this.#hasContent || this.#lastWasBlank) return;
61
+ this.#out.push("");
62
+ this.#lastWasBlank = true;
63
+ }
64
+ write(token, space, padTo) {
65
+ if (this.#lineOpen && padTo !== void 0) this.#line = this.#line.padEnd(padTo);
66
+ else if (this.#lineOpen && space) this.#line += " ";
67
+ this.#line += token.text;
68
+ this.#lineOpen = true;
69
+ this.#prevKind = token.kind;
70
+ }
71
+ writeRaw(text) {
72
+ this.#line += text;
73
+ this.#lineOpen = true;
74
+ }
75
+ comment(text) {
76
+ if (this.#lineOpen) this.#line += ` ${text}`;
77
+ else this.#line = text;
78
+ this.#lineOpen = true;
79
+ this.newline();
80
+ }
81
+ finish() {
82
+ this.newline();
83
+ const body = this.#out.join(this.#newline);
84
+ return body.length > 0 ? `${body}${this.#newline}` : "";
85
+ }
86
+ };
87
+ function spaceBetween(prev, cur, inQualifiedName) {
88
+ if (prev === void 0) return false;
89
+ if (inQualifiedName) return false;
90
+ switch (cur) {
91
+ case "LParen":
92
+ case "LBracket":
93
+ case "RParen":
94
+ case "RBracket":
95
+ case "Comma":
96
+ case "Question":
97
+ case "Dot":
98
+ case "Colon": return false;
99
+ case "RBrace": return prev !== "LBrace";
100
+ default: break;
101
+ }
102
+ switch (prev) {
103
+ case "LParen":
104
+ case "LBracket":
105
+ case "Dot":
106
+ case "At":
107
+ case "DoubleAt": return false;
108
+ default: return true;
109
+ }
110
+ }
111
+ function streamNode(writer, node, padTo) {
112
+ let continuation = 0;
113
+ let first = true;
114
+ let prevQualified = false;
115
+ const walk = (parent, qualified) => {
116
+ for (const child of parent.children()) {
117
+ if (child instanceof SyntaxNode) {
118
+ walk(child, qualified || child.kind === "QualifiedName");
119
+ continue;
120
+ }
121
+ if (child.kind === "Whitespace" || child.kind === "Newline") continue;
122
+ if (child.kind === "Comment") {
123
+ writer.comment(child.text);
124
+ writer.indent();
125
+ continuation += 1;
126
+ prevQualified = false;
127
+ first = false;
128
+ continue;
129
+ }
130
+ const pad = first ? padTo : void 0;
131
+ const space = spaceBetween(writer.prevKind(), child.kind, qualified && prevQualified);
132
+ writer.write(child, space, writer.lineOpen() ? pad : void 0);
133
+ prevQualified = qualified;
134
+ first = false;
135
+ }
136
+ };
137
+ walk(node, false);
138
+ return continuation;
139
+ }
140
+ function closeContinuation(writer, count) {
141
+ for (let i = 0; i < count; i++) writer.unindent();
142
+ }
143
+ function emitField(writer, field, columns) {
144
+ return streamRow(writer, field.syntax, columns);
145
+ }
146
+ function emitNamedType(writer, decl) {
147
+ return streamRow(writer, decl.syntax, void 0);
148
+ }
149
+ function streamRow(writer, row, columns) {
150
+ let continuation = 0;
151
+ let sawAttribute = false;
152
+ for (const child of row.children()) {
153
+ if (child instanceof SyntaxNode) {
154
+ let padTo;
155
+ if (child.kind === "TypeAnnotation" && continuation === 0) padTo = columns?.typeColumn;
156
+ else if (child.kind === "FieldAttribute") {
157
+ if (continuation > 0) writer.newline();
158
+ else if (!sawAttribute) padTo = columns?.attributeColumn;
159
+ sawAttribute = true;
160
+ }
161
+ continuation += streamNode(writer, child, padTo);
162
+ continue;
163
+ }
164
+ if (child.kind === "Whitespace" || child.kind === "Newline") continue;
165
+ if (child.kind === "Comment") {
166
+ writer.comment(child.text);
167
+ writer.indent();
168
+ continuation += 1;
169
+ continue;
170
+ }
171
+ const space = spaceBetween(writer.prevKind(), child.kind, false);
172
+ writer.write(child, space);
173
+ }
174
+ return continuation;
175
+ }
176
+ function emitBlockAttribute(writer, attribute) {
177
+ return streamNode(writer, attribute.syntax);
178
+ }
179
+ function emitKeyValue(writer, pair) {
180
+ return streamNode(writer, pair.syntax);
181
+ }
182
+ function leafMember(writer, category, print) {
183
+ return {
184
+ category,
185
+ emit(trailing) {
186
+ const continuation = print();
187
+ if (trailing !== void 0) writer.comment(trailing);
188
+ else writer.newline();
189
+ return continuation;
190
+ }
191
+ };
192
+ }
193
+ function emitModel(writer, model, trailing) {
194
+ const columns = alignmentMap(model.syntax);
195
+ emitBlockBody(writer, model.syntax, trailing, (node) => {
196
+ const field = FieldDeclarationAst.cast(node);
197
+ if (field) return leafMember(writer, "regular", () => emitField(writer, field, columns));
198
+ const attribute = ModelAttributeAst.cast(node);
199
+ if (attribute) return leafMember(writer, "blockAttribute", () => emitBlockAttribute(writer, attribute));
200
+ });
201
+ }
202
+ function emitCompositeType(writer, composite, trailing) {
203
+ const columns = alignmentMap(composite.syntax);
204
+ emitBlockBody(writer, composite.syntax, trailing, (node) => {
205
+ const field = FieldDeclarationAst.cast(node);
206
+ if (field) return leafMember(writer, "regular", () => emitField(writer, field, columns));
207
+ const attribute = ModelAttributeAst.cast(node);
208
+ if (attribute) return leafMember(writer, "blockAttribute", () => emitBlockAttribute(writer, attribute));
209
+ });
210
+ }
211
+ function emitGenericBlock(writer, block, trailing) {
212
+ emitBlockBody(writer, block.syntax, trailing, (node) => {
213
+ const entry = KeyValuePairAst.cast(node);
214
+ if (entry) return leafMember(writer, "regular", () => emitKeyValue(writer, entry));
215
+ const attribute = ModelAttributeAst.cast(node);
216
+ if (attribute) return leafMember(writer, "blockAttribute", () => emitBlockAttribute(writer, attribute));
217
+ });
218
+ }
219
+ function emitNamespace(writer, namespace, trailing) {
220
+ emitBlockBody(writer, namespace.syntax, trailing, (node) => {
221
+ const declaration = castBlockDeclaration(node);
222
+ if (declaration) return nestedBlockMember(writer, declaration);
223
+ });
224
+ }
225
+ function emitTypesBlock(writer, block, trailing) {
226
+ emitBlockBody(writer, block.syntax, trailing, (node) => {
227
+ const named = NamedTypeDeclarationAst.cast(node);
228
+ if (named) return leafMember(writer, "regular", () => emitNamedType(writer, named));
229
+ });
230
+ }
231
+ function emitTopLevel(writer, document) {
232
+ walkRegion(writer, Array.from(document.syntax.children()), void 0, (node) => {
233
+ const declaration = castTopLevelDeclaration(node);
234
+ if (declaration) return nestedBlockMember(writer, declaration);
235
+ });
236
+ }
237
+ function nestedBlockMember(writer, block) {
238
+ return {
239
+ category: "nestedBlock",
240
+ emit(trailing) {
241
+ block(writer, trailing);
242
+ return 0;
243
+ }
244
+ };
245
+ }
246
+ function castBlockDeclaration(node) {
247
+ const model = ModelDeclarationAst.cast(node);
248
+ if (model) return (writer, trailing) => emitModel(writer, model, trailing);
249
+ const composite = CompositeTypeDeclarationAst.cast(node);
250
+ if (composite) return (writer, trailing) => emitCompositeType(writer, composite, trailing);
251
+ const generic = GenericBlockDeclarationAst.cast(node);
252
+ if (generic) return (writer, trailing) => emitGenericBlock(writer, generic, trailing);
253
+ }
254
+ function castTopLevelDeclaration(node) {
255
+ const block = castBlockDeclaration(node);
256
+ if (block) return block;
257
+ const namespace = NamespaceDeclarationAst.cast(node);
258
+ if (namespace) return (writer, trailing) => emitNamespace(writer, namespace, trailing);
259
+ const types = TypesBlockAst.cast(node);
260
+ if (types) return (writer, trailing) => emitTypesBlock(writer, types, trailing);
261
+ }
262
+ function emitBlockBody(writer, node, closingTrailing, classify) {
263
+ const children = Array.from(node.children());
264
+ const openIndex = children.findIndex((el) => !(el instanceof SyntaxNode) && el.kind === "LBrace");
265
+ streamHeader(writer, node);
266
+ const headerComment = sameLineCommentAfter(children, openIndex);
267
+ if (headerComment !== void 0) writer.comment(headerComment);
268
+ else writer.newline();
269
+ writer.indent();
270
+ walkRegion(writer, children, "RBrace", classify);
271
+ writer.unindent();
272
+ writer.writeRaw("}");
273
+ if (closingTrailing !== void 0) writer.comment(closingTrailing);
274
+ else writer.newline();
275
+ }
276
+ function streamHeader(writer, node) {
277
+ let done = false;
278
+ const walk = (parent) => {
279
+ for (const child of parent.children()) {
280
+ if (done) return;
281
+ if (child instanceof SyntaxNode) {
282
+ walk(child);
283
+ continue;
284
+ }
285
+ if (child.kind === "Whitespace" || child.kind === "Newline" || child.kind === "Comment") continue;
286
+ const space = spaceBetween(writer.prevKind(), child.kind, false);
287
+ writer.write(child, space);
288
+ if (child.kind === "LBrace") {
289
+ done = true;
290
+ return;
291
+ }
292
+ }
293
+ };
294
+ walk(node);
295
+ }
296
+ function walkRegion(writer, elements, closeKind, classify) {
297
+ let sawOpenBrace = closeKind === void 0;
298
+ let sawContent = false;
299
+ let lastWasRegular = false;
300
+ let ledByComment = false;
301
+ let newlines = 0;
302
+ for (let i = 0; i < elements.length; i++) {
303
+ const element = elements[i];
304
+ if (element === void 0) continue;
305
+ if (element instanceof SyntaxNode) {
306
+ if (!sawOpenBrace) continue;
307
+ const member = classify(element);
308
+ if (member === void 0) continue;
309
+ if (!ledByComment) {
310
+ if (newlines >= 2 && sawContent && !writer.lastIsBlank()) writer.blank();
311
+ else if (separationBlankWanted(writer, member.category, sawContent, lastWasRegular)) writer.blank();
312
+ }
313
+ const trailing = sameLineTrailingComment(elements, i);
314
+ closeContinuation(writer, member.emit(trailing.text));
315
+ if (trailing.index !== void 0) i = trailing.index;
316
+ sawContent = true;
317
+ lastWasRegular = member.category !== "blockAttribute";
318
+ ledByComment = false;
319
+ newlines = 0;
320
+ continue;
321
+ }
322
+ if (element.kind === "LBrace" && closeKind === "RBrace" && !sawOpenBrace) {
323
+ sawOpenBrace = true;
324
+ newlines = 0;
325
+ continue;
326
+ }
327
+ if (!sawOpenBrace) continue;
328
+ if (closeKind === "RBrace" && element.kind === "RBrace") break;
329
+ if (element.kind === "Whitespace") continue;
330
+ if (element.kind === "Newline") {
331
+ newlines += 1;
332
+ continue;
333
+ }
334
+ if (element.kind === "Comment") {
335
+ if (closeKind === "RBrace" && newlines === 0 && !sawContent) continue;
336
+ if (newlines >= 2 && sawContent && !writer.lastIsBlank()) writer.blank();
337
+ else if (!ledByComment) {
338
+ const led = leadingMemberAfter(elements, i, classify);
339
+ if (led && separationBlankWanted(writer, led, sawContent, lastWasRegular)) writer.blank();
340
+ }
341
+ writer.writeRaw(element.text);
342
+ writer.newline();
343
+ sawContent = true;
344
+ ledByComment = true;
345
+ newlines = 0;
346
+ }
347
+ }
348
+ }
349
+ function separationBlankWanted(writer, category, sawContent, lastWasRegular) {
350
+ if (!sawContent || writer.lastIsBlank()) return false;
351
+ if (category === "nestedBlock") return true;
352
+ return category === "blockAttribute" && lastWasRegular;
353
+ }
354
+ function leadingMemberAfter(elements, commentIndex, classify) {
355
+ for (let i = commentIndex + 1; i < elements.length; i++) {
356
+ const element = elements[i];
357
+ if (element === void 0) continue;
358
+ if (element instanceof SyntaxNode) return classify(element)?.category;
359
+ if (element.kind === "RBrace") return void 0;
360
+ }
361
+ }
362
+ function sameLineTrailingComment(elements, memberIndex) {
363
+ for (let i = memberIndex + 1; i < elements.length; i++) {
364
+ const element = elements[i];
365
+ if (element === void 0) continue;
366
+ if (element instanceof SyntaxNode) break;
367
+ if (element.kind === "Whitespace") continue;
368
+ if (element.kind === "Comment") return {
369
+ text: element.text,
370
+ index: i
371
+ };
372
+ break;
373
+ }
374
+ return {
375
+ text: void 0,
376
+ index: void 0
377
+ };
378
+ }
379
+ function sameLineCommentAfter(children, openIndex) {
380
+ for (let i = openIndex + 1; i < children.length; i++) {
381
+ const child = children[i];
382
+ if (child === void 0) continue;
383
+ if (child instanceof SyntaxNode) return void 0;
384
+ if (child.kind === "Whitespace") continue;
385
+ if (child.kind === "Comment") return child.text;
386
+ return;
387
+ }
388
+ }
389
+ function alignmentMap(block) {
390
+ const fields = [];
391
+ for (const element of block.children()) {
392
+ if (!(element instanceof SyntaxNode)) continue;
393
+ if (FieldDeclarationAst.cast(element) === void 0) continue;
394
+ if (hasInteriorComment(element)) continue;
395
+ fields.push(element);
396
+ }
397
+ if (fields.length === 0) return void 0;
398
+ return alignmentColumns(fields);
399
+ }
400
+ function alignmentColumns(rows) {
401
+ let nameWidth = 0;
402
+ for (const row of rows) {
403
+ const field = FieldDeclarationAst.cast(row);
404
+ if (!field) continue;
405
+ nameWidth = Math.max(nameWidth, renderTokens(field.name()?.syntax).length);
406
+ }
407
+ const typeColumn = nameWidth + 1;
408
+ let cellEnd = 0;
409
+ for (const row of rows) {
410
+ const field = FieldDeclarationAst.cast(row);
411
+ if (!field) continue;
412
+ const name = renderTokens(field.name()?.syntax);
413
+ const type = renderTokens(field.typeAnnotation()?.syntax);
414
+ cellEnd = Math.max(cellEnd, type.length > 0 ? typeColumn + type.length : name.length);
415
+ }
416
+ return {
417
+ typeColumn,
418
+ attributeColumn: cellEnd + 1
419
+ };
420
+ }
421
+ function hasInteriorComment(node) {
422
+ for (const token of node.tokens()) if (token.kind === "Comment") return true;
423
+ return false;
424
+ }
425
+ function renderTokens(node) {
426
+ if (!node) return "";
427
+ let out = "";
428
+ let prev;
429
+ let prevQualified = false;
430
+ const walk = (parent, qualified) => {
431
+ for (const child of parent.children()) {
432
+ if (child instanceof SyntaxNode) {
433
+ walk(child, qualified || child.kind === "QualifiedName");
434
+ continue;
435
+ }
436
+ if (child.kind === "Whitespace" || child.kind === "Newline" || child.kind === "Comment") continue;
437
+ if (spaceBetween(prev, child.kind, qualified && prevQualified)) out += " ";
438
+ out += child.text;
439
+ prev = child.kind;
440
+ prevQualified = qualified;
441
+ }
442
+ };
443
+ walk(node, false);
444
+ return out;
445
+ }
446
+ //#endregion
447
+ //#region src/format/options.ts
448
+ function resolveFormatOptions(options) {
449
+ const indent = options?.indent ?? 2;
450
+ if (indent !== "tab" && (typeof indent !== "number" || !Number.isInteger(indent) || indent < 1)) throw new TypeError(`Invalid format options: indent must be a positive integer or 'tab', got ${String(indent)}`);
451
+ const newline = options?.newline ?? "LF";
452
+ if (newline !== "LF" && newline !== "CRLF") throw new TypeError(`Invalid format options: newline must be 'LF' or 'CRLF', got ${String(newline)}`);
453
+ return {
454
+ indentUnit: indent === "tab" ? " " : " ".repeat(indent),
455
+ newline: newline === "CRLF" ? "\r\n" : "\n"
456
+ };
457
+ }
458
+ //#endregion
459
+ //#region src/format/format.ts
460
+ function format(source, options) {
461
+ const resolved = resolveFormatOptions(options);
462
+ const { document, diagnostics } = parse(source);
463
+ if (diagnostics.length > 0) throw new PslFormatError(diagnostics);
464
+ return emitDocument(document, resolved.indentUnit, resolved.newline);
465
+ }
466
+ //#endregion
467
+ export { PslFormatError, format };
468
+
469
+ //# sourceMappingURL=format.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.mjs","names":["#indentUnit","#newline","#out","#depth","#lastWasBlank","#lineOpen","#prevKind","#line","#hasContent"],"sources":["../src/format/error.ts","../src/format/emit.ts","../src/format/options.ts","../src/format/format.ts"],"sourcesContent":["import type { ParseDiagnostic } from '../parse';\n\nexport class PslFormatError extends Error {\n readonly diagnostics: readonly ParseDiagnostic[];\n\n constructor(diagnostics: readonly ParseDiagnostic[]) {\n const summary = diagnostics[0]?.message ?? 'unknown parse error';\n const more = diagnostics.length > 1 ? ` (and ${diagnostics.length - 1} more)` : '';\n super(`Cannot format PSL with parse errors: ${summary}${more}`);\n this.name = 'PslFormatError';\n this.diagnostics = diagnostics;\n }\n}\n","import { ModelAttributeAst } from '../syntax/ast/attributes';\nimport {\n CompositeTypeDeclarationAst,\n type DocumentAst,\n FieldDeclarationAst,\n GenericBlockDeclarationAst,\n KeyValuePairAst,\n ModelDeclarationAst,\n NamedTypeDeclarationAst,\n NamespaceDeclarationAst,\n TypesBlockAst,\n} from '../syntax/ast/declarations';\nimport { type SyntaxElement, SyntaxNode, type SyntaxToken } from '../syntax/red';\nimport type { TokenKind } from '../tokenizer';\n\nexport function emitDocument(document: DocumentAst, indentUnit: string, newline: string): string {\n const writer = new LineWriter(indentUnit, newline);\n emitTopLevel(writer, document);\n return writer.finish();\n}\n\nclass LineWriter {\n readonly #indentUnit: string;\n readonly #newline: string;\n readonly #out: string[] = [];\n #depth = 0;\n #line = '';\n #lineOpen = false;\n #prevKind: TokenKind | undefined;\n #lastWasBlank = false;\n #hasContent = false;\n\n constructor(indentUnit: string, newline: string) {\n this.#indentUnit = indentUnit;\n this.#newline = newline;\n }\n\n indent(): void {\n this.#depth += 1;\n }\n\n unindent(): void {\n this.#depth = Math.max(0, this.#depth - 1);\n }\n\n lastIsBlank(): boolean {\n return this.#lastWasBlank;\n }\n\n lineOpen(): boolean {\n return this.#lineOpen;\n }\n\n prevKind(): TokenKind | undefined {\n return this.#prevKind;\n }\n\n newline(): void {\n if (!this.#lineOpen) return;\n this.#out.push(`${this.#indentUnit.repeat(this.#depth)}${this.#line}`);\n this.#line = '';\n this.#lineOpen = false;\n this.#prevKind = undefined;\n this.#lastWasBlank = false;\n this.#hasContent = true;\n }\n\n blank(): void {\n this.newline();\n if (!this.#hasContent || this.#lastWasBlank) return;\n this.#out.push('');\n this.#lastWasBlank = true;\n }\n\n write(token: SyntaxToken, space: boolean, padTo?: number): void {\n if (this.#lineOpen && padTo !== undefined) {\n this.#line = this.#line.padEnd(padTo);\n } else if (this.#lineOpen && space) {\n this.#line += ' ';\n }\n this.#line += token.text;\n this.#lineOpen = true;\n this.#prevKind = token.kind;\n }\n\n writeRaw(text: string): void {\n this.#line += text;\n this.#lineOpen = true;\n }\n\n comment(text: string): void {\n if (this.#lineOpen) this.#line += ` ${text}`;\n else this.#line = text;\n this.#lineOpen = true;\n this.newline();\n }\n\n finish(): string {\n this.newline();\n const body = this.#out.join(this.#newline);\n return body.length > 0 ? `${body}${this.#newline}` : '';\n }\n}\n\n// Qualified-name separators hug; argument/object colons keep the usual value space.\nfunction spaceBetween(\n prev: TokenKind | undefined,\n cur: TokenKind,\n inQualifiedName: boolean,\n): boolean {\n if (prev === undefined) return false;\n if (inQualifiedName) return false;\n\n switch (cur) {\n case 'LParen':\n case 'LBracket':\n case 'RParen':\n case 'RBracket':\n case 'Comma':\n case 'Question':\n case 'Dot':\n case 'Colon':\n return false;\n case 'RBrace':\n return prev !== 'LBrace';\n default:\n break;\n }\n switch (prev) {\n case 'LParen':\n case 'LBracket':\n case 'Dot':\n case 'At':\n case 'DoubleAt':\n return false;\n default:\n return true;\n }\n}\n\nfunction streamNode(writer: LineWriter, node: SyntaxNode, padTo?: number): number {\n let continuation = 0;\n let first = true;\n let prevQualified = false;\n\n const walk = (parent: SyntaxNode, qualified: boolean): void => {\n for (const child of parent.children()) {\n if (child instanceof SyntaxNode) {\n walk(child, qualified || child.kind === 'QualifiedName');\n continue;\n }\n if (child.kind === 'Whitespace' || child.kind === 'Newline') continue;\n if (child.kind === 'Comment') {\n writer.comment(child.text);\n writer.indent();\n continuation += 1;\n prevQualified = false;\n first = false;\n continue;\n }\n const pad = first ? padTo : undefined;\n const space = spaceBetween(writer.prevKind(), child.kind, qualified && prevQualified);\n writer.write(child, space, writer.lineOpen() ? pad : undefined);\n prevQualified = qualified;\n first = false;\n }\n };\n\n walk(node, false);\n return continuation;\n}\n\nfunction closeContinuation(writer: LineWriter, count: number): void {\n for (let i = 0; i < count; i++) writer.unindent();\n}\n\nfunction emitField(\n writer: LineWriter,\n field: FieldDeclarationAst,\n columns: AlignmentColumns | undefined,\n): number {\n return streamRow(writer, field.syntax, columns);\n}\n\nfunction emitNamedType(writer: LineWriter, decl: NamedTypeDeclarationAst): number {\n return streamRow(writer, decl.syntax, undefined);\n}\n\nfunction streamRow(\n writer: LineWriter,\n row: SyntaxNode,\n columns: AlignmentColumns | undefined,\n): number {\n let continuation = 0;\n let sawAttribute = false;\n\n for (const child of row.children()) {\n if (child instanceof SyntaxNode) {\n let padTo: number | undefined;\n if (child.kind === 'TypeAnnotation' && continuation === 0) {\n padTo = columns?.typeColumn;\n } else if (child.kind === 'FieldAttribute') {\n if (continuation > 0) writer.newline();\n else if (!sawAttribute) padTo = columns?.attributeColumn;\n sawAttribute = true;\n }\n continuation += streamNode(writer, child, padTo);\n continue;\n }\n if (child.kind === 'Whitespace' || child.kind === 'Newline') continue;\n if (child.kind === 'Comment') {\n writer.comment(child.text);\n writer.indent();\n continuation += 1;\n continue;\n }\n const space = spaceBetween(writer.prevKind(), child.kind, false);\n writer.write(child, space);\n }\n\n return continuation;\n}\n\nfunction emitBlockAttribute(writer: LineWriter, attribute: ModelAttributeAst): number {\n return streamNode(writer, attribute.syntax);\n}\n\nfunction emitKeyValue(writer: LineWriter, pair: KeyValuePairAst): number {\n return streamNode(writer, pair.syntax);\n}\n\ntype MemberCategory = 'regular' | 'blockAttribute' | 'nestedBlock';\n\ninterface BlockMember {\n readonly category: MemberCategory;\n emit(trailing: string | undefined): number;\n}\n\nfunction leafMember(\n writer: LineWriter,\n category: MemberCategory,\n print: () => number,\n): BlockMember {\n return {\n category,\n emit(trailing) {\n const continuation = print();\n if (trailing !== undefined) writer.comment(trailing);\n else writer.newline();\n return continuation;\n },\n };\n}\n\ntype MemberClassifier = (node: SyntaxNode) => BlockMember | undefined;\n\nfunction emitModel(\n writer: LineWriter,\n model: ModelDeclarationAst,\n trailing: string | undefined,\n): void {\n const columns = alignmentMap(model.syntax);\n emitBlockBody(writer, model.syntax, trailing, (node) => {\n const field = FieldDeclarationAst.cast(node);\n if (field) return leafMember(writer, 'regular', () => emitField(writer, field, columns));\n const attribute = ModelAttributeAst.cast(node);\n if (attribute)\n return leafMember(writer, 'blockAttribute', () => emitBlockAttribute(writer, attribute));\n return undefined;\n });\n}\n\nfunction emitCompositeType(\n writer: LineWriter,\n composite: CompositeTypeDeclarationAst,\n trailing: string | undefined,\n): void {\n const columns = alignmentMap(composite.syntax);\n emitBlockBody(writer, composite.syntax, trailing, (node) => {\n const field = FieldDeclarationAst.cast(node);\n if (field) return leafMember(writer, 'regular', () => emitField(writer, field, columns));\n const attribute = ModelAttributeAst.cast(node);\n if (attribute)\n return leafMember(writer, 'blockAttribute', () => emitBlockAttribute(writer, attribute));\n return undefined;\n });\n}\n\nfunction emitGenericBlock(\n writer: LineWriter,\n block: GenericBlockDeclarationAst,\n trailing: string | undefined,\n): void {\n emitBlockBody(writer, block.syntax, trailing, (node) => {\n const entry = KeyValuePairAst.cast(node);\n if (entry) return leafMember(writer, 'regular', () => emitKeyValue(writer, entry));\n const attribute = ModelAttributeAst.cast(node);\n if (attribute)\n return leafMember(writer, 'blockAttribute', () => emitBlockAttribute(writer, attribute));\n return undefined;\n });\n}\n\nfunction emitNamespace(\n writer: LineWriter,\n namespace: NamespaceDeclarationAst,\n trailing: string | undefined,\n): void {\n emitBlockBody(writer, namespace.syntax, trailing, (node) => {\n const declaration = castBlockDeclaration(node);\n if (declaration) return nestedBlockMember(writer, declaration);\n return undefined;\n });\n}\n\nfunction emitTypesBlock(\n writer: LineWriter,\n block: TypesBlockAst,\n trailing: string | undefined,\n): void {\n emitBlockBody(writer, block.syntax, trailing, (node) => {\n const named = NamedTypeDeclarationAst.cast(node);\n if (named) return leafMember(writer, 'regular', () => emitNamedType(writer, named));\n return undefined;\n });\n}\n\nfunction emitTopLevel(writer: LineWriter, document: DocumentAst): void {\n walkRegion(writer, Array.from(document.syntax.children()), undefined, (node) => {\n const declaration = castTopLevelDeclaration(node);\n if (declaration) return nestedBlockMember(writer, declaration);\n return undefined;\n });\n}\n\ntype BlockEmitter = (writer: LineWriter, trailing: string | undefined) => void;\n\nfunction nestedBlockMember(writer: LineWriter, block: BlockEmitter): BlockMember {\n return {\n category: 'nestedBlock',\n emit(trailing) {\n block(writer, trailing);\n return 0;\n },\n };\n}\n\nfunction castBlockDeclaration(node: SyntaxNode): BlockEmitter | undefined {\n const model = ModelDeclarationAst.cast(node);\n if (model) return (writer, trailing) => emitModel(writer, model, trailing);\n const composite = CompositeTypeDeclarationAst.cast(node);\n if (composite) return (writer, trailing) => emitCompositeType(writer, composite, trailing);\n const generic = GenericBlockDeclarationAst.cast(node);\n if (generic) return (writer, trailing) => emitGenericBlock(writer, generic, trailing);\n return undefined;\n}\n\nfunction castTopLevelDeclaration(node: SyntaxNode): BlockEmitter | undefined {\n const block = castBlockDeclaration(node);\n if (block) return block;\n const namespace = NamespaceDeclarationAst.cast(node);\n if (namespace) return (writer, trailing) => emitNamespace(writer, namespace, trailing);\n const types = TypesBlockAst.cast(node);\n if (types) return (writer, trailing) => emitTypesBlock(writer, types, trailing);\n return undefined;\n}\n\nfunction emitBlockBody(\n writer: LineWriter,\n node: SyntaxNode,\n closingTrailing: string | undefined,\n classify: MemberClassifier,\n): void {\n const children = Array.from(node.children());\n const openIndex = children.findIndex((el) => !(el instanceof SyntaxNode) && el.kind === 'LBrace');\n\n streamHeader(writer, node);\n const headerComment = sameLineCommentAfter(children, openIndex);\n if (headerComment !== undefined) writer.comment(headerComment);\n else writer.newline();\n\n writer.indent();\n walkRegion(writer, children, 'RBrace', classify);\n writer.unindent();\n\n writer.writeRaw('}');\n if (closingTrailing !== undefined) writer.comment(closingTrailing);\n else writer.newline();\n}\n\nfunction streamHeader(writer: LineWriter, node: SyntaxNode): void {\n let done = false;\n const walk = (parent: SyntaxNode): void => {\n for (const child of parent.children()) {\n if (done) return;\n if (child instanceof SyntaxNode) {\n walk(child);\n continue;\n }\n if (child.kind === 'Whitespace' || child.kind === 'Newline' || child.kind === 'Comment') {\n continue;\n }\n const space = spaceBetween(writer.prevKind(), child.kind, false);\n writer.write(child, space);\n if (child.kind === 'LBrace') {\n done = true;\n return;\n }\n }\n };\n walk(node);\n}\n\nfunction walkRegion(\n writer: LineWriter,\n elements: readonly SyntaxElement[],\n closeKind: 'RBrace' | undefined,\n classify: MemberClassifier,\n): void {\n let sawOpenBrace = closeKind === undefined;\n let sawContent = false;\n let lastWasRegular = false;\n let ledByComment = false;\n let newlines = 0;\n\n for (let i = 0; i < elements.length; i++) {\n const element = elements[i];\n if (element === undefined) continue;\n\n if (element instanceof SyntaxNode) {\n if (!sawOpenBrace) continue;\n const member = classify(element);\n if (member === undefined) continue;\n if (!ledByComment) {\n if (newlines >= 2 && sawContent && !writer.lastIsBlank()) writer.blank();\n else if (separationBlankWanted(writer, member.category, sawContent, lastWasRegular)) {\n writer.blank();\n }\n }\n\n const trailing = sameLineTrailingComment(elements, i);\n closeContinuation(writer, member.emit(trailing.text));\n if (trailing.index !== undefined) i = trailing.index;\n sawContent = true;\n lastWasRegular = member.category !== 'blockAttribute';\n ledByComment = false;\n newlines = 0;\n continue;\n }\n\n if (element.kind === 'LBrace' && closeKind === 'RBrace' && !sawOpenBrace) {\n sawOpenBrace = true;\n newlines = 0;\n continue;\n }\n if (!sawOpenBrace) continue;\n if (closeKind === 'RBrace' && element.kind === 'RBrace') break;\n if (element.kind === 'Whitespace') continue;\n if (element.kind === 'Newline') {\n newlines += 1;\n continue;\n }\n if (element.kind === 'Comment') {\n if (closeKind === 'RBrace' && newlines === 0 && !sawContent) {\n // Same-line comment trailing the opening `{`: owned by the block header.\n continue;\n }\n if (newlines >= 2 && sawContent && !writer.lastIsBlank()) writer.blank();\n else if (!ledByComment) {\n const led = leadingMemberAfter(elements, i, classify);\n if (led && separationBlankWanted(writer, led, sawContent, lastWasRegular)) writer.blank();\n }\n writer.writeRaw(element.text);\n writer.newline();\n sawContent = true;\n ledByComment = true;\n newlines = 0;\n }\n }\n}\n\nfunction separationBlankWanted(\n writer: LineWriter,\n category: MemberCategory,\n sawContent: boolean,\n lastWasRegular: boolean,\n): boolean {\n if (!sawContent || writer.lastIsBlank()) return false;\n if (category === 'nestedBlock') return true;\n return category === 'blockAttribute' && lastWasRegular;\n}\n\nfunction leadingMemberAfter(\n elements: readonly SyntaxElement[],\n commentIndex: number,\n classify: MemberClassifier,\n): MemberCategory | undefined {\n for (let i = commentIndex + 1; i < elements.length; i++) {\n const element = elements[i];\n if (element === undefined) continue;\n if (element instanceof SyntaxNode) return classify(element)?.category;\n if (element.kind === 'RBrace') return undefined;\n }\n return undefined;\n}\n\nfunction sameLineTrailingComment(\n elements: readonly SyntaxElement[],\n memberIndex: number,\n): { text: string | undefined; index: number | undefined } {\n for (let i = memberIndex + 1; i < elements.length; i++) {\n const element = elements[i];\n if (element === undefined) continue;\n if (element instanceof SyntaxNode) break;\n if (element.kind === 'Whitespace') continue;\n if (element.kind === 'Comment') return { text: element.text, index: i };\n break;\n }\n return { text: undefined, index: undefined };\n}\n\nfunction sameLineCommentAfter(\n children: readonly SyntaxElement[],\n openIndex: number,\n): string | undefined {\n for (let i = openIndex + 1; i < children.length; i++) {\n const child = children[i];\n if (child === undefined) continue;\n if (child instanceof SyntaxNode) return undefined;\n if (child.kind === 'Whitespace') continue;\n if (child.kind === 'Comment') return child.text;\n return undefined;\n }\n return undefined;\n}\n\ninterface AlignmentColumns {\n readonly typeColumn: number;\n readonly attributeColumn: number;\n}\n\nfunction alignmentMap(block: SyntaxNode): AlignmentColumns | undefined {\n const fields: SyntaxNode[] = [];\n for (const element of block.children()) {\n if (!(element instanceof SyntaxNode)) continue;\n if (FieldDeclarationAst.cast(element) === undefined) continue;\n // Interior comments split rows into continuation lines, so those rows opt out of alignment.\n if (hasInteriorComment(element)) continue;\n fields.push(element);\n }\n if (fields.length === 0) return undefined;\n return alignmentColumns(fields);\n}\n\nfunction alignmentColumns(rows: readonly SyntaxNode[]): AlignmentColumns {\n let nameWidth = 0;\n for (const row of rows) {\n const field = FieldDeclarationAst.cast(row);\n if (!field) continue;\n nameWidth = Math.max(nameWidth, renderTokens(field.name()?.syntax).length);\n }\n const typeColumn = nameWidth + 1;\n let cellEnd = 0;\n for (const row of rows) {\n const field = FieldDeclarationAst.cast(row);\n if (!field) continue;\n const name = renderTokens(field.name()?.syntax);\n const type = renderTokens(field.typeAnnotation()?.syntax);\n cellEnd = Math.max(cellEnd, type.length > 0 ? typeColumn + type.length : name.length);\n }\n return { typeColumn, attributeColumn: cellEnd + 1 };\n}\n\nfunction hasInteriorComment(node: SyntaxNode): boolean {\n for (const token of node.tokens()) {\n if (token.kind === 'Comment') return true;\n }\n return false;\n}\n\nfunction renderTokens(node: SyntaxNode | undefined): string {\n if (!node) return '';\n let out = '';\n let prev: TokenKind | undefined;\n let prevQualified = false;\n const walk = (parent: SyntaxNode, qualified: boolean): void => {\n for (const child of parent.children()) {\n if (child instanceof SyntaxNode) {\n walk(child, qualified || child.kind === 'QualifiedName');\n continue;\n }\n if (child.kind === 'Whitespace' || child.kind === 'Newline' || child.kind === 'Comment') {\n continue;\n }\n if (spaceBetween(prev, child.kind, qualified && prevQualified)) out += ' ';\n out += child.text;\n prev = child.kind;\n prevQualified = qualified;\n }\n };\n walk(node, false);\n return out;\n}\n","export interface FormatOptions {\n readonly indent?: number | 'tab';\n readonly newline?: 'LF' | 'CRLF';\n}\n\nexport interface ResolvedFormatOptions {\n readonly indentUnit: string;\n readonly newline: string;\n}\n\nexport function resolveFormatOptions(options: FormatOptions | undefined): ResolvedFormatOptions {\n const indent = options?.indent ?? 2;\n if (indent !== 'tab' && (typeof indent !== 'number' || !Number.isInteger(indent) || indent < 1)) {\n throw new TypeError(\n `Invalid format options: indent must be a positive integer or 'tab', got ${String(indent)}`,\n );\n }\n const newline = options?.newline ?? 'LF';\n if (newline !== 'LF' && newline !== 'CRLF') {\n throw new TypeError(\n `Invalid format options: newline must be 'LF' or 'CRLF', got ${String(newline)}`,\n );\n }\n return {\n indentUnit: indent === 'tab' ? '\\t' : ' '.repeat(indent),\n newline: newline === 'CRLF' ? '\\r\\n' : '\\n',\n };\n}\n","import { parse } from '../parse';\nimport { emitDocument } from './emit';\nimport { PslFormatError } from './error';\nimport { type FormatOptions, resolveFormatOptions } from './options';\n\nexport function format(source: string, options?: FormatOptions): string {\n const resolved = resolveFormatOptions(options);\n const { document, diagnostics } = parse(source);\n if (diagnostics.length > 0) {\n throw new PslFormatError(diagnostics);\n }\n return emitDocument(document, resolved.indentUnit, resolved.newline);\n}\n"],"mappings":";;AAEA,IAAa,iBAAb,cAAoC,MAAM;CACxC;CAEA,YAAY,aAAyC;EACnD,MAAM,UAAU,YAAY,EAAE,EAAE,WAAW;EAC3C,MAAM,OAAO,YAAY,SAAS,IAAI,SAAS,YAAY,SAAS,EAAE,UAAU;EAChF,MAAM,wCAAwC,UAAU,MAAM;EAC9D,KAAK,OAAO;EACZ,KAAK,cAAc;CACrB;AACF;;;ACGA,SAAgB,aAAa,UAAuB,YAAoB,SAAyB;CAC/F,MAAM,SAAS,IAAI,WAAW,YAAY,OAAO;CACjD,aAAa,QAAQ,QAAQ;CAC7B,OAAO,OAAO,OAAO;AACvB;AAEA,IAAM,aAAN,MAAiB;CACf;CACA;CACA,OAA0B,CAAC;CAC3B,SAAS;CACT,QAAQ;CACR,YAAY;CACZ;CACA,gBAAgB;CAChB,cAAc;CAEd,YAAY,YAAoB,SAAiB;EAC/C,KAAKA,cAAc;EACnB,KAAKC,WAAW;CAClB;CAEA,SAAe;EACb,KAAKE,UAAU;CACjB;CAEA,WAAiB;EACf,KAAKA,SAAS,KAAK,IAAI,GAAG,KAAKA,SAAS,CAAC;CAC3C;CAEA,cAAuB;EACrB,OAAO,KAAKC;CACd;CAEA,WAAoB;EAClB,OAAO,KAAKC;CACd;CAEA,WAAkC;EAChC,OAAO,KAAKC;CACd;CAEA,UAAgB;EACd,IAAI,CAAC,KAAKD,WAAW;EACrB,KAAKH,KAAK,KAAK,GAAG,KAAKF,YAAY,OAAO,KAAKG,MAAM,IAAI,KAAKI,OAAO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