@cobol-ts/cursor-loader-cobol 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/index.d.ts +6 -0
  2. package/dist/index.js +23 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/src/cobol.array.selection.d.ts +56 -0
  5. package/dist/src/cobol.array.selection.js +172 -0
  6. package/dist/src/cobol.array.selection.js.map +1 -0
  7. package/dist/src/cobol.array.selection.spec.d.ts +1 -0
  8. package/dist/src/cobol.array.selection.spec.js +64 -0
  9. package/dist/src/cobol.array.selection.spec.js.map +1 -0
  10. package/dist/src/cobol.callback.spec.d.ts +1 -0
  11. package/dist/src/cobol.callback.spec.js +69 -0
  12. package/dist/src/cobol.callback.spec.js.map +1 -0
  13. package/dist/src/cobol.debug.range.d.ts +21 -0
  14. package/dist/src/cobol.debug.range.js +53 -0
  15. package/dist/src/cobol.debug.range.js.map +1 -0
  16. package/dist/src/cobol.debug.range.spec.d.ts +1 -0
  17. package/dist/src/cobol.debug.range.spec.js +29 -0
  18. package/dist/src/cobol.debug.range.spec.js.map +1 -0
  19. package/dist/src/cobol.decoded.file.spec.d.ts +1 -0
  20. package/dist/src/cobol.decoded.file.spec.js +41 -0
  21. package/dist/src/cobol.decoded.file.spec.js.map +1 -0
  22. package/dist/src/cobol.decoded.integration.spec.d.ts +1 -0
  23. package/dist/src/cobol.decoded.integration.spec.js +124 -0
  24. package/dist/src/cobol.decoded.integration.spec.js.map +1 -0
  25. package/dist/src/cobol.file.node.d.ts +37 -0
  26. package/dist/src/cobol.file.node.js +65 -0
  27. package/dist/src/cobol.file.node.js.map +1 -0
  28. package/dist/src/cobol.fixed.array.projection.spec.d.ts +1 -0
  29. package/dist/src/cobol.fixed.array.projection.spec.js +128 -0
  30. package/dist/src/cobol.fixed.array.projection.spec.js.map +1 -0
  31. package/dist/src/cobol.layout.index.d.ts +18 -0
  32. package/dist/src/cobol.layout.index.js +33 -0
  33. package/dist/src/cobol.layout.index.js.map +1 -0
  34. package/dist/src/cobol.layout.index.spec.d.ts +1 -0
  35. package/dist/src/cobol.layout.index.spec.js +195 -0
  36. package/dist/src/cobol.layout.index.spec.js.map +1 -0
  37. package/dist/src/cobol.metrics.odo.spec.d.ts +1 -0
  38. package/dist/src/cobol.metrics.odo.spec.js +52 -0
  39. package/dist/src/cobol.metrics.odo.spec.js.map +1 -0
  40. package/dist/src/cobol.metrics.scalar.spec.d.ts +1 -0
  41. package/dist/src/cobol.metrics.scalar.spec.js +28 -0
  42. package/dist/src/cobol.metrics.scalar.spec.js.map +1 -0
  43. package/dist/src/cobol.multiple.nested.arrays.spec.d.ts +1 -0
  44. package/dist/src/cobol.multiple.nested.arrays.spec.js +253 -0
  45. package/dist/src/cobol.multiple.nested.arrays.spec.js.map +1 -0
  46. package/dist/src/cobol.multiple.nested.odo.spec.d.ts +1 -0
  47. package/dist/src/cobol.multiple.nested.odo.spec.js +129 -0
  48. package/dist/src/cobol.multiple.nested.odo.spec.js.map +1 -0
  49. package/dist/src/cobol.nested.redefines.projection.spec.d.ts +1 -0
  50. package/dist/src/cobol.nested.redefines.projection.spec.js +195 -0
  51. package/dist/src/cobol.nested.redefines.projection.spec.js.map +1 -0
  52. package/dist/src/cobol.occurrence.context.spec.d.ts +1 -0
  53. package/dist/src/cobol.occurrence.context.spec.js +187 -0
  54. package/dist/src/cobol.occurrence.context.spec.js.map +1 -0
  55. package/dist/src/cobol.occurs.clause.d.ts +10 -0
  56. package/dist/src/cobol.occurs.clause.js +14 -0
  57. package/dist/src/cobol.occurs.clause.js.map +1 -0
  58. package/dist/src/cobol.occurs.clause.spec.d.ts +1 -0
  59. package/dist/src/cobol.occurs.clause.spec.js +21 -0
  60. package/dist/src/cobol.occurs.clause.spec.js.map +1 -0
  61. package/dist/src/cobol.odo.positions.d.ts +17 -0
  62. package/dist/src/cobol.odo.positions.js +70 -0
  63. package/dist/src/cobol.odo.positions.js.map +1 -0
  64. package/dist/src/cobol.odo.positions.spec.d.ts +1 -0
  65. package/dist/src/cobol.odo.positions.spec.js +108 -0
  66. package/dist/src/cobol.odo.positions.spec.js.map +1 -0
  67. package/dist/src/cobol.odo.projection.spec.d.ts +1 -0
  68. package/dist/src/cobol.odo.projection.spec.js +246 -0
  69. package/dist/src/cobol.odo.projection.spec.js.map +1 -0
  70. package/dist/src/cobol.odo.three.level.spec.d.ts +1 -0
  71. package/dist/src/cobol.odo.three.level.spec.js +202 -0
  72. package/dist/src/cobol.odo.three.level.spec.js.map +1 -0
  73. package/dist/src/cobol.parser.d.ts +112 -0
  74. package/dist/src/cobol.parser.js +322 -0
  75. package/dist/src/cobol.parser.js.map +1 -0
  76. package/dist/src/cobol.projection.path.d.ts +50 -0
  77. package/dist/src/cobol.projection.path.js +146 -0
  78. package/dist/src/cobol.projection.path.js.map +1 -0
  79. package/dist/src/cobol.projection.symbolic.d.ts +68 -0
  80. package/dist/src/cobol.projection.symbolic.js +257 -0
  81. package/dist/src/cobol.projection.symbolic.js.map +1 -0
  82. package/dist/src/cobol.registration.d.ts +4 -0
  83. package/dist/src/cobol.registration.js +17 -0
  84. package/dist/src/cobol.registration.js.map +1 -0
  85. package/dist/src/cobol.representation.d.ts +16 -0
  86. package/dist/src/cobol.representation.js +29 -0
  87. package/dist/src/cobol.representation.js.map +1 -0
  88. package/dist/src/cobol.shared.fixed.lifecycle.spec.d.ts +1 -0
  89. package/dist/src/cobol.shared.fixed.lifecycle.spec.js +50 -0
  90. package/dist/src/cobol.shared.fixed.lifecycle.spec.js.map +1 -0
  91. package/dist/src/cobol.shared.odo.lifecycle.spec.d.ts +1 -0
  92. package/dist/src/cobol.shared.odo.lifecycle.spec.js +152 -0
  93. package/dist/src/cobol.shared.odo.lifecycle.spec.js.map +1 -0
  94. package/dist/src/cobol.symbolic.allocation.spec.d.ts +1 -0
  95. package/dist/src/cobol.symbolic.allocation.spec.js +84 -0
  96. package/dist/src/cobol.symbolic.allocation.spec.js.map +1 -0
  97. package/dist/src/customer.fixtures.d.ts +90 -0
  98. package/dist/src/customer.fixtures.js +167 -0
  99. package/dist/src/customer.fixtures.js.map +1 -0
  100. package/dist/src/customer.fixtures.spec.d.ts +1 -0
  101. package/dist/src/customer.fixtures.spec.js +132 -0
  102. package/dist/src/customer.fixtures.spec.js.map +1 -0
  103. package/dist/src/customer.projections.d.ts +44 -0
  104. package/dist/src/customer.projections.js +31 -0
  105. package/dist/src/customer.projections.js.map +1 -0
  106. package/dist/src/customer.projections.spec.d.ts +1 -0
  107. package/dist/src/customer.projections.spec.js +209 -0
  108. package/dist/src/customer.projections.spec.js.map +1 -0
  109. package/package.json +11 -11
  110. package/node.d.ts +0 -1
  111. package/node.js +0 -2
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cursor_projection_1 = require("@cobol-ts/cursor-projection");
4
+ const copybook_1 = require("@cobol-ts/copybook");
5
+ const layout_1 = require("@cobol-ts/layout");
6
+ const errors_1 = require("@cobol-ts/errors");
7
+ const cobol_parser_1 = require("./cobol.parser");
8
+ const copybook = [
9
+ "01 ROW.",
10
+ " 05 O-COUNT PIC 9.",
11
+ " 05 M-COUNT PIC 9.",
12
+ " 05 I-COUNT PIC 9.",
13
+ " 05 OUTERS OCCURS 0 TO 3 TIMES DEPENDING ON O-COUNT.",
14
+ " 10 O-HEAD PIC X.",
15
+ " 10 MIDDLES OCCURS 0 TO 3 TIMES DEPENDING ON M-COUNT.",
16
+ " 15 M-HEAD PIC X.",
17
+ " 15 INNERS OCCURS 0 TO 3 TIMES DEPENDING ON I-COUNT.",
18
+ " 20 CODE PIC X(2).",
19
+ " 15 M-TAIL PIC X.",
20
+ " 10 O-TAIL PIC X.",
21
+ " 05 FINAL PIC X."
22
+ ].join("\n");
23
+ const details = (0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolProjectionDetails)((0, errors_1.valueOrThrow)((0, layout_1.compileCobolLayout)((0, errors_1.valueOrThrow)((0, copybook_1.parseCopybook)(copybook)), "three-level-odo.cpy"))));
24
+ const projection = (0, cursor_projection_1.defineProjection)({
25
+ outers: { type: "array", path: ["ROW", "OUTERS"], element: {
26
+ head: { type: "string", path: ["O-HEAD"] },
27
+ middles: { type: "array", path: ["MIDDLES"], element: {
28
+ head: { type: "string", path: ["M-HEAD"] },
29
+ inners: { type: "array", path: ["INNERS"], element: { code: { type: "string", path: ["CODE"] } } },
30
+ tail: { type: "string", path: ["M-TAIL"] }
31
+ } }, tail: { type: "string", path: ["O-TAIL"] }
32
+ } }, final: { type: "string", path: ["ROW", "FINAL"] }
33
+ });
34
+ /** Literal byte fixture: counts 2/2/2; 3-byte header + 2 x 14-byte outer body + final. */
35
+ const bytes = Uint8Array.from([
36
+ 0xf2, 0xf2, 0xf2,
37
+ 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,
38
+ 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
39
+ 0xe9
40
+ ]);
41
+ const record = (content = bytes, state = (0, cobol_parser_1.createCobolRecordState)(), number = 41) => ({
42
+ buffers: [content], startByte: 0, endByte: content.length, lastValidByte: content.length,
43
+ source: "three-level-odo.fb", recordNumber: number, recordState: state
44
+ });
45
+ describe("three levels of ODO projected arrays", () => {
46
+ test("finds third-level selections out of order without making preceding views", () => {
47
+ const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, projection);
48
+ const row = factory.create(), physical = record();
49
+ factory.bind(row, physical, physical);
50
+ try {
51
+ expect(row.outers.length).toBe(2);
52
+ const second = row.outers[1];
53
+ expect(second.head()).toBe("17/18/d1");
54
+ const secondMiddle = second.middles[1];
55
+ expect(secondMiddle.head()).toBe("24/25/d8");
56
+ expect(secondMiddle.inners[1].code()).toBe("27/29/db dc");
57
+ expect(secondMiddle.tail()).toBe("29/30/dd");
58
+ expect(second.tail()).toBe("30/31/de");
59
+ expect(row.final()).toBe("31/32/e9");
60
+ expect(secondMiddle.inners[0].code()).toBe("25/27/d9 da");
61
+ expect(row.outers[1]).toBe(second);
62
+ expect(second.middles[1]).toBe(secondMiddle);
63
+ }
64
+ finally {
65
+ factory.clear(row);
66
+ }
67
+ });
68
+ test("locates a third-level scalar that straddles physical byte buffers", () => {
69
+ const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, projection), row = factory.create();
70
+ const physical = { ...record(),
71
+ buffers: [bytes.subarray(0, 6), bytes.subarray(6, 28), bytes.subarray(28)] };
72
+ factory.bind(row, physical, physical);
73
+ try {
74
+ expect(row.outers[1].middles[1].inners[1].code()).toBe("27/29/db dc");
75
+ }
76
+ finally {
77
+ factory.clear(row);
78
+ }
79
+ });
80
+ test("changes all three counts after cleaning and rebinding the same record state", () => {
81
+ const state = (0, cobol_parser_1.createCobolRecordState)(), factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, projection);
82
+ const row = factory.create(), first = record(bytes, state);
83
+ factory.bind(row, first, first);
84
+ const original = row.outers[0].middles[0].inners[1];
85
+ expect(original.code()).toBe("7/9/c5 c6");
86
+ factory.clear(row);
87
+ (0, cobol_parser_1.cleanCobolRecordState)(state);
88
+ // Counts 1/1/0: one outer (head + middle head/tail + outer tail), then final.
89
+ const shorter = Uint8Array.of(0xf1, 0xf1, 0xf0, 0xc1, 0xc2, 0xc3, 0xc4, 0xe9);
90
+ const next = record(shorter, state, 42);
91
+ factory.bind(row, next, next);
92
+ try {
93
+ expect(row.outers.length).toBe(1);
94
+ expect(row.outers[0].middles.length).toBe(1);
95
+ expect(row.outers[0].middles[0].inners.length).toBe(0);
96
+ expect(row.outers[0].middles[0].inners[0]).toBeUndefined();
97
+ expect(row.outers[0].middles[0].tail()).toBe("5/6/c3");
98
+ expect(row.outers[0].tail()).toBe("6/7/c4");
99
+ expect(row.final()).toBe("7/8/e9");
100
+ }
101
+ finally {
102
+ factory.clear(row);
103
+ }
104
+ });
105
+ test("an invalid inner count reports source, record number, projection path and bytes", () => {
106
+ const wrong = Uint8Array.from(bytes);
107
+ wrong[2] = 0xff;
108
+ const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, projection);
109
+ const row = factory.create(), p = record(wrong, (0, cobol_parser_1.createCobolRecordState)(), 93);
110
+ factory.bind(row, p, p);
111
+ try {
112
+ expect(row.final()).toBe("31/32/e9"); // right anchored; no count decoding
113
+ let message = "";
114
+ try {
115
+ row.outers[1];
116
+ }
117
+ catch (e) {
118
+ message = e instanceof Error ? e.message : String(e);
119
+ }
120
+ expect(message).toMatch(/three-level-odo\.fb: record 93:/);
121
+ expect(message).toMatch(/projection ROW\.OUTERS/);
122
+ expect(message).toMatch(/Invalid unsigned DISPLAY ODO controller digit/);
123
+ expect(message).toMatch(/f2 f2 ff/);
124
+ }
125
+ finally {
126
+ factory.clear(row);
127
+ }
128
+ });
129
+ });
130
+ describe("nested ODO allocation and diagnostic regression", () => {
131
+ test("reuses the array provider, selected child and occurrence index array across leases", () => {
132
+ const outerPath = cobol_parser_1.cobolParser.compileProjectionPath(details, undefined, ["ROW", "OUTERS"]);
133
+ const state = (0, cobol_parser_1.createCobolRecordState)(), first = record(bytes, state, 101);
134
+ const provider = cobol_parser_1.cobolParser.array(first, details, outerPath);
135
+ const selection = provider.element(1);
136
+ if (!("originBits" in selection))
137
+ throw new Error("Expected symbolic view");
138
+ const indices = selection.enclosingIndices;
139
+ expect(selection.originBits).toBe(17 * 8);
140
+ (0, cobol_parser_1.cleanCobolRecordState)(state);
141
+ const second = record(bytes, state, 102);
142
+ const rebound = cobol_parser_1.cobolParser.array(second, details, outerPath, provider);
143
+ expect(rebound).toBe(provider);
144
+ const same = rebound.element(1, selection);
145
+ expect(same).toBe(selection);
146
+ if (!("originBits" in same))
147
+ throw new Error("Expected symbolic view");
148
+ expect(same.enclosingIndices).toBe(indices);
149
+ expect(same.enclosingIndices).toEqual([1]);
150
+ expect(same.originBits).toBe(17 * 8);
151
+ });
152
+ test("reports the fully indexed access path and controller on nested count errors", () => {
153
+ const changed = Uint8Array.from(bytes);
154
+ const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, projection);
155
+ const row = factory.create(), p = record(changed, (0, cobol_parser_1.createCobolRecordState)(), 113);
156
+ factory.bind(row, p, p);
157
+ try {
158
+ const inner = row.outers[1].middles[1].inners;
159
+ // After geometry was selected, invalidate the count field solely to
160
+ // exercise deferred length diagnostics. Production bytes stay stable.
161
+ changed[2] = 0xff;
162
+ let message = "";
163
+ try {
164
+ void inner.length;
165
+ }
166
+ catch (e) {
167
+ message = e instanceof Error ? e.message : String(e);
168
+ }
169
+ expect(message).toMatch(/three-level-odo\.fb: record 113/);
170
+ expect(message).toMatch(/outers\[1\]\.middles\[1\]\.inners/);
171
+ expect(message).toMatch(/ROW\.I-COUNT/);
172
+ expect(message).toMatch(/f2 f2 ff/);
173
+ }
174
+ finally {
175
+ factory.clear(row);
176
+ }
177
+ });
178
+ test("fully qualified scalar diagnostic retains all three occurrence indexes", () => {
179
+ const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, projection);
180
+ const row = factory.create(), p = record(bytes, (0, cobol_parser_1.createCobolRecordState)(), 114);
181
+ factory.bind(row, p, p);
182
+ try {
183
+ const inner = row.outers[1].middles[1].inners[1];
184
+ p.endByte = 28; // Test-only truncated frame after selection.
185
+ let message = "";
186
+ try {
187
+ inner.code();
188
+ }
189
+ catch (e) {
190
+ message = e instanceof Error ? e.message : String(e);
191
+ }
192
+ expect(message).toMatch(/three-level-odo\.fb: record 114/);
193
+ expect(message).toMatch(/outers\[1\]\.middles\[1\]\.inners\[1\]\.code/);
194
+ expect(message).toMatch(/extends beyond the completed record/);
195
+ expect(message).toMatch(/f2 f2 f2/);
196
+ }
197
+ finally {
198
+ factory.clear(row);
199
+ }
200
+ });
201
+ });
202
+ //# sourceMappingURL=cobol.odo.three.level.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.odo.three.level.spec.js","sourceRoot":"","sources":["../../src/cobol.odo.three.level.spec.ts"],"names":[],"mappings":";;AAEA,mEAA8E;AAC9E,iDAAiD;AACjD,6CAAoD;AACpD,6CAA8C;AAC9C,iDAAqH;AAErH,MAAM,QAAQ,GAAC;IACX,SAAS;IACT,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;IACrB,uDAAuD;IACvD,sBAAsB;IACtB,0DAA0D;IAC1D,wBAAwB;IACxB,2DAA2D;IAC3D,2BAA2B;IAC3B,wBAAwB;IACxB,sBAAsB;IACtB,mBAAmB;CACtB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAKb,MAAM,OAAO,GAAC,IAAA,qBAAY,EAAC,IAAA,2CAA4B,EAAC,IAAA,qBAAY,EAChE,IAAA,2BAAkB,EAAC,IAAA,qBAAY,EAAC,IAAA,wBAAa,EAAC,QAAQ,CAAC,CAAC,EAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;AACvF,MAAM,UAAU,GAAC,IAAA,oCAAgB,EAAM;IACnC,MAAM,EAAC,EAAC,IAAI,EAAC,OAAO,EAAC,IAAI,EAAC,CAAC,KAAK,EAAC,QAAQ,CAAC,EAAC,OAAO,EAAC;YAC/C,IAAI,EAAC,EAAC,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,CAAC,QAAQ,CAAC,EAAC;YACpC,OAAO,EAAC,EAAC,IAAI,EAAC,OAAO,EAAC,IAAI,EAAC,CAAC,SAAS,CAAC,EAAC,OAAO,EAAC;oBAC3C,IAAI,EAAC,EAAC,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,CAAC,QAAQ,CAAC,EAAC;oBACpC,MAAM,EAAC,EAAC,IAAI,EAAC,OAAO,EAAC,IAAI,EAAC,CAAC,QAAQ,CAAC,EAAC,OAAO,EAAC,EAA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C,CAAC,GAAC,MAAM,CAAC,KAAK,EAAC,IAAA,qCAAsB,GAAE,EAAC,GAAG,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAC,CAAC,EAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC;YACD,MAAM,KAAK,GAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC9C,CAAmD,CAAC,OAAO,GAAC,EAAE,CAAC,CAAC,6CAA6C;YAC9G,IAAI,OAAO,GAAC,EAAE,CAAC;YACf,IAAI,CAAC;gBAAA,KAAK,CAAC,IAAI,EAAE,CAAC;YAAA,CAAC;YAAA,OAAM,CAAC,EAAC,CAAC;gBAAA,OAAO,GAAC,CAAC,YAAY,KAAK,CAAA,CAAC,CAAA,CAAC,CAAC,OAAO,CAAA,CAAC,CAAA,MAAM,CAAC,CAAC,CAAC,CAAC;YAAA,CAAC;YAC5E,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC;YAC3D,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,8CAA8C,CAAC,CAAC;YACxE,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,qCAAqC,CAAC,CAAC;YAC/D,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACxC,CAAC;gBAAQ,CAAC;YAAA,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAAA,CAAC;IAClC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,112 @@
1
+ import { type IPutMetrics } from "@cobol-ts/metrics";
2
+ import type { Parser, ParserPhysicalRecordContent, ProjectionPhysicalRecord, PhysicalRecordContext, ProjectionRecordState } from "@cobol-ts/cursor-loader-types";
3
+ import { bytesToDebugString } from "@cobol-ts/cursor-loader-types";
4
+ import type { CompiledCobolEntry, CompiledCobolElementary } from "@cobol-ts/layout";
5
+ import { FragmentedByteCursor, type CobolDecodeOptions, type CobolFieldDecoder } from "@cobol-ts/codec";
6
+ import { type ErrorsOr } from "@cobol-ts/errors";
7
+ import type { ProjectedArraySource } from "@cobol-ts/arrays";
8
+ import { type CountContext } from "./cobol.representation";
9
+ import { type OdoPositionCache } from "./cobol.odo.positions";
10
+ import { type CobolNameIndex } from "./cobol.layout.index";
11
+ import { type CobolProjectionPath } from "./cobol.projection.path";
12
+ import { type CobolSymbolicView, type MutableSymbolicView } from "./cobol.projection.symbolic";
13
+ export type CobolProjectionDetails = Readonly<{
14
+ layout: readonly CompiledCobolEntry[];
15
+ names: CobolNameIndex;
16
+ recordLengthBytes?: number;
17
+ /** RDW is physical framing, never part of the copybook layout. */
18
+ framing?: 'rdw';
19
+ dataOffsetBytes?: number;
20
+ controllerLocations: WeakMap<readonly (string | number)[], import("./cobol.projection.symbolic").CobolControllerLocation>;
21
+ metrics?: IPutMetrics;
22
+ /** Experimental, restricted native-array ODO execution; default is lazy Proxy. */
23
+ experimentalSharedOdoArrays?: boolean;
24
+ }>;
25
+ export type CobolFixedDetails = CobolProjectionDetails & Readonly<{
26
+ recordLengthBytes: number;
27
+ }>;
28
+ /** Fixed capacity is independent of the number of active ODO occurrences. */
29
+ export type CobolFraming = Readonly<{
30
+ kind: 'fixed';
31
+ recordLength?: number;
32
+ }> | Readonly<{
33
+ kind: 'rdw';
34
+ }>;
35
+ /** Opt-in decoded-value details. Existing diagnostic fixture helpers continue
36
+ * to use createCobolProjectionDetails / createCobolFixedDetails unchanged. */
37
+ export type CobolDecodedDetails = CobolProjectionDetails & Readonly<{
38
+ decodeOptions: CobolDecodeOptions;
39
+ decoderCache: WeakMap<CompiledCobolElementary, CobolFieldDecoder>;
40
+ }>;
41
+ /**
42
+ * Selected occurrences borrow the same physical record. Fixed layouts retain
43
+ * their numeric displacement, while symbolic selections carry the resolved
44
+ * group origin and, when independently known, its right boundary.
45
+ */
46
+ export type CobolRepresentation = ProjectionPhysicalRecord | Readonly<{
47
+ physical: ProjectionPhysicalRecord;
48
+ displacementBits: number;
49
+ }> | CobolSymbolicView;
50
+ export type CobolRecordState = ProjectionRecordState & {
51
+ readonly odoPositions: OdoPositionCache;
52
+ readonly countContext: CountContext;
53
+ readonly metrics: IPutMetrics;
54
+ /** Start of copybook data relative to the physical record start. */
55
+ dataOffsetBytes?: number;
56
+ rootScratch?: MutableSymbolicView;
57
+ scalarScratch?: MutableSymbolicView;
58
+ rangeScratch?: {
59
+ from: number;
60
+ to: number;
61
+ };
62
+ fixedScratch?: {
63
+ offsetBits: number;
64
+ sizeBits: number;
65
+ };
66
+ byteCursor?: FragmentedByteCursor;
67
+ };
68
+ export type CobolParser = Parser<CobolRepresentation, CobolProjectionDetails, CobolProjectionDetails, CobolRecordState, CobolProjectionPath>;
69
+ /** Compile the source-scoped index and validate the initially supported FB record size. */
70
+ export declare function createCobolProjectionDetails(layout: readonly CompiledCobolEntry[]): ErrorsOr<CobolProjectionDetails>;
71
+ export declare function createCobolFixedDetails(layout: readonly CompiledCobolEntry[]): ErrorsOr<CobolFixedDetails>;
72
+ /** Production setup: the same compiled storage layout, with scalar decoders
73
+ * compiled for selected elementary projections during opened-source setup. */
74
+ export declare function createCobolDecodedProjectionDetails(layout: readonly CompiledCobolEntry[], decodeOptions?: CobolDecodeOptions): ErrorsOr<CobolDecodedDetails>;
75
+ /** One source-scoped decoder setup for FB (compiled or declared physical length)
76
+ * and RDW-prefixed records. Record framing is independent of active ODO count.
77
+ * In particular, an FB file may reserve unused table capacity. */
78
+ export declare function createCobolDecodedFramedDetails(layout: readonly CompiledCobolEntry[], framing: CobolFraming | undefined, decodeOptions?: CobolDecodeOptions): ErrorsOr<CobolDecodedDetails>;
79
+ export declare function createCobolDecodedFixedDetails(layout: readonly CompiledCobolEntry[], decodeOptions?: CobolDecodeOptions): ErrorsOr<CobolFixedDetails & CobolDecodedDetails>;
80
+ /** The parser owns COBOL record boundaries. The physical cursor supplies only
81
+ * reusable buffers and readMore(); neither a payload nor field is assembled.
82
+ * The RDW's 16-bit big-endian length includes its four header bytes. */
83
+ /** The same synchronous framing routine serves both delivery models.
84
+ * Ordinary iteration retains its Promise API, but buffered parsing itself
85
+ * never suspends. Only an actual need for more input awaits readMore().
86
+ */
87
+ declare function parse(record: ParserPhysicalRecordContent<CobolRecordState>, details: CobolProjectionDetails): Promise<CobolRepresentation | {
88
+ errors: string[];
89
+ }>;
90
+ /**
91
+ * Synchronous counterpart for the callback cursor. undefined means that the
92
+ * caller must read another byte buffer and retry with the SAME record.
93
+ * No physical byte array is copied, and RDW/FB rules match parse().
94
+ */
95
+ declare function parseBuffered(record: ParserPhysicalRecordContent<CobolRecordState>, details: CobolProjectionDetails): CobolRepresentation | {
96
+ errors: string[];
97
+ } | undefined;
98
+ export declare const cobolParser: {
99
+ parse: typeof parse;
100
+ parseBuffered: typeof parseBuffered;
101
+ compileProjectionPath(details: CobolProjectionDetails, _context: PhysicalRecordContext | undefined, path: readonly (string | number)[], parent?: CobolProjectionPath): CobolProjectionPath;
102
+ object(view: CobolRepresentation, details: CobolProjectionDetails, path: CobolProjectionPath, reusable?: CobolRepresentation): CobolRepresentation;
103
+ array(view: CobolRepresentation, details: CobolProjectionDetails, path: CobolProjectionPath, reusable?: ProjectedArraySource<CobolRepresentation>): ProjectedArraySource<CobolRepresentation>;
104
+ integer(record: CobolRepresentation, details: CobolProjectionDetails, path: CobolProjectionPath, ...indices: number[]): number;
105
+ float(record: CobolRepresentation, details: CobolProjectionDetails, path: CobolProjectionPath, ...indices: number[]): number;
106
+ character(record: CobolRepresentation, details: CobolProjectionDetails, path: CobolProjectionPath, ...indices: number[]): string;
107
+ string(record: CobolRepresentation, details: CobolProjectionDetails, path: CobolProjectionPath, ...indices: number[]): string;
108
+ toDebugString: typeof bytesToDebugString;
109
+ };
110
+ export declare function createCobolRecordState(metrics?: IPutMetrics): CobolRecordState;
111
+ export declare function cleanCobolRecordState(state: CobolRecordState): void;
112
+ export {};
@@ -0,0 +1,322 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cobolParser = void 0;
4
+ exports.createCobolProjectionDetails = createCobolProjectionDetails;
5
+ exports.createCobolFixedDetails = createCobolFixedDetails;
6
+ exports.createCobolDecodedProjectionDetails = createCobolDecodedProjectionDetails;
7
+ exports.createCobolDecodedFramedDetails = createCobolDecodedFramedDetails;
8
+ exports.createCobolDecodedFixedDetails = createCobolDecodedFixedDetails;
9
+ exports.createCobolRecordState = createCobolRecordState;
10
+ exports.cleanCobolRecordState = cleanCobolRecordState;
11
+ const metrics_1 = require("@cobol-ts/metrics");
12
+ const cursor_loader_types_1 = require("@cobol-ts/cursor-loader-types");
13
+ const codec_1 = require("@cobol-ts/codec");
14
+ const errors_1 = require("@cobol-ts/errors");
15
+ const size_1 = require("@cobol-ts/size");
16
+ const cobol_representation_1 = require("./cobol.representation");
17
+ const cobol_array_selection_1 = require("./cobol.array.selection");
18
+ const cobol_odo_positions_1 = require("./cobol.odo.positions");
19
+ const cobol_occurs_clause_1 = require("./cobol.occurs.clause");
20
+ const cobol_layout_index_1 = require("./cobol.layout.index");
21
+ const cobol_debug_range_1 = require("./cobol.debug.range");
22
+ const cobol_projection_path_1 = require("./cobol.projection.path");
23
+ const cobol_projection_symbolic_1 = require("./cobol.projection.symbolic");
24
+ /** Compile the source-scoped index and validate the initially supported FB record size. */
25
+ function createCobolProjectionDetails(layout) {
26
+ if (layout.length !== 1)
27
+ return (0, errors_1.errors)("COBOL projection requires exactly one 01 record layout");
28
+ return (0, errors_1.flatMapErrorsOr)((0, cobol_layout_index_1.createCobolNameIndex)(layout), names => (0, errors_1.value)({ layout, names, controllerLocations: new WeakMap() }));
29
+ }
30
+ function createCobolFixedDetails(layout) {
31
+ if (layout.length !== 1)
32
+ return (0, errors_1.errors)("Fixed COBOL parser requires exactly one 01 record layout");
33
+ return (0, errors_1.flatMapErrorsOr)((0, cobol_layout_index_1.createCobolNameIndex)(layout), names => {
34
+ try {
35
+ const bits = (0, size_1.evaluateStorageSize)(layout[0].size, () => {
36
+ throw new Error("variable-length ODO storage");
37
+ });
38
+ if (!Number.isSafeInteger(bits) || bits <= 0 || bits % 8 !== 0) {
39
+ return (0, errors_1.errors)("Fixed COBOL record length must be a positive whole number of bytes");
40
+ }
41
+ return (0, errors_1.value)({ layout, names, recordLengthBytes: bits / 8, controllerLocations: new WeakMap() });
42
+ }
43
+ catch (e) {
44
+ return (0, errors_1.errors)(`COBOL fixed-record framing cannot determine record size: ${e instanceof Error ? e.message : String(e)}`);
45
+ }
46
+ });
47
+ }
48
+ /** Production setup: the same compiled storage layout, with scalar decoders
49
+ * compiled for selected elementary projections during opened-source setup. */
50
+ function createCobolDecodedProjectionDetails(layout, decodeOptions = {}) {
51
+ return (0, errors_1.flatMapErrorsOr)(createCobolProjectionDetails(layout), details => (0, errors_1.value)({ ...details, decodeOptions, decoderCache: new WeakMap() }));
52
+ }
53
+ /** One source-scoped decoder setup for FB (compiled or declared physical length)
54
+ * and RDW-prefixed records. Record framing is independent of active ODO count.
55
+ * In particular, an FB file may reserve unused table capacity. */
56
+ function createCobolDecodedFramedDetails(layout, framing, decodeOptions = {}) {
57
+ if (!framing || (framing.kind === 'fixed' && framing.recordLength === undefined))
58
+ return createCobolDecodedFixedDetails(layout, decodeOptions);
59
+ if (framing.kind === 'fixed') {
60
+ const length = framing.recordLength;
61
+ if (!Number.isSafeInteger(length) || length === undefined || length <= 0)
62
+ return (0, errors_1.errors)('Fixed COBOL record length must be a positive whole number of bytes');
63
+ return (0, errors_1.flatMapErrorsOr)(createCobolDecodedProjectionDetails(layout, decodeOptions), details => (0, errors_1.value)({ ...details, recordLengthBytes: length }));
64
+ }
65
+ return (0, errors_1.flatMapErrorsOr)(createCobolDecodedProjectionDetails(layout, decodeOptions), details => (0, errors_1.value)({ ...details, framing: 'rdw', dataOffsetBytes: 4 }));
66
+ }
67
+ function createCobolDecodedFixedDetails(layout, decodeOptions = {}) {
68
+ return (0, errors_1.flatMapErrorsOr)(createCobolFixedDetails(layout), details => (0, errors_1.value)({ ...details, decodeOptions, decoderCache: new WeakMap() }));
69
+ }
70
+ function isDecoded(details) {
71
+ return 'decoderCache' in details;
72
+ }
73
+ /** Construct selected-field plans before record iteration, never per record. */
74
+ function ensureDecoder(details, path) {
75
+ if (path.node.kind !== 'elementary' || details.decoderCache.has(path.node))
76
+ return;
77
+ const bits = path.node.size;
78
+ if (typeof bits !== 'number' || bits % 8 !== 0)
79
+ throw new Error(`Cannot compile primitive with non-constant storage width: ${path.fullPath.join('.')}`);
80
+ // Honour group-inherited USAGE, as the layout compiler does. Only stable
81
+ // declaration metadata is walked, once, during projection compilation.
82
+ let inheritedUsage;
83
+ let current = details.layout;
84
+ for (const part of path.fullPath) {
85
+ if (typeof part !== 'string')
86
+ continue;
87
+ let found;
88
+ for (const entry of current) {
89
+ if (entry.kind === 'padding')
90
+ continue;
91
+ if (entry.source.name.kind === 'named' && entry.source.name.name.toUpperCase() === part.toUpperCase()) {
92
+ found = entry;
93
+ break;
94
+ }
95
+ }
96
+ if (!found)
97
+ break;
98
+ if (found.kind === 'group') {
99
+ for (const clause of found.source.clauses)
100
+ if (clause.kind === 'usage')
101
+ inheritedUsage = clause.usage;
102
+ current = found.children;
103
+ }
104
+ }
105
+ const source = path.node.source;
106
+ const explicit = source.clauses.some(c => c.kind === 'usage');
107
+ const declaration = explicit || !inheritedUsage ? source
108
+ : { ...source, clauses: [...source.clauses, { kind: 'usage', usage: inheritedUsage }] };
109
+ try {
110
+ details.metrics?.put(metrics_1.METRIC.COBOL_DECODER_COMPILE);
111
+ details.decoderCache.set(path.node, (0, codec_1.compileCobolFieldDecoder)(declaration, bits / 8, details.decodeOptions));
112
+ }
113
+ catch (error) {
114
+ throw new Error(`COBOL decoder for ${path.fullPath.join('.')}: ${error instanceof Error ? error.message : String(error)}`);
115
+ }
116
+ }
117
+ function decodedField(representation, details, path, occurrenceIndices) {
118
+ const decoder = path.node.kind === 'elementary' ? details.decoderCache.get(path.node) : undefined;
119
+ if (!decoder)
120
+ throw new Error(`No compiled COBOL decoder for ${path.fullPath.join('.')}`);
121
+ const range = fieldRange(representation, details, path, occurrenceIndices);
122
+ const record = (0, cobol_representation_1.physical)(representation);
123
+ const state = record.recordState;
124
+ const cursor = state.byteCursor ?? (state.byteCursor = new codec_1.FragmentedByteCursor());
125
+ cursor.bind(record, record.startByte + range.from, record.startByte + range.to);
126
+ details.metrics?.put(metrics_1.METRIC.COBOL_DECODER_INVOKE);
127
+ return decoder.decode(cursor);
128
+ }
129
+ /** The parser owns COBOL record boundaries. The physical cursor supplies only
130
+ * reusable buffers and readMore(); neither a payload nor field is assembled.
131
+ * The RDW's 16-bit big-endian length includes its four header bytes. */
132
+ /** The same synchronous framing routine serves both delivery models.
133
+ * Ordinary iteration retains its Promise API, but buffered parsing itself
134
+ * never suspends. Only an actual need for more input awaits readMore().
135
+ */
136
+ async function parse(record, details) {
137
+ let result = parseBuffered(record, details);
138
+ while (result === undefined) {
139
+ await record.readMore();
140
+ result = parseBuffered(record, details);
141
+ }
142
+ return result;
143
+ }
144
+ /**
145
+ * Synchronous counterpart for the callback cursor. undefined means that the
146
+ * caller must read another byte buffer and retry with the SAME record.
147
+ * No physical byte array is copied, and RDW/FB rules match parse().
148
+ */
149
+ function parseBuffered(record, details) {
150
+ details.metrics?.put(metrics_1.METRIC.FILE_SCAN_BUFFERED_PARSE);
151
+ const start = record.startByte;
152
+ if (details.framing === 'rdw') {
153
+ const headerEnd = start + 4;
154
+ if (record.lastValidByte < headerEnd) {
155
+ if (!record.fileFinished)
156
+ return undefined;
157
+ if (record.lastValidByte === start) {
158
+ record.endByte = start;
159
+ return record;
160
+ }
161
+ record.endByte = record.lastValidByte;
162
+ return { errors: [`Truncated COBOL RDW: expected 4 bytes, got ${record.lastValidByte - start}`] };
163
+ }
164
+ const state = record.recordState;
165
+ const cursor = state.byteCursor ?? (state.byteCursor = new codec_1.FragmentedByteCursor());
166
+ cursor.bind(record, start, headerEnd);
167
+ const hi = cursor.next(), lo = cursor.next(), control1 = cursor.next(), control2 = cursor.next();
168
+ if (control1 !== 0 || control2 !== 0)
169
+ throw new Error('Unsupported COBOL RDW control bytes (spanned records are not supported)');
170
+ const length = hi * 256 + lo;
171
+ if (length < 4)
172
+ throw new Error(`Invalid COBOL RDW length ${length}: must include four header bytes`);
173
+ const endByte = start + length;
174
+ if (record.lastValidByte < endByte) {
175
+ if (!record.fileFinished)
176
+ return undefined;
177
+ record.endByte = record.lastValidByte;
178
+ return { errors: [`Truncated COBOL RDW record: expected ${length} bytes, got ${record.lastValidByte - start}`] };
179
+ }
180
+ state.dataOffsetBytes = 4;
181
+ record.endByte = endByte;
182
+ return record;
183
+ }
184
+ if (details.recordLengthBytes === undefined)
185
+ throw new Error('COBOL source framing is required for an ODO layout');
186
+ const endByte = start + details.recordLengthBytes;
187
+ if (record.lastValidByte < endByte) {
188
+ if (!record.fileFinished)
189
+ return undefined;
190
+ record.endByte = record.lastValidByte;
191
+ return { errors: [`Truncated COBOL fixed record: expected ${details.recordLengthBytes} bytes, got ${record.lastValidByte - start}`] };
192
+ }
193
+ record.recordState.dataOffsetBytes = 0;
194
+ record.endByte = endByte;
195
+ return record;
196
+ }
197
+ function fieldRange(representation, details, path, occurrenceIndices) {
198
+ details.metrics?.put(metrics_1.METRIC.COBOL_FIELD_RANGE);
199
+ if (path.node.kind !== "elementary")
200
+ throw new Error("COBOL scalar projection must select an elementary field");
201
+ const record = (0, cobol_representation_1.physical)(representation);
202
+ let offsetBits, sizeBits;
203
+ if ("symbolic" in path) {
204
+ details.metrics?.put(metrics_1.METRIC.COBOL_SYMBOLIC_LOCATE);
205
+ const state = record.recordState;
206
+ const scratch = state.scalarScratch ?? (state.scalarScratch = { physical: record, originBits: 0, enclosingIndices: [] });
207
+ (0, cobol_projection_symbolic_1.selectSymbolicInto)((0, cobol_representation_1.symbolicView)(representation), path, (0, cobol_representation_1.countResolver)(details, record), occurrenceIndices, scratch);
208
+ offsetBits = scratch.originBits;
209
+ sizeBits = typeof path.node.size === "number" ? path.node.size : NaN;
210
+ }
211
+ else {
212
+ const state = record.recordState;
213
+ if (path.runtimeDimensions.length === 0 && occurrenceIndices.length === 0) {
214
+ details.metrics?.put(metrics_1.METRIC.COBOL_FIXED_FAST);
215
+ // The size-expression compiler has already reduced this geometry
216
+ // to numbers. No occurrence resolution or scratch is required.
217
+ offsetBits = path.offsetBits + (0, cobol_representation_1.displacement)(representation) + (state.dataOffsetBytes ?? 0) * 8;
218
+ sizeBits = path.sizeBits;
219
+ }
220
+ else {
221
+ details.metrics?.put(metrics_1.METRIC.COBOL_FIXED_LOCATE);
222
+ // Preserve occurrence-count and index validation for indexed fields.
223
+ const located = (0, cobol_projection_path_1.locateCompiledCobolPath)(path, occurrenceIndices, state.fixedScratch ?? (state.fixedScratch = { offsetBits: 0, sizeBits: 0 }), details.metrics);
224
+ offsetBits = located.offsetBits + (0, cobol_representation_1.displacement)(representation) + (state.dataOffsetBytes ?? 0) * 8;
225
+ sizeBits = located.sizeBits;
226
+ }
227
+ }
228
+ const state = record.recordState;
229
+ const range = (0, cobol_debug_range_1.cobolDebugRangeFromBits)(offsetBits, sizeBits, state.rangeScratch ?? (state.rangeScratch = { from: 0, to: 0 }));
230
+ if (record.startByte + range.to > record.endByte) {
231
+ throw new RangeError("COBOL projection extends beyond the completed record");
232
+ }
233
+ return range;
234
+ }
235
+ exports.cobolParser = {
236
+ parse,
237
+ parseBuffered,
238
+ compileProjectionPath(details, _context, path, parent) {
239
+ details.metrics?.put(metrics_1.METRIC.COBOL_PATH_COMPILE);
240
+ const compiled = (0, cobol_projection_path_1.compileCobolMemberPath)(details.names, path, parent);
241
+ if (isDecoded(details))
242
+ ensureDecoder(details, compiled);
243
+ return compiled;
244
+ },
245
+ object(view, details, path, reusable) {
246
+ if ("symbolic" in path) {
247
+ if (path.node.kind !== "group" || (0, cobol_occurs_clause_1.hasOccursClause)(path.node.source.clauses))
248
+ throw new Error("COBOL object selection requires a non-repeated group");
249
+ const record = (0, cobol_representation_1.physical)(view);
250
+ const selected = "originBits" in (reusable ?? {})
251
+ ? reusable
252
+ : { physical: record, originBits: 0, enclosingIndices: [] };
253
+ (0, cobol_projection_symbolic_1.selectSymbolicInto)((0, cobol_representation_1.symbolicView)(view), path, (0, cobol_representation_1.countResolver)(details, record), [], selected);
254
+ return selected;
255
+ }
256
+ if (path.node.kind !== "group" || path.runtimeDimensions.length !== 0) {
257
+ throw new Error("COBOL object selection requires a non-repeated group");
258
+ }
259
+ return view;
260
+ },
261
+ array(view, details, path, reusable) {
262
+ return (0, cobol_array_selection_1.bindCobolArraySelection)(view, details, path, reusable);
263
+ },
264
+ integer(record, details, path, ...indices) {
265
+ if (isDecoded(details)) {
266
+ const decoded = decodedField(record, details, path, indices);
267
+ if (typeof decoded !== 'number' || !Number.isInteger(decoded))
268
+ throw new TypeError(`Expected integral COBOL value at ${path.fullPath.join('.')}`);
269
+ return decoded;
270
+ }
271
+ return (0, cobol_debug_range_1.cobolDebugRangeNumber)(fieldRange(record, details, path, indices));
272
+ },
273
+ float(record, details, path, ...indices) {
274
+ if (isDecoded(details)) {
275
+ const decoded = decodedField(record, details, path, indices);
276
+ if (typeof decoded !== 'number')
277
+ throw new TypeError(`Expected numeric COBOL value at ${path.fullPath.join('.')}`);
278
+ return decoded;
279
+ }
280
+ return (0, cobol_debug_range_1.cobolDebugRangeNumber)(fieldRange(record, details, path, indices));
281
+ },
282
+ character(record, details, path, ...indices) {
283
+ if (isDecoded(details)) {
284
+ const decoded = decodedField(record, details, path, indices);
285
+ if (typeof decoded !== 'string' || decoded.length !== 1)
286
+ throw new TypeError(`Expected one COBOL character at ${path.fullPath.join('.')}`);
287
+ return decoded;
288
+ }
289
+ return (0, cobol_debug_range_1.cobolDebugRangeString)((0, cobol_representation_1.physical)(record), fieldRange(record, details, path, indices));
290
+ },
291
+ string(record, details, path, ...indices) {
292
+ if (isDecoded(details)) {
293
+ const decoded = decodedField(record, details, path, indices);
294
+ if (typeof decoded !== 'string')
295
+ throw new TypeError(`Expected text COBOL value at ${path.fullPath.join('.')}`);
296
+ return decoded;
297
+ }
298
+ return (0, cobol_debug_range_1.cobolDebugRangeString)((0, cobol_representation_1.physical)(record), fieldRange(record, details, path, indices));
299
+ },
300
+ toDebugString: cursor_loader_types_1.bytesToDebugString
301
+ };
302
+ function createCobolRecordState(metrics = metrics_1.NULL_METRICS) {
303
+ const context = { resolve: path => {
304
+ if (!context.details || !context.record)
305
+ throw new Error("COBOL count resolver is not bound to a record");
306
+ return (0, cobol_projection_symbolic_1.resolveCobolCount)(context.details, context.record, path);
307
+ } };
308
+ return { projectionViews: new Map(), odoPositions: new Map(), countContext: context, metrics };
309
+ }
310
+ function cleanCobolRecordState(state) {
311
+ (0, cobol_odo_positions_1.cleanOdoPositions)(state.odoPositions, state.metrics);
312
+ // The function and allocated scratch buffers survive; the old record
313
+ // and source-specific details do not remain bound after final release.
314
+ state.countContext.record = undefined;
315
+ state.countContext.details = undefined;
316
+ state.dataOffsetBytes = undefined;
317
+ if (state.rootScratch)
318
+ state.rootScratch.endBits = undefined;
319
+ if (state.scalarScratch)
320
+ state.scalarScratch.endBits = undefined;
321
+ }
322
+ //# sourceMappingURL=cobol.parser.js.map