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