@abapify/abap-ast 0.4.0 → 0.4.3

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/dist/index.mjs ADDED
@@ -0,0 +1,1150 @@
1
+ //#region src/nodes/errors.ts
2
+ var AbapAstError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "AbapAstError";
6
+ }
7
+ };
8
+ function requireField(value, field, nodeKind) {
9
+ if (value === void 0 || value === null || value === "") throw new AbapAstError(`${nodeKind}: required field "${field}" is missing`);
10
+ return value;
11
+ }
12
+
13
+ //#endregion
14
+ //#region src/nodes/base.ts
15
+ function comment(input) {
16
+ if (typeof input.text !== "string") throw new AbapAstError("Comment: required field \"text\" is missing");
17
+ return Object.freeze({
18
+ kind: "Comment",
19
+ text: input.text,
20
+ style: input.style ?? "line"
21
+ });
22
+ }
23
+
24
+ //#endregion
25
+ //#region src/nodes/types.ts
26
+ const BUILTIN_TYPE_NAMES = /* @__PURE__ */ new Set([
27
+ "i",
28
+ "int8",
29
+ "f",
30
+ "decfloat34",
31
+ "d",
32
+ "t",
33
+ "timestampl",
34
+ "string",
35
+ "xstring",
36
+ "abap_bool",
37
+ "sysuuid_x16"
38
+ ]);
39
+ function builtinType(input) {
40
+ if (!input.name) throw new AbapAstError("BuiltinType: required field \"name\" is missing");
41
+ if (!BUILTIN_TYPE_NAMES.has(input.name)) throw new AbapAstError(`BuiltinType: unknown builtin type "${String(input.name)}"`);
42
+ return Object.freeze({
43
+ kind: "BuiltinType",
44
+ name: input.name,
45
+ length: input.length,
46
+ decimals: input.decimals
47
+ });
48
+ }
49
+ function namedTypeRef(input) {
50
+ if (!input.name) throw new AbapAstError("NamedTypeRef: required field \"name\" is missing");
51
+ return Object.freeze({
52
+ kind: "NamedTypeRef",
53
+ name: input.name
54
+ });
55
+ }
56
+ function tableType(input) {
57
+ if (!input.rowType) throw new AbapAstError("TableType: required field \"rowType\" is missing");
58
+ return Object.freeze({
59
+ kind: "TableType",
60
+ rowType: input.rowType,
61
+ tableKind: input.tableKind ?? "standard",
62
+ uniqueness: input.uniqueness,
63
+ keyFields: input.keyFields ? Object.freeze([...input.keyFields]) : void 0
64
+ });
65
+ }
66
+ function structureType(input) {
67
+ if (!input.fields || input.fields.length === 0) throw new AbapAstError("StructureType: must declare at least one field");
68
+ for (const f of input.fields) {
69
+ if (!f.name) throw new AbapAstError("StructureType: field is missing \"name\"");
70
+ if (!f.type) throw new AbapAstError(`StructureType: field "${f.name}" is missing "type"`);
71
+ }
72
+ return Object.freeze({
73
+ kind: "StructureType",
74
+ fields: Object.freeze(input.fields.map((f) => Object.freeze({ ...f })))
75
+ });
76
+ }
77
+ function enumType(input) {
78
+ if (!input.baseType) throw new AbapAstError("EnumType: required field \"baseType\" is missing");
79
+ if (!input.members || input.members.length === 0) throw new AbapAstError("EnumType: must declare at least one member");
80
+ for (const m of input.members) if (!m.name) throw new AbapAstError("EnumType: member is missing \"name\"");
81
+ return Object.freeze({
82
+ kind: "EnumType",
83
+ baseType: input.baseType,
84
+ members: Object.freeze(input.members.map((m) => Object.freeze({ ...m })))
85
+ });
86
+ }
87
+ function typeDef(input) {
88
+ if (!input.name) throw new AbapAstError("TypeDef: required field \"name\" is missing");
89
+ if (!input.type) throw new AbapAstError("TypeDef: required field \"type\" is missing");
90
+ return Object.freeze({
91
+ kind: "TypeDef",
92
+ name: input.name,
93
+ type: input.type,
94
+ abapDoc: input.abapDoc ? Object.freeze([...input.abapDoc]) : void 0
95
+ });
96
+ }
97
+
98
+ //#endregion
99
+ //#region src/nodes/data.ts
100
+ function dataDecl(input) {
101
+ if (!input.name) throw new AbapAstError("DataDecl: required field \"name\" is missing");
102
+ if (!input.type) throw new AbapAstError("DataDecl: required field \"type\" is missing");
103
+ return Object.freeze({
104
+ kind: "DataDecl",
105
+ name: input.name,
106
+ type: input.type,
107
+ initial: input.initial,
108
+ classData: input.classData
109
+ });
110
+ }
111
+ function constantDecl(input) {
112
+ if (!input.name) throw new AbapAstError("ConstantDecl: required field \"name\" is missing");
113
+ if (!input.type) throw new AbapAstError("ConstantDecl: required field \"type\" is missing");
114
+ if (!input.value) throw new AbapAstError("ConstantDecl: required field \"value\" is missing");
115
+ return Object.freeze({
116
+ kind: "ConstantDecl",
117
+ name: input.name,
118
+ type: input.type,
119
+ value: input.value,
120
+ classData: input.classData
121
+ });
122
+ }
123
+ function fieldSymbolDecl(input) {
124
+ if (!input.name) throw new AbapAstError("FieldSymbolDecl: required field \"name\" is missing");
125
+ if (!input.name.startsWith("<") || !input.name.endsWith(">")) throw new AbapAstError(`FieldSymbolDecl: name "${input.name}" must be wrapped in angle brackets (e.g. <fs_x>)`);
126
+ if (!input.type) throw new AbapAstError("FieldSymbolDecl: required field \"type\" is missing");
127
+ return Object.freeze({
128
+ kind: "FieldSymbolDecl",
129
+ name: input.name,
130
+ type: input.type
131
+ });
132
+ }
133
+
134
+ //#endregion
135
+ //#region src/nodes/expressions.ts
136
+ function literal(input) {
137
+ if (!input.literalKind) throw new AbapAstError("Literal: required field \"literalKind\" is missing");
138
+ if (input.value === void 0 || input.value === null) throw new AbapAstError("Literal: required field \"value\" is missing");
139
+ if (input.literalKind === "int" && typeof input.value !== "number") throw new AbapAstError("Literal: int literal requires a number value");
140
+ if (input.literalKind === "bool" && typeof input.value !== "boolean") throw new AbapAstError("Literal: bool literal requires a boolean value");
141
+ if ((input.literalKind === "string" || input.literalKind === "hex") && typeof input.value !== "string") throw new AbapAstError(`Literal: ${input.literalKind} literal requires a string value`);
142
+ return Object.freeze({
143
+ kind: "Literal",
144
+ literalKind: input.literalKind,
145
+ value: input.value
146
+ });
147
+ }
148
+ function identifierExpr(input) {
149
+ if (!input.name) throw new AbapAstError("IdentifierExpr: required field \"name\" is missing");
150
+ return Object.freeze({
151
+ kind: "IdentifierExpr",
152
+ name: input.name
153
+ });
154
+ }
155
+ function constructorExpr(input) {
156
+ if (!input.type) throw new AbapAstError("ConstructorExpr: required field \"type\" is missing");
157
+ return Object.freeze({
158
+ kind: "ConstructorExpr",
159
+ type: input.type,
160
+ args: Object.freeze((input.args ?? []).map((a) => Object.freeze({ ...a })))
161
+ });
162
+ }
163
+ function methodCallExpr(input) {
164
+ if (!input.method) throw new AbapAstError("MethodCallExpr: required field \"method\" is missing");
165
+ if (input.callKind === "instance" && !input.receiver) throw new AbapAstError("MethodCallExpr: instance calls require a receiver");
166
+ return Object.freeze({
167
+ kind: "MethodCallExpr",
168
+ receiver: input.receiver,
169
+ method: input.method,
170
+ callKind: input.callKind,
171
+ args: Object.freeze((input.args ?? []).map((a) => Object.freeze({ ...a })))
172
+ });
173
+ }
174
+ function binOp(input) {
175
+ if (!input.op) throw new AbapAstError("BinOp: required field \"op\" is missing");
176
+ if (!input.left) throw new AbapAstError("BinOp: required field \"left\" is missing");
177
+ if (!input.right) throw new AbapAstError("BinOp: required field \"right\" is missing");
178
+ return Object.freeze({
179
+ kind: "BinOp",
180
+ op: input.op,
181
+ left: input.left,
182
+ right: input.right
183
+ });
184
+ }
185
+ function stringTemplate(input) {
186
+ if (!input.parts) throw new AbapAstError("StringTemplate: required field \"parts\" is missing");
187
+ return Object.freeze({
188
+ kind: "StringTemplate",
189
+ parts: Object.freeze(input.parts.map((p) => Object.freeze({ ...p })))
190
+ });
191
+ }
192
+ function cast(input) {
193
+ if (!input.type) throw new AbapAstError("Cast: required field \"type\" is missing");
194
+ if (!input.expr) throw new AbapAstError("Cast: required field \"expr\" is missing");
195
+ return Object.freeze({
196
+ kind: "Cast",
197
+ type: input.type,
198
+ expr: input.expr
199
+ });
200
+ }
201
+
202
+ //#endregion
203
+ //#region src/nodes/statements.ts
204
+ function assign(input) {
205
+ if (!input.target) throw new AbapAstError("Assign: required field \"target\" is missing");
206
+ if (!input.value) throw new AbapAstError("Assign: required field \"value\" is missing");
207
+ return Object.freeze({
208
+ kind: "Assign",
209
+ target: input.target,
210
+ value: input.value
211
+ });
212
+ }
213
+ function call(input) {
214
+ if (!input.method) throw new AbapAstError("Call: required field \"method\" is missing");
215
+ if (input.callKind !== "static" && input.callKind !== "instance") throw new AbapAstError("Call: required field \"callKind\" must be \"static\" or \"instance\"");
216
+ if (input.callKind === "instance" && !input.receiver) throw new AbapAstError("Call: instance calls require a receiver");
217
+ return Object.freeze({
218
+ kind: "Call",
219
+ receiver: input.receiver,
220
+ method: input.method,
221
+ callKind: input.callKind,
222
+ args: Object.freeze((input.args ?? []).map((a) => Object.freeze({ ...a })))
223
+ });
224
+ }
225
+ function raise(input) {
226
+ if (!input.exceptionType) throw new AbapAstError("Raise: required field \"exceptionType\" is missing");
227
+ return Object.freeze({
228
+ kind: "Raise",
229
+ exceptionType: input.exceptionType,
230
+ args: Object.freeze((input.args ?? []).map((a) => Object.freeze({ ...a })))
231
+ });
232
+ }
233
+ function ifStmt(input) {
234
+ if (!input.condition) throw new AbapAstError("If: required field \"condition\" is missing");
235
+ if (!input.thenBody) throw new AbapAstError("If: required field \"thenBody\" is missing");
236
+ return Object.freeze({
237
+ kind: "If",
238
+ condition: input.condition,
239
+ thenBody: Object.freeze([...input.thenBody]),
240
+ elseIfs: Object.freeze((input.elseIfs ?? []).map((b) => Object.freeze({
241
+ ...b,
242
+ body: Object.freeze([...b.body])
243
+ }))),
244
+ else: input.else ? Object.freeze([...input.else]) : void 0
245
+ });
246
+ }
247
+ function loop(input) {
248
+ if (!input.table) throw new AbapAstError("Loop: required field \"table\" is missing");
249
+ if (!input.binding) throw new AbapAstError("Loop: required field \"binding\" is missing");
250
+ if (input.binding.bindKind === "assigning") {
251
+ const fs = input.binding.fieldSymbol;
252
+ if (!fs.startsWith("<") || !fs.endsWith(">")) throw new AbapAstError(`Loop: assigning target "${fs}" must be a field symbol wrapped in angle brackets`);
253
+ }
254
+ if (!input.body) throw new AbapAstError("Loop: required field \"body\" is missing");
255
+ return Object.freeze({
256
+ kind: "Loop",
257
+ table: input.table,
258
+ binding: Object.freeze({ ...input.binding }),
259
+ body: Object.freeze([...input.body])
260
+ });
261
+ }
262
+ function returnStmt(input) {
263
+ if (input?.value !== void 0 && !input.target) throw new AbapAstError("returnStmt: `target` (the RETURNING parameter name) is required when `value` is set — ABAP has no implicit `rv` variable");
264
+ return Object.freeze({
265
+ kind: "Return",
266
+ value: input?.value,
267
+ target: input?.target
268
+ });
269
+ }
270
+ function tryStmt(input) {
271
+ if (!input.body) throw new AbapAstError("Try: required field \"body\" is missing");
272
+ if (!input.catches || input.catches.length === 0) throw new AbapAstError("Try: must declare at least one CATCH clause");
273
+ for (const c of input.catches) if (!c.exceptionTypes || c.exceptionTypes.length === 0) throw new AbapAstError("Try: CATCH clause must declare at least one exception type");
274
+ return Object.freeze({
275
+ kind: "Try",
276
+ body: Object.freeze([...input.body]),
277
+ catches: Object.freeze(input.catches.map((c) => Object.freeze({
278
+ ...c,
279
+ exceptionTypes: Object.freeze([...c.exceptionTypes]),
280
+ body: Object.freeze([...c.body])
281
+ }))),
282
+ cleanup: input.cleanup ? Object.freeze([...input.cleanup]) : void 0
283
+ });
284
+ }
285
+ function append(input) {
286
+ if (!input.value) throw new AbapAstError("Append: required field \"value\" is missing");
287
+ if (!input.table) throw new AbapAstError("Append: required field \"table\" is missing");
288
+ return Object.freeze({
289
+ kind: "Append",
290
+ value: input.value,
291
+ table: input.table
292
+ });
293
+ }
294
+ function insert(input) {
295
+ if (!input.value) throw new AbapAstError("Insert: required field \"value\" is missing");
296
+ if (!input.table) throw new AbapAstError("Insert: required field \"table\" is missing");
297
+ return Object.freeze({
298
+ kind: "Insert",
299
+ value: input.value,
300
+ table: input.table
301
+ });
302
+ }
303
+ function read(input) {
304
+ if (!input.table) throw new AbapAstError("Read: required field \"table\" is missing");
305
+ if (!input.binding) throw new AbapAstError("Read: required field \"binding\" is missing");
306
+ return Object.freeze({
307
+ kind: "Read",
308
+ table: input.table,
309
+ binding: Object.freeze({ ...input.binding }),
310
+ withKey: input.withKey ? Object.freeze(input.withKey.map((a) => Object.freeze({ ...a }))) : void 0,
311
+ index: input.index
312
+ });
313
+ }
314
+ function clear(input) {
315
+ if (!input.target) throw new AbapAstError("Clear: required field \"target\" is missing");
316
+ return Object.freeze({
317
+ kind: "Clear",
318
+ target: input.target
319
+ });
320
+ }
321
+ function exit() {
322
+ return Object.freeze({ kind: "Exit" });
323
+ }
324
+ function continueStmt() {
325
+ return Object.freeze({ kind: "Continue" });
326
+ }
327
+ function raw(input) {
328
+ if (typeof input.source !== "string" || input.source.length === 0) throw new AbapAstError("Raw: required field \"source\" is missing");
329
+ return Object.freeze({
330
+ kind: "Raw",
331
+ source: input.source
332
+ });
333
+ }
334
+
335
+ //#endregion
336
+ //#region src/nodes/members.ts
337
+ function methodParam(input) {
338
+ if (!input.paramKind) throw new AbapAstError("MethodParam: required field \"paramKind\" is missing");
339
+ if (!input.name) throw new AbapAstError("MethodParam: required field \"name\" is missing");
340
+ if (!input.typeRef) throw new AbapAstError("MethodParam: required field \"typeRef\" is missing");
341
+ if (input.paramKind === "returning" && input.optional) throw new AbapAstError("MethodParam: RETURNING parameters cannot be optional");
342
+ if (input.paramKind === "returning" && input.default !== void 0) throw new AbapAstError("MethodParam: RETURNING parameters cannot have a default");
343
+ return Object.freeze({
344
+ kind: "MethodParam",
345
+ paramKind: input.paramKind,
346
+ name: input.name,
347
+ typeRef: input.typeRef,
348
+ optional: input.optional,
349
+ default: input.default
350
+ });
351
+ }
352
+ function methodDef(input) {
353
+ if (!input.name) throw new AbapAstError("MethodDef: required field \"name\" is missing");
354
+ if (!input.visibility) throw new AbapAstError("MethodDef: required field \"visibility\" is missing");
355
+ const params = input.params ?? [];
356
+ const returning = params.filter((p) => p.paramKind === "returning");
357
+ if (returning.length > 1) throw new AbapAstError("MethodDef: a method can have at most one RETURNING parameter");
358
+ if (returning.length === 1) {
359
+ if (params.some((p) => p.paramKind === "exporting" || p.paramKind === "changing")) throw new AbapAstError("MethodDef: RETURNING parameter cannot be combined with EXPORTING or CHANGING");
360
+ }
361
+ return Object.freeze({
362
+ kind: "MethodDef",
363
+ name: input.name,
364
+ params: Object.freeze([...params]),
365
+ raising: Object.freeze([...input.raising ?? []]),
366
+ visibility: input.visibility,
367
+ isClassMethod: input.isClassMethod,
368
+ isAbstract: input.isAbstract,
369
+ isFinal: input.isFinal,
370
+ isRedefinition: input.isRedefinition,
371
+ isForTesting: input.isForTesting,
372
+ abapDoc: input.abapDoc ? Object.freeze([...input.abapDoc]) : void 0
373
+ });
374
+ }
375
+ function methodImpl(input) {
376
+ if (!input.name) throw new AbapAstError("MethodImpl: required field \"name\" is missing");
377
+ if (!input.body) throw new AbapAstError("MethodImpl: required field \"body\" is missing");
378
+ return Object.freeze({
379
+ kind: "MethodImpl",
380
+ name: input.name,
381
+ body: Object.freeze([...input.body])
382
+ });
383
+ }
384
+ function eventDef(input) {
385
+ if (!input.name) throw new AbapAstError("EventDef: required field \"name\" is missing");
386
+ if (!input.visibility) throw new AbapAstError("EventDef: required field \"visibility\" is missing");
387
+ return Object.freeze({
388
+ kind: "EventDef",
389
+ name: input.name,
390
+ visibility: input.visibility,
391
+ isClassEvent: input.isClassEvent
392
+ });
393
+ }
394
+ function attributeDef(input) {
395
+ if (!input.name) throw new AbapAstError("AttributeDef: required field \"name\" is missing");
396
+ if (!input.type) throw new AbapAstError("AttributeDef: required field \"type\" is missing");
397
+ if (!input.visibility) throw new AbapAstError("AttributeDef: required field \"visibility\" is missing");
398
+ return Object.freeze({
399
+ kind: "AttributeDef",
400
+ name: input.name,
401
+ type: input.type,
402
+ visibility: input.visibility,
403
+ classData: input.classData,
404
+ readOnly: input.readOnly,
405
+ initial: input.initial,
406
+ abapDoc: input.abapDoc ? Object.freeze([...input.abapDoc]) : void 0
407
+ });
408
+ }
409
+
410
+ //#endregion
411
+ //#region src/nodes/class.ts
412
+ function section(input) {
413
+ if (!input.visibility) throw new AbapAstError("Section: required field \"visibility\" is missing");
414
+ const members = input.members ?? [];
415
+ for (const m of members) if ("visibility" in m && m.visibility !== input.visibility) throw new AbapAstError(`Section: member "${m.name}" has visibility "${m.visibility}" but section is "${input.visibility}"`);
416
+ return Object.freeze({
417
+ kind: "Section",
418
+ visibility: input.visibility,
419
+ members: Object.freeze([...members])
420
+ });
421
+ }
422
+ function classDef(input) {
423
+ if (!input.name) throw new AbapAstError("ClassDef: required field \"name\" is missing");
424
+ if (input.isFinal && input.isAbstract) throw new AbapAstError("ClassDef: class cannot be both FINAL and ABSTRACT");
425
+ return Object.freeze({
426
+ kind: "ClassDef",
427
+ name: input.name,
428
+ superclass: input.superclass,
429
+ interfaces: Object.freeze([...input.interfaces ?? []]),
430
+ isFinal: input.isFinal,
431
+ isAbstract: input.isAbstract,
432
+ isForTesting: input.isForTesting,
433
+ isCreatePrivate: input.isCreatePrivate,
434
+ sections: Object.freeze([...input.sections ?? []]),
435
+ implementations: Object.freeze([...input.implementations ?? []]),
436
+ abapDoc: input.abapDoc ? Object.freeze([...input.abapDoc]) : void 0
437
+ });
438
+ }
439
+ function localClassDef(input) {
440
+ if (!input.name) throw new AbapAstError("LocalClassDef: required field \"name\" is missing");
441
+ if (input.isFinal && input.isAbstract) throw new AbapAstError("LocalClassDef: class cannot be both FINAL and ABSTRACT");
442
+ return Object.freeze({
443
+ kind: "LocalClassDef",
444
+ name: input.name,
445
+ superclass: input.superclass,
446
+ interfaces: Object.freeze([...input.interfaces ?? []]),
447
+ isFinal: input.isFinal,
448
+ isAbstract: input.isAbstract,
449
+ isForTesting: input.isForTesting,
450
+ sections: Object.freeze([...input.sections ?? []]),
451
+ implementations: Object.freeze([...input.implementations ?? []]),
452
+ local: true
453
+ });
454
+ }
455
+
456
+ //#endregion
457
+ //#region src/nodes/interface.ts
458
+ function interfaceDef(input) {
459
+ if (!input.name) throw new AbapAstError("InterfaceDef: required field \"name\" is missing");
460
+ const members = input.members ?? [];
461
+ for (const m of members) if (m.kind === "MethodDef" && m.visibility !== "public") throw new AbapAstError(`InterfaceDef: method "${m.name}" must be public (interfaces expose only public methods)`);
462
+ return Object.freeze({
463
+ kind: "InterfaceDef",
464
+ name: input.name,
465
+ members: Object.freeze([...members]),
466
+ abapDoc: input.abapDoc ? Object.freeze([...input.abapDoc]) : void 0
467
+ });
468
+ }
469
+
470
+ //#endregion
471
+ //#region src/printer/options.ts
472
+ function resolveOptions(o) {
473
+ return {
474
+ indent: o?.indent ?? 2,
475
+ keywordCase: o?.keywordCase ?? "upper",
476
+ eol: o?.eol ?? "\n"
477
+ };
478
+ }
479
+
480
+ //#endregion
481
+ //#region src/printer/writer.ts
482
+ /** Tiny indentation-aware string builder. */
483
+ var Writer = class {
484
+ lines = [];
485
+ level = 0;
486
+ opts;
487
+ constructor(opts) {
488
+ this.opts = opts;
489
+ }
490
+ get options() {
491
+ return this.opts;
492
+ }
493
+ indent() {
494
+ this.level += 1;
495
+ }
496
+ dedent() {
497
+ if (this.level === 0) throw new Error("Writer: cannot dedent below 0");
498
+ this.level -= 1;
499
+ }
500
+ /** Current indent prefix. */
501
+ prefix() {
502
+ return " ".repeat(this.level * this.opts.indent);
503
+ }
504
+ /** Write a full line with current indent. Empty string = blank line (no whitespace). */
505
+ writeLine(s = "") {
506
+ if (s.length === 0) this.lines.push("");
507
+ else this.lines.push(this.prefix() + s);
508
+ }
509
+ /** Append text to the most recent line (no newline). Starts a new indented line if none exists. */
510
+ write(s) {
511
+ if (this.lines.length === 0) this.lines.push(this.prefix() + s);
512
+ else this.lines[this.lines.length - 1] += s;
513
+ }
514
+ /** Emit a blank line. */
515
+ blank() {
516
+ this.lines.push("");
517
+ }
518
+ /** Emit a line with no indent prefix (used by star comments, which must begin at column 1). */
519
+ rawLine(s) {
520
+ this.lines.push(s);
521
+ }
522
+ /** Transform a keyword according to keywordCase. */
523
+ kw(word) {
524
+ return this.opts.keywordCase === "lower" ? word.toLowerCase() : word.toUpperCase();
525
+ }
526
+ toString() {
527
+ return this.lines.join(this.opts.eol);
528
+ }
529
+ };
530
+
531
+ //#endregion
532
+ //#region src/printer/print-types.ts
533
+ /**
534
+ * Emit each ABAPDoc line as `"! <line>` at the current indent, immediately
535
+ * above the following declaration. Does nothing when `doc` is undefined or
536
+ * empty. Content is passed through verbatim — tabs and special characters
537
+ * are preserved.
538
+ */
539
+ function printAbapDoc(doc, writer) {
540
+ if (!doc || doc.length === 0) return;
541
+ for (const line of doc) writer.writeLine(line.length === 0 ? "\"!" : `"! ${line}`);
542
+ }
543
+ /** Print a TypeRef as an inline type expression (e.g. 'string', 'i', 'zcl_foo'). */
544
+ function printInlineType(type, writer) {
545
+ switch (type.kind) {
546
+ case "BuiltinType": {
547
+ const parts = [type.name];
548
+ if (type.length !== void 0) parts.push(`${writer.kw("LENGTH")} ${type.length}`);
549
+ if (type.decimals !== void 0) parts.push(`${writer.kw("DECIMALS")} ${type.decimals}`);
550
+ return parts.join(" ");
551
+ }
552
+ case "NamedTypeRef": return type.name;
553
+ case "TableType": throw new Error("printInlineType: TableType cannot be used as an inline type reference");
554
+ case "StructureType": throw new Error("printInlineType: StructureType cannot be used as an inline type reference");
555
+ }
556
+ }
557
+ /** Print a TYPES top-level declaration. */
558
+ function printTypeDef(node, writer) {
559
+ printAbapDoc(node.abapDoc, writer);
560
+ const K = (s) => writer.kw(s);
561
+ const t = node.type;
562
+ if (t.kind === "StructureType") {
563
+ writer.writeLine(`${K("TYPES")}: ${K("BEGIN OF")} ${node.name},`);
564
+ writer.indent();
565
+ const maxName = Math.max(...t.fields.map((f) => f.name.length));
566
+ t.fields.forEach((f) => {
567
+ const pad = " ".repeat(maxName - f.name.length);
568
+ writer.writeLine(`${f.name}${pad} ${K("TYPE")} ${printInlineType(f.type, writer)},`);
569
+ });
570
+ writer.dedent();
571
+ writer.writeLine(`${K("END OF")} ${node.name}.`);
572
+ return;
573
+ }
574
+ if (t.kind === "TableType") {
575
+ const kindKw = {
576
+ standard: K("STANDARD"),
577
+ sorted: K("SORTED"),
578
+ hashed: K("HASHED")
579
+ }[t.tableKind];
580
+ const row = printInlineType(t.rowType, writer);
581
+ let key;
582
+ if (t.keyFields && t.keyFields.length > 0) {
583
+ const uniq = t.uniqueness === "unique" ? K("UNIQUE") : K("NON-UNIQUE");
584
+ key = `${K("WITH")} ${uniq} ${K("KEY")} ${t.keyFields.join(" ")}`;
585
+ } else key = `${K("WITH")} ${K("DEFAULT KEY")}`;
586
+ writer.writeLine(`${K("TYPES")} ${node.name} ${K("TYPE")} ${kindKw} ${K("TABLE OF")} ${row} ${key}.`);
587
+ return;
588
+ }
589
+ if (t.kind === "EnumType") {
590
+ writer.writeLine(`${K("TYPES")}: ${K("BEGIN OF ENUM")} ${node.name} ${K("BASE TYPE")} ${printInlineType(t.baseType, writer)},`);
591
+ writer.indent();
592
+ const maxName = Math.max(...t.members.map((m) => m.name.length));
593
+ t.members.forEach((m) => {
594
+ const pad = " ".repeat(maxName - m.name.length);
595
+ const val = typeof m.value === "number" ? String(m.value) : `'${m.value}'`;
596
+ writer.writeLine(`${m.name}${pad} ${K("VALUE")} ${val},`);
597
+ });
598
+ writer.dedent();
599
+ writer.writeLine(`${K("END OF ENUM")} ${node.name}.`);
600
+ return;
601
+ }
602
+ writer.writeLine(`${K("TYPES")} ${node.name} ${K("TYPE")} ${printInlineType(t, writer)}.`);
603
+ }
604
+
605
+ //#endregion
606
+ //#region src/printer/print-expressions.ts
607
+ /** Print an expression to a single string (no newlines unless forced by wrapping). */
608
+ function printExpression(expr, writer) {
609
+ switch (expr.kind) {
610
+ case "Literal": return printLiteral(expr.literalKind, expr.value);
611
+ case "IdentifierExpr": return expr.name;
612
+ case "ConstructorExpr": {
613
+ const type = printInlineType(expr.type, writer);
614
+ const args = printArgs(expr.args, writer, 0);
615
+ return `${writer.kw("NEW")} ${type}(${args})`;
616
+ }
617
+ case "MethodCallExpr": {
618
+ const args = printArgs(expr.args, writer, 0);
619
+ if (expr.callKind === "static") {
620
+ const recv = expr.receiver !== void 0 ? printExpression(expr.receiver, writer) : "";
621
+ return `${recv.length > 0 ? `${recv}=>${expr.method}` : expr.method}(${args})`;
622
+ }
623
+ if (expr.receiver === void 0) throw new Error("MethodCallExpr: instance call has no receiver");
624
+ return `${printExpression(expr.receiver, writer)}->${expr.method}(${args})`;
625
+ }
626
+ case "BinOp": {
627
+ const wrap = (inner) => {
628
+ const src = printExpression(inner, writer);
629
+ return inner.kind === "BinOp" ? `( ${src} )` : src;
630
+ };
631
+ const left = wrap(expr.left);
632
+ const right = wrap(expr.right);
633
+ return `${left} ${expr.op === "AND" || expr.op === "OR" ? writer.kw(expr.op) : expr.op} ${right}`;
634
+ }
635
+ case "StringTemplate": return printStringTemplate(expr, writer);
636
+ case "Cast": {
637
+ const type = printInlineType(expr.type, writer);
638
+ const inner = printExpression(expr.expr, writer);
639
+ return `${writer.kw("CAST")} ${type}( ${inner} )`;
640
+ }
641
+ }
642
+ }
643
+ function printLiteral(kind, value) {
644
+ switch (kind) {
645
+ case "string": return `'${String(value).replaceAll("'", `''`)}'`;
646
+ case "int": return String(value);
647
+ case "bool": return value ? "abap_true" : "abap_false";
648
+ case "hex": return `'${String(value)}'`;
649
+ }
650
+ }
651
+ /** Print the inside of `( ... )` for a named-arg list. Empty → ' ' (ABAP convention). */
652
+ function printArgs(args, writer, currentColumn) {
653
+ if (args.length === 0) return " ";
654
+ const singleLine = ` ${args.map((a) => `${a.name} = ${printExpression(a.value, writer)}`).join(" ")} `;
655
+ if (currentColumn + singleLine.length + 2 <= 80) return singleLine;
656
+ const eol = writer.options.eol;
657
+ const pad = " ".repeat(currentColumn + writer.options.indent);
658
+ return eol + args.map((a) => `${pad}${a.name} = ${printExpression(a.value, writer)}`).join(eol) + eol + " ".repeat(currentColumn);
659
+ }
660
+ function printStringTemplate(node, writer) {
661
+ let out = "|";
662
+ for (const part of node.parts) if (part.partKind === "text") out += part.text;
663
+ else out += `{ ${printExpression(part.expr, writer)} }`;
664
+ out += "|";
665
+ return out;
666
+ }
667
+
668
+ //#endregion
669
+ //#region src/printer/print-statements.ts
670
+ function printStatements(stmts, writer) {
671
+ for (const s of stmts) printStatement(s, writer);
672
+ }
673
+ function printStatement(stmt, writer) {
674
+ const K = (s) => writer.kw(s);
675
+ switch (stmt.kind) {
676
+ case "Comment":
677
+ printComment(stmt, writer);
678
+ return;
679
+ case "DataDecl":
680
+ printDataDecl(stmt, writer);
681
+ return;
682
+ case "FieldSymbolDecl":
683
+ printFieldSymbolDecl(stmt, writer);
684
+ return;
685
+ case "Assign": {
686
+ const target = printExpression(stmt.target, writer);
687
+ const value = printExpression(stmt.value, writer);
688
+ writer.writeLine(`${target} = ${value}.`);
689
+ return;
690
+ }
691
+ case "Call": {
692
+ const col = writer.prefix().length;
693
+ if (stmt.callKind === "static") {
694
+ const recv = stmt.receiver !== void 0 ? printExpression(stmt.receiver, writer) : "";
695
+ const head = recv.length > 0 ? `${recv}=>${stmt.method}` : stmt.method;
696
+ const args = printArgs(stmt.args, writer, col + head.length + 1);
697
+ writer.writeLine(`${head}(${args}).`);
698
+ } else {
699
+ if (stmt.receiver === void 0) throw new Error("Call: instance call has no receiver");
700
+ const head = `${printExpression(stmt.receiver, writer)}->${stmt.method}`;
701
+ const args = printArgs(stmt.args, writer, col + head.length + 1);
702
+ writer.writeLine(`${head}(${args}).`);
703
+ }
704
+ return;
705
+ }
706
+ case "Raise": {
707
+ const col = writer.prefix().length;
708
+ const type = printInlineType(stmt.exceptionType, writer);
709
+ const head = `${K("RAISE EXCEPTION")} ${K("NEW")} ${type}`;
710
+ const args = printArgs(stmt.args, writer, col + head.length + 1);
711
+ writer.writeLine(`${head}(${args}).`);
712
+ return;
713
+ }
714
+ case "If":
715
+ writer.writeLine(`${K("IF")} ${printExpression(stmt.condition, writer)}.`);
716
+ writer.indent();
717
+ printStatements(stmt.thenBody, writer);
718
+ writer.dedent();
719
+ for (const b of stmt.elseIfs) {
720
+ writer.writeLine(`${K("ELSEIF")} ${printExpression(b.condition, writer)}.`);
721
+ writer.indent();
722
+ printStatements(b.body, writer);
723
+ writer.dedent();
724
+ }
725
+ if (stmt.else) {
726
+ writer.writeLine(`${K("ELSE")}.`);
727
+ writer.indent();
728
+ printStatements(stmt.else, writer);
729
+ writer.dedent();
730
+ }
731
+ writer.writeLine(`${K("ENDIF")}.`);
732
+ return;
733
+ case "Loop": {
734
+ const table = printExpression(stmt.table, writer);
735
+ const bind = stmt.binding.bindKind === "into" ? `${K("INTO")} ${stmt.binding.target}` : `${K("ASSIGNING")} ${stmt.binding.fieldSymbol}`;
736
+ writer.writeLine(`${K("LOOP AT")} ${table} ${bind}.`);
737
+ writer.indent();
738
+ printStatements(stmt.body, writer);
739
+ writer.dedent();
740
+ writer.writeLine(`${K("ENDLOOP")}.`);
741
+ return;
742
+ }
743
+ case "Return":
744
+ if (stmt.value !== void 0) writer.writeLine(`${stmt.target} = ${printExpression(stmt.value, writer)}.`);
745
+ writer.writeLine(`${K("RETURN")}.`);
746
+ return;
747
+ case "Try":
748
+ writer.writeLine(`${K("TRY")}.`);
749
+ writer.indent();
750
+ printStatements(stmt.body, writer);
751
+ writer.dedent();
752
+ for (const c of stmt.catches) {
753
+ const types = c.exceptionTypes.map((t) => printInlineType(t, writer)).join(" ");
754
+ const into = c.into ? ` ${K("INTO")} ${c.into}` : "";
755
+ writer.writeLine(`${K("CATCH")} ${types}${into}.`);
756
+ writer.indent();
757
+ printStatements(c.body, writer);
758
+ writer.dedent();
759
+ }
760
+ if (stmt.cleanup) {
761
+ writer.writeLine(`${K("CLEANUP")}.`);
762
+ writer.indent();
763
+ printStatements(stmt.cleanup, writer);
764
+ writer.dedent();
765
+ }
766
+ writer.writeLine(`${K("ENDTRY")}.`);
767
+ return;
768
+ case "Append": {
769
+ const v = printExpression(stmt.value, writer);
770
+ const t = printExpression(stmt.table, writer);
771
+ writer.writeLine(`${K("APPEND")} ${v} ${K("TO")} ${t}.`);
772
+ return;
773
+ }
774
+ case "Insert": {
775
+ const v = printExpression(stmt.value, writer);
776
+ const t = printExpression(stmt.table, writer);
777
+ writer.writeLine(`${K("INSERT")} ${v} ${K("INTO TABLE")} ${t}.`);
778
+ return;
779
+ }
780
+ case "Read": {
781
+ const t = printExpression(stmt.table, writer);
782
+ const bind = stmt.binding.bindKind === "into" ? `${K("INTO")} ${stmt.binding.target}` : `${K("ASSIGNING")} ${stmt.binding.fieldSymbol}`;
783
+ const parts = [`${K("READ TABLE")} ${t}`];
784
+ if (stmt.index !== void 0) parts.push(`${K("INDEX")} ${printExpression(stmt.index, writer)}`);
785
+ parts.push(bind);
786
+ if (stmt.withKey && stmt.withKey.length > 0) {
787
+ const kv = stmt.withKey.map((a) => `${a.name} = ${printExpression(a.value, writer)}`).join(" ");
788
+ parts.push(`${K("WITH KEY")} ${kv}`);
789
+ }
790
+ writer.writeLine(parts.join(" ") + ".");
791
+ return;
792
+ }
793
+ case "Clear":
794
+ writer.writeLine(`${K("CLEAR")} ${printExpression(stmt.target, writer)}.`);
795
+ return;
796
+ case "Exit":
797
+ writer.writeLine(`${K("EXIT")}.`);
798
+ return;
799
+ case "Continue":
800
+ writer.writeLine(`${K("CONTINUE")}.`);
801
+ return;
802
+ case "Raw": {
803
+ const lines = stmt.source.split(/\r?\n/);
804
+ for (const line of lines) writer.writeLine(line);
805
+ return;
806
+ }
807
+ }
808
+ }
809
+ function printComment(node, writer) {
810
+ if (node.style === "star") {
811
+ const lines = node.text.split(/\r?\n/);
812
+ for (const line of lines) writer.rawLine(`* ${line}`);
813
+ } else {
814
+ const lines = node.text.split(/\r?\n/);
815
+ for (const line of lines) writer.writeLine(`" ${line}`);
816
+ }
817
+ }
818
+ function printDataDecl(node, writer) {
819
+ const K = (s) => writer.kw(s);
820
+ const kw = node.classData ? K("CLASS-DATA") : K("DATA");
821
+ const type = printInlineType(node.type, writer);
822
+ let line = `${kw} ${node.name} ${K("TYPE")} ${type}`;
823
+ if (node.initial !== void 0) line += ` ${K("VALUE")} ${printExpression(node.initial, writer)}`;
824
+ writer.writeLine(`${line}.`);
825
+ }
826
+ function printFieldSymbolDecl(node, writer) {
827
+ const K = (s) => writer.kw(s);
828
+ const type = printInlineType(node.type, writer);
829
+ writer.writeLine(`${K("FIELD-SYMBOLS")} ${node.name} ${K("TYPE")} ${type}.`);
830
+ }
831
+
832
+ //#endregion
833
+ //#region src/printer/print-members.ts
834
+ function printAttributeDef(node, writer) {
835
+ printAbapDoc(node.abapDoc, writer);
836
+ const K = (s) => writer.kw(s);
837
+ const kw = node.classData ? K("CLASS-DATA") : K("DATA");
838
+ const type = printInlineType(node.type, writer);
839
+ let line = `${kw} ${node.name} ${K("TYPE")} ${type}`;
840
+ if (node.readOnly) line += ` ${K("READ-ONLY")}`;
841
+ if (node.initial !== void 0) line += ` ${K("VALUE")} ${printExpression(node.initial, writer)}`;
842
+ writer.writeLine(`${line}.`);
843
+ }
844
+ function printConstantDecl(node, writer) {
845
+ const K = (s) => writer.kw(s);
846
+ const kw = node.classData ? K("CLASS-CONSTANTS") : K("CONSTANTS");
847
+ const type = printInlineType(node.type, writer);
848
+ writer.writeLine(`${kw} ${node.name} ${K("TYPE")} ${type} ${K("VALUE")} ${printExpression(node.value, writer)}.`);
849
+ }
850
+ function printEventDef(node, writer) {
851
+ const K = (s) => writer.kw(s);
852
+ const kw = node.isClassEvent ? K("CLASS-EVENTS") : K("EVENTS");
853
+ writer.writeLine(`${kw} ${node.name}.`);
854
+ }
855
+ const PARAM_KW = {
856
+ importing: "IMPORTING",
857
+ exporting: "EXPORTING",
858
+ changing: "CHANGING",
859
+ returning: "RETURNING"
860
+ };
861
+ /** Group params by kind (preserving AST order within each group). */
862
+ function groupParams(params) {
863
+ const order = [
864
+ "importing",
865
+ "exporting",
866
+ "changing",
867
+ "returning"
868
+ ];
869
+ const result = [];
870
+ for (const k of order) {
871
+ const items = params.filter((p) => p.paramKind === k);
872
+ if (items.length > 0) result.push({
873
+ kind: k,
874
+ items
875
+ });
876
+ }
877
+ return result;
878
+ }
879
+ function printParamBody(p, writer) {
880
+ const K = (s) => writer.kw(s);
881
+ const type = printInlineType(p.typeRef, writer);
882
+ let body;
883
+ if (p.paramKind === "returning") body = `${K("VALUE")}(${p.name}) ${K("TYPE")} ${type}`;
884
+ else body = `${p.name} ${K("TYPE")} ${type}`;
885
+ if (p.optional) body += ` ${K("OPTIONAL")}`;
886
+ if (p.default !== void 0) body += ` ${K("DEFAULT")} ${printExpression(p.default, writer)}`;
887
+ return body;
888
+ }
889
+ function printMethodDef(node, writer) {
890
+ printAbapDoc(node.abapDoc, writer);
891
+ const K = (s) => writer.kw(s);
892
+ const flagsPrefix = node.isClassMethod ? K("CLASS-METHODS") : K("METHODS");
893
+ const suffixFlags = [];
894
+ if (node.isAbstract) suffixFlags.push(K("ABSTRACT"));
895
+ if (node.isFinal) suffixFlags.push(K("FINAL"));
896
+ if (node.isRedefinition) suffixFlags.push(K("REDEFINITION"));
897
+ if (node.isForTesting) suffixFlags.push(K("FOR TESTING"));
898
+ const groups = groupParams(node.params);
899
+ const hasAny = groups.length > 0 || node.raising.length > 0;
900
+ if (!hasAny && suffixFlags.length === 0) {
901
+ writer.writeLine(`${flagsPrefix} ${node.name}.`);
902
+ return;
903
+ }
904
+ if (!hasAny) {
905
+ writer.writeLine(`${flagsPrefix} ${node.name} ${suffixFlags.join(" ")}.`);
906
+ return;
907
+ }
908
+ writer.writeLine(`${flagsPrefix} ${node.name}`);
909
+ writer.indent();
910
+ for (const g of groups) {
911
+ const kw = K(PARAM_KW[g.kind]);
912
+ if (g.items.length === 1) writer.writeLine(`${kw} ${printParamBody(g.items[0], writer)}`);
913
+ else {
914
+ writer.writeLine(kw);
915
+ writer.indent();
916
+ g.items.forEach((p) => {
917
+ writer.writeLine(printParamBody(p, writer));
918
+ });
919
+ writer.dedent();
920
+ }
921
+ }
922
+ if (node.raising.length > 0) {
923
+ const types = node.raising.map((t) => printInlineType(t, writer)).join(" ");
924
+ writer.writeLine(`${K("RAISING")} ${types}`);
925
+ }
926
+ if (suffixFlags.length > 0) writer.writeLine(suffixFlags.join(" "));
927
+ writer.dedent();
928
+ writer.write(".");
929
+ }
930
+ function printMethodImpl(node, writer) {
931
+ const K = (s) => writer.kw(s);
932
+ writer.writeLine(`${K("METHOD")} ${node.name}.`);
933
+ writer.indent();
934
+ printStatements(node.body, writer);
935
+ writer.dedent();
936
+ writer.writeLine(`${K("ENDMETHOD")}.`);
937
+ }
938
+
939
+ //#endregion
940
+ //#region src/printer/print-class.ts
941
+ const VIS_KW = {
942
+ public: "PUBLIC SECTION",
943
+ protected: "PROTECTED SECTION",
944
+ private: "PRIVATE SECTION"
945
+ };
946
+ function printSection(sec, writer, opts) {
947
+ writer.writeLine(`${writer.kw(VIS_KW[sec.visibility])}.`);
948
+ writer.indent();
949
+ for (const i of opts?.leadingInterfaces ?? []) writer.writeLine(`${writer.kw("INTERFACES")} ${i}.`);
950
+ for (const m of sec.members) switch (m.kind) {
951
+ case "TypeDef":
952
+ printTypeDef(m, writer);
953
+ break;
954
+ case "AttributeDef":
955
+ printAttributeDef(m, writer);
956
+ break;
957
+ case "MethodDef":
958
+ printMethodDef(m, writer);
959
+ break;
960
+ case "ConstantDecl":
961
+ printConstantDecl(m, writer);
962
+ break;
963
+ case "EventDef": printEventDef(m, writer);
964
+ }
965
+ writer.dedent();
966
+ }
967
+ function printDefinitionHeader(name, opts, writer) {
968
+ const K = (s) => writer.kw(s);
969
+ const parts = [`${K("CLASS")} ${name} ${K("DEFINITION")}`];
970
+ if (!opts.local) parts.push(K("PUBLIC"));
971
+ if (opts.isFinal) parts.push(K("FINAL"));
972
+ if (opts.isAbstract) parts.push(K("ABSTRACT"));
973
+ if (opts.isForTesting) parts.push(K("FOR TESTING"));
974
+ if (opts.superclass) parts.push(`${K("INHERITING FROM")} ${opts.superclass}`);
975
+ if (!opts.local) parts.push(opts.isCreatePrivate ? K("CREATE PRIVATE") : K("CREATE PUBLIC"));
976
+ writer.writeLine(parts.join(" ") + ".");
977
+ if (!opts.interfacesInsidePublicSection && opts.interfaces.length > 0) {
978
+ writer.indent();
979
+ for (const i of opts.interfaces) writer.writeLine(`${K("INTERFACES")} ${i}.`);
980
+ writer.dedent();
981
+ }
982
+ }
983
+ function printSections(sections, writer, opts) {
984
+ const leadingInterfaces = opts?.leadingInterfaces ?? [];
985
+ let publicEmitted = false;
986
+ for (const s of sections) if (!publicEmitted && s.visibility === "public") {
987
+ printSection(s, writer, { leadingInterfaces });
988
+ publicEmitted = true;
989
+ } else printSection(s, writer);
990
+ if (!publicEmitted && leadingInterfaces.length > 0) {
991
+ const K = (s) => writer.kw(s);
992
+ writer.writeLine(`${K("PUBLIC SECTION")}.`);
993
+ writer.indent();
994
+ for (const i of leadingInterfaces) writer.writeLine(`${K("INTERFACES")} ${i}.`);
995
+ writer.dedent();
996
+ }
997
+ }
998
+ function printImplementations(name, impls, writer) {
999
+ const K = (s) => writer.kw(s);
1000
+ writer.writeLine(`${K("CLASS")} ${name} ${K("IMPLEMENTATION")}.`);
1001
+ writer.indent();
1002
+ impls.forEach((impl, idx) => {
1003
+ if (idx > 0) writer.blank();
1004
+ printMethodImpl(impl, writer);
1005
+ });
1006
+ writer.dedent();
1007
+ writer.writeLine(`${K("ENDCLASS")}.`);
1008
+ }
1009
+ function printClassDef(node, writer) {
1010
+ printAbapDoc(node.abapDoc, writer);
1011
+ const K = (s) => writer.kw(s);
1012
+ const hasSections = node.sections.length > 0;
1013
+ printDefinitionHeader(node.name, {
1014
+ local: false,
1015
+ superclass: node.superclass,
1016
+ interfaces: node.interfaces,
1017
+ isFinal: node.isFinal,
1018
+ isAbstract: node.isAbstract,
1019
+ isForTesting: node.isForTesting,
1020
+ isCreatePrivate: node.isCreatePrivate,
1021
+ interfacesInsidePublicSection: hasSections
1022
+ }, writer);
1023
+ writer.indent();
1024
+ printSections(node.sections, writer, { leadingInterfaces: hasSections ? node.interfaces : [] });
1025
+ writer.dedent();
1026
+ writer.writeLine(`${K("ENDCLASS")}.`);
1027
+ writer.blank();
1028
+ printImplementations(node.name, node.implementations, writer);
1029
+ }
1030
+ function printLocalClassDef(node, writer) {
1031
+ const K = (s) => writer.kw(s);
1032
+ printDefinitionHeader(node.name, {
1033
+ local: true,
1034
+ superclass: node.superclass,
1035
+ interfaces: node.interfaces,
1036
+ isFinal: node.isFinal,
1037
+ isAbstract: node.isAbstract,
1038
+ isForTesting: node.isForTesting
1039
+ }, writer);
1040
+ writer.indent();
1041
+ printSections(node.sections, writer);
1042
+ writer.dedent();
1043
+ writer.writeLine(`${K("ENDCLASS")}.`);
1044
+ if (node.implementations.length > 0) {
1045
+ writer.blank();
1046
+ printImplementations(node.name, node.implementations, writer);
1047
+ }
1048
+ }
1049
+
1050
+ //#endregion
1051
+ //#region src/printer/print-interface.ts
1052
+ function printInterfaceDef(node, writer) {
1053
+ printAbapDoc(node.abapDoc, writer);
1054
+ const K = (s) => writer.kw(s);
1055
+ writer.writeLine(`${K("INTERFACE")} ${node.name} ${K("PUBLIC")}.`);
1056
+ writer.indent();
1057
+ for (const m of node.members) switch (m.kind) {
1058
+ case "TypeDef":
1059
+ printTypeDef(m, writer);
1060
+ break;
1061
+ case "MethodDef": printMethodDef(m, writer);
1062
+ }
1063
+ writer.dedent();
1064
+ writer.writeLine(`${K("ENDINTERFACE")}.`);
1065
+ }
1066
+
1067
+ //#endregion
1068
+ //#region src/printer/index.ts
1069
+ /** Pretty-print an ABAP AST node to source code. */
1070
+ function print(node, options) {
1071
+ const writer = new Writer(resolveOptions(options));
1072
+ printNode(node, writer);
1073
+ return writer.toString();
1074
+ }
1075
+ function printNode(node, writer) {
1076
+ switch (node.kind) {
1077
+ case "ClassDef":
1078
+ printClassDef(node, writer);
1079
+ return;
1080
+ case "LocalClassDef":
1081
+ printLocalClassDef(node, writer);
1082
+ return;
1083
+ case "InterfaceDef":
1084
+ printInterfaceDef(node, writer);
1085
+ return;
1086
+ case "TypeDef":
1087
+ printTypeDef(node, writer);
1088
+ return;
1089
+ case "BuiltinType":
1090
+ case "NamedTypeRef":
1091
+ case "TableType":
1092
+ case "StructureType":
1093
+ case "EnumType": throw new Error(`print: ${node.kind} is not a top-level node — wrap it in a TypeDef`);
1094
+ case "AttributeDef":
1095
+ printAttributeDef(node, writer);
1096
+ return;
1097
+ case "MethodDef":
1098
+ printMethodDef(node, writer);
1099
+ return;
1100
+ case "MethodImpl":
1101
+ printMethodImpl(node, writer);
1102
+ return;
1103
+ case "EventDef":
1104
+ printEventDef(node, writer);
1105
+ return;
1106
+ case "ConstantDecl":
1107
+ printConstantDecl(node, writer);
1108
+ return;
1109
+ case "Section": throw new Error("print: Section is an internal node — print its enclosing ClassDef/LocalClassDef instead");
1110
+ case "MethodParam": throw new Error("print: MethodParam is an internal node — print its enclosing MethodDef");
1111
+ case "DataDecl":
1112
+ printDataDecl(node, writer);
1113
+ return;
1114
+ case "FieldSymbolDecl":
1115
+ printFieldSymbolDecl(node, writer);
1116
+ return;
1117
+ case "Assign":
1118
+ case "Call":
1119
+ case "Raise":
1120
+ case "If":
1121
+ case "Loop":
1122
+ case "Return":
1123
+ case "Try":
1124
+ case "Append":
1125
+ case "Insert":
1126
+ case "Read":
1127
+ case "Clear":
1128
+ case "Exit":
1129
+ case "Continue":
1130
+ case "Raw":
1131
+ printStatement(node, writer);
1132
+ return;
1133
+ case "Comment":
1134
+ printComment(node, writer);
1135
+ return;
1136
+ case "Literal":
1137
+ case "IdentifierExpr":
1138
+ case "ConstructorExpr":
1139
+ case "MethodCallExpr":
1140
+ case "BinOp":
1141
+ case "StringTemplate":
1142
+ case "Cast":
1143
+ writer.writeLine(printExpression(node, writer));
1144
+ return;
1145
+ }
1146
+ }
1147
+
1148
+ //#endregion
1149
+ export { AbapAstError, Writer, append, assign, attributeDef, binOp, builtinType, call, cast, classDef, clear, comment, constantDecl, constructorExpr, continueStmt, dataDecl, enumType, eventDef, exit, fieldSymbolDecl, identifierExpr, ifStmt, insert, interfaceDef, literal, localClassDef, loop, methodCallExpr, methodDef, methodImpl, methodParam, namedTypeRef, print, printExpression, printInlineType, raise, raw, read, requireField, returnStmt, section, stringTemplate, structureType, tableType, tryStmt, typeDef };
1150
+ //# sourceMappingURL=index.mjs.map