@swagger-api/apidom-parser-adapter-yaml-1-2 0.92.0 → 0.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/cjs/syntactic-analysis/TreeCursorIterator.cjs +1 -0
- package/cjs/syntactic-analysis/TreeCursorSyntaxNode.cjs +10 -0
- package/cjs/syntactic-analysis/indirect/index.cjs +4 -2
- package/cjs/syntactic-analysis/indirect/visitors/CstVisitor.cjs +153 -127
- package/cjs/syntactic-analysis/indirect/visitors/YamlAstVisitor.cjs +2 -0
- package/dist/apidom-parser-adapter-yaml-1-2.browser.js +2241 -2285
- package/dist/apidom-parser-adapter-yaml1-2.browser.min.js +1 -1
- package/es/syntactic-analysis/TreeCursorIterator.mjs +1 -0
- package/es/syntactic-analysis/TreeCursorSyntaxNode.mjs +10 -0
- package/es/syntactic-analysis/indirect/index.mjs +5 -3
- package/es/syntactic-analysis/indirect/visitors/CstVisitor.mjs +154 -128
- package/es/syntactic-analysis/indirect/visitors/YamlAstVisitor.mjs +2 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.94.0](https://github.com/swagger-api/apidom/compare/v0.93.0...v0.94.0) (2024-02-05)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **parser-adapter-yaml-1-2:** add syntactic analysis for YAML aliases ([#3785](https://github.com/swagger-api/apidom/issues/3785)) ([e975718](https://github.com/swagger-api/apidom/commit/e97571823d1d3154fe3b13936260ed13230cf573)), closes [#3703](https://github.com/swagger-api/apidom/issues/3703)
|
|
11
|
+
|
|
12
|
+
# [0.93.0](https://github.com/swagger-api/apidom/compare/v0.92.0...v0.93.0) (2024-01-23)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @swagger-api/apidom-parser-adapter-yaml-1-2
|
|
15
|
+
|
|
6
16
|
# [0.92.0](https://github.com/swagger-api/apidom/compare/v0.91.0...v0.92.0) (2024-01-12)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @swagger-api/apidom-parser-adapter-yaml-1-2
|
|
@@ -3,8 +3,18 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
5
|
class TreeCursorSyntaxNode {
|
|
6
|
+
type;
|
|
7
|
+
startPosition;
|
|
8
|
+
endPosition;
|
|
9
|
+
startIndex;
|
|
10
|
+
endIndex;
|
|
11
|
+
text;
|
|
12
|
+
isNamed;
|
|
13
|
+
isMissing;
|
|
14
|
+
fieldName;
|
|
6
15
|
hasError = false;
|
|
7
16
|
children = [];
|
|
17
|
+
previousSibling;
|
|
8
18
|
constructor(cursor) {
|
|
9
19
|
this.type = cursor.nodeType;
|
|
10
20
|
this.startPosition = cursor.startPosition;
|
|
@@ -21,14 +21,16 @@ const analyze = (cst, {
|
|
|
21
21
|
const [rootNode] = Array.from(iterator);
|
|
22
22
|
const cstVisitor = new _CstVisitor.default();
|
|
23
23
|
const astVisitor = new _YamlAstVisitor.default();
|
|
24
|
-
const schema =
|
|
24
|
+
const schema = new _apidomAst.YamlJsonSchema();
|
|
25
|
+
const referenceManager = new _apidomAst.YamlReferenceManager();
|
|
25
26
|
const yamlAst = (0, _apidomAst.visit)(rootNode, cstVisitor, {
|
|
26
27
|
// @ts-ignore
|
|
27
28
|
keyMap: _CstVisitor.keyMap,
|
|
28
29
|
nodePredicate: _CstVisitor.isNode,
|
|
29
30
|
state: {
|
|
30
31
|
schema,
|
|
31
|
-
sourceMap
|
|
32
|
+
sourceMap,
|
|
33
|
+
referenceManager
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
36
|
return (0, _apidomAst.visit)(yamlAst.rootNode, astVisitor, {
|
|
@@ -25,21 +25,31 @@ class CstVisitor {
|
|
|
25
25
|
return node => node != null && typeof node === 'object' && 'type' in node && typeof node.type === 'string' && node.type.endsWith(ending);
|
|
26
26
|
}
|
|
27
27
|
static toPosition(node) {
|
|
28
|
-
const start =
|
|
28
|
+
const start = new _apidomAst.Point({
|
|
29
29
|
row: node.startPosition.row,
|
|
30
30
|
column: node.startPosition.column,
|
|
31
31
|
char: node.startIndex
|
|
32
32
|
});
|
|
33
|
-
const end =
|
|
33
|
+
const end = new _apidomAst.Point({
|
|
34
34
|
row: node.endPosition.row,
|
|
35
35
|
column: node.endPosition.column,
|
|
36
36
|
char: node.endIndex
|
|
37
37
|
});
|
|
38
|
-
return
|
|
38
|
+
return new _apidomAst.Position({
|
|
39
39
|
start,
|
|
40
40
|
end
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
+
static kindNodeToYamlAnchor(node) {
|
|
44
|
+
const {
|
|
45
|
+
anchor: anchorNode
|
|
46
|
+
} = node;
|
|
47
|
+
if (typeof anchorNode === 'undefined') return undefined;
|
|
48
|
+
return new _apidomAst.YamlAnchor({
|
|
49
|
+
name: anchorNode.text,
|
|
50
|
+
position: CstVisitor.toPosition(anchorNode)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
43
53
|
static hasKeyValuePairEmptyKey(node) {
|
|
44
54
|
if (node.type !== 'block_mapping_pair' && node.type !== 'flow_pair') {
|
|
45
55
|
return false;
|
|
@@ -60,109 +70,28 @@ class CstVisitor {
|
|
|
60
70
|
} = node;
|
|
61
71
|
const explicitName = (tagNode == null ? void 0 : tagNode.text) || (node.type === 'plain_scalar' ? '?' : '!');
|
|
62
72
|
const kind = node.type.endsWith('mapping') ? _apidomAst.YamlNodeKind.Mapping : node.type.endsWith('sequence') ? _apidomAst.YamlNodeKind.Sequence : _apidomAst.YamlNodeKind.Scalar;
|
|
63
|
-
const position = tagNode ? CstVisitor.toPosition(tagNode) :
|
|
64
|
-
return
|
|
73
|
+
const position = tagNode ? CstVisitor.toPosition(tagNode) : undefined;
|
|
74
|
+
return new _apidomAst.YamlTag({
|
|
65
75
|
explicitName,
|
|
66
76
|
kind,
|
|
67
77
|
position
|
|
68
78
|
});
|
|
69
79
|
}
|
|
70
|
-
static kindNodeToYamlAnchor(node) {
|
|
71
|
-
const {
|
|
72
|
-
anchor: anchorNode
|
|
73
|
-
} = node;
|
|
74
|
-
if (typeof anchorNode === 'undefined') return null;
|
|
75
|
-
return (0, _apidomAst.YamlAnchor)({
|
|
76
|
-
name: anchorNode.text,
|
|
77
|
-
position: CstVisitor.toPosition(anchorNode)
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
static createKeyValuePairEmptyKey(node) {
|
|
81
|
-
const emptyPoint = (0, _apidomAst.Point)({
|
|
82
|
-
row: node.startPosition.row,
|
|
83
|
-
column: node.startPosition.column,
|
|
84
|
-
char: node.startIndex
|
|
85
|
-
});
|
|
86
|
-
const {
|
|
87
|
-
keyNode
|
|
88
|
-
} = node;
|
|
89
|
-
const children = (keyNode == null ? void 0 : keyNode.children) || [];
|
|
90
|
-
const tagNode = children.find(CstVisitor.isKind('tag'));
|
|
91
|
-
const anchorNode = children.find(CstVisitor.isKind('anchor'));
|
|
92
|
-
const tag = typeof tagNode !== 'undefined' ? (0, _apidomAst.YamlTag)({
|
|
93
|
-
explicitName: tagNode.text,
|
|
94
|
-
kind: _apidomAst.YamlNodeKind.Scalar,
|
|
95
|
-
position: CstVisitor.toPosition(tagNode)
|
|
96
|
-
}) : (0, _apidomAst.YamlTag)({
|
|
97
|
-
explicitName: '?',
|
|
98
|
-
kind: _apidomAst.YamlNodeKind.Scalar
|
|
99
|
-
});
|
|
100
|
-
const anchor = typeof anchorNode !== 'undefined' ? (0, _apidomAst.YamlAnchor)({
|
|
101
|
-
name: anchorNode.text,
|
|
102
|
-
position: CstVisitor.toPosition(anchorNode)
|
|
103
|
-
}) : null;
|
|
104
|
-
return (0, _apidomAst.YamlScalar)({
|
|
105
|
-
content: '',
|
|
106
|
-
position: (0, _apidomAst.Position)({
|
|
107
|
-
start: emptyPoint,
|
|
108
|
-
end: emptyPoint
|
|
109
|
-
}),
|
|
110
|
-
tag,
|
|
111
|
-
anchor,
|
|
112
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
113
|
-
style: _apidomAst.YamlStyle.Plain
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
static createKeyValuePairEmptyValue(node) {
|
|
117
|
-
const emptyPoint = (0, _apidomAst.Point)({
|
|
118
|
-
row: node.endPosition.row,
|
|
119
|
-
column: node.endPosition.column,
|
|
120
|
-
char: node.endIndex
|
|
121
|
-
});
|
|
122
|
-
const {
|
|
123
|
-
valueNode
|
|
124
|
-
} = node;
|
|
125
|
-
const children = (valueNode == null ? void 0 : valueNode.children) || [];
|
|
126
|
-
const tagNode = children.find(CstVisitor.isKind('tag'));
|
|
127
|
-
const anchorNode = children.find(CstVisitor.isKind('anchor'));
|
|
128
|
-
const tag = typeof tagNode !== 'undefined' ? (0, _apidomAst.YamlTag)({
|
|
129
|
-
explicitName: tagNode.text,
|
|
130
|
-
kind: _apidomAst.YamlNodeKind.Scalar,
|
|
131
|
-
position: CstVisitor.toPosition(tagNode)
|
|
132
|
-
}) : (0, _apidomAst.YamlTag)({
|
|
133
|
-
explicitName: '?',
|
|
134
|
-
kind: _apidomAst.YamlNodeKind.Scalar
|
|
135
|
-
});
|
|
136
|
-
const anchor = typeof anchorNode !== 'undefined' ? (0, _apidomAst.YamlAnchor)({
|
|
137
|
-
name: anchorNode.text,
|
|
138
|
-
position: CstVisitor.toPosition(anchorNode)
|
|
139
|
-
}) : null;
|
|
140
|
-
return (0, _apidomAst.YamlScalar)({
|
|
141
|
-
content: '',
|
|
142
|
-
position: (0, _apidomAst.Position)({
|
|
143
|
-
start: emptyPoint,
|
|
144
|
-
end: emptyPoint
|
|
145
|
-
}),
|
|
146
|
-
tag,
|
|
147
|
-
anchor,
|
|
148
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
149
|
-
style: _apidomAst.YamlStyle.Plain
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
80
|
|
|
153
81
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
|
-
|
|
82
|
+
schema;
|
|
83
|
+
referenceManager;
|
|
155
84
|
stream = {
|
|
156
85
|
enter: node => {
|
|
157
86
|
const position = CstVisitor.toPosition(node);
|
|
158
|
-
return
|
|
87
|
+
return new _apidomAst.YamlStream({
|
|
159
88
|
children: node.children,
|
|
160
89
|
position,
|
|
161
90
|
isMissing: node.isMissing
|
|
162
91
|
});
|
|
163
92
|
},
|
|
164
93
|
leave: stream => {
|
|
165
|
-
return
|
|
94
|
+
return new _apidomAst.ParseResult({
|
|
166
95
|
children: [stream]
|
|
167
96
|
});
|
|
168
97
|
}
|
|
@@ -171,8 +100,8 @@ class CstVisitor {
|
|
|
171
100
|
enter: node => {
|
|
172
101
|
var _node$firstNamedChild;
|
|
173
102
|
const position = CstVisitor.toPosition(node);
|
|
174
|
-
const version =
|
|
175
|
-
return
|
|
103
|
+
const version = node == null || (_node$firstNamedChild = node.firstNamedChild) == null ? void 0 : _node$firstNamedChild.text;
|
|
104
|
+
return new _apidomAst.YamlDirective({
|
|
176
105
|
position,
|
|
177
106
|
name: '%YAML',
|
|
178
107
|
parameters: {
|
|
@@ -186,12 +115,12 @@ class CstVisitor {
|
|
|
186
115
|
const position = CstVisitor.toPosition(node);
|
|
187
116
|
const tagHandleNode = node.children[0];
|
|
188
117
|
const tagPrefixNode = node.children[1];
|
|
189
|
-
const tagDirective =
|
|
118
|
+
const tagDirective = new _apidomAst.YamlDirective({
|
|
190
119
|
position,
|
|
191
120
|
name: '%TAG',
|
|
192
121
|
parameters: {
|
|
193
|
-
handle:
|
|
194
|
-
prefix:
|
|
122
|
+
handle: tagHandleNode == null ? void 0 : tagHandleNode.text,
|
|
123
|
+
prefix: tagPrefixNode == null ? void 0 : tagPrefixNode.text
|
|
195
124
|
}
|
|
196
125
|
});
|
|
197
126
|
this.schema.registerTagDirective(tagDirective);
|
|
@@ -204,12 +133,12 @@ class CstVisitor {
|
|
|
204
133
|
const directiveNameNode = node.children[0];
|
|
205
134
|
const directiveParameter1Node = node.children[1];
|
|
206
135
|
const directiveParameter2Node = node.children[2];
|
|
207
|
-
return
|
|
136
|
+
return new _apidomAst.YamlDirective({
|
|
208
137
|
position,
|
|
209
|
-
name:
|
|
138
|
+
name: directiveNameNode == null ? void 0 : directiveNameNode.text,
|
|
210
139
|
parameters: {
|
|
211
|
-
handle:
|
|
212
|
-
prefix:
|
|
140
|
+
handle: directiveParameter1Node == null ? void 0 : directiveParameter1Node.text,
|
|
141
|
+
prefix: directiveParameter2Node == null ? void 0 : directiveParameter2Node.text
|
|
213
142
|
}
|
|
214
143
|
});
|
|
215
144
|
}
|
|
@@ -217,7 +146,7 @@ class CstVisitor {
|
|
|
217
146
|
document = {
|
|
218
147
|
enter: node => {
|
|
219
148
|
const position = CstVisitor.toPosition(node);
|
|
220
|
-
return
|
|
149
|
+
return new _apidomAst.YamlDocument({
|
|
221
150
|
children: node.children,
|
|
222
151
|
position,
|
|
223
152
|
isMissing: node.isMissing
|
|
@@ -242,22 +171,23 @@ class CstVisitor {
|
|
|
242
171
|
}
|
|
243
172
|
|
|
244
173
|
// kind node not present in flow node, creating empty node
|
|
245
|
-
const emptyPoint =
|
|
174
|
+
const emptyPoint = new _apidomAst.Point({
|
|
246
175
|
row: kindCandidate.endPosition.row,
|
|
247
176
|
column: kindCandidate.endPosition.column,
|
|
248
177
|
char: kindCandidate.endIndex
|
|
249
178
|
});
|
|
250
|
-
const emptyScalarNode =
|
|
179
|
+
const emptyScalarNode = new _apidomAst.YamlScalar({
|
|
251
180
|
content: '',
|
|
252
181
|
anchor: CstVisitor.kindNodeToYamlAnchor(kindCandidate),
|
|
253
182
|
tag: CstVisitor.kindNodeToYamlTag(kindCandidate),
|
|
254
|
-
position:
|
|
183
|
+
position: new _apidomAst.Position({
|
|
255
184
|
start: emptyPoint,
|
|
256
185
|
end: emptyPoint
|
|
257
186
|
}),
|
|
258
187
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
259
188
|
style: _apidomAst.YamlStyle.Plain
|
|
260
189
|
});
|
|
190
|
+
this.registerAnchor(emptyScalarNode);
|
|
261
191
|
return [...node.children, emptyScalarNode];
|
|
262
192
|
}
|
|
263
193
|
};
|
|
@@ -276,7 +206,7 @@ class CstVisitor {
|
|
|
276
206
|
const position = CstVisitor.toPosition(node);
|
|
277
207
|
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
278
208
|
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
279
|
-
const mappingNode =
|
|
209
|
+
const mappingNode = new _apidomAst.YamlMapping({
|
|
280
210
|
children: node.children,
|
|
281
211
|
position,
|
|
282
212
|
anchor,
|
|
@@ -285,6 +215,7 @@ class CstVisitor {
|
|
|
285
215
|
style: _apidomAst.YamlStyle.NextLine,
|
|
286
216
|
isMissing: node.isMissing
|
|
287
217
|
});
|
|
218
|
+
this.registerAnchor(mappingNode);
|
|
288
219
|
return this.schema.resolve(mappingNode);
|
|
289
220
|
}
|
|
290
221
|
};
|
|
@@ -293,14 +224,14 @@ class CstVisitor {
|
|
|
293
224
|
const position = CstVisitor.toPosition(node);
|
|
294
225
|
const children = [...node.children];
|
|
295
226
|
if (CstVisitor.hasKeyValuePairEmptyKey(node)) {
|
|
296
|
-
const keyNode =
|
|
227
|
+
const keyNode = this.createKeyValuePairEmptyKey(node);
|
|
297
228
|
children.unshift(keyNode);
|
|
298
229
|
}
|
|
299
230
|
if (CstVisitor.hasKeyValuePairEmptyValue(node)) {
|
|
300
|
-
const valueNode =
|
|
231
|
+
const valueNode = this.createKeyValuePairEmptyValue(node);
|
|
301
232
|
children.push(valueNode);
|
|
302
233
|
}
|
|
303
|
-
return
|
|
234
|
+
return new _apidomAst.YamlKeyValuePair({
|
|
304
235
|
children,
|
|
305
236
|
position,
|
|
306
237
|
styleGroup: _apidomAst.YamlStyleGroup.Block,
|
|
@@ -313,7 +244,7 @@ class CstVisitor {
|
|
|
313
244
|
const position = CstVisitor.toPosition(node);
|
|
314
245
|
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
315
246
|
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
316
|
-
const mappingNode =
|
|
247
|
+
const mappingNode = new _apidomAst.YamlMapping({
|
|
317
248
|
children: node.children,
|
|
318
249
|
position,
|
|
319
250
|
anchor,
|
|
@@ -322,6 +253,7 @@ class CstVisitor {
|
|
|
322
253
|
style: _apidomAst.YamlStyle.Explicit,
|
|
323
254
|
isMissing: node.isMissing
|
|
324
255
|
});
|
|
256
|
+
this.registerAnchor(mappingNode);
|
|
325
257
|
return this.schema.resolve(mappingNode);
|
|
326
258
|
}
|
|
327
259
|
};
|
|
@@ -330,14 +262,14 @@ class CstVisitor {
|
|
|
330
262
|
const position = CstVisitor.toPosition(node);
|
|
331
263
|
const children = [...node.children];
|
|
332
264
|
if (CstVisitor.hasKeyValuePairEmptyKey(node)) {
|
|
333
|
-
const keyNode =
|
|
265
|
+
const keyNode = this.createKeyValuePairEmptyKey(node);
|
|
334
266
|
children.unshift(keyNode);
|
|
335
267
|
}
|
|
336
268
|
if (CstVisitor.hasKeyValuePairEmptyValue(node)) {
|
|
337
|
-
const valueNode =
|
|
269
|
+
const valueNode = this.createKeyValuePairEmptyValue(node);
|
|
338
270
|
children.push(valueNode);
|
|
339
271
|
}
|
|
340
|
-
return
|
|
272
|
+
return new _apidomAst.YamlKeyValuePair({
|
|
341
273
|
children,
|
|
342
274
|
position,
|
|
343
275
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
@@ -355,7 +287,7 @@ class CstVisitor {
|
|
|
355
287
|
const position = CstVisitor.toPosition(node);
|
|
356
288
|
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
357
289
|
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
358
|
-
const sequenceNode =
|
|
290
|
+
const sequenceNode = new _apidomAst.YamlSequence({
|
|
359
291
|
children: node.children,
|
|
360
292
|
position,
|
|
361
293
|
anchor,
|
|
@@ -363,6 +295,7 @@ class CstVisitor {
|
|
|
363
295
|
styleGroup: _apidomAst.YamlStyleGroup.Block,
|
|
364
296
|
style: _apidomAst.YamlStyle.NextLine
|
|
365
297
|
});
|
|
298
|
+
this.registerAnchor(sequenceNode);
|
|
366
299
|
return this.schema.resolve(sequenceNode);
|
|
367
300
|
}
|
|
368
301
|
};
|
|
@@ -374,19 +307,18 @@ class CstVisitor {
|
|
|
374
307
|
}
|
|
375
308
|
|
|
376
309
|
// create empty node
|
|
377
|
-
const emptyPoint =
|
|
310
|
+
const emptyPoint = new _apidomAst.Point({
|
|
378
311
|
row: node.endPosition.row,
|
|
379
312
|
column: node.endPosition.column,
|
|
380
313
|
char: node.endIndex
|
|
381
314
|
});
|
|
382
|
-
const emptyScalarNode =
|
|
315
|
+
const emptyScalarNode = new _apidomAst.YamlScalar({
|
|
383
316
|
content: '',
|
|
384
|
-
|
|
385
|
-
tag: (0, _apidomAst.YamlTag)({
|
|
317
|
+
tag: new _apidomAst.YamlTag({
|
|
386
318
|
explicitName: '?',
|
|
387
319
|
kind: _apidomAst.YamlNodeKind.Scalar
|
|
388
320
|
}),
|
|
389
|
-
position:
|
|
321
|
+
position: new _apidomAst.Position({
|
|
390
322
|
start: emptyPoint,
|
|
391
323
|
end: emptyPoint
|
|
392
324
|
}),
|
|
@@ -401,7 +333,7 @@ class CstVisitor {
|
|
|
401
333
|
const position = CstVisitor.toPosition(node);
|
|
402
334
|
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
403
335
|
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
404
|
-
const sequenceNode =
|
|
336
|
+
const sequenceNode = new _apidomAst.YamlSequence({
|
|
405
337
|
children: node.children.flat(),
|
|
406
338
|
position,
|
|
407
339
|
anchor,
|
|
@@ -409,6 +341,7 @@ class CstVisitor {
|
|
|
409
341
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
410
342
|
style: _apidomAst.YamlStyle.Explicit
|
|
411
343
|
});
|
|
344
|
+
this.registerAnchor(sequenceNode);
|
|
412
345
|
return this.schema.resolve(sequenceNode);
|
|
413
346
|
}
|
|
414
347
|
};
|
|
@@ -422,7 +355,7 @@ class CstVisitor {
|
|
|
422
355
|
const position = CstVisitor.toPosition(node);
|
|
423
356
|
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
424
357
|
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
425
|
-
const scalarNode =
|
|
358
|
+
const scalarNode = new _apidomAst.YamlScalar({
|
|
426
359
|
content: node.text,
|
|
427
360
|
anchor,
|
|
428
361
|
tag,
|
|
@@ -430,6 +363,7 @@ class CstVisitor {
|
|
|
430
363
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
431
364
|
style: _apidomAst.YamlStyle.Plain
|
|
432
365
|
});
|
|
366
|
+
this.registerAnchor(scalarNode);
|
|
433
367
|
return this.schema.resolve(scalarNode);
|
|
434
368
|
}
|
|
435
369
|
};
|
|
@@ -438,7 +372,7 @@ class CstVisitor {
|
|
|
438
372
|
const position = CstVisitor.toPosition(node);
|
|
439
373
|
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
440
374
|
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
441
|
-
const scalarNode =
|
|
375
|
+
const scalarNode = new _apidomAst.YamlScalar({
|
|
442
376
|
content: node.text,
|
|
443
377
|
anchor,
|
|
444
378
|
tag,
|
|
@@ -446,6 +380,7 @@ class CstVisitor {
|
|
|
446
380
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
447
381
|
style: _apidomAst.YamlStyle.SingleQuoted
|
|
448
382
|
});
|
|
383
|
+
this.registerAnchor(scalarNode);
|
|
449
384
|
return this.schema.resolve(scalarNode);
|
|
450
385
|
}
|
|
451
386
|
};
|
|
@@ -454,7 +389,7 @@ class CstVisitor {
|
|
|
454
389
|
const position = CstVisitor.toPosition(node);
|
|
455
390
|
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
456
391
|
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
457
|
-
const scalarNode =
|
|
392
|
+
const scalarNode = new _apidomAst.YamlScalar({
|
|
458
393
|
content: node.text,
|
|
459
394
|
anchor,
|
|
460
395
|
tag,
|
|
@@ -462,6 +397,7 @@ class CstVisitor {
|
|
|
462
397
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
463
398
|
style: _apidomAst.YamlStyle.DoubleQuoted
|
|
464
399
|
});
|
|
400
|
+
this.registerAnchor(scalarNode);
|
|
465
401
|
return this.schema.resolve(scalarNode);
|
|
466
402
|
}
|
|
467
403
|
};
|
|
@@ -470,8 +406,8 @@ class CstVisitor {
|
|
|
470
406
|
const position = CstVisitor.toPosition(node);
|
|
471
407
|
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
472
408
|
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
473
|
-
const style = node.text.startsWith('|') ? _apidomAst.YamlStyle.Literal : node.text.startsWith('>') ? _apidomAst.YamlStyle.Folded :
|
|
474
|
-
const scalarNode =
|
|
409
|
+
const style = node.text.startsWith('|') ? _apidomAst.YamlStyle.Literal : node.text.startsWith('>') ? _apidomAst.YamlStyle.Folded : _apidomAst.YamlStyle.Plain;
|
|
410
|
+
const scalarNode = new _apidomAst.YamlScalar({
|
|
475
411
|
content: node.text,
|
|
476
412
|
anchor,
|
|
477
413
|
tag,
|
|
@@ -479,16 +415,25 @@ class CstVisitor {
|
|
|
479
415
|
styleGroup: _apidomAst.YamlStyleGroup.Block,
|
|
480
416
|
style
|
|
481
417
|
});
|
|
418
|
+
this.registerAnchor(scalarNode);
|
|
482
419
|
return this.schema.resolve(scalarNode);
|
|
483
420
|
}
|
|
484
421
|
};
|
|
485
422
|
comment = {
|
|
486
423
|
enter: node => {
|
|
487
|
-
return
|
|
424
|
+
return new _apidomAst.YamlComment({
|
|
488
425
|
content: node.text
|
|
489
426
|
});
|
|
490
427
|
}
|
|
491
428
|
};
|
|
429
|
+
alias = {
|
|
430
|
+
enter: node => {
|
|
431
|
+
const alias = new _apidomAst.YamlAlias({
|
|
432
|
+
content: node.text
|
|
433
|
+
});
|
|
434
|
+
return this.referenceManager.resolveAlias(alias);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
492
437
|
|
|
493
438
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
494
439
|
constructor(schema) {
|
|
@@ -504,7 +449,7 @@ class CstVisitor {
|
|
|
504
449
|
const {
|
|
505
450
|
isMissing
|
|
506
451
|
} = node;
|
|
507
|
-
return
|
|
452
|
+
return new _apidomAst.Literal({
|
|
508
453
|
value,
|
|
509
454
|
position,
|
|
510
455
|
isMissing
|
|
@@ -516,7 +461,7 @@ class CstVisitor {
|
|
|
516
461
|
// eslint-disable-next-line class-methods-use-this
|
|
517
462
|
ERROR(node, key, parent, path) {
|
|
518
463
|
const position = CstVisitor.toPosition(node);
|
|
519
|
-
const errorNode =
|
|
464
|
+
const errorNode = new _apidomAst.Error({
|
|
520
465
|
children: node.children,
|
|
521
466
|
position,
|
|
522
467
|
isUnexpected: !node.hasError,
|
|
@@ -524,11 +469,92 @@ class CstVisitor {
|
|
|
524
469
|
value: node.text
|
|
525
470
|
});
|
|
526
471
|
if (path.length === 0) {
|
|
527
|
-
return
|
|
472
|
+
return new _apidomAst.ParseResult({
|
|
528
473
|
children: [errorNode]
|
|
529
474
|
});
|
|
530
475
|
}
|
|
531
476
|
return errorNode;
|
|
532
477
|
}
|
|
478
|
+
registerAnchor(node) {
|
|
479
|
+
if (node.anchor !== undefined) {
|
|
480
|
+
this.referenceManager.addAnchor(node);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
createKeyValuePairEmptyKey(node) {
|
|
484
|
+
const emptyPoint = new _apidomAst.Point({
|
|
485
|
+
row: node.startPosition.row,
|
|
486
|
+
column: node.startPosition.column,
|
|
487
|
+
char: node.startIndex
|
|
488
|
+
});
|
|
489
|
+
const {
|
|
490
|
+
keyNode
|
|
491
|
+
} = node;
|
|
492
|
+
const children = (keyNode == null ? void 0 : keyNode.children) || [];
|
|
493
|
+
const tagNode = children.find(CstVisitor.isKind('tag'));
|
|
494
|
+
const anchorNode = children.find(CstVisitor.isKind('anchor'));
|
|
495
|
+
const tag = typeof tagNode !== 'undefined' ? new _apidomAst.YamlTag({
|
|
496
|
+
explicitName: tagNode.text,
|
|
497
|
+
kind: _apidomAst.YamlNodeKind.Scalar,
|
|
498
|
+
position: CstVisitor.toPosition(tagNode)
|
|
499
|
+
}) : new _apidomAst.YamlTag({
|
|
500
|
+
explicitName: '?',
|
|
501
|
+
kind: _apidomAst.YamlNodeKind.Scalar
|
|
502
|
+
});
|
|
503
|
+
const anchor = typeof anchorNode !== 'undefined' ? new _apidomAst.YamlAnchor({
|
|
504
|
+
name: anchorNode.text,
|
|
505
|
+
position: CstVisitor.toPosition(anchorNode)
|
|
506
|
+
}) : undefined;
|
|
507
|
+
const scalarNode = new _apidomAst.YamlScalar({
|
|
508
|
+
content: '',
|
|
509
|
+
position: new _apidomAst.Position({
|
|
510
|
+
start: emptyPoint,
|
|
511
|
+
end: emptyPoint
|
|
512
|
+
}),
|
|
513
|
+
tag,
|
|
514
|
+
anchor,
|
|
515
|
+
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
516
|
+
style: _apidomAst.YamlStyle.Plain
|
|
517
|
+
});
|
|
518
|
+
this.registerAnchor(scalarNode);
|
|
519
|
+
return scalarNode;
|
|
520
|
+
}
|
|
521
|
+
createKeyValuePairEmptyValue(node) {
|
|
522
|
+
const emptyPoint = new _apidomAst.Point({
|
|
523
|
+
row: node.endPosition.row,
|
|
524
|
+
column: node.endPosition.column,
|
|
525
|
+
char: node.endIndex
|
|
526
|
+
});
|
|
527
|
+
const {
|
|
528
|
+
valueNode
|
|
529
|
+
} = node;
|
|
530
|
+
const children = (valueNode == null ? void 0 : valueNode.children) || [];
|
|
531
|
+
const tagNode = children.find(CstVisitor.isKind('tag'));
|
|
532
|
+
const anchorNode = children.find(CstVisitor.isKind('anchor'));
|
|
533
|
+
const tag = typeof tagNode !== 'undefined' ? new _apidomAst.YamlTag({
|
|
534
|
+
explicitName: tagNode.text,
|
|
535
|
+
kind: _apidomAst.YamlNodeKind.Scalar,
|
|
536
|
+
position: CstVisitor.toPosition(tagNode)
|
|
537
|
+
}) : new _apidomAst.YamlTag({
|
|
538
|
+
explicitName: '?',
|
|
539
|
+
kind: _apidomAst.YamlNodeKind.Scalar
|
|
540
|
+
});
|
|
541
|
+
const anchor = typeof anchorNode !== 'undefined' ? new _apidomAst.YamlAnchor({
|
|
542
|
+
name: anchorNode.text,
|
|
543
|
+
position: CstVisitor.toPosition(anchorNode)
|
|
544
|
+
}) : undefined;
|
|
545
|
+
const scalarNode = new _apidomAst.YamlScalar({
|
|
546
|
+
content: '',
|
|
547
|
+
position: new _apidomAst.Position({
|
|
548
|
+
start: emptyPoint,
|
|
549
|
+
end: emptyPoint
|
|
550
|
+
}),
|
|
551
|
+
tag,
|
|
552
|
+
anchor,
|
|
553
|
+
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
554
|
+
style: _apidomAst.YamlStyle.Plain
|
|
555
|
+
});
|
|
556
|
+
this.registerAnchor(scalarNode);
|
|
557
|
+
return scalarNode;
|
|
558
|
+
}
|
|
533
559
|
}
|
|
534
560
|
var _default = exports.default = CstVisitor;
|