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