@speclynx/apidom-parser-adapter-yaml-1-2 1.12.2 → 2.0.1

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 (103) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/NOTICE +16 -7
  3. package/README.md +34 -7
  4. package/dist/167.apidom-parser-adapter-yaml-1-2.browser.min.js +1 -1
  5. package/dist/451.apidom-parser-adapter-yaml-1-2.browser.min.js +1 -1
  6. package/dist/apidom-parser-adapter-yaml-1-2.browser.js +19340 -16731
  7. package/dist/apidom-parser-adapter-yaml-1-2.browser.min.js +1 -1
  8. package/package.json +10 -9
  9. package/src/adapter.cjs +28 -16
  10. package/src/adapter.mjs +25 -15
  11. package/src/tree-sitter/index.cjs +44 -0
  12. package/src/tree-sitter/index.mjs +38 -0
  13. package/src/{lexical-analysis → tree-sitter/lexical-analysis}/index.cjs +1 -1
  14. package/src/{lexical-analysis → tree-sitter/lexical-analysis}/index.mjs +1 -1
  15. package/src/tree-sitter/syntactic-analysis/CstTransformer.cjs +625 -0
  16. package/src/tree-sitter/syntactic-analysis/CstTransformer.mjs +618 -0
  17. package/src/tree-sitter/syntactic-analysis/YamlAstTransformer.cjs +271 -0
  18. package/src/tree-sitter/syntactic-analysis/YamlAstTransformer.mjs +263 -0
  19. package/src/tree-sitter/syntactic-analysis/ast/Error.cjs +30 -0
  20. package/src/tree-sitter/syntactic-analysis/ast/Error.mjs +24 -0
  21. package/src/tree-sitter/syntactic-analysis/ast/Literal.cjs +27 -0
  22. package/src/tree-sitter/syntactic-analysis/ast/Literal.mjs +21 -0
  23. package/src/tree-sitter/syntactic-analysis/ast/Node.cjs +60 -0
  24. package/src/tree-sitter/syntactic-analysis/ast/Node.mjs +56 -0
  25. package/src/tree-sitter/syntactic-analysis/ast/ParseResult.cjs +17 -0
  26. package/src/tree-sitter/syntactic-analysis/ast/ParseResult.mjs +12 -0
  27. package/src/tree-sitter/syntactic-analysis/ast/anchors-aliases/ReferenceManager.cjs +23 -0
  28. package/src/tree-sitter/syntactic-analysis/ast/anchors-aliases/ReferenceManager.mjs +18 -0
  29. package/src/tree-sitter/syntactic-analysis/ast/errors/YamlError.cjs +10 -0
  30. package/src/tree-sitter/syntactic-analysis/ast/errors/YamlError.mjs +7 -0
  31. package/src/tree-sitter/syntactic-analysis/ast/errors/YamlSchemaError.cjs +11 -0
  32. package/src/tree-sitter/syntactic-analysis/ast/errors/YamlSchemaError.mjs +6 -0
  33. package/src/tree-sitter/syntactic-analysis/ast/errors/YamlTagError.cjs +43 -0
  34. package/src/tree-sitter/syntactic-analysis/ast/errors/YamlTagError.mjs +37 -0
  35. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAlias.cjs +27 -0
  36. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAlias.mjs +21 -0
  37. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAnchor.cjs +27 -0
  38. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAnchor.mjs +21 -0
  39. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlCollection.cjs +11 -0
  40. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlCollection.mjs +6 -0
  41. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlComment.cjs +27 -0
  42. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlComment.mjs +21 -0
  43. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDirective.cjs +39 -0
  44. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDirective.mjs +32 -0
  45. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDocument.cjs +13 -0
  46. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDocument.mjs +8 -0
  47. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlKeyValuePair.cjs +48 -0
  48. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlKeyValuePair.mjs +42 -0
  49. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlMapping.cjs +20 -0
  50. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlMapping.mjs +15 -0
  51. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlNode.cjs +35 -0
  52. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlNode.mjs +29 -0
  53. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlScalar.cjs +27 -0
  54. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlScalar.mjs +21 -0
  55. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlSequence.cjs +23 -0
  56. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlSequence.mjs +18 -0
  57. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStream.cjs +20 -0
  58. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStream.mjs +15 -0
  59. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStyle.cjs +27 -0
  60. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStyle.mjs +24 -0
  61. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlTag.cjs +38 -0
  62. package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlTag.mjs +35 -0
  63. package/src/tree-sitter/syntactic-analysis/ast/nodes/predicates.cjs +26 -0
  64. package/src/tree-sitter/syntactic-analysis/ast/nodes/predicates.mjs +14 -0
  65. package/src/tree-sitter/syntactic-analysis/ast/schemas/ScalarTag.cjs +33 -0
  66. package/src/tree-sitter/syntactic-analysis/ast/schemas/ScalarTag.mjs +29 -0
  67. package/src/tree-sitter/syntactic-analysis/ast/schemas/Tag.cjs +20 -0
  68. package/src/tree-sitter/syntactic-analysis/ast/schemas/Tag.mjs +16 -0
  69. package/src/tree-sitter/syntactic-analysis/ast/schemas/canonical-format.cjs +127 -0
  70. package/src/tree-sitter/syntactic-analysis/ast/schemas/canonical-format.mjs +122 -0
  71. package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericMapping.cjs +14 -0
  72. package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericMapping.mjs +9 -0
  73. package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericSequence.cjs +14 -0
  74. package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericSequence.mjs +9 -0
  75. package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericString.cjs +10 -0
  76. package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericString.mjs +5 -0
  77. package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/index.cjs +116 -0
  78. package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/index.mjs +111 -0
  79. package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Boolean.cjs +19 -0
  80. package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Boolean.mjs +14 -0
  81. package/src/tree-sitter/syntactic-analysis/ast/schemas/json/FloatingPoint.cjs +19 -0
  82. package/src/tree-sitter/syntactic-analysis/ast/schemas/json/FloatingPoint.mjs +14 -0
  83. package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Integer.cjs +19 -0
  84. package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Integer.mjs +14 -0
  85. package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Null.cjs +18 -0
  86. package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Null.mjs +13 -0
  87. package/src/tree-sitter/syntactic-analysis/ast/schemas/json/index.cjs +43 -0
  88. package/src/tree-sitter/syntactic-analysis/ast/schemas/json/index.mjs +38 -0
  89. package/src/tree-sitter/syntactic-analysis/index.cjs +39 -0
  90. package/src/tree-sitter/syntactic-analysis/index.mjs +33 -0
  91. package/src/yaml/index.cjs +31 -0
  92. package/src/yaml/index.mjs +26 -0
  93. package/types/apidom-parser-adapter-yaml-1-2.d.ts +11 -3
  94. package/src/syntactic-analysis/TreeCursorIterator.cjs +0 -93
  95. package/src/syntactic-analysis/TreeCursorIterator.mjs +0 -88
  96. package/src/syntactic-analysis/TreeCursorSyntaxNode.cjs +0 -80
  97. package/src/syntactic-analysis/TreeCursorSyntaxNode.mjs +0 -76
  98. package/src/syntactic-analysis/indirect/index.cjs +0 -51
  99. package/src/syntactic-analysis/indirect/index.mjs +0 -44
  100. package/src/syntactic-analysis/indirect/visitors/CstVisitor.cjs +0 -553
  101. package/src/syntactic-analysis/indirect/visitors/CstVisitor.mjs +0 -547
  102. package/src/syntactic-analysis/indirect/visitors/YamlAstVisitor.cjs +0 -164
  103. package/src/syntactic-analysis/indirect/visitors/YamlAstVisitor.mjs +0 -158
