@speclynx/apidom-parser-adapter-yaml-1-2 1.12.1 → 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.
- package/CHANGELOG.md +24 -0
- package/NOTICE +16 -7
- package/README.md +34 -7
- package/dist/167.apidom-parser-adapter-yaml-1-2.browser.min.js +1 -1
- package/dist/451.apidom-parser-adapter-yaml-1-2.browser.min.js +1 -1
- package/dist/apidom-parser-adapter-yaml-1-2.browser.js +19340 -16731
- package/dist/apidom-parser-adapter-yaml-1-2.browser.min.js +1 -1
- package/package.json +10 -9
- package/src/adapter.cjs +28 -16
- package/src/adapter.mjs +25 -15
- package/src/tree-sitter/index.cjs +44 -0
- package/src/tree-sitter/index.mjs +38 -0
- package/src/{lexical-analysis → tree-sitter/lexical-analysis}/index.cjs +1 -1
- package/src/{lexical-analysis → tree-sitter/lexical-analysis}/index.mjs +1 -1
- package/src/tree-sitter/syntactic-analysis/CstTransformer.cjs +625 -0
- package/src/tree-sitter/syntactic-analysis/CstTransformer.mjs +618 -0
- package/src/tree-sitter/syntactic-analysis/YamlAstTransformer.cjs +271 -0
- package/src/tree-sitter/syntactic-analysis/YamlAstTransformer.mjs +263 -0
- package/src/tree-sitter/syntactic-analysis/ast/Error.cjs +30 -0
- package/src/tree-sitter/syntactic-analysis/ast/Error.mjs +24 -0
- package/src/tree-sitter/syntactic-analysis/ast/Literal.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/Literal.mjs +21 -0
- package/src/tree-sitter/syntactic-analysis/ast/Node.cjs +60 -0
- package/src/tree-sitter/syntactic-analysis/ast/Node.mjs +56 -0
- package/src/tree-sitter/syntactic-analysis/ast/ParseResult.cjs +17 -0
- package/src/tree-sitter/syntactic-analysis/ast/ParseResult.mjs +12 -0
- package/src/tree-sitter/syntactic-analysis/ast/anchors-aliases/ReferenceManager.cjs +23 -0
- package/src/tree-sitter/syntactic-analysis/ast/anchors-aliases/ReferenceManager.mjs +18 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlError.cjs +10 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlError.mjs +7 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlSchemaError.cjs +11 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlSchemaError.mjs +6 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlTagError.cjs +43 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlTagError.mjs +37 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAlias.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAlias.mjs +21 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAnchor.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAnchor.mjs +21 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlCollection.cjs +11 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlCollection.mjs +6 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlComment.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlComment.mjs +21 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDirective.cjs +39 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDirective.mjs +32 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDocument.cjs +13 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDocument.mjs +8 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlKeyValuePair.cjs +48 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlKeyValuePair.mjs +42 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlMapping.cjs +20 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlMapping.mjs +15 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlNode.cjs +35 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlNode.mjs +29 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlScalar.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlScalar.mjs +21 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlSequence.cjs +23 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlSequence.mjs +18 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStream.cjs +20 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStream.mjs +15 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStyle.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStyle.mjs +24 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlTag.cjs +38 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlTag.mjs +35 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/predicates.cjs +26 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/predicates.mjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/ScalarTag.cjs +33 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/ScalarTag.mjs +29 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/Tag.cjs +20 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/Tag.mjs +16 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/canonical-format.cjs +127 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/canonical-format.mjs +122 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericMapping.cjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericMapping.mjs +9 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericSequence.cjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericSequence.mjs +9 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericString.cjs +10 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericString.mjs +5 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/index.cjs +116 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/index.mjs +111 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Boolean.cjs +19 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Boolean.mjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/FloatingPoint.cjs +19 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/FloatingPoint.mjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Integer.cjs +19 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Integer.mjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Null.cjs +18 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Null.mjs +13 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/index.cjs +43 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/index.mjs +38 -0
- package/src/tree-sitter/syntactic-analysis/index.cjs +39 -0
- package/src/tree-sitter/syntactic-analysis/index.mjs +33 -0
- package/src/yaml/index.cjs +31 -0
- package/src/yaml/index.mjs +26 -0
- package/types/apidom-parser-adapter-yaml-1-2.d.ts +11 -3
- package/src/syntactic-analysis/TreeCursorIterator.cjs +0 -93
- package/src/syntactic-analysis/TreeCursorIterator.mjs +0 -88
- package/src/syntactic-analysis/TreeCursorSyntaxNode.cjs +0 -80
- package/src/syntactic-analysis/TreeCursorSyntaxNode.mjs +0 -76
- package/src/syntactic-analysis/indirect/index.cjs +0 -51
- package/src/syntactic-analysis/indirect/index.mjs +0 -44
- package/src/syntactic-analysis/indirect/visitors/CstVisitor.cjs +0 -553
- package/src/syntactic-analysis/indirect/visitors/CstVisitor.mjs +0 -547
- package/src/syntactic-analysis/indirect/visitors/YamlAstVisitor.cjs +0 -164
- package/src/syntactic-analysis/indirect/visitors/YamlAstVisitor.mjs +0 -158
|
@@ -1,553 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
exports.__esModule = true;
|
|
5
|
-
exports.keyMap = exports.isNode = exports.default = void 0;
|
|
6
|
-
var _apidomAst = require("@speclynx/apidom-ast");
|
|
7
|
-
var _TreeCursorSyntaxNode = _interopRequireDefault(require("../../TreeCursorSyntaxNode.cjs"));
|
|
8
|
-
const keyMap = exports.keyMap = {
|
|
9
|
-
stream: ['children'],
|
|
10
|
-
document: ['children'],
|
|
11
|
-
mapping: ['children'],
|
|
12
|
-
keyValuePair: ['children'],
|
|
13
|
-
sequence: ['children'],
|
|
14
|
-
error: ['children']
|
|
15
|
-
};
|
|
16
|
-
const isNode = node => Array.isArray(node) || (0, _apidomAst.isNode)(node);
|
|
17
|
-
exports.isNode = isNode;
|
|
18
|
-
class CstVisitor {
|
|
19
|
-
static isScalar = this.isKind('scalar');
|
|
20
|
-
static isMapping = this.isKind('mapping');
|
|
21
|
-
static isSequence = this.isKind('sequence');
|
|
22
|
-
static isKind(ending) {
|
|
23
|
-
return node => node != null && typeof node === 'object' && 'type' in node && typeof node.type === 'string' && node.type.endsWith(ending);
|
|
24
|
-
}
|
|
25
|
-
static toPosition(node) {
|
|
26
|
-
const start = new _apidomAst.Point({
|
|
27
|
-
row: node.startPosition.row,
|
|
28
|
-
column: node.startPosition.column,
|
|
29
|
-
char: node.startIndex
|
|
30
|
-
});
|
|
31
|
-
const end = new _apidomAst.Point({
|
|
32
|
-
row: node.endPosition.row,
|
|
33
|
-
column: node.endPosition.column,
|
|
34
|
-
char: node.endIndex
|
|
35
|
-
});
|
|
36
|
-
return new _apidomAst.Position({
|
|
37
|
-
start,
|
|
38
|
-
end
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
static kindNodeToYamlAnchor(node) {
|
|
42
|
-
const {
|
|
43
|
-
anchor: anchorNode
|
|
44
|
-
} = node;
|
|
45
|
-
if (typeof anchorNode === 'undefined') return undefined;
|
|
46
|
-
return new _apidomAst.YamlAnchor({
|
|
47
|
-
name: anchorNode.text,
|
|
48
|
-
position: CstVisitor.toPosition(anchorNode)
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
static hasKeyValuePairEmptyKey(node) {
|
|
52
|
-
if (node.type !== 'block_mapping_pair' && node.type !== 'flow_pair') {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
// keyNode was not explicitly provided; tag and anchor are missing too
|
|
56
|
-
return typeof node.keyNode === 'undefined';
|
|
57
|
-
}
|
|
58
|
-
static hasKeyValuePairEmptyValue(node) {
|
|
59
|
-
if (node.type !== 'block_mapping_pair' && node.type !== 'flow_pair') {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
// valueNode was not explicitly provided; tag and anchor are missing too
|
|
63
|
-
return typeof node.valueNode === 'undefined';
|
|
64
|
-
}
|
|
65
|
-
static kindNodeToYamlTag(node) {
|
|
66
|
-
const {
|
|
67
|
-
tag: tagNode
|
|
68
|
-
} = node;
|
|
69
|
-
const explicitName = tagNode?.text || (node.type === 'plain_scalar' ? '?' : '!');
|
|
70
|
-
const kind = node.type.endsWith('mapping') ? _apidomAst.YamlNodeKind.Mapping : node.type.endsWith('sequence') ? _apidomAst.YamlNodeKind.Sequence : _apidomAst.YamlNodeKind.Scalar;
|
|
71
|
-
const position = tagNode ? CstVisitor.toPosition(tagNode) : undefined;
|
|
72
|
-
return new _apidomAst.YamlTag({
|
|
73
|
-
explicitName,
|
|
74
|
-
kind,
|
|
75
|
-
position
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
-
schema;
|
|
81
|
-
referenceManager;
|
|
82
|
-
stream = {
|
|
83
|
-
enter: node => {
|
|
84
|
-
const position = CstVisitor.toPosition(node);
|
|
85
|
-
return new _apidomAst.YamlStream({
|
|
86
|
-
children: node.children,
|
|
87
|
-
position,
|
|
88
|
-
isMissing: node.isMissing
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
leave: stream => {
|
|
92
|
-
return new _apidomAst.ParseResult({
|
|
93
|
-
children: [stream]
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
yaml_directive = {
|
|
98
|
-
enter: node => {
|
|
99
|
-
const position = CstVisitor.toPosition(node);
|
|
100
|
-
const version = node?.firstNamedChild?.text;
|
|
101
|
-
return new _apidomAst.YamlDirective({
|
|
102
|
-
position,
|
|
103
|
-
name: '%YAML',
|
|
104
|
-
parameters: {
|
|
105
|
-
version
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
tag_directive = {
|
|
111
|
-
enter: node => {
|
|
112
|
-
const position = CstVisitor.toPosition(node);
|
|
113
|
-
const tagHandleNode = node.children[0];
|
|
114
|
-
const tagPrefixNode = node.children[1];
|
|
115
|
-
const tagDirective = new _apidomAst.YamlDirective({
|
|
116
|
-
position,
|
|
117
|
-
name: '%TAG',
|
|
118
|
-
parameters: {
|
|
119
|
-
handle: tagHandleNode?.text,
|
|
120
|
-
prefix: tagPrefixNode?.text
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
this.schema.registerTagDirective(tagDirective);
|
|
124
|
-
return tagDirective;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
reserved_directive = {
|
|
128
|
-
enter: node => {
|
|
129
|
-
const position = CstVisitor.toPosition(node);
|
|
130
|
-
const directiveNameNode = node.children[0];
|
|
131
|
-
const directiveParameter1Node = node.children[1];
|
|
132
|
-
const directiveParameter2Node = node.children[2];
|
|
133
|
-
return new _apidomAst.YamlDirective({
|
|
134
|
-
position,
|
|
135
|
-
name: directiveNameNode?.text,
|
|
136
|
-
parameters: {
|
|
137
|
-
handle: directiveParameter1Node?.text,
|
|
138
|
-
prefix: directiveParameter2Node?.text
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
document = {
|
|
144
|
-
enter: node => {
|
|
145
|
-
const position = CstVisitor.toPosition(node);
|
|
146
|
-
return new _apidomAst.YamlDocument({
|
|
147
|
-
children: node.children,
|
|
148
|
-
position,
|
|
149
|
-
isMissing: node.isMissing
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
leave: node => {
|
|
153
|
-
node.children = node.children.flat();
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
block_node = {
|
|
157
|
-
enter: node => {
|
|
158
|
-
return node.children;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
flow_node = {
|
|
162
|
-
enter: node => {
|
|
163
|
-
const [kindCandidate] = node.children.slice(-1);
|
|
164
|
-
|
|
165
|
-
// kind node is present in flow node
|
|
166
|
-
if (CstVisitor.isScalar(kindCandidate) || CstVisitor.isMapping(kindCandidate) || CstVisitor.isSequence(kindCandidate)) {
|
|
167
|
-
return node.children;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// kind node not present in flow node, creating empty node
|
|
171
|
-
const emptyPoint = new _apidomAst.Point({
|
|
172
|
-
row: kindCandidate.endPosition.row,
|
|
173
|
-
column: kindCandidate.endPosition.column,
|
|
174
|
-
char: kindCandidate.endIndex
|
|
175
|
-
});
|
|
176
|
-
const emptyScalarNode = new _apidomAst.YamlScalar({
|
|
177
|
-
content: '',
|
|
178
|
-
anchor: CstVisitor.kindNodeToYamlAnchor(kindCandidate),
|
|
179
|
-
tag: CstVisitor.kindNodeToYamlTag(kindCandidate),
|
|
180
|
-
position: new _apidomAst.Position({
|
|
181
|
-
start: emptyPoint,
|
|
182
|
-
end: emptyPoint
|
|
183
|
-
}),
|
|
184
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
185
|
-
style: _apidomAst.YamlStyle.Plain
|
|
186
|
-
});
|
|
187
|
-
this.registerAnchor(emptyScalarNode);
|
|
188
|
-
return [...node.children, emptyScalarNode];
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
tag = {
|
|
192
|
-
enter: () => {
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
anchor = {
|
|
197
|
-
enter: () => {
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
block_mapping = {
|
|
202
|
-
enter: node => {
|
|
203
|
-
const position = CstVisitor.toPosition(node);
|
|
204
|
-
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
205
|
-
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
206
|
-
const mappingNode = new _apidomAst.YamlMapping({
|
|
207
|
-
children: node.children,
|
|
208
|
-
position,
|
|
209
|
-
anchor,
|
|
210
|
-
tag,
|
|
211
|
-
styleGroup: _apidomAst.YamlStyleGroup.Block,
|
|
212
|
-
style: _apidomAst.YamlStyle.NextLine,
|
|
213
|
-
isMissing: node.isMissing
|
|
214
|
-
});
|
|
215
|
-
this.registerAnchor(mappingNode);
|
|
216
|
-
return this.schema.resolve(mappingNode);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
block_mapping_pair = {
|
|
220
|
-
enter: node => {
|
|
221
|
-
const position = CstVisitor.toPosition(node);
|
|
222
|
-
const children = [...node.children];
|
|
223
|
-
if (CstVisitor.hasKeyValuePairEmptyKey(node)) {
|
|
224
|
-
const keyNode = this.createKeyValuePairEmptyKey(node);
|
|
225
|
-
children.unshift(keyNode);
|
|
226
|
-
}
|
|
227
|
-
if (CstVisitor.hasKeyValuePairEmptyValue(node)) {
|
|
228
|
-
const valueNode = this.createKeyValuePairEmptyValue(node);
|
|
229
|
-
children.push(valueNode);
|
|
230
|
-
}
|
|
231
|
-
return new _apidomAst.YamlKeyValuePair({
|
|
232
|
-
children,
|
|
233
|
-
position,
|
|
234
|
-
styleGroup: _apidomAst.YamlStyleGroup.Block,
|
|
235
|
-
isMissing: node.isMissing
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
flow_mapping = {
|
|
240
|
-
enter: node => {
|
|
241
|
-
const position = CstVisitor.toPosition(node);
|
|
242
|
-
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
243
|
-
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
244
|
-
const mappingNode = new _apidomAst.YamlMapping({
|
|
245
|
-
children: node.children,
|
|
246
|
-
position,
|
|
247
|
-
anchor,
|
|
248
|
-
tag,
|
|
249
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
250
|
-
style: _apidomAst.YamlStyle.Explicit,
|
|
251
|
-
isMissing: node.isMissing
|
|
252
|
-
});
|
|
253
|
-
this.registerAnchor(mappingNode);
|
|
254
|
-
return this.schema.resolve(mappingNode);
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
flow_pair = {
|
|
258
|
-
enter: node => {
|
|
259
|
-
const position = CstVisitor.toPosition(node);
|
|
260
|
-
const children = [...node.children];
|
|
261
|
-
if (CstVisitor.hasKeyValuePairEmptyKey(node)) {
|
|
262
|
-
const keyNode = this.createKeyValuePairEmptyKey(node);
|
|
263
|
-
children.unshift(keyNode);
|
|
264
|
-
}
|
|
265
|
-
if (CstVisitor.hasKeyValuePairEmptyValue(node)) {
|
|
266
|
-
const valueNode = this.createKeyValuePairEmptyValue(node);
|
|
267
|
-
children.push(valueNode);
|
|
268
|
-
}
|
|
269
|
-
return new _apidomAst.YamlKeyValuePair({
|
|
270
|
-
children,
|
|
271
|
-
position,
|
|
272
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
273
|
-
isMissing: node.isMissing
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
keyValuePair = {
|
|
278
|
-
leave: node => {
|
|
279
|
-
node.children = node.children.flat();
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
block_sequence = {
|
|
283
|
-
enter: node => {
|
|
284
|
-
const position = CstVisitor.toPosition(node);
|
|
285
|
-
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
286
|
-
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
287
|
-
const sequenceNode = new _apidomAst.YamlSequence({
|
|
288
|
-
children: node.children,
|
|
289
|
-
position,
|
|
290
|
-
anchor,
|
|
291
|
-
tag,
|
|
292
|
-
styleGroup: _apidomAst.YamlStyleGroup.Block,
|
|
293
|
-
style: _apidomAst.YamlStyle.NextLine
|
|
294
|
-
});
|
|
295
|
-
this.registerAnchor(sequenceNode);
|
|
296
|
-
return this.schema.resolve(sequenceNode);
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
block_sequence_item = {
|
|
300
|
-
enter: node => {
|
|
301
|
-
// flow or block node present; first node is always `-` literal
|
|
302
|
-
if (node.children.length > 1) {
|
|
303
|
-
return node.children;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// create empty node
|
|
307
|
-
const emptyPoint = new _apidomAst.Point({
|
|
308
|
-
row: node.endPosition.row,
|
|
309
|
-
column: node.endPosition.column,
|
|
310
|
-
char: node.endIndex
|
|
311
|
-
});
|
|
312
|
-
const emptyScalarNode = new _apidomAst.YamlScalar({
|
|
313
|
-
content: '',
|
|
314
|
-
tag: new _apidomAst.YamlTag({
|
|
315
|
-
explicitName: '?',
|
|
316
|
-
kind: _apidomAst.YamlNodeKind.Scalar
|
|
317
|
-
}),
|
|
318
|
-
position: new _apidomAst.Position({
|
|
319
|
-
start: emptyPoint,
|
|
320
|
-
end: emptyPoint
|
|
321
|
-
}),
|
|
322
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
323
|
-
style: _apidomAst.YamlStyle.Plain
|
|
324
|
-
});
|
|
325
|
-
return [emptyScalarNode];
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
flow_sequence = {
|
|
329
|
-
enter: node => {
|
|
330
|
-
const position = CstVisitor.toPosition(node);
|
|
331
|
-
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
332
|
-
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
333
|
-
const sequenceNode = new _apidomAst.YamlSequence({
|
|
334
|
-
children: node.children.flat(),
|
|
335
|
-
position,
|
|
336
|
-
anchor,
|
|
337
|
-
tag,
|
|
338
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
339
|
-
style: _apidomAst.YamlStyle.Explicit
|
|
340
|
-
});
|
|
341
|
-
this.registerAnchor(sequenceNode);
|
|
342
|
-
return this.schema.resolve(sequenceNode);
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
sequence = {
|
|
346
|
-
leave: node => {
|
|
347
|
-
node.children = node.children.flat(+Infinity);
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
plain_scalar = {
|
|
351
|
-
enter: node => {
|
|
352
|
-
const position = CstVisitor.toPosition(node);
|
|
353
|
-
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
354
|
-
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
355
|
-
const scalarNode = new _apidomAst.YamlScalar({
|
|
356
|
-
content: node.text,
|
|
357
|
-
anchor,
|
|
358
|
-
tag,
|
|
359
|
-
position,
|
|
360
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
361
|
-
style: _apidomAst.YamlStyle.Plain
|
|
362
|
-
});
|
|
363
|
-
this.registerAnchor(scalarNode);
|
|
364
|
-
return this.schema.resolve(scalarNode);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
single_quote_scalar = {
|
|
368
|
-
enter: node => {
|
|
369
|
-
const position = CstVisitor.toPosition(node);
|
|
370
|
-
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
371
|
-
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
372
|
-
const scalarNode = new _apidomAst.YamlScalar({
|
|
373
|
-
content: node.text,
|
|
374
|
-
anchor,
|
|
375
|
-
tag,
|
|
376
|
-
position,
|
|
377
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
378
|
-
style: _apidomAst.YamlStyle.SingleQuoted
|
|
379
|
-
});
|
|
380
|
-
this.registerAnchor(scalarNode);
|
|
381
|
-
return this.schema.resolve(scalarNode);
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
double_quote_scalar = {
|
|
385
|
-
enter: node => {
|
|
386
|
-
const position = CstVisitor.toPosition(node);
|
|
387
|
-
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
388
|
-
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
389
|
-
const scalarNode = new _apidomAst.YamlScalar({
|
|
390
|
-
content: node.text,
|
|
391
|
-
anchor,
|
|
392
|
-
tag,
|
|
393
|
-
position,
|
|
394
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
395
|
-
style: _apidomAst.YamlStyle.DoubleQuoted
|
|
396
|
-
});
|
|
397
|
-
this.registerAnchor(scalarNode);
|
|
398
|
-
return this.schema.resolve(scalarNode);
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
block_scalar = {
|
|
402
|
-
enter: node => {
|
|
403
|
-
const position = CstVisitor.toPosition(node);
|
|
404
|
-
const tag = CstVisitor.kindNodeToYamlTag(node);
|
|
405
|
-
const anchor = CstVisitor.kindNodeToYamlAnchor(node);
|
|
406
|
-
const style = node.text.startsWith('|') ? _apidomAst.YamlStyle.Literal : node.text.startsWith('>') ? _apidomAst.YamlStyle.Folded : _apidomAst.YamlStyle.Plain;
|
|
407
|
-
const scalarNode = new _apidomAst.YamlScalar({
|
|
408
|
-
content: node.text,
|
|
409
|
-
anchor,
|
|
410
|
-
tag,
|
|
411
|
-
position,
|
|
412
|
-
styleGroup: _apidomAst.YamlStyleGroup.Block,
|
|
413
|
-
style
|
|
414
|
-
});
|
|
415
|
-
this.registerAnchor(scalarNode);
|
|
416
|
-
return this.schema.resolve(scalarNode);
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
comment = {
|
|
420
|
-
enter: node => {
|
|
421
|
-
return new _apidomAst.YamlComment({
|
|
422
|
-
content: node.text
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
alias = {
|
|
427
|
-
enter: node => {
|
|
428
|
-
const alias = new _apidomAst.YamlAlias({
|
|
429
|
-
content: node.text
|
|
430
|
-
});
|
|
431
|
-
return this.referenceManager.resolveAlias(alias);
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
436
|
-
constructor(schema) {
|
|
437
|
-
this.schema = schema;
|
|
438
|
-
}
|
|
439
|
-
enter(node) {
|
|
440
|
-
// missing anonymous literals from CST transformed into AST literal nodes
|
|
441
|
-
if (node instanceof _TreeCursorSyntaxNode.default && !node.isNamed) {
|
|
442
|
-
const position = CstVisitor.toPosition(node);
|
|
443
|
-
const value = node.type || node.text;
|
|
444
|
-
const {
|
|
445
|
-
isMissing
|
|
446
|
-
} = node;
|
|
447
|
-
return new _apidomAst.Literal({
|
|
448
|
-
value,
|
|
449
|
-
position,
|
|
450
|
-
isMissing
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
return undefined;
|
|
454
|
-
}
|
|
455
|
-
ERROR(node, key, parent, path) {
|
|
456
|
-
const position = CstVisitor.toPosition(node);
|
|
457
|
-
const errorNode = new _apidomAst.Error({
|
|
458
|
-
children: node.children,
|
|
459
|
-
position,
|
|
460
|
-
isUnexpected: !node.hasError,
|
|
461
|
-
isMissing: node.isMissing,
|
|
462
|
-
value: node.text
|
|
463
|
-
});
|
|
464
|
-
if (path.length === 0) {
|
|
465
|
-
return new _apidomAst.ParseResult({
|
|
466
|
-
children: [errorNode]
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
return errorNode;
|
|
470
|
-
}
|
|
471
|
-
registerAnchor(node) {
|
|
472
|
-
if (node.anchor !== undefined) {
|
|
473
|
-
this.referenceManager.addAnchor(node);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
createKeyValuePairEmptyKey(node) {
|
|
477
|
-
const emptyPoint = new _apidomAst.Point({
|
|
478
|
-
row: node.startPosition.row,
|
|
479
|
-
column: node.startPosition.column,
|
|
480
|
-
char: node.startIndex
|
|
481
|
-
});
|
|
482
|
-
const {
|
|
483
|
-
keyNode
|
|
484
|
-
} = node;
|
|
485
|
-
const children = keyNode?.children || [];
|
|
486
|
-
const tagNode = children.find(CstVisitor.isKind('tag'));
|
|
487
|
-
const anchorNode = children.find(CstVisitor.isKind('anchor'));
|
|
488
|
-
const tag = typeof tagNode !== 'undefined' ? new _apidomAst.YamlTag({
|
|
489
|
-
explicitName: tagNode.text,
|
|
490
|
-
kind: _apidomAst.YamlNodeKind.Scalar,
|
|
491
|
-
position: CstVisitor.toPosition(tagNode)
|
|
492
|
-
}) : new _apidomAst.YamlTag({
|
|
493
|
-
explicitName: '?',
|
|
494
|
-
kind: _apidomAst.YamlNodeKind.Scalar
|
|
495
|
-
});
|
|
496
|
-
const anchor = typeof anchorNode !== 'undefined' ? new _apidomAst.YamlAnchor({
|
|
497
|
-
name: anchorNode.text,
|
|
498
|
-
position: CstVisitor.toPosition(anchorNode)
|
|
499
|
-
}) : undefined;
|
|
500
|
-
const scalarNode = new _apidomAst.YamlScalar({
|
|
501
|
-
content: '',
|
|
502
|
-
position: new _apidomAst.Position({
|
|
503
|
-
start: emptyPoint,
|
|
504
|
-
end: emptyPoint
|
|
505
|
-
}),
|
|
506
|
-
tag,
|
|
507
|
-
anchor,
|
|
508
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
509
|
-
style: _apidomAst.YamlStyle.Plain
|
|
510
|
-
});
|
|
511
|
-
this.registerAnchor(scalarNode);
|
|
512
|
-
return scalarNode;
|
|
513
|
-
}
|
|
514
|
-
createKeyValuePairEmptyValue(node) {
|
|
515
|
-
const emptyPoint = new _apidomAst.Point({
|
|
516
|
-
row: node.endPosition.row,
|
|
517
|
-
column: node.endPosition.column,
|
|
518
|
-
char: node.endIndex
|
|
519
|
-
});
|
|
520
|
-
const {
|
|
521
|
-
valueNode
|
|
522
|
-
} = node;
|
|
523
|
-
const children = valueNode?.children || [];
|
|
524
|
-
const tagNode = children.find(CstVisitor.isKind('tag'));
|
|
525
|
-
const anchorNode = children.find(CstVisitor.isKind('anchor'));
|
|
526
|
-
const tag = typeof tagNode !== 'undefined' ? new _apidomAst.YamlTag({
|
|
527
|
-
explicitName: tagNode.text,
|
|
528
|
-
kind: _apidomAst.YamlNodeKind.Scalar,
|
|
529
|
-
position: CstVisitor.toPosition(tagNode)
|
|
530
|
-
}) : new _apidomAst.YamlTag({
|
|
531
|
-
explicitName: '?',
|
|
532
|
-
kind: _apidomAst.YamlNodeKind.Scalar
|
|
533
|
-
});
|
|
534
|
-
const anchor = typeof anchorNode !== 'undefined' ? new _apidomAst.YamlAnchor({
|
|
535
|
-
name: anchorNode.text,
|
|
536
|
-
position: CstVisitor.toPosition(anchorNode)
|
|
537
|
-
}) : undefined;
|
|
538
|
-
const scalarNode = new _apidomAst.YamlScalar({
|
|
539
|
-
content: '',
|
|
540
|
-
position: new _apidomAst.Position({
|
|
541
|
-
start: emptyPoint,
|
|
542
|
-
end: emptyPoint
|
|
543
|
-
}),
|
|
544
|
-
tag,
|
|
545
|
-
anchor,
|
|
546
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
547
|
-
style: _apidomAst.YamlStyle.Plain
|
|
548
|
-
});
|
|
549
|
-
this.registerAnchor(scalarNode);
|
|
550
|
-
return scalarNode;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
var _default = exports.default = CstVisitor;
|