@swagger-api/apidom-parser-adapter-yaml-1-2 1.11.0 → 1.11.2
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/dist/apidom-parser-adapter-yaml-1-2.browser.js +14805 -19527
- package/dist/apidom-parser-adapter-yaml-1-2.browser.min.js +6365 -1
- package/package.json +5 -5
- package/src/adapter-browser.cjs +1 -1
- package/src/adapter-browser.mjs +1 -1
- package/src/adapter-node.cjs +1 -1
- package/src/adapter-node.mjs +1 -1
- package/src/syntactic-analysis/direct/index.cjs +389 -0
- package/src/syntactic-analysis/direct/index.mjs +385 -0
- package/src/syntactic-analysis/index.cjs +26 -0
- package/src/syntactic-analysis/index.mjs +20 -0
- package/types/apidom-parser-adapter-yaml-1-2.d.ts +7 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swagger-api/apidom-parser-adapter-yaml-1-2",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.2",
|
|
4
4
|
"description": "Parser adapter for parsing YAML documents into base namespace.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"license": "Apache-2.0",
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@babel/runtime-corejs3": "^7.26.10",
|
|
54
|
-
"@swagger-api/apidom-ast": "^1.11.
|
|
55
|
-
"@swagger-api/apidom-core": "^1.11.
|
|
56
|
-
"@swagger-api/apidom-error": "^1.11.
|
|
54
|
+
"@swagger-api/apidom-ast": "^1.11.2",
|
|
55
|
+
"@swagger-api/apidom-core": "^1.11.2",
|
|
56
|
+
"@swagger-api/apidom-error": "^1.11.2",
|
|
57
57
|
"@tree-sitter-grammars/tree-sitter-yaml": "=0.7.1",
|
|
58
58
|
"@types/ramda": "~0.30.0",
|
|
59
59
|
"ramda": "~0.30.0",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"README.md",
|
|
76
76
|
"CHANGELOG.md"
|
|
77
77
|
],
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "0ace20a29a3ed690af50b47734114fe06219dc20"
|
|
79
79
|
}
|
package/src/adapter-browser.cjs
CHANGED
|
@@ -5,7 +5,7 @@ exports.__esModule = true;
|
|
|
5
5
|
exports.parse = exports.namespace = exports.mediaTypes = exports.detect = void 0;
|
|
6
6
|
var _browser = _interopRequireDefault(require("./lexical-analysis/browser.cjs"));
|
|
7
7
|
exports.lexicalAnalysis = _browser.default;
|
|
8
|
-
var _index = _interopRequireDefault(require("./syntactic-analysis/
|
|
8
|
+
var _index = _interopRequireDefault(require("./syntactic-analysis/index.cjs"));
|
|
9
9
|
exports.syntacticAnalysis = _index.default;
|
|
10
10
|
var _adapter = require("./adapter.cjs");
|
|
11
11
|
exports.mediaTypes = _adapter.mediaTypes;
|
package/src/adapter-browser.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import lexicalAnalysis from "./lexical-analysis/browser.mjs";
|
|
2
|
-
import syntacticAnalysis from "./syntactic-analysis/
|
|
2
|
+
import syntacticAnalysis from "./syntactic-analysis/index.mjs";
|
|
3
3
|
export { mediaTypes, namespace } from "./adapter.mjs";
|
|
4
4
|
export { lexicalAnalysis, syntacticAnalysis };
|
|
5
5
|
|
package/src/adapter-node.cjs
CHANGED
|
@@ -5,7 +5,7 @@ exports.__esModule = true;
|
|
|
5
5
|
exports.parse = exports.namespace = exports.mediaTypes = exports.detect = void 0;
|
|
6
6
|
var _node = _interopRequireDefault(require("./lexical-analysis/node.cjs"));
|
|
7
7
|
exports.lexicalAnalysis = _node.default;
|
|
8
|
-
var _index = _interopRequireDefault(require("./syntactic-analysis/
|
|
8
|
+
var _index = _interopRequireDefault(require("./syntactic-analysis/index.cjs"));
|
|
9
9
|
exports.syntacticAnalysis = _index.default;
|
|
10
10
|
var _adapter = require("./adapter.cjs");
|
|
11
11
|
exports.mediaTypes = _adapter.mediaTypes;
|
package/src/adapter-node.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import lexicalAnalysis from "./lexical-analysis/node.mjs";
|
|
2
|
-
import syntacticAnalysis from "./syntactic-analysis/
|
|
2
|
+
import syntacticAnalysis from "./syntactic-analysis/index.mjs";
|
|
3
3
|
export { mediaTypes, namespace } from "./adapter.mjs";
|
|
4
4
|
export { lexicalAnalysis, syntacticAnalysis };
|
|
5
5
|
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = exports.FallbackNeeded = void 0;
|
|
5
|
+
var _apidomCore = require("@swagger-api/apidom-core");
|
|
6
|
+
var _apidomAst = require("@swagger-api/apidom-ast");
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Thrown when the direct analysis encounters a YAML feature (tag, anchor, alias)
|
|
13
|
+
* that requires the full indirect two-pass analysis.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
class FallbackNeeded extends Error {
|
|
17
|
+
name = 'FallbackNeeded';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// YAML 1.2 Core Schema type detection — matches apidom-ast/yaml/schemas/json/* order:
|
|
21
|
+
// Null → Integer → FloatingPoint → Boolean
|
|
22
|
+
exports.FallbackNeeded = FallbackNeeded;
|
|
23
|
+
const NULL_RE = /^null$/;
|
|
24
|
+
const INT_RE = /^-?(0|[1-9][0-9]*)$/;
|
|
25
|
+
const FLOAT_RE = /^-?(0|[1-9][0-9]*)(\.[0-9]*)?([eE][-+]?[0-9]+)?$/;
|
|
26
|
+
const BOOL_RE = /^(true|false)$/;
|
|
27
|
+
function resolveScalarContent(s) {
|
|
28
|
+
if (NULL_RE.test(s)) return null;
|
|
29
|
+
if (INT_RE.test(s)) return parseInt(s, 10);
|
|
30
|
+
if (FLOAT_RE.test(s)) return parseFloat(s);
|
|
31
|
+
if (BOOL_RE.test(s)) return s === 'true';
|
|
32
|
+
return s;
|
|
33
|
+
}
|
|
34
|
+
function setSourceMap(element, cursor) {
|
|
35
|
+
// eslint-disable-next-line no-param-reassign
|
|
36
|
+
element.startPositionRow = cursor.startPosition.row;
|
|
37
|
+
// eslint-disable-next-line no-param-reassign
|
|
38
|
+
element.startPositionColumn = cursor.startPosition.column;
|
|
39
|
+
// eslint-disable-next-line no-param-reassign
|
|
40
|
+
element.startIndex = cursor.startIndex;
|
|
41
|
+
// eslint-disable-next-line no-param-reassign
|
|
42
|
+
element.endPositionRow = cursor.endPosition.row;
|
|
43
|
+
// eslint-disable-next-line no-param-reassign
|
|
44
|
+
element.endPositionColumn = cursor.endPosition.column;
|
|
45
|
+
// eslint-disable-next-line no-param-reassign
|
|
46
|
+
element.endIndex = cursor.endIndex;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Iterates named children of the current cursor node.
|
|
51
|
+
* Adds warning annotations for missing unnamed (structural) nodes.
|
|
52
|
+
* Restores cursor to parent when done.
|
|
53
|
+
*/
|
|
54
|
+
const forEachNamedChild = (cursor, ctx, fn) => {
|
|
55
|
+
if (!cursor.gotoFirstChild()) return;
|
|
56
|
+
do {
|
|
57
|
+
if (!cursor.nodeIsNamed) {
|
|
58
|
+
if (cursor.nodeIsMissing) {
|
|
59
|
+
const ann = new _apidomCore.AnnotationElement(`(Missing ${cursor.nodeType})`);
|
|
60
|
+
ann.classes.push('warning');
|
|
61
|
+
if (ctx.sourceMap) setSourceMap(ann, cursor);
|
|
62
|
+
ctx.annotations.push(ann);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
var _cursor$currentFieldN;
|
|
66
|
+
fn(cursor, (_cursor$currentFieldN = cursor.currentFieldName) != null ? _cursor$currentFieldN : null);
|
|
67
|
+
}
|
|
68
|
+
} while (cursor.gotoNextSibling());
|
|
69
|
+
cursor.gotoParent();
|
|
70
|
+
};
|
|
71
|
+
const walkFunctions = {
|
|
72
|
+
walkStream: (cursor, ctx) => {
|
|
73
|
+
const parseResult = new _apidomCore.ParseResultElement();
|
|
74
|
+
if (ctx.sourceMap) setSourceMap(parseResult, cursor);
|
|
75
|
+
forEachNamedChild(cursor, ctx, child => {
|
|
76
|
+
const {
|
|
77
|
+
nodeType
|
|
78
|
+
} = child;
|
|
79
|
+
if (nodeType === 'document') {
|
|
80
|
+
const docContent = walkFunctions.walkDocument(child, ctx);
|
|
81
|
+
if (docContent !== null) parseResult.push(docContent);
|
|
82
|
+
} else if (nodeType === 'comment' && ctx.documentCount === 0) {
|
|
83
|
+
const comment = new _apidomCore.CommentElement(child.nodeText);
|
|
84
|
+
if (ctx.sourceMap) setSourceMap(comment, child);
|
|
85
|
+
parseResult.push(comment);
|
|
86
|
+
} else if (nodeType === 'ERROR') {
|
|
87
|
+
walkFunctions.walkError(child, ctx);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Mark the first content element as 'result' (matches YamlAstVisitor.stream.leave behaviour)
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
const resultCandidates = parseResult.findElements(_apidomCore.isPrimitiveElement);
|
|
94
|
+
if (resultCandidates.length > 0) {
|
|
95
|
+
resultCandidates[0].classes.push('result');
|
|
96
|
+
}
|
|
97
|
+
ctx.annotations.forEach(ann => parseResult.push(ann));
|
|
98
|
+
ctx.annotations = [];
|
|
99
|
+
return parseResult;
|
|
100
|
+
},
|
|
101
|
+
walkDocument: (cursor, ctx) => {
|
|
102
|
+
if (ctx.documentCount >= 1) {
|
|
103
|
+
if (ctx.documentCount === 1) {
|
|
104
|
+
const ann = new _apidomCore.AnnotationElement('Only first document within YAML stream will be used. Rest will be discarded.');
|
|
105
|
+
ann.classes.push('warning');
|
|
106
|
+
if (ctx.sourceMap) setSourceMap(ann, cursor);
|
|
107
|
+
ctx.annotations.push(ann);
|
|
108
|
+
}
|
|
109
|
+
ctx.documentCount += 1;
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
ctx.documentCount += 1;
|
|
113
|
+
let content = null;
|
|
114
|
+
forEachNamedChild(cursor, ctx, child => {
|
|
115
|
+
const {
|
|
116
|
+
nodeType
|
|
117
|
+
} = child;
|
|
118
|
+
if (nodeType === 'tag' || nodeType === 'anchor' || nodeType === 'alias') {
|
|
119
|
+
throw new FallbackNeeded();
|
|
120
|
+
}
|
|
121
|
+
if (nodeType.endsWith('_directive') || nodeType === 'comment') return;
|
|
122
|
+
if (nodeType === 'ERROR') {
|
|
123
|
+
walkFunctions.walkError(child, ctx);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const result = walkFunctions.walkNode(child, ctx);
|
|
127
|
+
if (result !== null) content = result;
|
|
128
|
+
});
|
|
129
|
+
return content;
|
|
130
|
+
},
|
|
131
|
+
walkMapping: (cursor, ctx) => {
|
|
132
|
+
const element = new _apidomCore.ObjectElement();
|
|
133
|
+
if (ctx.sourceMap) setSourceMap(element, cursor);
|
|
134
|
+
forEachNamedChild(cursor, ctx, child => {
|
|
135
|
+
const {
|
|
136
|
+
nodeType
|
|
137
|
+
} = child;
|
|
138
|
+
if (nodeType === 'tag' || nodeType === 'anchor' || nodeType === 'alias') {
|
|
139
|
+
throw new FallbackNeeded();
|
|
140
|
+
}
|
|
141
|
+
if (nodeType === 'block_mapping_pair' || nodeType === 'flow_pair') {
|
|
142
|
+
element.push(walkFunctions.walkPair(child, ctx));
|
|
143
|
+
} else if (nodeType === 'ERROR') {
|
|
144
|
+
walkFunctions.walkError(child, ctx);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return element;
|
|
148
|
+
},
|
|
149
|
+
walkSequence: (cursor, ctx) => {
|
|
150
|
+
const element = new _apidomCore.ArrayElement();
|
|
151
|
+
if (ctx.sourceMap) setSourceMap(element, cursor);
|
|
152
|
+
forEachNamedChild(cursor, ctx, child => {
|
|
153
|
+
const {
|
|
154
|
+
nodeType
|
|
155
|
+
} = child;
|
|
156
|
+
if (nodeType === 'tag' || nodeType === 'anchor' || nodeType === 'alias') {
|
|
157
|
+
throw new FallbackNeeded();
|
|
158
|
+
}
|
|
159
|
+
if (nodeType === 'ERROR') {
|
|
160
|
+
walkFunctions.walkError(child, ctx);
|
|
161
|
+
} else if (nodeType === 'block_sequence_item') {
|
|
162
|
+
const item = walkFunctions.walkSequenceItem(child, ctx);
|
|
163
|
+
if (item !== null) element.push(item);
|
|
164
|
+
} else {
|
|
165
|
+
// flow_sequence items (flow_node, flow_pair, scalars) appear directly
|
|
166
|
+
const item = walkFunctions.walkNode(child, ctx);
|
|
167
|
+
if (item !== null) element.push(item);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
return element;
|
|
171
|
+
},
|
|
172
|
+
walkPair: (cursor, ctx) => {
|
|
173
|
+
const pairStartRow = cursor.startPosition.row;
|
|
174
|
+
const pairStartCol = cursor.startPosition.column;
|
|
175
|
+
const pairStartIdx = cursor.startIndex;
|
|
176
|
+
const pairEndRow = cursor.endPosition.row;
|
|
177
|
+
const pairEndCol = cursor.endPosition.column;
|
|
178
|
+
const pairEndIdx = cursor.endIndex;
|
|
179
|
+
let keyElement = null;
|
|
180
|
+
let valueElement = null;
|
|
181
|
+
forEachNamedChild(cursor, ctx, (child, fieldName) => {
|
|
182
|
+
const {
|
|
183
|
+
nodeType
|
|
184
|
+
} = child;
|
|
185
|
+
if (nodeType === 'tag' || nodeType === 'anchor' || nodeType === 'alias') {
|
|
186
|
+
throw new FallbackNeeded();
|
|
187
|
+
}
|
|
188
|
+
if (nodeType === 'ERROR') {
|
|
189
|
+
walkFunctions.walkError(child, ctx);
|
|
190
|
+
} else if (fieldName === 'key') {
|
|
191
|
+
keyElement = walkFunctions.walkNode(child, ctx);
|
|
192
|
+
} else if (fieldName === 'value') {
|
|
193
|
+
valueElement = walkFunctions.walkNode(child, ctx);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
if (keyElement === null) {
|
|
197
|
+
keyElement = ctx.namespace.toElement('');
|
|
198
|
+
keyElement.classes.push('yaml-e-node');
|
|
199
|
+
keyElement.classes.push('yaml-e-scalar');
|
|
200
|
+
if (ctx.sourceMap) {
|
|
201
|
+
keyElement.startPositionRow = pairStartRow;
|
|
202
|
+
keyElement.startPositionColumn = pairStartCol;
|
|
203
|
+
keyElement.startIndex = pairStartIdx;
|
|
204
|
+
keyElement.endPositionRow = pairStartRow;
|
|
205
|
+
keyElement.endPositionColumn = pairStartCol;
|
|
206
|
+
keyElement.endIndex = pairStartIdx;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (valueElement === null) {
|
|
210
|
+
valueElement = ctx.namespace.toElement('');
|
|
211
|
+
valueElement.classes.push('yaml-e-node');
|
|
212
|
+
valueElement.classes.push('yaml-e-scalar');
|
|
213
|
+
if (ctx.sourceMap) {
|
|
214
|
+
valueElement.startPositionRow = pairEndRow;
|
|
215
|
+
valueElement.startPositionColumn = pairEndCol;
|
|
216
|
+
valueElement.startIndex = pairEndIdx;
|
|
217
|
+
valueElement.endPositionRow = pairEndRow;
|
|
218
|
+
valueElement.endPositionColumn = pairEndCol;
|
|
219
|
+
valueElement.endIndex = pairEndIdx;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const member = new _apidomCore.MemberElement();
|
|
223
|
+
if (ctx.sourceMap) {
|
|
224
|
+
member.startPositionRow = pairStartRow;
|
|
225
|
+
member.startPositionColumn = pairStartCol;
|
|
226
|
+
member.startIndex = pairStartIdx;
|
|
227
|
+
member.endPositionRow = pairEndRow;
|
|
228
|
+
member.endPositionColumn = pairEndCol;
|
|
229
|
+
member.endIndex = pairEndIdx;
|
|
230
|
+
}
|
|
231
|
+
member.key = keyElement;
|
|
232
|
+
member.value = valueElement;
|
|
233
|
+
return member;
|
|
234
|
+
},
|
|
235
|
+
walkSequenceItem: (cursor, ctx) => {
|
|
236
|
+
const endRow = cursor.endPosition.row;
|
|
237
|
+
const endCol = cursor.endPosition.column;
|
|
238
|
+
const endIdx = cursor.endIndex;
|
|
239
|
+
let content = null;
|
|
240
|
+
forEachNamedChild(cursor, ctx, child => {
|
|
241
|
+
const {
|
|
242
|
+
nodeType
|
|
243
|
+
} = child;
|
|
244
|
+
if (nodeType === 'tag' || nodeType === 'anchor' || nodeType === 'alias') {
|
|
245
|
+
throw new FallbackNeeded();
|
|
246
|
+
}
|
|
247
|
+
const result = walkFunctions.walkNode(child, ctx);
|
|
248
|
+
if (result !== null) content = result;
|
|
249
|
+
});
|
|
250
|
+
if (content === null) {
|
|
251
|
+
// empty sequence item (just '-' with no value)
|
|
252
|
+
content = ctx.namespace.toElement('');
|
|
253
|
+
content.classes.push('yaml-e-node');
|
|
254
|
+
content.classes.push('yaml-e-scalar');
|
|
255
|
+
if (ctx.sourceMap) {
|
|
256
|
+
content.startPositionRow = endRow;
|
|
257
|
+
content.startPositionColumn = endCol;
|
|
258
|
+
content.startIndex = endIdx;
|
|
259
|
+
content.endPositionRow = endRow;
|
|
260
|
+
content.endPositionColumn = endCol;
|
|
261
|
+
content.endIndex = endIdx;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return content;
|
|
265
|
+
},
|
|
266
|
+
walkBlockFlowNode: (cursor, ctx) => {
|
|
267
|
+
let content = null;
|
|
268
|
+
forEachNamedChild(cursor, ctx, child => {
|
|
269
|
+
const {
|
|
270
|
+
nodeType
|
|
271
|
+
} = child;
|
|
272
|
+
if (nodeType === 'tag' || nodeType === 'anchor' || nodeType === 'alias') {
|
|
273
|
+
throw new FallbackNeeded();
|
|
274
|
+
}
|
|
275
|
+
if (nodeType === 'comment') return;
|
|
276
|
+
const result = walkFunctions.walkNode(child, ctx);
|
|
277
|
+
if (result !== null && content === null) {
|
|
278
|
+
content = result;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
return content;
|
|
282
|
+
},
|
|
283
|
+
walkPlainScalar: (cursor, ctx) => {
|
|
284
|
+
const formatted = (0, _apidomAst.formatFlowPlain)(cursor.nodeText);
|
|
285
|
+
const element = ctx.namespace.toElement(resolveScalarContent(formatted));
|
|
286
|
+
if (ctx.sourceMap) setSourceMap(element, cursor);
|
|
287
|
+
if (formatted === '') {
|
|
288
|
+
element.classes.push('yaml-e-node');
|
|
289
|
+
element.classes.push('yaml-e-scalar');
|
|
290
|
+
}
|
|
291
|
+
return element;
|
|
292
|
+
},
|
|
293
|
+
walkSingleQuoteScalar: (cursor, ctx) => {
|
|
294
|
+
const formatted = (0, _apidomAst.formatFlowSingleQuoted)(cursor.nodeText);
|
|
295
|
+
const element = ctx.namespace.toElement(formatted);
|
|
296
|
+
if (ctx.sourceMap) setSourceMap(element, cursor);
|
|
297
|
+
return element;
|
|
298
|
+
},
|
|
299
|
+
walkDoubleQuoteScalar: (cursor, ctx) => {
|
|
300
|
+
const formatted = (0, _apidomAst.formatFlowDoubleQuoted)(cursor.nodeText);
|
|
301
|
+
const element = ctx.namespace.toElement(formatted);
|
|
302
|
+
if (ctx.sourceMap) setSourceMap(element, cursor);
|
|
303
|
+
return element;
|
|
304
|
+
},
|
|
305
|
+
walkBlockScalar: (cursor, ctx) => {
|
|
306
|
+
const raw = cursor.nodeText;
|
|
307
|
+
const formatted = raw.trimStart().startsWith('>') ? (0, _apidomAst.formatBlockFolded)(raw) : (0, _apidomAst.formatBlockLiteral)(raw);
|
|
308
|
+
const element = ctx.namespace.toElement(formatted);
|
|
309
|
+
if (ctx.sourceMap) setSourceMap(element, cursor);
|
|
310
|
+
return element;
|
|
311
|
+
},
|
|
312
|
+
walkError: (cursor, ctx) => {
|
|
313
|
+
const isUnexpected = !cursor.currentNode.hasError;
|
|
314
|
+
const message = isUnexpected ? '(Unexpected YAML syntax error)' : '(Error YAML syntax error)';
|
|
315
|
+
const ann = new _apidomCore.AnnotationElement(message);
|
|
316
|
+
ann.classes.push('error');
|
|
317
|
+
if (ctx.sourceMap) setSourceMap(ann, cursor);
|
|
318
|
+
ctx.annotations.push(ann);
|
|
319
|
+
return null;
|
|
320
|
+
},
|
|
321
|
+
walkNode: (cursor, ctx) => {
|
|
322
|
+
switch (cursor.nodeType) {
|
|
323
|
+
case 'block_mapping':
|
|
324
|
+
case 'flow_mapping':
|
|
325
|
+
return walkFunctions.walkMapping(cursor, ctx);
|
|
326
|
+
case 'block_sequence':
|
|
327
|
+
case 'flow_sequence':
|
|
328
|
+
return walkFunctions.walkSequence(cursor, ctx);
|
|
329
|
+
case 'block_mapping_pair':
|
|
330
|
+
case 'flow_pair':
|
|
331
|
+
return walkFunctions.walkPair(cursor, ctx);
|
|
332
|
+
case 'block_sequence_item':
|
|
333
|
+
return walkFunctions.walkSequenceItem(cursor, ctx);
|
|
334
|
+
case 'block_node':
|
|
335
|
+
case 'flow_node':
|
|
336
|
+
return walkFunctions.walkBlockFlowNode(cursor, ctx);
|
|
337
|
+
case 'plain_scalar':
|
|
338
|
+
return walkFunctions.walkPlainScalar(cursor, ctx);
|
|
339
|
+
case 'single_quote_scalar':
|
|
340
|
+
return walkFunctions.walkSingleQuoteScalar(cursor, ctx);
|
|
341
|
+
case 'double_quote_scalar':
|
|
342
|
+
return walkFunctions.walkDoubleQuoteScalar(cursor, ctx);
|
|
343
|
+
case 'block_scalar':
|
|
344
|
+
return walkFunctions.walkBlockScalar(cursor, ctx);
|
|
345
|
+
case 'tag':
|
|
346
|
+
case 'anchor':
|
|
347
|
+
case 'alias':
|
|
348
|
+
throw new FallbackNeeded();
|
|
349
|
+
case 'ERROR':
|
|
350
|
+
return walkFunctions.walkError(cursor, ctx);
|
|
351
|
+
default:
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Direct cursor-based syntactic analysis.
|
|
359
|
+
* Walks the tree-sitter CST once and builds ApiDOM elements directly,
|
|
360
|
+
* eliminating both the TreeCursorSyntaxNode pre-materialization and the
|
|
361
|
+
* intermediate YAML AST passes used by the indirect analysis.
|
|
362
|
+
*
|
|
363
|
+
* Throws FallbackNeeded when the document uses YAML tags, anchors, or aliases,
|
|
364
|
+
* which require the full two-pass indirect analysis to resolve correctly.
|
|
365
|
+
* @public
|
|
366
|
+
*/
|
|
367
|
+
const analyze = (cst, {
|
|
368
|
+
sourceMap = false
|
|
369
|
+
} = {}) => {
|
|
370
|
+
const cursor = cst.walk();
|
|
371
|
+
const ctx = {
|
|
372
|
+
sourceMap,
|
|
373
|
+
namespace: (0, _apidomCore.createNamespace)(),
|
|
374
|
+
annotations: [],
|
|
375
|
+
documentCount: 0
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// When tree-sitter can't parse the input at all, the root node is ERROR rather than stream.
|
|
379
|
+
// In that case return an empty ParseResultElement containing only the error annotation.
|
|
380
|
+
if (cursor.nodeType !== 'stream') {
|
|
381
|
+
const parseResult = new _apidomCore.ParseResultElement();
|
|
382
|
+
if (ctx.sourceMap) setSourceMap(parseResult, cursor);
|
|
383
|
+
walkFunctions.walkError(cursor, ctx);
|
|
384
|
+
ctx.annotations.forEach(ann => parseResult.push(ann));
|
|
385
|
+
return parseResult;
|
|
386
|
+
}
|
|
387
|
+
return walkFunctions.walkStream(cursor, ctx);
|
|
388
|
+
};
|
|
389
|
+
var _default = exports.default = analyze;
|