cdk8s-operator 0.1.407 → 0.1.408
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/.jsii +3 -3
- package/lib/operator.js +1 -1
- package/lib/server.js +1 -1
- package/node_modules/yaml/browser/dist/PlainValue-183afbad.js +751 -0
- package/node_modules/yaml/browser/dist/Schema-9530c078.js +467 -0
- package/node_modules/yaml/browser/dist/index.js +436 -746
- package/node_modules/yaml/browser/dist/legacy-exports.js +3 -3
- package/node_modules/yaml/browser/dist/parse-cst.js +1290 -1689
- package/node_modules/yaml/browser/dist/resolveSeq-67caf78a.js +1835 -0
- package/node_modules/yaml/browser/dist/types.js +4 -4
- package/node_modules/yaml/browser/dist/util.js +2 -2
- package/node_modules/yaml/browser/dist/warnings-5e4358fe.js +348 -0
- package/node_modules/yaml/dist/{Document-9b4560a1.js → Document-a8d0fbf9.js} +11 -131
- package/node_modules/yaml/dist/{PlainValue-ec8e588e.js → PlainValue-516d5bc2.js} +35 -146
- package/node_modules/yaml/dist/{Schema-88e323a7.js → Schema-bcc6c2d7.js} +10 -66
- package/node_modules/yaml/dist/index.js +5 -17
- package/node_modules/yaml/dist/legacy-exports.js +3 -3
- package/node_modules/yaml/dist/parse-cst.js +45 -291
- package/node_modules/yaml/dist/{resolveSeq-d03cb037.js → resolveSeq-95613e94.js} +44 -346
- package/node_modules/yaml/dist/test-events.js +28 -44
- package/node_modules/yaml/dist/types.js +4 -4
- package/node_modules/yaml/dist/util.js +2 -2
- package/node_modules/yaml/dist/{warnings-1000a372.js → warnings-793925ce.js} +16 -73
- package/node_modules/yaml/package.json +2 -3
- package/package.json +2 -2
- package/node_modules/yaml/browser/dist/PlainValue-b8036b75.js +0 -1275
- package/node_modules/yaml/browser/dist/Schema-e94716c8.js +0 -682
- package/node_modules/yaml/browser/dist/resolveSeq-492ab440.js +0 -2419
- package/node_modules/yaml/browser/dist/warnings-df54cb69.js +0 -499
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var PlainValue = require('./PlainValue-
|
|
3
|
+
var PlainValue = require('./PlainValue-516d5bc2.js');
|
|
4
4
|
|
|
5
5
|
class BlankLine extends PlainValue.Node {
|
|
6
6
|
constructor() {
|
|
7
7
|
super(PlainValue.Type.BLANK_LINE);
|
|
8
8
|
}
|
|
9
|
-
/* istanbul ignore next */
|
|
10
|
-
|
|
11
9
|
|
|
10
|
+
/* istanbul ignore next */
|
|
12
11
|
get includesTrailingLines() {
|
|
13
12
|
// This is never called from anywhere, but if it were,
|
|
14
13
|
// this is the value it should return.
|
|
15
14
|
return true;
|
|
16
15
|
}
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Parses a blank line from the source
|
|
19
19
|
*
|
|
@@ -21,14 +21,11 @@ class BlankLine extends PlainValue.Node {
|
|
|
21
21
|
* @param {number} start - Index of first \n character
|
|
22
22
|
* @returns {number} - Index of the character after this
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
24
|
parse(context, start) {
|
|
27
25
|
this.context = context;
|
|
28
26
|
this.range = new PlainValue.Range(start, start + 1);
|
|
29
27
|
return start + 1;
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
class CollectionItem extends PlainValue.Node {
|
|
@@ -36,17 +33,15 @@ class CollectionItem extends PlainValue.Node {
|
|
|
36
33
|
super(type, props);
|
|
37
34
|
this.node = null;
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
get includesTrailingLines() {
|
|
41
37
|
return !!this.node && this.node.includesTrailingLines;
|
|
42
38
|
}
|
|
39
|
+
|
|
43
40
|
/**
|
|
44
41
|
* @param {ParseContext} context
|
|
45
42
|
* @param {number} start - Index of first character
|
|
46
43
|
* @returns {number} - Index of the character after this
|
|
47
44
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
45
|
parse(context, start) {
|
|
51
46
|
this.context = context;
|
|
52
47
|
const {
|
|
@@ -64,7 +59,6 @@ class CollectionItem extends PlainValue.Node {
|
|
|
64
59
|
const inlineComment = ch === '#';
|
|
65
60
|
const comments = [];
|
|
66
61
|
let blankLine = null;
|
|
67
|
-
|
|
68
62
|
while (ch === '\n' || ch === '#') {
|
|
69
63
|
if (ch === '#') {
|
|
70
64
|
const end = PlainValue.Node.endOfLine(src, offset + 1);
|
|
@@ -74,20 +68,16 @@ class CollectionItem extends PlainValue.Node {
|
|
|
74
68
|
atLineStart = true;
|
|
75
69
|
lineStart = offset + 1;
|
|
76
70
|
const wsEnd = PlainValue.Node.endOfWhiteSpace(src, lineStart);
|
|
77
|
-
|
|
78
71
|
if (src[wsEnd] === '\n' && comments.length === 0) {
|
|
79
72
|
blankLine = new BlankLine();
|
|
80
73
|
lineStart = blankLine.parse({
|
|
81
74
|
src
|
|
82
75
|
}, lineStart);
|
|
83
76
|
}
|
|
84
|
-
|
|
85
77
|
offset = PlainValue.Node.endOfIndent(src, lineStart);
|
|
86
78
|
}
|
|
87
|
-
|
|
88
79
|
ch = src[offset];
|
|
89
80
|
}
|
|
90
|
-
|
|
91
81
|
if (PlainValue.Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== PlainValue.Type.SEQ_ITEM)) {
|
|
92
82
|
this.node = parseNode({
|
|
93
83
|
atLineStart,
|
|
@@ -99,7 +89,6 @@ class CollectionItem extends PlainValue.Node {
|
|
|
99
89
|
} else if (ch && lineStart > start + 1) {
|
|
100
90
|
offset = lineStart - 1;
|
|
101
91
|
}
|
|
102
|
-
|
|
103
92
|
if (this.node) {
|
|
104
93
|
if (blankLine) {
|
|
105
94
|
// Only blank lines preceding non-empty nodes are captured. Note that
|
|
@@ -108,7 +97,6 @@ class CollectionItem extends PlainValue.Node {
|
|
|
108
97
|
const items = context.parent.items || context.parent.contents;
|
|
109
98
|
if (items) items.push(blankLine);
|
|
110
99
|
}
|
|
111
|
-
|
|
112
100
|
if (comments.length) Array.prototype.push.apply(this.props, comments);
|
|
113
101
|
offset = this.node.range.end;
|
|
114
102
|
} else {
|
|
@@ -120,17 +108,14 @@ class CollectionItem extends PlainValue.Node {
|
|
|
120
108
|
offset = PlainValue.Node.endOfLine(src, start + 1);
|
|
121
109
|
}
|
|
122
110
|
}
|
|
123
|
-
|
|
124
111
|
const end = this.node ? this.node.valueRange.end : offset;
|
|
125
112
|
this.valueRange = new PlainValue.Range(start, end);
|
|
126
113
|
return offset;
|
|
127
114
|
}
|
|
128
|
-
|
|
129
115
|
setOrigRanges(cr, offset) {
|
|
130
116
|
offset = super.setOrigRanges(cr, offset);
|
|
131
117
|
return this.node ? this.node.setOrigRanges(cr, offset) : offset;
|
|
132
118
|
}
|
|
133
|
-
|
|
134
119
|
toString() {
|
|
135
120
|
const {
|
|
136
121
|
context: {
|
|
@@ -144,13 +129,13 @@ class CollectionItem extends PlainValue.Node {
|
|
|
144
129
|
const str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end);
|
|
145
130
|
return PlainValue.Node.addStringTerminator(src, range.end, str);
|
|
146
131
|
}
|
|
147
|
-
|
|
148
132
|
}
|
|
149
133
|
|
|
150
134
|
class Comment extends PlainValue.Node {
|
|
151
135
|
constructor() {
|
|
152
136
|
super(PlainValue.Type.COMMENT);
|
|
153
137
|
}
|
|
138
|
+
|
|
154
139
|
/**
|
|
155
140
|
* Parses a comment line from the source
|
|
156
141
|
*
|
|
@@ -158,29 +143,22 @@ class Comment extends PlainValue.Node {
|
|
|
158
143
|
* @param {number} start - Index of first character
|
|
159
144
|
* @returns {number} - Index of the character after this scalar
|
|
160
145
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
146
|
parse(context, start) {
|
|
164
147
|
this.context = context;
|
|
165
148
|
const offset = this.parseComment(start);
|
|
166
149
|
this.range = new PlainValue.Range(start, offset);
|
|
167
150
|
return offset;
|
|
168
151
|
}
|
|
169
|
-
|
|
170
152
|
}
|
|
171
153
|
|
|
172
154
|
function grabCollectionEndComments(node) {
|
|
173
155
|
let cnode = node;
|
|
174
|
-
|
|
175
156
|
while (cnode instanceof CollectionItem) cnode = cnode.node;
|
|
176
|
-
|
|
177
157
|
if (!(cnode instanceof Collection)) return null;
|
|
178
158
|
const len = cnode.items.length;
|
|
179
159
|
let ci = -1;
|
|
180
|
-
|
|
181
160
|
for (let i = len - 1; i >= 0; --i) {
|
|
182
161
|
const n = cnode.items[i];
|
|
183
|
-
|
|
184
162
|
if (n.type === PlainValue.Type.COMMENT) {
|
|
185
163
|
// Keep sufficiently indented comments with preceding node
|
|
186
164
|
const {
|
|
@@ -191,18 +169,15 @@ function grabCollectionEndComments(node) {
|
|
|
191
169
|
ci = i;
|
|
192
170
|
} else if (n.type === PlainValue.Type.BLANK_LINE) ci = i;else break;
|
|
193
171
|
}
|
|
194
|
-
|
|
195
172
|
if (ci === -1) return null;
|
|
196
173
|
const ca = cnode.items.splice(ci, len - ci);
|
|
197
174
|
const prevEnd = ca[0].range.start;
|
|
198
|
-
|
|
199
175
|
while (true) {
|
|
200
176
|
cnode.range.end = prevEnd;
|
|
201
177
|
if (cnode.valueRange && cnode.valueRange.end > prevEnd) cnode.valueRange.end = prevEnd;
|
|
202
178
|
if (cnode === node) break;
|
|
203
179
|
cnode = cnode.context.parent;
|
|
204
180
|
}
|
|
205
|
-
|
|
206
181
|
return ca;
|
|
207
182
|
}
|
|
208
183
|
class Collection extends PlainValue.Node {
|
|
@@ -215,10 +190,8 @@ class Collection extends PlainValue.Node {
|
|
|
215
190
|
if (ch !== '#' && ch !== '\n') return false;
|
|
216
191
|
return Collection.nextContentHasIndent(src, offset, indent);
|
|
217
192
|
}
|
|
218
|
-
|
|
219
193
|
constructor(firstItem) {
|
|
220
194
|
super(firstItem.type === PlainValue.Type.SEQ_ITEM ? PlainValue.Type.SEQ : PlainValue.Type.MAP);
|
|
221
|
-
|
|
222
195
|
for (let i = firstItem.props.length - 1; i >= 0; --i) {
|
|
223
196
|
if (firstItem.props[i].start < firstItem.context.lineStart) {
|
|
224
197
|
// props on previous line are assumed by the collection
|
|
@@ -229,34 +202,31 @@ class Collection extends PlainValue.Node {
|
|
|
229
202
|
break;
|
|
230
203
|
}
|
|
231
204
|
}
|
|
232
|
-
|
|
233
205
|
this.items = [firstItem];
|
|
234
206
|
const ec = grabCollectionEndComments(firstItem);
|
|
235
207
|
if (ec) Array.prototype.push.apply(this.items, ec);
|
|
236
208
|
}
|
|
237
|
-
|
|
238
209
|
get includesTrailingLines() {
|
|
239
210
|
return this.items.length > 0;
|
|
240
211
|
}
|
|
212
|
+
|
|
241
213
|
/**
|
|
242
214
|
* @param {ParseContext} context
|
|
243
215
|
* @param {number} start - Index of first character
|
|
244
216
|
* @returns {number} - Index of the character after this
|
|
245
217
|
*/
|
|
246
|
-
|
|
247
|
-
|
|
248
218
|
parse(context, start) {
|
|
249
219
|
this.context = context;
|
|
250
220
|
const {
|
|
251
221
|
parseNode,
|
|
252
222
|
src
|
|
253
|
-
} = context;
|
|
223
|
+
} = context;
|
|
224
|
+
// It's easier to recalculate lineStart here rather than tracking down the
|
|
254
225
|
// last context from which to read it -- eemeli/yaml#2
|
|
255
|
-
|
|
256
226
|
let lineStart = PlainValue.Node.startOfLine(src, start);
|
|
257
|
-
const firstItem = this.items[0];
|
|
227
|
+
const firstItem = this.items[0];
|
|
228
|
+
// First-item context needs to be correct for later comment handling
|
|
258
229
|
// -- eemeli/yaml#17
|
|
259
|
-
|
|
260
230
|
firstItem.context.parent = this;
|
|
261
231
|
this.valueRange = PlainValue.Range.copy(firstItem.valueRange);
|
|
262
232
|
const indent = firstItem.range.start - firstItem.context.lineStart;
|
|
@@ -265,7 +235,6 @@ class Collection extends PlainValue.Node {
|
|
|
265
235
|
let ch = src[offset];
|
|
266
236
|
let atLineStart = PlainValue.Node.endOfWhiteSpace(src, lineStart) === offset;
|
|
267
237
|
let prevIncludesTrailingLines = false;
|
|
268
|
-
|
|
269
238
|
while (ch) {
|
|
270
239
|
while (ch === '\n' || ch === '#') {
|
|
271
240
|
if (atLineStart && ch === '\n' && !prevIncludesTrailingLines) {
|
|
@@ -274,19 +243,16 @@ class Collection extends PlainValue.Node {
|
|
|
274
243
|
src
|
|
275
244
|
}, offset);
|
|
276
245
|
this.valueRange.end = offset;
|
|
277
|
-
|
|
278
246
|
if (offset >= src.length) {
|
|
279
247
|
ch = null;
|
|
280
248
|
break;
|
|
281
249
|
}
|
|
282
|
-
|
|
283
250
|
this.items.push(blankLine);
|
|
284
251
|
offset -= 1; // blankLine.parse() consumes terminal newline
|
|
285
252
|
} else if (ch === '#') {
|
|
286
253
|
if (offset < lineStart + indent && !Collection.nextContentHasIndent(src, offset, indent)) {
|
|
287
254
|
return offset;
|
|
288
255
|
}
|
|
289
|
-
|
|
290
256
|
const comment = new Comment();
|
|
291
257
|
offset = comment.parse({
|
|
292
258
|
indent,
|
|
@@ -295,33 +261,26 @@ class Collection extends PlainValue.Node {
|
|
|
295
261
|
}, offset);
|
|
296
262
|
this.items.push(comment);
|
|
297
263
|
this.valueRange.end = offset;
|
|
298
|
-
|
|
299
264
|
if (offset >= src.length) {
|
|
300
265
|
ch = null;
|
|
301
266
|
break;
|
|
302
267
|
}
|
|
303
268
|
}
|
|
304
|
-
|
|
305
269
|
lineStart = offset + 1;
|
|
306
270
|
offset = PlainValue.Node.endOfIndent(src, lineStart);
|
|
307
|
-
|
|
308
271
|
if (PlainValue.Node.atBlank(src, offset)) {
|
|
309
272
|
const wsEnd = PlainValue.Node.endOfWhiteSpace(src, offset);
|
|
310
273
|
const next = src[wsEnd];
|
|
311
|
-
|
|
312
274
|
if (!next || next === '\n' || next === '#') {
|
|
313
275
|
offset = wsEnd;
|
|
314
276
|
}
|
|
315
277
|
}
|
|
316
|
-
|
|
317
278
|
ch = src[offset];
|
|
318
279
|
atLineStart = true;
|
|
319
280
|
}
|
|
320
|
-
|
|
321
281
|
if (!ch) {
|
|
322
282
|
break;
|
|
323
283
|
}
|
|
324
|
-
|
|
325
284
|
if (offset !== lineStart + indent && (atLineStart || ch !== ':')) {
|
|
326
285
|
if (offset < lineStart + indent) {
|
|
327
286
|
if (lineStart > start) offset = lineStart;
|
|
@@ -331,7 +290,6 @@ class Collection extends PlainValue.Node {
|
|
|
331
290
|
this.error = new PlainValue.YAMLSyntaxError(this, msg);
|
|
332
291
|
}
|
|
333
292
|
}
|
|
334
|
-
|
|
335
293
|
if (firstItem.type === PlainValue.Type.SEQ_ITEM) {
|
|
336
294
|
if (ch !== '-') {
|
|
337
295
|
if (lineStart > start) offset = lineStart;
|
|
@@ -340,13 +298,11 @@ class Collection extends PlainValue.Node {
|
|
|
340
298
|
} else if (ch === '-' && !this.error) {
|
|
341
299
|
// map key may start with -, as long as it's followed by a non-whitespace char
|
|
342
300
|
const next = src[offset + 1];
|
|
343
|
-
|
|
344
301
|
if (!next || next === '\n' || next === '\t' || next === ' ') {
|
|
345
302
|
const msg = 'A collection cannot be both a mapping and a sequence';
|
|
346
303
|
this.error = new PlainValue.YAMLSyntaxError(this, msg);
|
|
347
304
|
}
|
|
348
305
|
}
|
|
349
|
-
|
|
350
306
|
const node = parseNode({
|
|
351
307
|
atLineStart,
|
|
352
308
|
inCollection: true,
|
|
@@ -355,35 +311,29 @@ class Collection extends PlainValue.Node {
|
|
|
355
311
|
parent: this
|
|
356
312
|
}, offset);
|
|
357
313
|
if (!node) return offset; // at next document start
|
|
358
|
-
|
|
359
314
|
this.items.push(node);
|
|
360
315
|
this.valueRange.end = node.valueRange.end;
|
|
361
316
|
offset = PlainValue.Node.normalizeOffset(src, node.range.end);
|
|
362
317
|
ch = src[offset];
|
|
363
318
|
atLineStart = false;
|
|
364
|
-
prevIncludesTrailingLines = node.includesTrailingLines;
|
|
319
|
+
prevIncludesTrailingLines = node.includesTrailingLines;
|
|
320
|
+
// Need to reset lineStart and atLineStart here if preceding node's range
|
|
365
321
|
// has advanced to check the current line's indentation level
|
|
366
322
|
// -- eemeli/yaml#10 & eemeli/yaml#38
|
|
367
|
-
|
|
368
323
|
if (ch) {
|
|
369
324
|
let ls = offset - 1;
|
|
370
325
|
let prev = src[ls];
|
|
371
|
-
|
|
372
326
|
while (prev === ' ' || prev === '\t') prev = src[--ls];
|
|
373
|
-
|
|
374
327
|
if (prev === '\n') {
|
|
375
328
|
lineStart = ls + 1;
|
|
376
329
|
atLineStart = true;
|
|
377
330
|
}
|
|
378
331
|
}
|
|
379
|
-
|
|
380
332
|
const ec = grabCollectionEndComments(node);
|
|
381
333
|
if (ec) Array.prototype.push.apply(this.items, ec);
|
|
382
334
|
}
|
|
383
|
-
|
|
384
335
|
return offset;
|
|
385
336
|
}
|
|
386
|
-
|
|
387
337
|
setOrigRanges(cr, offset) {
|
|
388
338
|
offset = super.setOrigRanges(cr, offset);
|
|
389
339
|
this.items.forEach(node => {
|
|
@@ -391,7 +341,6 @@ class Collection extends PlainValue.Node {
|
|
|
391
341
|
});
|
|
392
342
|
return offset;
|
|
393
343
|
}
|
|
394
|
-
|
|
395
344
|
toString() {
|
|
396
345
|
const {
|
|
397
346
|
context: {
|
|
@@ -403,7 +352,6 @@ class Collection extends PlainValue.Node {
|
|
|
403
352
|
} = this;
|
|
404
353
|
if (value != null) return value;
|
|
405
354
|
let str = src.slice(range.start, items[0].range.start) + String(items[0]);
|
|
406
|
-
|
|
407
355
|
for (let i = 1; i < items.length; ++i) {
|
|
408
356
|
const item = items[i];
|
|
409
357
|
const {
|
|
@@ -413,10 +361,8 @@ class Collection extends PlainValue.Node {
|
|
|
413
361
|
if (atLineStart) for (let i = 0; i < indent; ++i) str += ' ';
|
|
414
362
|
str += String(item);
|
|
415
363
|
}
|
|
416
|
-
|
|
417
364
|
return PlainValue.Node.addStringTerminator(src, range.end, str);
|
|
418
365
|
}
|
|
419
|
-
|
|
420
366
|
}
|
|
421
367
|
|
|
422
368
|
class Directive extends PlainValue.Node {
|
|
@@ -424,38 +370,30 @@ class Directive extends PlainValue.Node {
|
|
|
424
370
|
super(PlainValue.Type.DIRECTIVE);
|
|
425
371
|
this.name = null;
|
|
426
372
|
}
|
|
427
|
-
|
|
428
373
|
get parameters() {
|
|
429
374
|
const raw = this.rawValue;
|
|
430
375
|
return raw ? raw.trim().split(/[ \t]+/) : [];
|
|
431
376
|
}
|
|
432
|
-
|
|
433
377
|
parseName(start) {
|
|
434
378
|
const {
|
|
435
379
|
src
|
|
436
380
|
} = this.context;
|
|
437
381
|
let offset = start;
|
|
438
382
|
let ch = src[offset];
|
|
439
|
-
|
|
440
383
|
while (ch && ch !== '\n' && ch !== '\t' && ch !== ' ') ch = src[offset += 1];
|
|
441
|
-
|
|
442
384
|
this.name = src.slice(start, offset);
|
|
443
385
|
return offset;
|
|
444
386
|
}
|
|
445
|
-
|
|
446
387
|
parseParameters(start) {
|
|
447
388
|
const {
|
|
448
389
|
src
|
|
449
390
|
} = this.context;
|
|
450
391
|
let offset = start;
|
|
451
392
|
let ch = src[offset];
|
|
452
|
-
|
|
453
393
|
while (ch && ch !== '\n' && ch !== '#') ch = src[offset += 1];
|
|
454
|
-
|
|
455
394
|
this.valueRange = new PlainValue.Range(start, offset);
|
|
456
395
|
return offset;
|
|
457
396
|
}
|
|
458
|
-
|
|
459
397
|
parse(context, start) {
|
|
460
398
|
this.context = context;
|
|
461
399
|
let offset = this.parseName(start + 1);
|
|
@@ -464,7 +402,6 @@ class Directive extends PlainValue.Node {
|
|
|
464
402
|
this.range = new PlainValue.Range(start, offset);
|
|
465
403
|
return offset;
|
|
466
404
|
}
|
|
467
|
-
|
|
468
405
|
}
|
|
469
406
|
|
|
470
407
|
class Document extends PlainValue.Node {
|
|
@@ -473,7 +410,6 @@ class Document extends PlainValue.Node {
|
|
|
473
410
|
const ch = src[offset];
|
|
474
411
|
return ch === '#' || ch === '\n' ? offset : start;
|
|
475
412
|
}
|
|
476
|
-
|
|
477
413
|
constructor() {
|
|
478
414
|
super(PlainValue.Type.DOCUMENT);
|
|
479
415
|
this.directives = null;
|
|
@@ -481,7 +417,6 @@ class Document extends PlainValue.Node {
|
|
|
481
417
|
this.directivesEndMarker = null;
|
|
482
418
|
this.documentEndMarker = null;
|
|
483
419
|
}
|
|
484
|
-
|
|
485
420
|
parseDirectives(start) {
|
|
486
421
|
const {
|
|
487
422
|
src
|
|
@@ -490,10 +425,8 @@ class Document extends PlainValue.Node {
|
|
|
490
425
|
let atLineStart = true;
|
|
491
426
|
let hasDirectives = false;
|
|
492
427
|
let offset = start;
|
|
493
|
-
|
|
494
428
|
while (!PlainValue.Node.atDocumentBoundary(src, offset, PlainValue.Char.DIRECTIVES_END)) {
|
|
495
429
|
offset = Document.startCommentOrEndBlankLine(src, offset);
|
|
496
|
-
|
|
497
430
|
switch (src[offset]) {
|
|
498
431
|
case '\n':
|
|
499
432
|
if (atLineStart) {
|
|
@@ -501,7 +434,6 @@ class Document extends PlainValue.Node {
|
|
|
501
434
|
offset = blankLine.parse({
|
|
502
435
|
src
|
|
503
436
|
}, offset);
|
|
504
|
-
|
|
505
437
|
if (offset < src.length) {
|
|
506
438
|
this.directives.push(blankLine);
|
|
507
439
|
}
|
|
@@ -509,9 +441,7 @@ class Document extends PlainValue.Node {
|
|
|
509
441
|
offset += 1;
|
|
510
442
|
atLineStart = true;
|
|
511
443
|
}
|
|
512
|
-
|
|
513
444
|
break;
|
|
514
|
-
|
|
515
445
|
case '#':
|
|
516
446
|
{
|
|
517
447
|
const comment = new Comment();
|
|
@@ -522,7 +452,6 @@ class Document extends PlainValue.Node {
|
|
|
522
452
|
atLineStart = false;
|
|
523
453
|
}
|
|
524
454
|
break;
|
|
525
|
-
|
|
526
455
|
case '%':
|
|
527
456
|
{
|
|
528
457
|
const directive = new Directive();
|
|
@@ -535,7 +464,6 @@ class Document extends PlainValue.Node {
|
|
|
535
464
|
atLineStart = false;
|
|
536
465
|
}
|
|
537
466
|
break;
|
|
538
|
-
|
|
539
467
|
default:
|
|
540
468
|
if (hasDirectives) {
|
|
541
469
|
this.error = new PlainValue.YAMLSemanticError(this, 'Missing directives-end indicator line');
|
|
@@ -543,26 +471,21 @@ class Document extends PlainValue.Node {
|
|
|
543
471
|
this.contents = this.directives;
|
|
544
472
|
this.directives = [];
|
|
545
473
|
}
|
|
546
|
-
|
|
547
474
|
return offset;
|
|
548
475
|
}
|
|
549
476
|
}
|
|
550
|
-
|
|
551
477
|
if (src[offset]) {
|
|
552
478
|
this.directivesEndMarker = new PlainValue.Range(offset, offset + 3);
|
|
553
479
|
return offset + 3;
|
|
554
480
|
}
|
|
555
|
-
|
|
556
481
|
if (hasDirectives) {
|
|
557
482
|
this.error = new PlainValue.YAMLSemanticError(this, 'Missing directives-end indicator line');
|
|
558
483
|
} else if (this.directives.length > 0) {
|
|
559
484
|
this.contents = this.directives;
|
|
560
485
|
this.directives = [];
|
|
561
486
|
}
|
|
562
|
-
|
|
563
487
|
return offset;
|
|
564
488
|
}
|
|
565
|
-
|
|
566
489
|
parseContents(start) {
|
|
567
490
|
const {
|
|
568
491
|
parseNode,
|
|
@@ -570,13 +493,10 @@ class Document extends PlainValue.Node {
|
|
|
570
493
|
} = this.context;
|
|
571
494
|
if (!this.contents) this.contents = [];
|
|
572
495
|
let lineStart = start;
|
|
573
|
-
|
|
574
496
|
while (src[lineStart - 1] === '-') lineStart -= 1;
|
|
575
|
-
|
|
576
497
|
let offset = PlainValue.Node.endOfWhiteSpace(src, start);
|
|
577
498
|
let atLineStart = lineStart === start;
|
|
578
499
|
this.valueRange = new PlainValue.Range(offset);
|
|
579
|
-
|
|
580
500
|
while (!PlainValue.Node.atDocumentBoundary(src, offset, PlainValue.Char.DOCUMENT_END)) {
|
|
581
501
|
switch (src[offset]) {
|
|
582
502
|
case '\n':
|
|
@@ -585,7 +505,6 @@ class Document extends PlainValue.Node {
|
|
|
585
505
|
offset = blankLine.parse({
|
|
586
506
|
src
|
|
587
507
|
}, offset);
|
|
588
|
-
|
|
589
508
|
if (offset < src.length) {
|
|
590
509
|
this.contents.push(blankLine);
|
|
591
510
|
}
|
|
@@ -593,10 +512,8 @@ class Document extends PlainValue.Node {
|
|
|
593
512
|
offset += 1;
|
|
594
513
|
atLineStart = true;
|
|
595
514
|
}
|
|
596
|
-
|
|
597
515
|
lineStart = offset;
|
|
598
516
|
break;
|
|
599
|
-
|
|
600
517
|
case '#':
|
|
601
518
|
{
|
|
602
519
|
const comment = new Comment();
|
|
@@ -607,7 +524,6 @@ class Document extends PlainValue.Node {
|
|
|
607
524
|
atLineStart = false;
|
|
608
525
|
}
|
|
609
526
|
break;
|
|
610
|
-
|
|
611
527
|
default:
|
|
612
528
|
{
|
|
613
529
|
const iEnd = PlainValue.Node.endOfIndent(src, offset);
|
|
@@ -621,7 +537,6 @@ class Document extends PlainValue.Node {
|
|
|
621
537
|
};
|
|
622
538
|
const node = parseNode(context, iEnd);
|
|
623
539
|
if (!node) return this.valueRange.end = iEnd; // at next document start
|
|
624
|
-
|
|
625
540
|
this.contents.push(node);
|
|
626
541
|
offset = node.range.end;
|
|
627
542
|
atLineStart = false;
|
|
@@ -629,19 +544,14 @@ class Document extends PlainValue.Node {
|
|
|
629
544
|
if (ec) Array.prototype.push.apply(this.contents, ec);
|
|
630
545
|
}
|
|
631
546
|
}
|
|
632
|
-
|
|
633
547
|
offset = Document.startCommentOrEndBlankLine(src, offset);
|
|
634
548
|
}
|
|
635
|
-
|
|
636
549
|
this.valueRange.end = offset;
|
|
637
|
-
|
|
638
550
|
if (src[offset]) {
|
|
639
551
|
this.documentEndMarker = new PlainValue.Range(offset, offset + 3);
|
|
640
552
|
offset += 3;
|
|
641
|
-
|
|
642
553
|
if (src[offset]) {
|
|
643
554
|
offset = PlainValue.Node.endOfWhiteSpace(src, offset);
|
|
644
|
-
|
|
645
555
|
if (src[offset] === '#') {
|
|
646
556
|
const comment = new Comment();
|
|
647
557
|
offset = comment.parse({
|
|
@@ -649,30 +559,25 @@ class Document extends PlainValue.Node {
|
|
|
649
559
|
}, offset);
|
|
650
560
|
this.contents.push(comment);
|
|
651
561
|
}
|
|
652
|
-
|
|
653
562
|
switch (src[offset]) {
|
|
654
563
|
case '\n':
|
|
655
564
|
offset += 1;
|
|
656
565
|
break;
|
|
657
|
-
|
|
658
566
|
case undefined:
|
|
659
567
|
break;
|
|
660
|
-
|
|
661
568
|
default:
|
|
662
569
|
this.error = new PlainValue.YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix');
|
|
663
570
|
}
|
|
664
571
|
}
|
|
665
572
|
}
|
|
666
|
-
|
|
667
573
|
return offset;
|
|
668
574
|
}
|
|
575
|
+
|
|
669
576
|
/**
|
|
670
577
|
* @param {ParseContext} context
|
|
671
578
|
* @param {number} start - Index of first character
|
|
672
579
|
* @returns {number} - Index of the character after this
|
|
673
580
|
*/
|
|
674
|
-
|
|
675
|
-
|
|
676
581
|
parse(context, start) {
|
|
677
582
|
context.root = this;
|
|
678
583
|
this.context = context;
|
|
@@ -680,12 +585,10 @@ class Document extends PlainValue.Node {
|
|
|
680
585
|
src
|
|
681
586
|
} = context;
|
|
682
587
|
let offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM
|
|
683
|
-
|
|
684
588
|
offset = this.parseDirectives(offset);
|
|
685
589
|
offset = this.parseContents(offset);
|
|
686
590
|
return offset;
|
|
687
591
|
}
|
|
688
|
-
|
|
689
592
|
setOrigRanges(cr, offset) {
|
|
690
593
|
offset = super.setOrigRanges(cr, offset);
|
|
691
594
|
this.directives.forEach(node => {
|
|
@@ -698,7 +601,6 @@ class Document extends PlainValue.Node {
|
|
|
698
601
|
if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset);
|
|
699
602
|
return offset;
|
|
700
603
|
}
|
|
701
|
-
|
|
702
604
|
toString() {
|
|
703
605
|
const {
|
|
704
606
|
contents,
|
|
@@ -707,16 +609,13 @@ class Document extends PlainValue.Node {
|
|
|
707
609
|
} = this;
|
|
708
610
|
if (value != null) return value;
|
|
709
611
|
let str = directives.join('');
|
|
710
|
-
|
|
711
612
|
if (contents.length > 0) {
|
|
712
613
|
if (directives.length > 0 || contents[0].type === PlainValue.Type.COMMENT) str += '---\n';
|
|
713
614
|
str += contents.join('');
|
|
714
615
|
}
|
|
715
|
-
|
|
716
616
|
if (str[str.length - 1] !== '\n') str += '\n';
|
|
717
617
|
return str;
|
|
718
618
|
}
|
|
719
|
-
|
|
720
619
|
}
|
|
721
620
|
|
|
722
621
|
class Alias extends PlainValue.Node {
|
|
@@ -738,7 +637,6 @@ class Alias extends PlainValue.Node {
|
|
|
738
637
|
offset = this.parseComment(offset);
|
|
739
638
|
return offset;
|
|
740
639
|
}
|
|
741
|
-
|
|
742
640
|
}
|
|
743
641
|
|
|
744
642
|
const Chomp = {
|
|
@@ -753,11 +651,9 @@ class BlockValue extends PlainValue.Node {
|
|
|
753
651
|
this.chomping = Chomp.CLIP;
|
|
754
652
|
this.header = null;
|
|
755
653
|
}
|
|
756
|
-
|
|
757
654
|
get includesTrailingLines() {
|
|
758
655
|
return this.chomping === Chomp.KEEP;
|
|
759
656
|
}
|
|
760
|
-
|
|
761
657
|
get strValue() {
|
|
762
658
|
if (!this.valueRange || !this.context) return null;
|
|
763
659
|
let {
|
|
@@ -771,20 +667,15 @@ class BlockValue extends PlainValue.Node {
|
|
|
771
667
|
if (this.valueRange.isEmpty()) return '';
|
|
772
668
|
let lastNewLine = null;
|
|
773
669
|
let ch = src[end - 1];
|
|
774
|
-
|
|
775
670
|
while (ch === '\n' || ch === '\t' || ch === ' ') {
|
|
776
671
|
end -= 1;
|
|
777
|
-
|
|
778
672
|
if (end <= start) {
|
|
779
673
|
if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens
|
|
780
674
|
}
|
|
781
|
-
|
|
782
675
|
if (ch === '\n') lastNewLine = end;
|
|
783
676
|
ch = src[end - 1];
|
|
784
677
|
}
|
|
785
|
-
|
|
786
678
|
let keepStart = end + 1;
|
|
787
|
-
|
|
788
679
|
if (lastNewLine) {
|
|
789
680
|
if (this.chomping === Chomp.KEEP) {
|
|
790
681
|
keepStart = lastNewLine;
|
|
@@ -793,33 +684,27 @@ class BlockValue extends PlainValue.Node {
|
|
|
793
684
|
end = lastNewLine;
|
|
794
685
|
}
|
|
795
686
|
}
|
|
796
|
-
|
|
797
687
|
const bi = indent + this.blockIndent;
|
|
798
688
|
const folded = this.type === PlainValue.Type.BLOCK_FOLDED;
|
|
799
689
|
let atStart = true;
|
|
800
690
|
let str = '';
|
|
801
691
|
let sep = '';
|
|
802
692
|
let prevMoreIndented = false;
|
|
803
|
-
|
|
804
693
|
for (let i = start; i < end; ++i) {
|
|
805
694
|
for (let j = 0; j < bi; ++j) {
|
|
806
695
|
if (src[i] !== ' ') break;
|
|
807
696
|
i += 1;
|
|
808
697
|
}
|
|
809
|
-
|
|
810
698
|
const ch = src[i];
|
|
811
|
-
|
|
812
699
|
if (ch === '\n') {
|
|
813
700
|
if (sep === '\n') str += '\n';else sep = '\n';
|
|
814
701
|
} else {
|
|
815
702
|
const lineEnd = PlainValue.Node.endOfLine(src, i);
|
|
816
703
|
const line = src.slice(i, lineEnd);
|
|
817
704
|
i = lineEnd;
|
|
818
|
-
|
|
819
705
|
if (folded && (ch === ' ' || ch === '\t') && i < keepStart) {
|
|
820
706
|
if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n';
|
|
821
707
|
str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '')
|
|
822
|
-
|
|
823
708
|
sep = lineEnd < end && src[lineEnd] || '';
|
|
824
709
|
prevMoreIndented = true;
|
|
825
710
|
} else {
|
|
@@ -827,33 +712,26 @@ class BlockValue extends PlainValue.Node {
|
|
|
827
712
|
sep = folded && i < keepStart ? ' ' : '\n';
|
|
828
713
|
prevMoreIndented = false;
|
|
829
714
|
}
|
|
830
|
-
|
|
831
715
|
if (atStart && line !== '') atStart = false;
|
|
832
716
|
}
|
|
833
717
|
}
|
|
834
|
-
|
|
835
718
|
return this.chomping === Chomp.STRIP ? str : str + '\n';
|
|
836
719
|
}
|
|
837
|
-
|
|
838
720
|
parseBlockHeader(start) {
|
|
839
721
|
const {
|
|
840
722
|
src
|
|
841
723
|
} = this.context;
|
|
842
724
|
let offset = start + 1;
|
|
843
725
|
let bi = '';
|
|
844
|
-
|
|
845
726
|
while (true) {
|
|
846
727
|
const ch = src[offset];
|
|
847
|
-
|
|
848
728
|
switch (ch) {
|
|
849
729
|
case '-':
|
|
850
730
|
this.chomping = Chomp.STRIP;
|
|
851
731
|
break;
|
|
852
|
-
|
|
853
732
|
case '+':
|
|
854
733
|
this.chomping = Chomp.KEEP;
|
|
855
734
|
break;
|
|
856
|
-
|
|
857
735
|
case '0':
|
|
858
736
|
case '1':
|
|
859
737
|
case '2':
|
|
@@ -866,17 +744,14 @@ class BlockValue extends PlainValue.Node {
|
|
|
866
744
|
case '9':
|
|
867
745
|
bi += ch;
|
|
868
746
|
break;
|
|
869
|
-
|
|
870
747
|
default:
|
|
871
748
|
this.blockIndent = Number(bi) || null;
|
|
872
749
|
this.header = new PlainValue.Range(start, offset);
|
|
873
750
|
return offset;
|
|
874
751
|
}
|
|
875
|
-
|
|
876
752
|
offset += 1;
|
|
877
753
|
}
|
|
878
754
|
}
|
|
879
|
-
|
|
880
755
|
parseBlockValue(start) {
|
|
881
756
|
const {
|
|
882
757
|
indent,
|
|
@@ -886,16 +761,13 @@ class BlockValue extends PlainValue.Node {
|
|
|
886
761
|
let offset = start;
|
|
887
762
|
let valueEnd = start;
|
|
888
763
|
let minBlockIndent = 1;
|
|
889
|
-
|
|
890
764
|
for (let ch = src[offset]; ch === '\n'; ch = src[offset]) {
|
|
891
765
|
offset += 1;
|
|
892
766
|
if (PlainValue.Node.atDocumentBoundary(src, offset)) break;
|
|
893
767
|
const end = PlainValue.Node.endOfBlockIndent(src, indent, offset); // should not include tab?
|
|
894
|
-
|
|
895
768
|
if (end === null) break;
|
|
896
769
|
const ch = src[end];
|
|
897
770
|
const lineIndent = end - (offset + indent);
|
|
898
|
-
|
|
899
771
|
if (!this.blockIndent) {
|
|
900
772
|
// no explicit block indent, none yet detected
|
|
901
773
|
if (src[end] !== '\n') {
|
|
@@ -904,7 +776,6 @@ class BlockValue extends PlainValue.Node {
|
|
|
904
776
|
const msg = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
|
|
905
777
|
this.error = new PlainValue.YAMLSemanticError(this, msg);
|
|
906
778
|
}
|
|
907
|
-
|
|
908
779
|
this.blockIndent = lineIndent;
|
|
909
780
|
} else if (lineIndent > minBlockIndent) {
|
|
910
781
|
// empty line with more whitespace
|
|
@@ -912,28 +783,25 @@ class BlockValue extends PlainValue.Node {
|
|
|
912
783
|
}
|
|
913
784
|
} else if (ch && ch !== '\n' && lineIndent < this.blockIndent) {
|
|
914
785
|
if (src[end] === '#') break;
|
|
915
|
-
|
|
916
786
|
if (!this.error) {
|
|
917
787
|
const src = explicit ? 'explicit indentation indicator' : 'first line';
|
|
918
788
|
const msg = `Block scalars must not be less indented than their ${src}`;
|
|
919
789
|
this.error = new PlainValue.YAMLSemanticError(this, msg);
|
|
920
790
|
}
|
|
921
791
|
}
|
|
922
|
-
|
|
923
792
|
if (src[end] === '\n') {
|
|
924
793
|
offset = end;
|
|
925
794
|
} else {
|
|
926
795
|
offset = valueEnd = PlainValue.Node.endOfLine(src, end);
|
|
927
796
|
}
|
|
928
797
|
}
|
|
929
|
-
|
|
930
798
|
if (this.chomping !== Chomp.KEEP) {
|
|
931
799
|
offset = src[valueEnd] ? valueEnd + 1 : valueEnd;
|
|
932
800
|
}
|
|
933
|
-
|
|
934
801
|
this.valueRange = new PlainValue.Range(start + 1, offset);
|
|
935
802
|
return offset;
|
|
936
803
|
}
|
|
804
|
+
|
|
937
805
|
/**
|
|
938
806
|
* Parses a block value from the source
|
|
939
807
|
*
|
|
@@ -954,8 +822,6 @@ class BlockValue extends PlainValue.Node {
|
|
|
954
822
|
* @param {number} start - Index of first character
|
|
955
823
|
* @returns {number} - Index of the character after this block
|
|
956
824
|
*/
|
|
957
|
-
|
|
958
|
-
|
|
959
825
|
parse(context, start) {
|
|
960
826
|
this.context = context;
|
|
961
827
|
const {
|
|
@@ -967,12 +833,10 @@ class BlockValue extends PlainValue.Node {
|
|
|
967
833
|
offset = this.parseBlockValue(offset);
|
|
968
834
|
return offset;
|
|
969
835
|
}
|
|
970
|
-
|
|
971
836
|
setOrigRanges(cr, offset) {
|
|
972
837
|
offset = super.setOrigRanges(cr, offset);
|
|
973
838
|
return this.header ? this.header.setOrigRange(cr, offset) : offset;
|
|
974
839
|
}
|
|
975
|
-
|
|
976
840
|
}
|
|
977
841
|
|
|
978
842
|
class FlowCollection extends PlainValue.Node {
|
|
@@ -980,18 +844,16 @@ class FlowCollection extends PlainValue.Node {
|
|
|
980
844
|
super(type, props);
|
|
981
845
|
this.items = null;
|
|
982
846
|
}
|
|
983
|
-
|
|
984
847
|
prevNodeIsJsonLike(idx = this.items.length) {
|
|
985
848
|
const node = this.items[idx - 1];
|
|
986
849
|
return !!node && (node.jsonLike || node.type === PlainValue.Type.COMMENT && this.prevNodeIsJsonLike(idx - 1));
|
|
987
850
|
}
|
|
851
|
+
|
|
988
852
|
/**
|
|
989
853
|
* @param {ParseContext} context
|
|
990
854
|
* @param {number} start - Index of first character
|
|
991
855
|
* @returns {number} - Index of the character after this
|
|
992
856
|
*/
|
|
993
|
-
|
|
994
|
-
|
|
995
857
|
parse(context, start) {
|
|
996
858
|
this.context = context;
|
|
997
859
|
const {
|
|
@@ -1003,21 +865,18 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1003
865
|
lineStart
|
|
1004
866
|
} = context;
|
|
1005
867
|
let char = src[start]; // { or [
|
|
1006
|
-
|
|
1007
868
|
this.items = [{
|
|
1008
869
|
char,
|
|
1009
870
|
offset: start
|
|
1010
871
|
}];
|
|
1011
872
|
let offset = PlainValue.Node.endOfWhiteSpace(src, start + 1);
|
|
1012
873
|
char = src[offset];
|
|
1013
|
-
|
|
1014
874
|
while (char && char !== ']' && char !== '}') {
|
|
1015
875
|
switch (char) {
|
|
1016
876
|
case '\n':
|
|
1017
877
|
{
|
|
1018
878
|
lineStart = offset + 1;
|
|
1019
879
|
const wsEnd = PlainValue.Node.endOfWhiteSpace(src, lineStart);
|
|
1020
|
-
|
|
1021
880
|
if (src[wsEnd] === '\n') {
|
|
1022
881
|
const blankLine = new BlankLine();
|
|
1023
882
|
lineStart = blankLine.parse({
|
|
@@ -1025,12 +884,9 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1025
884
|
}, lineStart);
|
|
1026
885
|
this.items.push(blankLine);
|
|
1027
886
|
}
|
|
1028
|
-
|
|
1029
887
|
offset = PlainValue.Node.endOfIndent(src, lineStart);
|
|
1030
|
-
|
|
1031
888
|
if (offset <= lineStart + indent) {
|
|
1032
889
|
char = src[offset];
|
|
1033
|
-
|
|
1034
890
|
if (offset < lineStart + indent || char !== ']' && char !== '}') {
|
|
1035
891
|
const msg = 'Insufficient indentation in flow collection';
|
|
1036
892
|
this.error = new PlainValue.YAMLSemanticError(this, msg);
|
|
@@ -1038,7 +894,6 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1038
894
|
}
|
|
1039
895
|
}
|
|
1040
896
|
break;
|
|
1041
|
-
|
|
1042
897
|
case ',':
|
|
1043
898
|
{
|
|
1044
899
|
this.items.push({
|
|
@@ -1048,7 +903,6 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1048
903
|
offset += 1;
|
|
1049
904
|
}
|
|
1050
905
|
break;
|
|
1051
|
-
|
|
1052
906
|
case '#':
|
|
1053
907
|
{
|
|
1054
908
|
const comment = new Comment();
|
|
@@ -1058,13 +912,12 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1058
912
|
this.items.push(comment);
|
|
1059
913
|
}
|
|
1060
914
|
break;
|
|
1061
|
-
|
|
1062
915
|
case '?':
|
|
1063
916
|
case ':':
|
|
1064
917
|
{
|
|
1065
918
|
const next = src[offset + 1];
|
|
1066
|
-
|
|
1067
|
-
|
|
919
|
+
if (next === '\n' || next === '\t' || next === ' ' || next === ',' ||
|
|
920
|
+
// in-flow : after JSON-like key does not need to be followed by whitespace
|
|
1068
921
|
char === ':' && this.prevNodeIsJsonLike()) {
|
|
1069
922
|
this.items.push({
|
|
1070
923
|
char,
|
|
@@ -1075,7 +928,6 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1075
928
|
}
|
|
1076
929
|
}
|
|
1077
930
|
// fallthrough
|
|
1078
|
-
|
|
1079
931
|
default:
|
|
1080
932
|
{
|
|
1081
933
|
const node = parseNode({
|
|
@@ -1086,24 +938,19 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1086
938
|
lineStart,
|
|
1087
939
|
parent: this
|
|
1088
940
|
}, offset);
|
|
1089
|
-
|
|
1090
941
|
if (!node) {
|
|
1091
942
|
// at next document start
|
|
1092
943
|
this.valueRange = new PlainValue.Range(start, offset);
|
|
1093
944
|
return offset;
|
|
1094
945
|
}
|
|
1095
|
-
|
|
1096
946
|
this.items.push(node);
|
|
1097
947
|
offset = PlainValue.Node.normalizeOffset(src, node.range.end);
|
|
1098
948
|
}
|
|
1099
949
|
}
|
|
1100
|
-
|
|
1101
950
|
offset = PlainValue.Node.endOfWhiteSpace(src, offset);
|
|
1102
951
|
char = src[offset];
|
|
1103
952
|
}
|
|
1104
|
-
|
|
1105
953
|
this.valueRange = new PlainValue.Range(start, offset + 1);
|
|
1106
|
-
|
|
1107
954
|
if (char) {
|
|
1108
955
|
this.items.push({
|
|
1109
956
|
char,
|
|
@@ -1112,10 +959,8 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1112
959
|
offset = PlainValue.Node.endOfWhiteSpace(src, offset + 1);
|
|
1113
960
|
offset = this.parseComment(offset);
|
|
1114
961
|
}
|
|
1115
|
-
|
|
1116
962
|
return offset;
|
|
1117
963
|
}
|
|
1118
|
-
|
|
1119
964
|
setOrigRanges(cr, offset) {
|
|
1120
965
|
offset = super.setOrigRanges(cr, offset);
|
|
1121
966
|
this.items.forEach(node => {
|
|
@@ -1125,18 +970,15 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1125
970
|
node.origOffset = node.offset;
|
|
1126
971
|
} else {
|
|
1127
972
|
let i = offset;
|
|
1128
|
-
|
|
1129
973
|
while (i < cr.length) {
|
|
1130
974
|
if (cr[i] > node.offset) break;else ++i;
|
|
1131
975
|
}
|
|
1132
|
-
|
|
1133
976
|
node.origOffset = node.offset + i;
|
|
1134
977
|
offset = i;
|
|
1135
978
|
}
|
|
1136
979
|
});
|
|
1137
980
|
return offset;
|
|
1138
981
|
}
|
|
1139
|
-
|
|
1140
982
|
toString() {
|
|
1141
983
|
const {
|
|
1142
984
|
context: {
|
|
@@ -1154,7 +996,6 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1154
996
|
const prefix = src.slice(prevEnd, node.range.start);
|
|
1155
997
|
prevEnd = node.range.end;
|
|
1156
998
|
str += prefix + String(node);
|
|
1157
|
-
|
|
1158
999
|
if (str[str.length - 1] === '\n' && src[prevEnd - 1] !== '\n' && src[prevEnd] === '\n') {
|
|
1159
1000
|
// Comment range does not include the terminal newline, but its
|
|
1160
1001
|
// stringified value does. Without this fix, newlines at comment ends
|
|
@@ -1165,25 +1006,21 @@ class FlowCollection extends PlainValue.Node {
|
|
|
1165
1006
|
str += src.slice(prevEnd, range.end);
|
|
1166
1007
|
return PlainValue.Node.addStringTerminator(src, range.end, str);
|
|
1167
1008
|
}
|
|
1168
|
-
|
|
1169
1009
|
}
|
|
1170
1010
|
|
|
1171
1011
|
class QuoteDouble extends PlainValue.Node {
|
|
1172
1012
|
static endOfQuote(src, offset) {
|
|
1173
1013
|
let ch = src[offset];
|
|
1174
|
-
|
|
1175
1014
|
while (ch && ch !== '"') {
|
|
1176
1015
|
offset += ch === '\\' ? 2 : 1;
|
|
1177
1016
|
ch = src[offset];
|
|
1178
1017
|
}
|
|
1179
|
-
|
|
1180
1018
|
return offset + 1;
|
|
1181
1019
|
}
|
|
1020
|
+
|
|
1182
1021
|
/**
|
|
1183
1022
|
* @returns {string | { str: string, errors: YAMLSyntaxError[] }}
|
|
1184
1023
|
*/
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
1024
|
get strValue() {
|
|
1188
1025
|
if (!this.valueRange || !this.context) return null;
|
|
1189
1026
|
const errors = [];
|
|
@@ -1195,14 +1032,12 @@ class QuoteDouble extends PlainValue.Node {
|
|
|
1195
1032
|
indent,
|
|
1196
1033
|
src
|
|
1197
1034
|
} = this.context;
|
|
1198
|
-
if (src[end - 1] !== '"') errors.push(new PlainValue.YAMLSyntaxError(this, 'Missing closing "quote'));
|
|
1035
|
+
if (src[end - 1] !== '"') errors.push(new PlainValue.YAMLSyntaxError(this, 'Missing closing "quote'));
|
|
1036
|
+
// Using String#replace is too painful with escaped newlines preceded by
|
|
1199
1037
|
// escaped backslashes; also, this should be faster.
|
|
1200
|
-
|
|
1201
1038
|
let str = '';
|
|
1202
|
-
|
|
1203
1039
|
for (let i = start + 1; i < end - 1; ++i) {
|
|
1204
1040
|
const ch = src[i];
|
|
1205
|
-
|
|
1206
1041
|
if (ch === '\n') {
|
|
1207
1042
|
if (PlainValue.Node.atDocumentBoundary(src, i + 1)) errors.push(new PlainValue.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
|
|
1208
1043
|
const {
|
|
@@ -1215,114 +1050,90 @@ class QuoteDouble extends PlainValue.Node {
|
|
|
1215
1050
|
if (error) errors.push(new PlainValue.YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented'));
|
|
1216
1051
|
} else if (ch === '\\') {
|
|
1217
1052
|
i += 1;
|
|
1218
|
-
|
|
1219
1053
|
switch (src[i]) {
|
|
1220
1054
|
case '0':
|
|
1221
1055
|
str += '\0';
|
|
1222
1056
|
break;
|
|
1223
1057
|
// null character
|
|
1224
|
-
|
|
1225
1058
|
case 'a':
|
|
1226
1059
|
str += '\x07';
|
|
1227
1060
|
break;
|
|
1228
1061
|
// bell character
|
|
1229
|
-
|
|
1230
1062
|
case 'b':
|
|
1231
1063
|
str += '\b';
|
|
1232
1064
|
break;
|
|
1233
1065
|
// backspace
|
|
1234
|
-
|
|
1235
1066
|
case 'e':
|
|
1236
1067
|
str += '\x1b';
|
|
1237
1068
|
break;
|
|
1238
1069
|
// escape character
|
|
1239
|
-
|
|
1240
1070
|
case 'f':
|
|
1241
1071
|
str += '\f';
|
|
1242
1072
|
break;
|
|
1243
1073
|
// form feed
|
|
1244
|
-
|
|
1245
1074
|
case 'n':
|
|
1246
1075
|
str += '\n';
|
|
1247
1076
|
break;
|
|
1248
1077
|
// line feed
|
|
1249
|
-
|
|
1250
1078
|
case 'r':
|
|
1251
1079
|
str += '\r';
|
|
1252
1080
|
break;
|
|
1253
1081
|
// carriage return
|
|
1254
|
-
|
|
1255
1082
|
case 't':
|
|
1256
1083
|
str += '\t';
|
|
1257
1084
|
break;
|
|
1258
1085
|
// horizontal tab
|
|
1259
|
-
|
|
1260
1086
|
case 'v':
|
|
1261
1087
|
str += '\v';
|
|
1262
1088
|
break;
|
|
1263
1089
|
// vertical tab
|
|
1264
|
-
|
|
1265
1090
|
case 'N':
|
|
1266
1091
|
str += '\u0085';
|
|
1267
1092
|
break;
|
|
1268
1093
|
// Unicode next line
|
|
1269
|
-
|
|
1270
1094
|
case '_':
|
|
1271
1095
|
str += '\u00a0';
|
|
1272
1096
|
break;
|
|
1273
1097
|
// Unicode non-breaking space
|
|
1274
|
-
|
|
1275
1098
|
case 'L':
|
|
1276
1099
|
str += '\u2028';
|
|
1277
1100
|
break;
|
|
1278
1101
|
// Unicode line separator
|
|
1279
|
-
|
|
1280
1102
|
case 'P':
|
|
1281
1103
|
str += '\u2029';
|
|
1282
1104
|
break;
|
|
1283
1105
|
// Unicode paragraph separator
|
|
1284
|
-
|
|
1285
1106
|
case ' ':
|
|
1286
1107
|
str += ' ';
|
|
1287
1108
|
break;
|
|
1288
|
-
|
|
1289
1109
|
case '"':
|
|
1290
1110
|
str += '"';
|
|
1291
1111
|
break;
|
|
1292
|
-
|
|
1293
1112
|
case '/':
|
|
1294
1113
|
str += '/';
|
|
1295
1114
|
break;
|
|
1296
|
-
|
|
1297
1115
|
case '\\':
|
|
1298
1116
|
str += '\\';
|
|
1299
1117
|
break;
|
|
1300
|
-
|
|
1301
1118
|
case '\t':
|
|
1302
1119
|
str += '\t';
|
|
1303
1120
|
break;
|
|
1304
|
-
|
|
1305
1121
|
case 'x':
|
|
1306
1122
|
str += this.parseCharCode(i + 1, 2, errors);
|
|
1307
1123
|
i += 2;
|
|
1308
1124
|
break;
|
|
1309
|
-
|
|
1310
1125
|
case 'u':
|
|
1311
1126
|
str += this.parseCharCode(i + 1, 4, errors);
|
|
1312
1127
|
i += 4;
|
|
1313
1128
|
break;
|
|
1314
|
-
|
|
1315
1129
|
case 'U':
|
|
1316
1130
|
str += this.parseCharCode(i + 1, 8, errors);
|
|
1317
1131
|
i += 8;
|
|
1318
1132
|
break;
|
|
1319
|
-
|
|
1320
1133
|
case '\n':
|
|
1321
1134
|
// skip escaped newlines, but still trim the following line
|
|
1322
1135
|
while (src[i + 1] === ' ' || src[i + 1] === '\t') i += 1;
|
|
1323
|
-
|
|
1324
1136
|
break;
|
|
1325
|
-
|
|
1326
1137
|
default:
|
|
1327
1138
|
errors.push(new PlainValue.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(i - 1, 2)}`));
|
|
1328
1139
|
str += '\\' + src[i];
|
|
@@ -1331,24 +1142,20 @@ class QuoteDouble extends PlainValue.Node {
|
|
|
1331
1142
|
// trim trailing whitespace
|
|
1332
1143
|
const wsStart = i;
|
|
1333
1144
|
let next = src[i + 1];
|
|
1334
|
-
|
|
1335
1145
|
while (next === ' ' || next === '\t') {
|
|
1336
1146
|
i += 1;
|
|
1337
1147
|
next = src[i + 1];
|
|
1338
1148
|
}
|
|
1339
|
-
|
|
1340
1149
|
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
|
|
1341
1150
|
} else {
|
|
1342
1151
|
str += ch;
|
|
1343
1152
|
}
|
|
1344
1153
|
}
|
|
1345
|
-
|
|
1346
1154
|
return errors.length > 0 ? {
|
|
1347
1155
|
errors,
|
|
1348
1156
|
str
|
|
1349
1157
|
} : str;
|
|
1350
1158
|
}
|
|
1351
|
-
|
|
1352
1159
|
parseCharCode(offset, length, errors) {
|
|
1353
1160
|
const {
|
|
1354
1161
|
src
|
|
@@ -1356,14 +1163,13 @@ class QuoteDouble extends PlainValue.Node {
|
|
|
1356
1163
|
const cc = src.substr(offset, length);
|
|
1357
1164
|
const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
|
|
1358
1165
|
const code = ok ? parseInt(cc, 16) : NaN;
|
|
1359
|
-
|
|
1360
1166
|
if (isNaN(code)) {
|
|
1361
1167
|
errors.push(new PlainValue.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(offset - 2, length + 2)}`));
|
|
1362
1168
|
return src.substr(offset - 2, length + 2);
|
|
1363
1169
|
}
|
|
1364
|
-
|
|
1365
1170
|
return String.fromCodePoint(code);
|
|
1366
1171
|
}
|
|
1172
|
+
|
|
1367
1173
|
/**
|
|
1368
1174
|
* Parses a "double quoted" value from the source
|
|
1369
1175
|
*
|
|
@@ -1371,8 +1177,6 @@ class QuoteDouble extends PlainValue.Node {
|
|
|
1371
1177
|
* @param {number} start - Index of first character
|
|
1372
1178
|
* @returns {number} - Index of the character after this scalar
|
|
1373
1179
|
*/
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
1180
|
parse(context, start) {
|
|
1377
1181
|
this.context = context;
|
|
1378
1182
|
const {
|
|
@@ -1384,13 +1188,11 @@ class QuoteDouble extends PlainValue.Node {
|
|
|
1384
1188
|
offset = this.parseComment(offset);
|
|
1385
1189
|
return offset;
|
|
1386
1190
|
}
|
|
1387
|
-
|
|
1388
1191
|
}
|
|
1389
1192
|
|
|
1390
1193
|
class QuoteSingle extends PlainValue.Node {
|
|
1391
1194
|
static endOfQuote(src, offset) {
|
|
1392
1195
|
let ch = src[offset];
|
|
1393
|
-
|
|
1394
1196
|
while (ch) {
|
|
1395
1197
|
if (ch === "'") {
|
|
1396
1198
|
if (src[offset + 1] !== "'") break;
|
|
@@ -1399,14 +1201,12 @@ class QuoteSingle extends PlainValue.Node {
|
|
|
1399
1201
|
ch = src[offset += 1];
|
|
1400
1202
|
}
|
|
1401
1203
|
}
|
|
1402
|
-
|
|
1403
1204
|
return offset + 1;
|
|
1404
1205
|
}
|
|
1206
|
+
|
|
1405
1207
|
/**
|
|
1406
1208
|
* @returns {string | { str: string, errors: YAMLSyntaxError[] }}
|
|
1407
1209
|
*/
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
1210
|
get strValue() {
|
|
1411
1211
|
if (!this.valueRange || !this.context) return null;
|
|
1412
1212
|
const errors = [];
|
|
@@ -1420,10 +1220,8 @@ class QuoteSingle extends PlainValue.Node {
|
|
|
1420
1220
|
} = this.context;
|
|
1421
1221
|
if (src[end - 1] !== "'") errors.push(new PlainValue.YAMLSyntaxError(this, "Missing closing 'quote"));
|
|
1422
1222
|
let str = '';
|
|
1423
|
-
|
|
1424
1223
|
for (let i = start + 1; i < end - 1; ++i) {
|
|
1425
1224
|
const ch = src[i];
|
|
1426
|
-
|
|
1427
1225
|
if (ch === '\n') {
|
|
1428
1226
|
if (PlainValue.Node.atDocumentBoundary(src, i + 1)) errors.push(new PlainValue.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
|
|
1429
1227
|
const {
|
|
@@ -1442,23 +1240,21 @@ class QuoteSingle extends PlainValue.Node {
|
|
|
1442
1240
|
// trim trailing whitespace
|
|
1443
1241
|
const wsStart = i;
|
|
1444
1242
|
let next = src[i + 1];
|
|
1445
|
-
|
|
1446
1243
|
while (next === ' ' || next === '\t') {
|
|
1447
1244
|
i += 1;
|
|
1448
1245
|
next = src[i + 1];
|
|
1449
1246
|
}
|
|
1450
|
-
|
|
1451
1247
|
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
|
|
1452
1248
|
} else {
|
|
1453
1249
|
str += ch;
|
|
1454
1250
|
}
|
|
1455
1251
|
}
|
|
1456
|
-
|
|
1457
1252
|
return errors.length > 0 ? {
|
|
1458
1253
|
errors,
|
|
1459
1254
|
str
|
|
1460
1255
|
} : str;
|
|
1461
1256
|
}
|
|
1257
|
+
|
|
1462
1258
|
/**
|
|
1463
1259
|
* Parses a 'single quoted' value from the source
|
|
1464
1260
|
*
|
|
@@ -1466,8 +1262,6 @@ class QuoteSingle extends PlainValue.Node {
|
|
|
1466
1262
|
* @param {number} start - Index of first character
|
|
1467
1263
|
* @returns {number} - Index of the character after this scalar
|
|
1468
1264
|
*/
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
1265
|
parse(context, start) {
|
|
1472
1266
|
this.context = context;
|
|
1473
1267
|
const {
|
|
@@ -1479,44 +1273,36 @@ class QuoteSingle extends PlainValue.Node {
|
|
|
1479
1273
|
offset = this.parseComment(offset);
|
|
1480
1274
|
return offset;
|
|
1481
1275
|
}
|
|
1482
|
-
|
|
1483
1276
|
}
|
|
1484
1277
|
|
|
1485
1278
|
function createNewNode(type, props) {
|
|
1486
1279
|
switch (type) {
|
|
1487
1280
|
case PlainValue.Type.ALIAS:
|
|
1488
1281
|
return new Alias(type, props);
|
|
1489
|
-
|
|
1490
1282
|
case PlainValue.Type.BLOCK_FOLDED:
|
|
1491
1283
|
case PlainValue.Type.BLOCK_LITERAL:
|
|
1492
1284
|
return new BlockValue(type, props);
|
|
1493
|
-
|
|
1494
1285
|
case PlainValue.Type.FLOW_MAP:
|
|
1495
1286
|
case PlainValue.Type.FLOW_SEQ:
|
|
1496
1287
|
return new FlowCollection(type, props);
|
|
1497
|
-
|
|
1498
1288
|
case PlainValue.Type.MAP_KEY:
|
|
1499
1289
|
case PlainValue.Type.MAP_VALUE:
|
|
1500
1290
|
case PlainValue.Type.SEQ_ITEM:
|
|
1501
1291
|
return new CollectionItem(type, props);
|
|
1502
|
-
|
|
1503
1292
|
case PlainValue.Type.COMMENT:
|
|
1504
1293
|
case PlainValue.Type.PLAIN:
|
|
1505
1294
|
return new PlainValue.PlainValue(type, props);
|
|
1506
|
-
|
|
1507
1295
|
case PlainValue.Type.QUOTE_DOUBLE:
|
|
1508
1296
|
return new QuoteDouble(type, props);
|
|
1509
|
-
|
|
1510
1297
|
case PlainValue.Type.QUOTE_SINGLE:
|
|
1511
1298
|
return new QuoteSingle(type, props);
|
|
1512
|
-
|
|
1513
1299
|
/* istanbul ignore next */
|
|
1514
|
-
|
|
1515
1300
|
default:
|
|
1516
1301
|
return null;
|
|
1517
1302
|
// should never happen
|
|
1518
1303
|
}
|
|
1519
1304
|
}
|
|
1305
|
+
|
|
1520
1306
|
/**
|
|
1521
1307
|
* @param {boolean} atLineStart - Node starts at beginning of line
|
|
1522
1308
|
* @param {boolean} inFlow - true if currently in a flow context
|
|
@@ -1526,46 +1312,33 @@ function createNewNode(type, props) {
|
|
|
1526
1312
|
* @param {Node} parent - The parent of the node
|
|
1527
1313
|
* @param {string} src - Source of the YAML document
|
|
1528
1314
|
*/
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
1315
|
class ParseContext {
|
|
1532
1316
|
static parseType(src, offset, inFlow) {
|
|
1533
1317
|
switch (src[offset]) {
|
|
1534
1318
|
case '*':
|
|
1535
1319
|
return PlainValue.Type.ALIAS;
|
|
1536
|
-
|
|
1537
1320
|
case '>':
|
|
1538
1321
|
return PlainValue.Type.BLOCK_FOLDED;
|
|
1539
|
-
|
|
1540
1322
|
case '|':
|
|
1541
1323
|
return PlainValue.Type.BLOCK_LITERAL;
|
|
1542
|
-
|
|
1543
1324
|
case '{':
|
|
1544
1325
|
return PlainValue.Type.FLOW_MAP;
|
|
1545
|
-
|
|
1546
1326
|
case '[':
|
|
1547
1327
|
return PlainValue.Type.FLOW_SEQ;
|
|
1548
|
-
|
|
1549
1328
|
case '?':
|
|
1550
1329
|
return !inFlow && PlainValue.Node.atBlank(src, offset + 1, true) ? PlainValue.Type.MAP_KEY : PlainValue.Type.PLAIN;
|
|
1551
|
-
|
|
1552
1330
|
case ':':
|
|
1553
1331
|
return !inFlow && PlainValue.Node.atBlank(src, offset + 1, true) ? PlainValue.Type.MAP_VALUE : PlainValue.Type.PLAIN;
|
|
1554
|
-
|
|
1555
1332
|
case '-':
|
|
1556
1333
|
return !inFlow && PlainValue.Node.atBlank(src, offset + 1, true) ? PlainValue.Type.SEQ_ITEM : PlainValue.Type.PLAIN;
|
|
1557
|
-
|
|
1558
1334
|
case '"':
|
|
1559
1335
|
return PlainValue.Type.QUOTE_DOUBLE;
|
|
1560
|
-
|
|
1561
1336
|
case "'":
|
|
1562
1337
|
return PlainValue.Type.QUOTE_SINGLE;
|
|
1563
|
-
|
|
1564
1338
|
default:
|
|
1565
1339
|
return PlainValue.Type.PLAIN;
|
|
1566
1340
|
}
|
|
1567
1341
|
}
|
|
1568
|
-
|
|
1569
1342
|
constructor(orig = {}, {
|
|
1570
1343
|
atLineStart,
|
|
1571
1344
|
inCollection,
|
|
@@ -1574,6 +1347,12 @@ class ParseContext {
|
|
|
1574
1347
|
lineStart,
|
|
1575
1348
|
parent
|
|
1576
1349
|
} = {}) {
|
|
1350
|
+
/**
|
|
1351
|
+
* Parses a node from the source
|
|
1352
|
+
* @param {ParseContext} overlay
|
|
1353
|
+
* @param {number} start - Index of first non-whitespace character for the node
|
|
1354
|
+
* @returns {?Node} - null if at a document boundary
|
|
1355
|
+
*/
|
|
1577
1356
|
PlainValue._defineProperty(this, "parseNode", (overlay, start) => {
|
|
1578
1357
|
if (PlainValue.Node.atDocumentBoundary(this.src, start)) return null;
|
|
1579
1358
|
const context = new ParseContext(this, overlay);
|
|
@@ -1583,33 +1362,34 @@ class ParseContext {
|
|
|
1583
1362
|
valueStart
|
|
1584
1363
|
} = context.parseProps(start);
|
|
1585
1364
|
const node = createNewNode(type, props);
|
|
1586
|
-
let offset =
|
|
1365
|
+
let offset = start;
|
|
1366
|
+
try {
|
|
1367
|
+
offset = node.parse(context, valueStart);
|
|
1368
|
+
} catch (error) {
|
|
1369
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
1370
|
+
if (!node.error) node.error = new PlainValue.YAMLSyntaxError(node, msg);
|
|
1371
|
+
}
|
|
1587
1372
|
node.range = new PlainValue.Range(start, offset);
|
|
1588
1373
|
/* istanbul ignore if */
|
|
1589
|
-
|
|
1590
1374
|
if (offset <= start) {
|
|
1591
1375
|
// This should never happen, but if it does, let's make sure to at least
|
|
1592
1376
|
// step one character forward to avoid a busy loop.
|
|
1593
|
-
node.error = new Error(`Node#parse consumed no characters`);
|
|
1377
|
+
if (!node.error) node.error = new Error(`Node#parse consumed no characters`);
|
|
1594
1378
|
node.error.parseEnd = offset;
|
|
1595
1379
|
node.error.source = node;
|
|
1596
1380
|
node.range.end = start + 1;
|
|
1597
1381
|
}
|
|
1598
|
-
|
|
1599
1382
|
if (context.nodeStartsCollection(node)) {
|
|
1600
1383
|
if (!node.error && !context.atLineStart && context.parent.type === PlainValue.Type.DOCUMENT) {
|
|
1601
1384
|
node.error = new PlainValue.YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)');
|
|
1602
1385
|
}
|
|
1603
|
-
|
|
1604
1386
|
const collection = new Collection(node);
|
|
1605
1387
|
offset = collection.parse(new ParseContext(context), offset);
|
|
1606
1388
|
collection.range = new PlainValue.Range(start, offset);
|
|
1607
1389
|
return collection;
|
|
1608
1390
|
}
|
|
1609
|
-
|
|
1610
1391
|
return node;
|
|
1611
1392
|
});
|
|
1612
|
-
|
|
1613
1393
|
this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false;
|
|
1614
1394
|
this.inCollection = inCollection != null ? inCollection : orig.inCollection || false;
|
|
1615
1395
|
this.inFlow = inFlow != null ? inFlow : orig.inFlow || false;
|
|
@@ -1619,7 +1399,6 @@ class ParseContext {
|
|
|
1619
1399
|
this.root = orig.root;
|
|
1620
1400
|
this.src = orig.src;
|
|
1621
1401
|
}
|
|
1622
|
-
|
|
1623
1402
|
nodeStartsCollection(node) {
|
|
1624
1403
|
const {
|
|
1625
1404
|
inCollection,
|
|
@@ -1627,16 +1406,16 @@ class ParseContext {
|
|
|
1627
1406
|
src
|
|
1628
1407
|
} = this;
|
|
1629
1408
|
if (inCollection || inFlow) return false;
|
|
1630
|
-
if (node instanceof CollectionItem) return true;
|
|
1631
|
-
|
|
1409
|
+
if (node instanceof CollectionItem) return true;
|
|
1410
|
+
// check for implicit key
|
|
1632
1411
|
let offset = node.range.end;
|
|
1633
1412
|
if (src[offset] === '\n' || src[offset - 1] === '\n') return false;
|
|
1634
1413
|
offset = PlainValue.Node.endOfWhiteSpace(src, offset);
|
|
1635
1414
|
return src[offset] === ':';
|
|
1636
|
-
}
|
|
1637
|
-
// class; hence this intermediate step.
|
|
1638
|
-
|
|
1415
|
+
}
|
|
1639
1416
|
|
|
1417
|
+
// Anchor and tag are before type, which determines the node implementation
|
|
1418
|
+
// class; hence this intermediate step.
|
|
1640
1419
|
parseProps(offset) {
|
|
1641
1420
|
const {
|
|
1642
1421
|
inFlow,
|
|
@@ -1647,17 +1426,14 @@ class ParseContext {
|
|
|
1647
1426
|
let lineHasProps = false;
|
|
1648
1427
|
offset = this.atLineStart ? PlainValue.Node.endOfIndent(src, offset) : PlainValue.Node.endOfWhiteSpace(src, offset);
|
|
1649
1428
|
let ch = src[offset];
|
|
1650
|
-
|
|
1651
1429
|
while (ch === PlainValue.Char.ANCHOR || ch === PlainValue.Char.COMMENT || ch === PlainValue.Char.TAG || ch === '\n') {
|
|
1652
1430
|
if (ch === '\n') {
|
|
1653
1431
|
let inEnd = offset;
|
|
1654
1432
|
let lineStart;
|
|
1655
|
-
|
|
1656
1433
|
do {
|
|
1657
1434
|
lineStart = inEnd + 1;
|
|
1658
1435
|
inEnd = PlainValue.Node.endOfIndent(src, lineStart);
|
|
1659
1436
|
} while (src[inEnd] === '\n');
|
|
1660
|
-
|
|
1661
1437
|
const indentDiff = inEnd - (lineStart + this.indent);
|
|
1662
1438
|
const noIndicatorAsIndent = parent.type === PlainValue.Type.SEQ_ITEM && parent.context.atLineStart;
|
|
1663
1439
|
if (src[inEnd] !== '#' && !PlainValue.Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break;
|
|
@@ -1671,7 +1447,6 @@ class ParseContext {
|
|
|
1671
1447
|
offset = end;
|
|
1672
1448
|
} else {
|
|
1673
1449
|
let end = PlainValue.Node.endOfIdentifier(src, offset + 1);
|
|
1674
|
-
|
|
1675
1450
|
if (ch === PlainValue.Char.TAG && src[end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, end + 13))) {
|
|
1676
1451
|
// Let's presume we're dealing with a YAML 1.0 domain tag here, rather
|
|
1677
1452
|
// than an empty but 'foo.bar' private-tagged node in a flow collection
|
|
@@ -1679,16 +1454,13 @@ class ParseContext {
|
|
|
1679
1454
|
// or date divided by something.
|
|
1680
1455
|
end = PlainValue.Node.endOfIdentifier(src, end + 5);
|
|
1681
1456
|
}
|
|
1682
|
-
|
|
1683
1457
|
props.push(new PlainValue.Range(offset, end));
|
|
1684
1458
|
lineHasProps = true;
|
|
1685
1459
|
offset = PlainValue.Node.endOfWhiteSpace(src, end);
|
|
1686
1460
|
}
|
|
1687
|
-
|
|
1688
1461
|
ch = src[offset];
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
|
|
1462
|
+
}
|
|
1463
|
+
// '- &a : b' has an anchor on an empty node
|
|
1692
1464
|
if (lineHasProps && ch === ':' && PlainValue.Node.atBlank(src, offset + 1, true)) offset -= 1;
|
|
1693
1465
|
const type = ParseContext.parseType(src, offset, inFlow);
|
|
1694
1466
|
return {
|
|
@@ -1697,30 +1469,19 @@ class ParseContext {
|
|
|
1697
1469
|
valueStart: offset
|
|
1698
1470
|
};
|
|
1699
1471
|
}
|
|
1700
|
-
/**
|
|
1701
|
-
* Parses a node from the source
|
|
1702
|
-
* @param {ParseContext} overlay
|
|
1703
|
-
* @param {number} start - Index of first non-whitespace character for the node
|
|
1704
|
-
* @returns {?Node} - null if at a document boundary
|
|
1705
|
-
*/
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
1472
|
}
|
|
1709
1473
|
|
|
1710
1474
|
// Published as 'yaml/parse-cst'
|
|
1711
1475
|
function parse(src) {
|
|
1712
1476
|
const cr = [];
|
|
1713
|
-
|
|
1714
1477
|
if (src.indexOf('\r') !== -1) {
|
|
1715
1478
|
src = src.replace(/\r\n?/g, (match, offset) => {
|
|
1716
1479
|
if (match.length > 1) cr.push(offset);
|
|
1717
1480
|
return '\n';
|
|
1718
1481
|
});
|
|
1719
1482
|
}
|
|
1720
|
-
|
|
1721
1483
|
const documents = [];
|
|
1722
1484
|
let offset = 0;
|
|
1723
|
-
|
|
1724
1485
|
do {
|
|
1725
1486
|
const doc = new Document();
|
|
1726
1487
|
const context = new ParseContext({
|
|
@@ -1729,24 +1490,17 @@ function parse(src) {
|
|
|
1729
1490
|
offset = doc.parse(context, offset);
|
|
1730
1491
|
documents.push(doc);
|
|
1731
1492
|
} while (offset < src.length);
|
|
1732
|
-
|
|
1733
1493
|
documents.setOrigRanges = () => {
|
|
1734
1494
|
if (cr.length === 0) return false;
|
|
1735
|
-
|
|
1736
1495
|
for (let i = 1; i < cr.length; ++i) cr[i] -= i;
|
|
1737
|
-
|
|
1738
1496
|
let crOffset = 0;
|
|
1739
|
-
|
|
1740
1497
|
for (let i = 0; i < documents.length; ++i) {
|
|
1741
1498
|
crOffset = documents[i].setOrigRanges(cr, crOffset);
|
|
1742
1499
|
}
|
|
1743
|
-
|
|
1744
1500
|
cr.splice(0, cr.length);
|
|
1745
1501
|
return true;
|
|
1746
1502
|
};
|
|
1747
|
-
|
|
1748
1503
|
documents.toString = () => documents.join('...\n');
|
|
1749
|
-
|
|
1750
1504
|
return documents;
|
|
1751
1505
|
}
|
|
1752
1506
|
|