@@ -0,0 +1,625 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ exports.__esModule = true;
6
+ exports.transformCstToYamlAst = exports.default = void 0;
7
+ var _Error = _interopRequireDefault(require("./ast/Error.cjs"));
8
+ var _Literal = _interopRequireDefault(require("./ast/Literal.cjs"));
9
+ var _ParseResult = _interopRequireDefault(require("./ast/ParseResult.cjs"));
10
+ var _YamlAlias = _interopRequireDefault(require("./ast/nodes/YamlAlias.cjs"));
11
+ var _YamlAnchor = _interopRequireDefault(require("./ast/nodes/YamlAnchor.cjs"));
12
+ var _YamlComment = _interopRequireDefault(require("./ast/nodes/YamlComment.cjs"));
13
+ var _YamlDirective = _interopRequireDefault(require("./ast/nodes/YamlDirective.cjs"));
14
+ var _YamlDocument = _interopRequireDefault(require("./ast/nodes/YamlDocument.cjs"));
15
+ var _YamlKeyValuePair = _interopRequireDefault(require("./ast/nodes/YamlKeyValuePair.cjs"));
16
+ var _YamlMapping = _interopRequireDefault(require("./ast/nodes/YamlMapping.cjs"));
17
+ var _YamlScalar = _interopRequireDefault(require("./ast/nodes/YamlScalar.cjs"));
18
+ var _YamlSequence = _interopRequireDefault(require("./ast/nodes/YamlSequence.cjs"));
19
+ var _YamlStream = _interopRequireDefault(require("./ast/nodes/YamlStream.cjs"));
20
+ var _YamlTag = _interopRequireWildcard(require("./ast/nodes/YamlTag.cjs"));
21
+ var _YamlStyle = require("./ast/nodes/YamlStyle.cjs");
22
+ const getCursorInfo = cursor => ({
23
+ type: cursor.nodeType,
24
+ startPosition: cursor.startPosition,
25
+ endPosition: cursor.endPosition,
26
+ startIndex: cursor.startIndex,
27
+ endIndex: cursor.endIndex,
28
+ text: cursor.nodeText,
29
+ isNamed: cursor.nodeIsNamed,
30
+ isMissing: cursor.nodeIsMissing,
31
+ hasError: cursor.currentNode.hasError,
32
+ fieldName: cursor.currentFieldName
33
+ });
34
+
35
+ // Flat position properties extracted from CursorInfo
36
+
37
+ const toPositionProps = info => ({
38
+ startLine: info.startPosition.row,
39
+ startCharacter: info.startPosition.column,
40
+ startOffset: info.startIndex,
41
+ endLine: info.endPosition.row,
42
+ endCharacter: info.endPosition.column,
43
+ endOffset: info.endIndex
44
+ });
45
+ const toYamlAnchor = info => {
46
+ return new _YamlAnchor.default({
47
+ name: info.text,
48
+ ...toPositionProps(info)
49
+ });
50
+ };
51
+ const toYamlTag = (info, tagInfo) => {
52
+ const explicitName = tagInfo?.text || (info.type === 'plain_scalar' ? '?' : '!');
53
+ const kind = info.type.endsWith('mapping') ? _YamlTag.YamlNodeKind.Mapping : info.type.endsWith('sequence') ? _YamlTag.YamlNodeKind.Sequence : _YamlTag.YamlNodeKind.Scalar;
54
+ const positionProps = tagInfo ? toPositionProps(tagInfo) : undefined;
55
+ return new _YamlTag.default({
56
+ explicitName,
57
+ kind,
58
+ ...positionProps
59
+ });
60
+ };
61
+ const registerAnchor = (node, ctx) => {
62
+ if (node.anchor !== undefined) {
63
+ ctx.referenceManager.addAnchor(node);
64
+ }
65
+ };
66
+
67
+ // Using 'any' for TransformResult to avoid recursive type issues
68
+ // The actual types are: YamlNode, YamlDirective, YamlDocument, YamlKeyValuePair, YamlComment, Literal, Error, ParseResult, arrays, or null
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+
71
+ // Helper to process children and track siblings for tag/anchor association
72
+ const processChildren = (cursor, ctx, transformerMap) => {
73
+ const results = [];
74
+ let siblings = {};
75
+ if (cursor.gotoFirstChild()) {
76
+ do {
77
+ const info = getCursorInfo(cursor);
78
+
79
+ // Track tag and anchor siblings
80
+ if (info.type === 'tag') {
81
+ siblings.tag = info;
82
+ continue;
83
+ }
84
+ if (info.type === 'anchor') {
85
+ siblings.anchor = info;
86
+ continue;
87
+ }
88
+ const result = transform(cursor, ctx, transformerMap, siblings);
89
+ if (result !== null) {
90
+ results.push(result);
91
+ }
92
+
93
+ // Reset siblings after consuming them for a value node
94
+ if (info.type.endsWith('scalar') || info.type.endsWith('mapping') || info.type.endsWith('sequence') || info.type === 'block_node' || info.type === 'flow_node') {
95
+ siblings = {};
96
+ }
97
+ } while (cursor.gotoNextSibling());
98
+ cursor.gotoParent();
99
+ }
100
+ return results;
101
+ };
102
+
103
+ // Helper to process key-value pair children
104
+ const processKeyValuePairChildren = (cursor, ctx, transformerMap) => {
105
+ let key = null;
106
+ let value = null;
107
+ const errors = [];
108
+ let siblings = {};
109
+ if (cursor.gotoFirstChild()) {
110
+ do {
111
+ const info = getCursorInfo(cursor);
112
+ const fieldName = cursor.currentFieldName;
113
+
114
+ // Track tag and anchor siblings
115
+ if (info.type === 'tag') {
116
+ siblings.tag = info;
117
+ continue;
118
+ }
119
+ if (info.type === 'anchor') {
120
+ siblings.anchor = info;
121
+ continue;
122
+ }
123
+ if (fieldName === 'key') {
124
+ key = transform(cursor, ctx, transformerMap, siblings);
125
+ siblings = {};
126
+ } else if (fieldName === 'value') {
127
+ value = transform(cursor, ctx, transformerMap, siblings);
128
+ siblings = {};
129
+ } else if (info.type === 'ERROR') {
130
+ const errorResult = transform(cursor, ctx, transformerMap, siblings);
131
+ if (errorResult !== null) {
132
+ errors.push(errorResult);
133
+ }
134
+ }
135
+ } while (cursor.gotoNextSibling());
136
+ cursor.gotoParent();
137
+ }
138
+ return {
139
+ key,
140
+ value,
141
+ errors
142
+ };
143
+ };
144
+ const transform = (cursor, ctx, transformerMap, siblings = {}) => {
145
+ const info = getCursorInfo(cursor);
146
+
147
+ // Handle missing anonymous literals
148
+ if (!info.isNamed && !info.isMissing) {
149
+ // Skip non-named, non-missing nodes (like punctuation)
150
+ return null;
151
+ }
152
+ if (!info.isNamed && info.isMissing) {
153
+ const nodeValue = info.type || info.text;
154
+ return new _Literal.default({
155
+ value: nodeValue,
156
+ ...toPositionProps(info),
157
+ isMissing: true
158
+ });
159
+ }
160
+ const transformer = transformerMap[info.type];
161
+ if (!transformer) {
162
+ return null;
163
+ }
164
+ return transformer(cursor, ctx, siblings);
165
+ };
166
+ const createTransformers = transformerMap => ({
167
+ stream(cursor, ctx) {
168
+ const info = getCursorInfo(cursor);
169
+ const children = processChildren(cursor, ctx, transformerMap);
170
+ const stream = new _YamlStream.default({
171
+ children: children.filter(c => c !== null),
172
+ ...toPositionProps(info),
173
+ isMissing: info.isMissing
174
+ });
175
+ return new _ParseResult.default({
176
+ children: [stream]
177
+ });
178
+ },
179
+ yaml_directive(cursor, _ctx) {
180
+ const info = getCursorInfo(cursor);
181
+
182
+ // Get version from first named child
183
+ let version;
184
+ if (cursor.gotoFirstChild()) {
185
+ do {
186
+ if (cursor.nodeIsNamed) {
187
+ version = cursor.nodeText;
188
+ break;
189
+ }
190
+ } while (cursor.gotoNextSibling());
191
+ cursor.gotoParent();
192
+ }
193
+ return new _YamlDirective.default({
194
+ ...toPositionProps(info),
195
+ name: '%YAML',
196
+ parameters: {
197
+ version
198
+ }
199
+ });
200
+ },
201
+ tag_directive(cursor, ctx) {
202
+ const info = getCursorInfo(cursor);
203
+ const children = [];
204
+ if (cursor.gotoFirstChild()) {
205
+ do {
206
+ if (cursor.nodeIsNamed) {
207
+ children.push(cursor.nodeText);
208
+ }
209
+ } while (cursor.gotoNextSibling());
210
+ cursor.gotoParent();
211
+ }
212
+ const tagDirective = new _YamlDirective.default({
213
+ ...toPositionProps(info),
214
+ name: '%TAG',
215
+ parameters: {
216
+ handle: children[0],
217
+ prefix: children[1]
218
+ }
219
+ });
220
+ ctx.schema.registerTagDirective(tagDirective);
221
+ return tagDirective;
222
+ },
223
+ reserved_directive(cursor, _ctx) {
224
+ const info = getCursorInfo(cursor);
225
+ const children = [];
226
+ if (cursor.gotoFirstChild()) {
227
+ do {
228
+ if (cursor.nodeIsNamed) {
229
+ children.push(cursor.nodeText);
230
+ }
231
+ } while (cursor.gotoNextSibling());
232
+ cursor.gotoParent();
233
+ }
234
+ return new _YamlDirective.default({
235
+ ...toPositionProps(info),
236
+ name: children[0],
237
+ parameters: {
238
+ handle: children[1],
239
+ prefix: children[2]
240
+ }
241
+ });
242
+ },
243
+ document(cursor, ctx) {
244
+ const info = getCursorInfo(cursor);
245
+ const children = processChildren(cursor, ctx, transformerMap);
246
+ return new _YamlDocument.default({
247
+ children: children.flat().filter(c => c !== null),
248
+ ...toPositionProps(info),
249
+ isMissing: info.isMissing
250
+ });
251
+ },
252
+ block_node(cursor, ctx, _siblings) {
253
+ // Block node is a wrapper - return its children
254
+ const children = processChildren(cursor, ctx, transformerMap);
255
+ return children;
256
+ },
257
+ flow_node(cursor, ctx, siblings) {
258
+ // Check if there's a kind node (scalar, mapping, or sequence)
259
+ let hasKindNode = false;
260
+ let lastChildInfo = null;
261
+ if (cursor.gotoFirstChild()) {
262
+ do {
263
+ const childInfo = getCursorInfo(cursor);
264
+ lastChildInfo = childInfo;
265
+ if (childInfo.type.endsWith('scalar') || childInfo.type.endsWith('mapping') || childInfo.type.endsWith('sequence')) {
266
+ hasKindNode = true;
267
+ }
268
+ } while (cursor.gotoNextSibling());
269
+ cursor.gotoParent();
270
+ }
271
+ if (hasKindNode) {
272
+ const children = processChildren(cursor, ctx, transformerMap);
273
+ return children;
274
+ }
275
+
276
+ // No kind node - create empty scalar
277
+ if (lastChildInfo) {
278
+ const emptyScalarNode = new _YamlScalar.default({
279
+ content: '',
280
+ anchor: siblings.anchor ? toYamlAnchor(siblings.anchor) : undefined,
281
+ tag: toYamlTag(lastChildInfo, siblings.tag),
282
+ startLine: lastChildInfo.endPosition.row,
283
+ startCharacter: lastChildInfo.endPosition.column,
284
+ startOffset: lastChildInfo.endIndex,
285
+ endLine: lastChildInfo.endPosition.row,
286
+ endCharacter: lastChildInfo.endPosition.column,
287
+ endOffset: lastChildInfo.endIndex,
288
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
289
+ style: _YamlStyle.YamlStyle.Plain
290
+ });
291
+ registerAnchor(emptyScalarNode, ctx);
292
+ return emptyScalarNode;
293
+ }
294
+ return [];
295
+ },
296
+ block_mapping(cursor, ctx, siblings) {
297
+ const info = getCursorInfo(cursor);
298
+ const tag = toYamlTag(info, siblings.tag);
299
+ const anchor = siblings.anchor ? toYamlAnchor(siblings.anchor) : undefined;
300
+ const children = processChildren(cursor, ctx, transformerMap);
301
+ const mappingNode = new _YamlMapping.default({
302
+ children: children.filter(c => c !== null),
303
+ ...toPositionProps(info),
304
+ anchor,
305
+ tag,
306
+ styleGroup: _YamlStyle.YamlStyleGroup.Block,
307
+ style: _YamlStyle.YamlStyle.NextLine,
308
+ isMissing: info.isMissing
309
+ });
310
+ registerAnchor(mappingNode, ctx);
311
+ return ctx.schema.resolve(mappingNode);
312
+ },
313
+ block_mapping_pair(cursor, ctx) {
314
+ const info = getCursorInfo(cursor);
315
+ const {
316
+ key,
317
+ value,
318
+ errors
319
+ } = processKeyValuePairChildren(cursor, ctx, transformerMap);
320
+ const children = [];
321
+
322
+ // Handle empty key
323
+ if (key === null) {
324
+ const emptyKey = new _YamlScalar.default({
325
+ content: '',
326
+ startLine: info.startPosition.row,
327
+ startCharacter: info.startPosition.column,
328
+ startOffset: info.startIndex,
329
+ endLine: info.startPosition.row,
330
+ endCharacter: info.startPosition.column,
331
+ endOffset: info.startIndex,
332
+ tag: new _YamlTag.default({
333
+ explicitName: '?',
334
+ kind: _YamlTag.YamlNodeKind.Scalar
335
+ }),
336
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
337
+ style: _YamlStyle.YamlStyle.Plain
338
+ });
339
+ children.push(emptyKey);
340
+ } else {
341
+ children.push(key);
342
+ }
343
+
344
+ // Handle empty value
345
+ if (value === null) {
346
+ const emptyValue = new _YamlScalar.default({
347
+ content: '',
348
+ startLine: info.endPosition.row,
349
+ startCharacter: info.endPosition.column,
350
+ startOffset: info.endIndex,
351
+ endLine: info.endPosition.row,
352
+ endCharacter: info.endPosition.column,
353
+ endOffset: info.endIndex,
354
+ tag: new _YamlTag.default({
355
+ explicitName: '?',
356
+ kind: _YamlTag.YamlNodeKind.Scalar
357
+ }),
358
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
359
+ style: _YamlStyle.YamlStyle.Plain
360
+ });
361
+ children.push(emptyValue);
362
+ } else {
363
+ children.push(value);
364
+ }
365
+ children.push(...errors);
366
+ return new _YamlKeyValuePair.default({
367
+ children: children.flat().filter(c => c !== null),
368
+ ...toPositionProps(info),
369
+ styleGroup: _YamlStyle.YamlStyleGroup.Block,
370
+ isMissing: info.isMissing
371
+ });
372
+ },
373
+ flow_mapping(cursor, ctx, siblings) {
374
+ const info = getCursorInfo(cursor);
375
+ const tag = toYamlTag(info, siblings.tag);
376
+ const anchor = siblings.anchor ? toYamlAnchor(siblings.anchor) : undefined;
377
+ const children = processChildren(cursor, ctx, transformerMap);
378
+ const mappingNode = new _YamlMapping.default({
379
+ children: children.flat().filter(c => c !== null),
380
+ ...toPositionProps(info),
381
+ anchor,
382
+ tag,
383
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
384
+ style: _YamlStyle.YamlStyle.Explicit,
385
+ isMissing: info.isMissing
386
+ });
387
+ registerAnchor(mappingNode, ctx);
388
+ return ctx.schema.resolve(mappingNode);
389
+ },
390
+ flow_pair(cursor, ctx) {
391
+ const info = getCursorInfo(cursor);
392
+ const {
393
+ key,
394
+ value,
395
+ errors
396
+ } = processKeyValuePairChildren(cursor, ctx, transformerMap);
397
+ const children = [];
398
+
399
+ // Handle empty key
400
+ if (key === null) {
401
+ const emptyKey = new _YamlScalar.default({
402
+ content: '',
403
+ startLine: info.startPosition.row,
404
+ startCharacter: info.startPosition.column,
405
+ startOffset: info.startIndex,
406
+ endLine: info.startPosition.row,
407
+ endCharacter: info.startPosition.column,
408
+ endOffset: info.startIndex,
409
+ tag: new _YamlTag.default({
410
+ explicitName: '?',
411
+ kind: _YamlTag.YamlNodeKind.Scalar
412
+ }),
413
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
414
+ style: _YamlStyle.YamlStyle.Plain
415
+ });
416
+ children.push(emptyKey);
417
+ } else {
418
+ children.push(key);
419
+ }
420
+
421
+ // Handle empty value
422
+ if (value === null) {
423
+ const emptyValue = new _YamlScalar.default({
424
+ content: '',
425
+ startLine: info.endPosition.row,
426
+ startCharacter: info.endPosition.column,
427
+ startOffset: info.endIndex,
428
+ endLine: info.endPosition.row,
429
+ endCharacter: info.endPosition.column,
430
+ endOffset: info.endIndex,
431
+ tag: new _YamlTag.default({
432
+ explicitName: '?',
433
+ kind: _YamlTag.YamlNodeKind.Scalar
434
+ }),
435
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
436
+ style: _YamlStyle.YamlStyle.Plain
437
+ });
438
+ children.push(emptyValue);
439
+ } else {
440
+ children.push(value);
441
+ }
442
+ children.push(...errors);
443
+ return new _YamlKeyValuePair.default({
444
+ children: children.flat().filter(c => c !== null),
445
+ ...toPositionProps(info),
446
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
447
+ isMissing: info.isMissing
448
+ });
449
+ },
450
+ block_sequence(cursor, ctx, siblings) {
451
+ const info = getCursorInfo(cursor);
452
+ const tag = toYamlTag(info, siblings.tag);
453
+ const anchor = siblings.anchor ? toYamlAnchor(siblings.anchor) : undefined;
454
+ const children = processChildren(cursor, ctx, transformerMap);
455
+ const sequenceNode = new _YamlSequence.default({
456
+ children: children.flat(Infinity).filter(c => c !== null),
457
+ ...toPositionProps(info),
458
+ anchor,
459
+ tag,
460
+ styleGroup: _YamlStyle.YamlStyleGroup.Block,
461
+ style: _YamlStyle.YamlStyle.NextLine
462
+ });
463
+ registerAnchor(sequenceNode, ctx);
464
+ return ctx.schema.resolve(sequenceNode);
465
+ },
466
+ block_sequence_item(cursor, ctx) {
467
+ const info = getCursorInfo(cursor);
468
+ const children = processChildren(cursor, ctx, transformerMap);
469
+
470
+ // If only one child (the "-" literal), create empty node
471
+ if (children.length === 0) {
472
+ const emptyScalarNode = new _YamlScalar.default({
473
+ content: '',
474
+ tag: new _YamlTag.default({
475
+ explicitName: '?',
476
+ kind: _YamlTag.YamlNodeKind.Scalar
477
+ }),
478
+ startLine: info.endPosition.row,
479
+ startCharacter: info.endPosition.column,
480
+ startOffset: info.endIndex,
481
+ endLine: info.endPosition.row,
482
+ endCharacter: info.endPosition.column,
483
+ endOffset: info.endIndex,
484
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
485
+ style: _YamlStyle.YamlStyle.Plain
486
+ });
487
+ return [emptyScalarNode];
488
+ }
489
+ return children;
490
+ },
491
+ flow_sequence(cursor, ctx, siblings) {
492
+ const info = getCursorInfo(cursor);
493
+ const tag = toYamlTag(info, siblings.tag);
494
+ const anchor = siblings.anchor ? toYamlAnchor(siblings.anchor) : undefined;
495
+ const children = processChildren(cursor, ctx, transformerMap);
496
+ const sequenceNode = new _YamlSequence.default({
497
+ children: children.flat().filter(c => c !== null),
498
+ ...toPositionProps(info),
499
+ anchor,
500
+ tag,
501
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
502
+ style: _YamlStyle.YamlStyle.Explicit
503
+ });
504
+ registerAnchor(sequenceNode, ctx);
505
+ return ctx.schema.resolve(sequenceNode);
506
+ },
507
+ plain_scalar(cursor, ctx, siblings) {
508
+ const info = getCursorInfo(cursor);
509
+ const tag = toYamlTag(info, siblings.tag);
510
+ const anchor = siblings.anchor ? toYamlAnchor(siblings.anchor) : undefined;
511
+ const scalarNode = new _YamlScalar.default({
512
+ content: info.text,
513
+ anchor,
514
+ tag,
515
+ ...toPositionProps(info),
516
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
517
+ style: _YamlStyle.YamlStyle.Plain
518
+ });
519
+ registerAnchor(scalarNode, ctx);
520
+ return ctx.schema.resolve(scalarNode);
521
+ },
522
+ single_quote_scalar(cursor, ctx, siblings) {
523
+ const info = getCursorInfo(cursor);
524
+ const tag = toYamlTag(info, siblings.tag);
525
+ const anchor = siblings.anchor ? toYamlAnchor(siblings.anchor) : undefined;
526
+ const scalarNode = new _YamlScalar.default({
527
+ content: info.text,
528
+ anchor,
529
+ tag,
530
+ ...toPositionProps(info),
531
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
532
+ style: _YamlStyle.YamlStyle.SingleQuoted
533
+ });
534
+ registerAnchor(scalarNode, ctx);
535
+ return ctx.schema.resolve(scalarNode);
536
+ },
537
+ double_quote_scalar(cursor, ctx, siblings) {
538
+ const info = getCursorInfo(cursor);
539
+ const tag = toYamlTag(info, siblings.tag);
540
+ const anchor = siblings.anchor ? toYamlAnchor(siblings.anchor) : undefined;
541
+ const scalarNode = new _YamlScalar.default({
542
+ content: info.text,
543
+ anchor,
544
+ tag,
545
+ ...toPositionProps(info),
546
+ styleGroup: _YamlStyle.YamlStyleGroup.Flow,
547
+ style: _YamlStyle.YamlStyle.DoubleQuoted
548
+ });
549
+ registerAnchor(scalarNode, ctx);
550
+ return ctx.schema.resolve(scalarNode);
551
+ },
552
+ block_scalar(cursor, ctx, siblings) {
553
+ const info = getCursorInfo(cursor);
554
+ const tag = toYamlTag(info, siblings.tag);
555
+ const anchor = siblings.anchor ? toYamlAnchor(siblings.anchor) : undefined;
556
+ const style = info.text.startsWith('|') ? _YamlStyle.YamlStyle.Literal : info.text.startsWith('>') ? _YamlStyle.YamlStyle.Folded : _YamlStyle.YamlStyle.Plain;
557
+ const scalarNode = new _YamlScalar.default({
558
+ content: info.text,
559
+ anchor,
560
+ tag,
561
+ ...toPositionProps(info),
562
+ styleGroup: _YamlStyle.YamlStyleGroup.Block,
563
+ style
564
+ });
565
+ registerAnchor(scalarNode, ctx);
566
+ return ctx.schema.resolve(scalarNode);
567
+ },
568
+ comment(cursor) {
569
+ const info = getCursorInfo(cursor);
570
+ return new _YamlComment.default({
571
+ content: info.text
572
+ });
573
+ },
574
+ alias(cursor, ctx) {
575
+ const info = getCursorInfo(cursor);
576
+ const alias = new _YamlAlias.default({
577
+ content: info.text
578
+ });
579
+ return ctx.referenceManager.resolveAlias(alias);
580
+ },
581
+ ERROR(cursor, ctx) {
582
+ const info = getCursorInfo(cursor);
583
+ const children = processChildren(cursor, ctx, transformerMap);
584
+ const errorNode = new _Error.default({
585
+ children: children.filter(c => c !== null),
586
+ ...toPositionProps(info),
587
+ isUnexpected: !info.hasError,
588
+ isMissing: info.isMissing,
589
+ value: info.text
590
+ });
591
+
592
+ // If at root level, wrap in ParseResult
593
+ // This check is simplified - we'll handle it in the main analyze function
594
+ return errorNode;
595
+ }
596
+ });
597
+
598
+ // Create transformers with self-reference for recursion
599
+ const transformers = {};
600
+ Object.assign(transformers, createTransformers(transformers));
601
+
602
+ /**
603
+ * Transform TreeSitter CST directly to YAML AST using cursor-based traversal.
604
+ */
605
+ const transformCstToYamlAst = (cursor, ctx) => {
606
+ const result = transform(cursor, ctx, transformers);
607
+ if (result === null) {
608
+ return new _ParseResult.default({
609
+ children: []
610
+ });
611
+ }
612
+ if (result instanceof _ParseResult.default) {
613
+ return result;
614
+ }
615
+ if (result instanceof _Error.default) {
616
+ return new _ParseResult.default({
617
+ children: [result]
618
+ });
619
+ }
620
+ return new _ParseResult.default({
621
+ children: [result]
622
+ });
623
+ };
624
+ exports.transformCstToYamlAst = transformCstToYamlAst;
625
+ var _default = exports.default = transformCstToYamlAst;