yaml 2.0.0-4 → 2.0.0-8
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/README.md +5 -5
- package/browser/dist/compose/compose-collection.js +12 -9
- package/browser/dist/compose/compose-doc.js +23 -6
- package/browser/dist/compose/compose-node.js +27 -17
- package/browser/dist/compose/compose-scalar.js +21 -23
- package/browser/dist/compose/composer.js +108 -78
- package/browser/dist/compose/resolve-block-map.js +41 -29
- package/browser/dist/compose/resolve-block-scalar.js +14 -17
- package/browser/dist/compose/resolve-block-seq.js +21 -17
- package/browser/dist/compose/resolve-end.js +7 -8
- package/browser/dist/compose/resolve-flow-collection.js +158 -199
- package/browser/dist/compose/resolve-flow-scalar.js +62 -26
- package/browser/dist/compose/resolve-props.js +72 -37
- package/browser/dist/compose/util-contains-newline.js +15 -12
- package/browser/dist/compose/util-map-includes.js +17 -0
- package/browser/dist/doc/Document.js +74 -99
- package/browser/dist/doc/anchors.js +72 -0
- package/browser/dist/doc/createNode.js +35 -19
- package/browser/dist/doc/directives.js +5 -0
- package/browser/dist/errors.js +16 -12
- package/browser/dist/index.js +3 -3
- package/browser/dist/nodes/Alias.js +51 -28
- package/browser/dist/nodes/Collection.js +23 -92
- package/browser/dist/nodes/Node.js +9 -1
- package/browser/dist/nodes/Pair.js +16 -231
- package/browser/dist/nodes/YAMLMap.js +8 -4
- package/browser/dist/nodes/YAMLSeq.js +7 -4
- package/browser/dist/nodes/addPairToJSMap.js +103 -0
- package/browser/dist/nodes/toJS.js +12 -10
- package/browser/dist/options.js +1 -2
- package/browser/dist/parse/cst-scalar.js +219 -0
- package/browser/dist/parse/cst-stringify.js +61 -0
- package/browser/dist/parse/cst-visit.js +97 -0
- package/{dist/parse/tokens.js → browser/dist/parse/cst.js} +12 -7
- package/browser/dist/parse/lexer.js +149 -125
- package/browser/dist/parse/parser.js +272 -196
- package/browser/dist/public-api.js +11 -14
- package/browser/dist/schema/Schema.js +28 -0
- package/browser/dist/{tags/failsafe → schema/common}/map.js +0 -0
- package/browser/dist/schema/common/null.js +13 -0
- package/browser/dist/{tags/failsafe → schema/common}/seq.js +1 -1
- package/browser/dist/{tags/failsafe → schema/common}/string.js +0 -0
- package/browser/dist/schema/core/bool.js +19 -0
- package/browser/dist/schema/core/float.js +40 -0
- package/browser/dist/schema/core/int.js +38 -0
- package/browser/dist/schema/core/schema.js +23 -0
- package/browser/dist/{tags/json.js → schema/json/schema.js} +5 -6
- package/browser/dist/schema/tags.js +79 -0
- package/browser/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
- package/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/browser/dist/schema/yaml-1.1/float.js +43 -0
- package/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/browser/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
- package/browser/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
- package/browser/dist/schema/yaml-1.1/schema.js +37 -0
- package/browser/dist/{tags → schema}/yaml-1.1/set.js +0 -0
- package/browser/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
- package/browser/dist/stringify/stringify.js +8 -6
- package/browser/dist/stringify/stringifyCollection.js +122 -0
- package/browser/dist/stringify/stringifyComment.js +14 -0
- package/browser/dist/stringify/stringifyDocument.js +64 -0
- package/browser/dist/stringify/stringifyPair.js +111 -0
- package/browser/dist/stringify/stringifyString.js +53 -52
- package/browser/dist/visit.js +20 -1
- package/dist/compose/compose-collection.d.ts +4 -4
- package/dist/compose/compose-collection.js +12 -9
- package/dist/compose/compose-doc.d.ts +4 -3
- package/dist/compose/compose-doc.js +23 -6
- package/dist/compose/compose-node.d.ts +15 -7
- package/dist/compose/compose-node.js +27 -17
- package/dist/compose/compose-scalar.d.ts +4 -3
- package/dist/compose/compose-scalar.js +20 -22
- package/dist/compose/composer.d.ts +28 -23
- package/dist/compose/composer.js +109 -79
- package/dist/compose/resolve-block-map.d.ts +5 -4
- package/dist/compose/resolve-block-map.js +41 -29
- package/dist/compose/resolve-block-scalar.d.ts +5 -3
- package/dist/compose/resolve-block-scalar.js +14 -17
- package/dist/compose/resolve-block-seq.d.ts +4 -4
- package/dist/compose/resolve-block-seq.js +21 -17
- package/dist/compose/resolve-end.d.ts +3 -2
- package/dist/compose/resolve-end.js +7 -8
- package/dist/compose/resolve-flow-collection.d.ts +4 -5
- package/dist/compose/resolve-flow-collection.js +157 -198
- package/dist/compose/resolve-flow-scalar.d.ts +5 -3
- package/dist/compose/resolve-flow-scalar.js +62 -26
- package/dist/compose/resolve-props.d.ts +16 -10
- package/dist/compose/resolve-props.js +72 -37
- package/dist/compose/util-contains-newline.d.ts +1 -1
- package/dist/compose/util-contains-newline.js +15 -12
- package/dist/compose/util-empty-scalar-position.d.ts +1 -1
- package/dist/compose/util-map-includes.d.ts +4 -0
- package/dist/compose/util-map-includes.js +19 -0
- package/dist/doc/Document.d.ts +35 -15
- package/dist/doc/Document.js +72 -97
- package/dist/doc/anchors.d.ts +24 -0
- package/dist/doc/anchors.js +77 -0
- package/dist/doc/createNode.d.ts +10 -11
- package/dist/doc/createNode.js +34 -18
- package/dist/doc/directives.d.ts +1 -0
- package/dist/doc/directives.js +5 -0
- package/dist/errors.d.ts +11 -8
- package/dist/errors.js +16 -12
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -3
- package/dist/nodes/Alias.d.ts +19 -9
- package/dist/nodes/Alias.js +51 -28
- package/dist/nodes/Collection.d.ts +9 -17
- package/dist/nodes/Collection.js +22 -91
- package/dist/nodes/Node.d.ts +10 -4
- package/dist/nodes/Node.js +9 -0
- package/dist/nodes/Pair.d.ts +10 -13
- package/dist/nodes/Pair.js +15 -230
- package/dist/nodes/Scalar.d.ts +6 -3
- package/dist/nodes/YAMLMap.d.ts +3 -3
- package/dist/nodes/YAMLMap.js +8 -4
- package/dist/nodes/YAMLSeq.d.ts +3 -3
- package/dist/nodes/YAMLSeq.js +7 -4
- package/dist/nodes/addPairToJSMap.d.ts +3 -0
- package/dist/nodes/addPairToJSMap.js +105 -0
- package/dist/nodes/toJS.d.ts +4 -5
- package/dist/nodes/toJS.js +12 -10
- package/dist/options.d.ts +41 -25
- package/dist/options.js +1 -2
- package/dist/parse/cst-scalar.d.ts +58 -0
- package/dist/parse/cst-scalar.js +223 -0
- package/dist/parse/cst-stringify.d.ts +8 -0
- package/dist/parse/cst-stringify.js +63 -0
- package/dist/parse/cst-visit.d.ts +39 -0
- package/dist/parse/cst-visit.js +99 -0
- package/dist/parse/{tokens.d.ts → cst.d.ts} +23 -7
- package/{browser/dist/parse/tokens.js → dist/parse/cst.js} +27 -1
- package/dist/parse/lexer.d.ts +7 -14
- package/dist/parse/lexer.js +150 -126
- package/dist/parse/parser.d.ts +31 -24
- package/dist/parse/parser.js +274 -198
- package/dist/public-api.d.ts +7 -7
- package/dist/public-api.js +11 -14
- package/dist/{doc → schema}/Schema.d.ts +6 -3
- package/dist/schema/Schema.js +30 -0
- package/dist/{tags/failsafe → schema/common}/map.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/map.js +0 -0
- package/dist/schema/common/null.d.ts +4 -0
- package/dist/schema/common/null.js +15 -0
- package/dist/{tags/failsafe → schema/common}/seq.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/seq.js +1 -1
- package/dist/{tags/failsafe → schema/common}/string.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/string.js +0 -0
- package/dist/schema/core/bool.d.ts +4 -0
- package/dist/schema/core/bool.js +21 -0
- package/dist/schema/core/float.d.ts +4 -0
- package/dist/schema/core/float.js +44 -0
- package/dist/schema/core/int.d.ts +4 -0
- package/dist/schema/core/int.js +42 -0
- package/dist/schema/core/schema.d.ts +1 -0
- package/dist/schema/core/schema.js +25 -0
- package/dist/schema/json/schema.d.ts +2 -0
- package/dist/{tags/json.js → schema/json/schema.js} +5 -6
- package/dist/schema/tags.d.ts +41 -0
- package/dist/schema/tags.js +82 -0
- package/dist/{tags → schema}/types.d.ts +3 -7
- package/dist/{tags → schema}/yaml-1.1/binary.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
- package/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/dist/schema/yaml-1.1/bool.js +29 -0
- package/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/dist/schema/yaml-1.1/float.js +47 -0
- package/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/dist/schema/yaml-1.1/int.js +76 -0
- package/dist/{tags → schema}/yaml-1.1/omap.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
- package/dist/{tags → schema}/yaml-1.1/pairs.d.ts +3 -2
- package/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
- package/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/dist/schema/yaml-1.1/schema.js +39 -0
- package/dist/{tags → schema}/yaml-1.1/set.d.ts +1 -1
- package/dist/{tags → schema}/yaml-1.1/set.js +0 -0
- package/dist/{tags → schema}/yaml-1.1/timestamp.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
- package/dist/stringify/stringify.d.ts +1 -2
- package/dist/stringify/stringify.js +8 -6
- package/dist/stringify/stringifyCollection.d.ts +21 -0
- package/dist/stringify/stringifyCollection.js +124 -0
- package/dist/stringify/stringifyComment.d.ts +2 -0
- package/dist/stringify/stringifyComment.js +17 -0
- package/dist/stringify/stringifyDocument.d.ts +3 -0
- package/dist/stringify/stringifyDocument.js +66 -0
- package/dist/stringify/stringifyPair.d.ts +3 -0
- package/dist/stringify/stringifyPair.js +113 -0
- package/dist/stringify/stringifyString.js +53 -52
- package/dist/test-events.d.ts +1 -2
- package/dist/test-events.js +25 -12
- package/dist/util.d.ts +1 -1
- package/dist/visit.d.ts +10 -1
- package/dist/visit.js +20 -1
- package/package.json +9 -8
- package/browser/dist/doc/Anchors.js +0 -102
- package/browser/dist/doc/Schema.js +0 -27
- package/browser/dist/doc/getSchemaTags.js +0 -30
- package/browser/dist/stringify/addComment.js +0 -17
- package/browser/dist/tags/core.js +0 -109
- package/browser/dist/tags/failsafe/index.js +0 -7
- package/browser/dist/tags/index.js +0 -34
- package/browser/dist/tags/yaml-1.1/index.js +0 -152
- package/dist/doc/Anchors.d.ts +0 -36
- package/dist/doc/Anchors.js +0 -104
- package/dist/doc/Schema.js +0 -29
- package/dist/doc/getSchemaTags.d.ts +0 -3
- package/dist/doc/getSchemaTags.js +0 -32
- package/dist/stringify/addComment.d.ts +0 -2
- package/dist/stringify/addComment.js +0 -20
- package/dist/tags/core.d.ts +0 -14
- package/dist/tags/core.js +0 -119
- package/dist/tags/failsafe/index.d.ts +0 -1
- package/dist/tags/failsafe/index.js +0 -9
- package/dist/tags/index.d.ts +0 -31
- package/dist/tags/index.js +0 -37
- package/dist/tags/json.d.ts +0 -2
- package/dist/tags/yaml-1.1/index.d.ts +0 -2
- package/dist/tags/yaml-1.1/index.js +0 -154
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BOM, DOCUMENT, FLOW_END, SCALAR } from './
|
|
1
|
+
import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.js';
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
START -> stream
|
|
@@ -79,9 +79,11 @@ function isEmpty(ch) {
|
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
82
|
+
const hexDigits = '0123456789ABCDEFabcdef'.split('');
|
|
83
|
+
const tagChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()".split('');
|
|
84
|
+
const invalidFlowScalarChars = ',[]{}'.split('');
|
|
85
|
+
const invalidAnchorChars = ' ,[]{}\n\r\t'.split('');
|
|
86
|
+
const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.includes(ch);
|
|
85
87
|
/**
|
|
86
88
|
* Splits an input string into lexical tokens, i.e. smaller strings that are
|
|
87
89
|
* easily identifiable by `tokens.tokenType()`.
|
|
@@ -98,13 +100,7 @@ const isNotIdentifierChar = (ch) => !ch || invalidIdentifierChars.includes(ch);
|
|
|
98
100
|
* - `\u{FEFF}` (Byte order mark): Emitted separately outside documents
|
|
99
101
|
*/
|
|
100
102
|
class Lexer {
|
|
101
|
-
|
|
102
|
-
* Define/initialise a YAML lexer. `push` will be called separately with each
|
|
103
|
-
* token when `lex()` is passed an input string.
|
|
104
|
-
*
|
|
105
|
-
* @public
|
|
106
|
-
*/
|
|
107
|
-
constructor(push) {
|
|
103
|
+
constructor() {
|
|
108
104
|
/**
|
|
109
105
|
* Flag indicating whether the end of the current buffer marks the end of
|
|
110
106
|
* all input
|
|
@@ -138,26 +134,28 @@ class Lexer {
|
|
|
138
134
|
this.indentNext = 0;
|
|
139
135
|
/** Indentation level of the current line. */
|
|
140
136
|
this.indentValue = 0;
|
|
137
|
+
/** Position of the next \n character. */
|
|
138
|
+
this.lineEndPos = null;
|
|
141
139
|
/** Stores the state of the lexer if reaching the end of incpomplete input */
|
|
142
140
|
this.next = null;
|
|
143
141
|
/** A pointer to `buffer`; the current position of the lexer. */
|
|
144
142
|
this.pos = 0;
|
|
145
|
-
this.push = push;
|
|
146
143
|
}
|
|
147
144
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* of the last line may be left as a buffer for the next call.
|
|
145
|
+
* Generate YAML tokens from the `source` string. If `incomplete`,
|
|
146
|
+
* a part of the last line may be left as a buffer for the next call.
|
|
151
147
|
*
|
|
152
|
-
* @
|
|
148
|
+
* @returns A generator of lexical tokens
|
|
153
149
|
*/
|
|
154
|
-
lex(source, incomplete) {
|
|
155
|
-
if (source)
|
|
150
|
+
*lex(source, incomplete = false) {
|
|
151
|
+
if (source) {
|
|
156
152
|
this.buffer = this.buffer ? this.buffer + source : source;
|
|
153
|
+
this.lineEndPos = null;
|
|
154
|
+
}
|
|
157
155
|
this.atEnd = !incomplete;
|
|
158
156
|
let next = this.next || 'stream';
|
|
159
157
|
while (next && (incomplete || this.hasChars(1)))
|
|
160
|
-
next = this.parseNext(next);
|
|
158
|
+
next = yield* this.parseNext(next);
|
|
161
159
|
}
|
|
162
160
|
atLineEnd() {
|
|
163
161
|
let i = this.pos;
|
|
@@ -196,7 +194,11 @@ class Lexer {
|
|
|
196
194
|
return offset;
|
|
197
195
|
}
|
|
198
196
|
getLine() {
|
|
199
|
-
let end = this.
|
|
197
|
+
let end = this.lineEndPos;
|
|
198
|
+
if (typeof end !== 'number' || (end !== -1 && end < this.pos)) {
|
|
199
|
+
end = this.buffer.indexOf('\n', this.pos);
|
|
200
|
+
this.lineEndPos = end;
|
|
201
|
+
}
|
|
200
202
|
if (end === -1)
|
|
201
203
|
return this.atEnd ? this.buffer.substring(this.pos) : null;
|
|
202
204
|
if (this.buffer[end - 1] === '\r')
|
|
@@ -209,38 +211,39 @@ class Lexer {
|
|
|
209
211
|
setNext(state) {
|
|
210
212
|
this.buffer = this.buffer.substring(this.pos);
|
|
211
213
|
this.pos = 0;
|
|
214
|
+
this.lineEndPos = null;
|
|
212
215
|
this.next = state;
|
|
213
216
|
return null;
|
|
214
217
|
}
|
|
215
218
|
peek(n) {
|
|
216
219
|
return this.buffer.substr(this.pos, n);
|
|
217
220
|
}
|
|
218
|
-
parseNext(next) {
|
|
221
|
+
*parseNext(next) {
|
|
219
222
|
switch (next) {
|
|
220
223
|
case 'stream':
|
|
221
|
-
return this.parseStream();
|
|
224
|
+
return yield* this.parseStream();
|
|
222
225
|
case 'line-start':
|
|
223
|
-
return this.parseLineStart();
|
|
226
|
+
return yield* this.parseLineStart();
|
|
224
227
|
case 'block-start':
|
|
225
|
-
return this.parseBlockStart();
|
|
228
|
+
return yield* this.parseBlockStart();
|
|
226
229
|
case 'doc':
|
|
227
|
-
return this.parseDocument();
|
|
230
|
+
return yield* this.parseDocument();
|
|
228
231
|
case 'flow':
|
|
229
|
-
return this.parseFlowCollection();
|
|
232
|
+
return yield* this.parseFlowCollection();
|
|
230
233
|
case 'quoted-scalar':
|
|
231
|
-
return this.parseQuotedScalar();
|
|
234
|
+
return yield* this.parseQuotedScalar();
|
|
232
235
|
case 'block-scalar':
|
|
233
|
-
return this.parseBlockScalar();
|
|
236
|
+
return yield* this.parseBlockScalar();
|
|
234
237
|
case 'plain-scalar':
|
|
235
|
-
return this.parsePlainScalar();
|
|
238
|
+
return yield* this.parsePlainScalar();
|
|
236
239
|
}
|
|
237
240
|
}
|
|
238
|
-
parseStream() {
|
|
241
|
+
*parseStream() {
|
|
239
242
|
let line = this.getLine();
|
|
240
243
|
if (line === null)
|
|
241
244
|
return this.setNext('stream');
|
|
242
245
|
if (line[0] === BOM) {
|
|
243
|
-
this.pushCount(1);
|
|
246
|
+
yield* this.pushCount(1);
|
|
244
247
|
line = line.substring(1);
|
|
245
248
|
}
|
|
246
249
|
if (line[0] === '%') {
|
|
@@ -258,21 +261,21 @@ class Lexer {
|
|
|
258
261
|
else
|
|
259
262
|
break;
|
|
260
263
|
}
|
|
261
|
-
const n = this.pushCount(dirEnd) + this.pushSpaces(true);
|
|
262
|
-
this.pushCount(line.length - n); // possible comment
|
|
264
|
+
const n = (yield* this.pushCount(dirEnd)) + (yield* this.pushSpaces(true));
|
|
265
|
+
yield* this.pushCount(line.length - n); // possible comment
|
|
263
266
|
this.pushNewline();
|
|
264
267
|
return 'stream';
|
|
265
268
|
}
|
|
266
269
|
if (this.atLineEnd()) {
|
|
267
|
-
const sp = this.pushSpaces(true);
|
|
268
|
-
this.pushCount(line.length - sp);
|
|
269
|
-
this.pushNewline();
|
|
270
|
+
const sp = yield* this.pushSpaces(true);
|
|
271
|
+
yield* this.pushCount(line.length - sp);
|
|
272
|
+
yield* this.pushNewline();
|
|
270
273
|
return 'stream';
|
|
271
274
|
}
|
|
272
|
-
|
|
273
|
-
return this.parseLineStart();
|
|
275
|
+
yield DOCUMENT;
|
|
276
|
+
return yield* this.parseLineStart();
|
|
274
277
|
}
|
|
275
|
-
parseLineStart() {
|
|
278
|
+
*parseLineStart() {
|
|
276
279
|
const ch = this.charAt(0);
|
|
277
280
|
if (!ch && !this.atEnd)
|
|
278
281
|
return this.setNext('line-start');
|
|
@@ -281,80 +284,80 @@ class Lexer {
|
|
|
281
284
|
return this.setNext('line-start');
|
|
282
285
|
const s = this.peek(3);
|
|
283
286
|
if (s === '---' && isEmpty(this.charAt(3))) {
|
|
284
|
-
this.pushCount(3);
|
|
287
|
+
yield* this.pushCount(3);
|
|
285
288
|
this.indentValue = 0;
|
|
286
289
|
this.indentNext = 0;
|
|
287
290
|
return 'doc';
|
|
288
291
|
}
|
|
289
292
|
else if (s === '...' && isEmpty(this.charAt(3))) {
|
|
290
|
-
this.pushCount(3);
|
|
293
|
+
yield* this.pushCount(3);
|
|
291
294
|
return 'stream';
|
|
292
295
|
}
|
|
293
296
|
}
|
|
294
|
-
this.indentValue = this.pushSpaces(false);
|
|
297
|
+
this.indentValue = yield* this.pushSpaces(false);
|
|
295
298
|
if (this.indentNext > this.indentValue && !isEmpty(this.charAt(1)))
|
|
296
299
|
this.indentNext = this.indentValue;
|
|
297
|
-
return this.parseBlockStart();
|
|
300
|
+
return yield* this.parseBlockStart();
|
|
298
301
|
}
|
|
299
|
-
parseBlockStart() {
|
|
302
|
+
*parseBlockStart() {
|
|
300
303
|
const [ch0, ch1] = this.peek(2);
|
|
301
304
|
if (!ch1 && !this.atEnd)
|
|
302
305
|
return this.setNext('block-start');
|
|
303
306
|
if ((ch0 === '-' || ch0 === '?' || ch0 === ':') && isEmpty(ch1)) {
|
|
304
|
-
const n = this.pushCount(1) + this.pushSpaces(true);
|
|
307
|
+
const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
|
|
305
308
|
this.indentNext = this.indentValue + 1;
|
|
306
309
|
this.indentValue += n;
|
|
307
|
-
return this.parseBlockStart();
|
|
310
|
+
return yield* this.parseBlockStart();
|
|
308
311
|
}
|
|
309
312
|
return 'doc';
|
|
310
313
|
}
|
|
311
|
-
parseDocument() {
|
|
312
|
-
this.pushSpaces(true);
|
|
314
|
+
*parseDocument() {
|
|
315
|
+
yield* this.pushSpaces(true);
|
|
313
316
|
const line = this.getLine();
|
|
314
317
|
if (line === null)
|
|
315
318
|
return this.setNext('doc');
|
|
316
|
-
let n = this.pushIndicators();
|
|
319
|
+
let n = yield* this.pushIndicators();
|
|
317
320
|
switch (line[n]) {
|
|
318
321
|
case '#':
|
|
319
|
-
this.pushCount(line.length - n);
|
|
322
|
+
yield* this.pushCount(line.length - n);
|
|
320
323
|
// fallthrough
|
|
321
324
|
case undefined:
|
|
322
|
-
this.pushNewline();
|
|
323
|
-
return this.parseLineStart();
|
|
325
|
+
yield* this.pushNewline();
|
|
326
|
+
return yield* this.parseLineStart();
|
|
324
327
|
case '{':
|
|
325
328
|
case '[':
|
|
326
|
-
this.pushCount(1);
|
|
329
|
+
yield* this.pushCount(1);
|
|
327
330
|
this.flowKey = false;
|
|
328
331
|
this.flowLevel = 1;
|
|
329
332
|
return 'flow';
|
|
330
333
|
case '}':
|
|
331
334
|
case ']':
|
|
332
335
|
// this is an error
|
|
333
|
-
this.pushCount(1);
|
|
336
|
+
yield* this.pushCount(1);
|
|
334
337
|
return 'doc';
|
|
335
338
|
case '*':
|
|
336
|
-
this.pushUntil(
|
|
339
|
+
yield* this.pushUntil(isNotAnchorChar);
|
|
337
340
|
return 'doc';
|
|
338
341
|
case '"':
|
|
339
342
|
case "'":
|
|
340
|
-
return this.parseQuotedScalar();
|
|
343
|
+
return yield* this.parseQuotedScalar();
|
|
341
344
|
case '|':
|
|
342
345
|
case '>':
|
|
343
|
-
n += this.parseBlockScalarHeader();
|
|
344
|
-
n += this.pushSpaces(true);
|
|
345
|
-
this.pushCount(line.length - n);
|
|
346
|
-
this.pushNewline();
|
|
347
|
-
return this.parseBlockScalar();
|
|
346
|
+
n += yield* this.parseBlockScalarHeader();
|
|
347
|
+
n += yield* this.pushSpaces(true);
|
|
348
|
+
yield* this.pushCount(line.length - n);
|
|
349
|
+
yield* this.pushNewline();
|
|
350
|
+
return yield* this.parseBlockScalar();
|
|
348
351
|
default:
|
|
349
|
-
return this.parsePlainScalar();
|
|
352
|
+
return yield* this.parsePlainScalar();
|
|
350
353
|
}
|
|
351
354
|
}
|
|
352
|
-
parseFlowCollection() {
|
|
355
|
+
*parseFlowCollection() {
|
|
353
356
|
let nl, sp;
|
|
354
357
|
let indent = -1;
|
|
355
358
|
do {
|
|
356
|
-
nl = this.pushNewline();
|
|
357
|
-
sp = this.pushSpaces(true);
|
|
359
|
+
nl = yield* this.pushNewline();
|
|
360
|
+
sp = yield* this.pushSpaces(true);
|
|
358
361
|
if (nl > 0)
|
|
359
362
|
this.indentValue = indent = sp;
|
|
360
363
|
} while (nl + sp > 0);
|
|
@@ -374,54 +377,54 @@ class Lexer {
|
|
|
374
377
|
if (!atFlowEndMarker) {
|
|
375
378
|
// this is an error
|
|
376
379
|
this.flowLevel = 0;
|
|
377
|
-
|
|
378
|
-
return this.parseLineStart();
|
|
380
|
+
yield FLOW_END;
|
|
381
|
+
return yield* this.parseLineStart();
|
|
379
382
|
}
|
|
380
383
|
}
|
|
381
384
|
let n = 0;
|
|
382
385
|
while (line[n] === ',')
|
|
383
|
-
n += this.pushCount(1) + this.pushSpaces(true);
|
|
384
|
-
n += this.pushIndicators();
|
|
386
|
+
n += (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
|
|
387
|
+
n += yield* this.pushIndicators();
|
|
385
388
|
switch (line[n]) {
|
|
386
389
|
case undefined:
|
|
387
390
|
return 'flow';
|
|
388
391
|
case '#':
|
|
389
|
-
this.pushCount(line.length - n);
|
|
392
|
+
yield* this.pushCount(line.length - n);
|
|
390
393
|
return 'flow';
|
|
391
394
|
case '{':
|
|
392
395
|
case '[':
|
|
393
|
-
this.pushCount(1);
|
|
396
|
+
yield* this.pushCount(1);
|
|
394
397
|
this.flowKey = false;
|
|
395
398
|
this.flowLevel += 1;
|
|
396
399
|
return 'flow';
|
|
397
400
|
case '}':
|
|
398
401
|
case ']':
|
|
399
|
-
this.pushCount(1);
|
|
402
|
+
yield* this.pushCount(1);
|
|
400
403
|
this.flowKey = true;
|
|
401
404
|
this.flowLevel -= 1;
|
|
402
405
|
return this.flowLevel ? 'flow' : 'doc';
|
|
403
406
|
case '*':
|
|
404
|
-
this.pushUntil(
|
|
407
|
+
yield* this.pushUntil(isNotAnchorChar);
|
|
405
408
|
return 'flow';
|
|
406
409
|
case '"':
|
|
407
410
|
case "'":
|
|
408
411
|
this.flowKey = true;
|
|
409
|
-
return this.parseQuotedScalar();
|
|
412
|
+
return yield* this.parseQuotedScalar();
|
|
410
413
|
case ':': {
|
|
411
414
|
const next = this.charAt(1);
|
|
412
415
|
if (this.flowKey || isEmpty(next) || next === ',') {
|
|
413
|
-
this.pushCount(1);
|
|
414
|
-
this.pushSpaces(true);
|
|
416
|
+
yield* this.pushCount(1);
|
|
417
|
+
yield* this.pushSpaces(true);
|
|
415
418
|
return 'flow';
|
|
416
419
|
}
|
|
417
420
|
}
|
|
418
421
|
// fallthrough
|
|
419
422
|
default:
|
|
420
423
|
this.flowKey = false;
|
|
421
|
-
return this.parsePlainScalar();
|
|
424
|
+
return yield* this.parsePlainScalar();
|
|
422
425
|
}
|
|
423
426
|
}
|
|
424
|
-
parseQuotedScalar() {
|
|
427
|
+
*parseQuotedScalar() {
|
|
425
428
|
const quote = this.charAt(0);
|
|
426
429
|
let end = this.buffer.indexOf(quote, this.pos + 1);
|
|
427
430
|
if (quote === "'") {
|
|
@@ -439,17 +442,19 @@ class Lexer {
|
|
|
439
442
|
end = this.buffer.indexOf('"', end + 1);
|
|
440
443
|
}
|
|
441
444
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
+
// Only looking for newlines within the quotes
|
|
446
|
+
const qb = this.buffer.substring(0, end);
|
|
447
|
+
let nl = qb.indexOf('\n', this.pos);
|
|
448
|
+
if (nl !== -1) {
|
|
449
|
+
while (nl !== -1) {
|
|
445
450
|
const cs = this.continueScalar(nl + 1);
|
|
446
451
|
if (cs === -1)
|
|
447
452
|
break;
|
|
448
|
-
nl =
|
|
453
|
+
nl = qb.indexOf('\n', cs);
|
|
449
454
|
}
|
|
450
|
-
if (nl !== -1
|
|
455
|
+
if (nl !== -1) {
|
|
451
456
|
// this is an error caused by an unexpected unindent
|
|
452
|
-
end = nl - 1;
|
|
457
|
+
end = nl - (qb[nl - 1] === '\r' ? 2 : 1);
|
|
453
458
|
}
|
|
454
459
|
}
|
|
455
460
|
if (end === -1) {
|
|
@@ -457,10 +462,10 @@ class Lexer {
|
|
|
457
462
|
return this.setNext('quoted-scalar');
|
|
458
463
|
end = this.buffer.length;
|
|
459
464
|
}
|
|
460
|
-
this.pushToIndex(end + 1, false);
|
|
465
|
+
yield* this.pushToIndex(end + 1, false);
|
|
461
466
|
return this.flowLevel ? 'flow' : 'doc';
|
|
462
467
|
}
|
|
463
|
-
parseBlockScalarHeader() {
|
|
468
|
+
*parseBlockScalarHeader() {
|
|
464
469
|
this.blockScalarIndent = -1;
|
|
465
470
|
this.blockScalarKeep = false;
|
|
466
471
|
let i = this.pos;
|
|
@@ -473,9 +478,9 @@ class Lexer {
|
|
|
473
478
|
else if (ch !== '-')
|
|
474
479
|
break;
|
|
475
480
|
}
|
|
476
|
-
return this.pushUntil(ch => isEmpty(ch) || ch === '#');
|
|
481
|
+
return yield* this.pushUntil(ch => isEmpty(ch) || ch === '#');
|
|
477
482
|
}
|
|
478
|
-
parseBlockScalar() {
|
|
483
|
+
*parseBlockScalar() {
|
|
479
484
|
let nl = this.pos - 1; // may be -1 if this.pos === 0
|
|
480
485
|
let indent = 0;
|
|
481
486
|
let ch;
|
|
@@ -532,11 +537,11 @@ class Lexer {
|
|
|
532
537
|
break;
|
|
533
538
|
} while (true);
|
|
534
539
|
}
|
|
535
|
-
|
|
536
|
-
this.pushToIndex(nl + 1, true);
|
|
537
|
-
return this.parseLineStart();
|
|
540
|
+
yield SCALAR;
|
|
541
|
+
yield* this.pushToIndex(nl + 1, true);
|
|
542
|
+
return yield* this.parseLineStart();
|
|
538
543
|
}
|
|
539
|
-
parsePlainScalar() {
|
|
544
|
+
*parsePlainScalar() {
|
|
540
545
|
const inFlow = this.flowLevel > 0;
|
|
541
546
|
let end = this.pos - 1;
|
|
542
547
|
let i = this.pos - 1;
|
|
@@ -549,17 +554,18 @@ class Lexer {
|
|
|
549
554
|
end = i;
|
|
550
555
|
}
|
|
551
556
|
else if (isEmpty(ch)) {
|
|
552
|
-
|
|
553
|
-
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
|
|
554
|
-
break;
|
|
557
|
+
let next = this.buffer[i + 1];
|
|
555
558
|
if (ch === '\r') {
|
|
556
559
|
if (next === '\n') {
|
|
557
560
|
i += 1;
|
|
558
561
|
ch = '\n';
|
|
562
|
+
next = this.buffer[i + 1];
|
|
559
563
|
}
|
|
560
564
|
else
|
|
561
565
|
end = i;
|
|
562
566
|
}
|
|
567
|
+
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
|
|
568
|
+
break;
|
|
563
569
|
if (ch === '\n') {
|
|
564
570
|
const cs = this.continueScalar(i + 1);
|
|
565
571
|
if (cs === -1)
|
|
@@ -575,69 +581,87 @@ class Lexer {
|
|
|
575
581
|
}
|
|
576
582
|
if (!ch && !this.atEnd)
|
|
577
583
|
return this.setNext('plain-scalar');
|
|
578
|
-
|
|
579
|
-
this.pushToIndex(end + 1, true);
|
|
584
|
+
yield SCALAR;
|
|
585
|
+
yield* this.pushToIndex(end + 1, true);
|
|
580
586
|
return inFlow ? 'flow' : 'doc';
|
|
581
587
|
}
|
|
582
|
-
pushCount(n) {
|
|
588
|
+
*pushCount(n) {
|
|
583
589
|
if (n > 0) {
|
|
584
|
-
this.
|
|
590
|
+
yield this.buffer.substr(this.pos, n);
|
|
585
591
|
this.pos += n;
|
|
586
592
|
return n;
|
|
587
593
|
}
|
|
588
594
|
return 0;
|
|
589
595
|
}
|
|
590
|
-
pushToIndex(i, allowEmpty) {
|
|
596
|
+
*pushToIndex(i, allowEmpty) {
|
|
591
597
|
const s = this.buffer.slice(this.pos, i);
|
|
592
598
|
if (s) {
|
|
593
|
-
|
|
599
|
+
yield s;
|
|
594
600
|
this.pos += s.length;
|
|
595
601
|
return s.length;
|
|
596
602
|
}
|
|
597
603
|
else if (allowEmpty)
|
|
598
|
-
|
|
604
|
+
yield '';
|
|
599
605
|
return 0;
|
|
600
606
|
}
|
|
601
|
-
pushIndicators() {
|
|
607
|
+
*pushIndicators() {
|
|
602
608
|
switch (this.charAt(0)) {
|
|
603
609
|
case '!':
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
this.pushIndicators());
|
|
608
|
-
// fallthrough
|
|
610
|
+
return ((yield* this.pushTag()) +
|
|
611
|
+
(yield* this.pushSpaces(true)) +
|
|
612
|
+
(yield* this.pushIndicators()));
|
|
609
613
|
case '&':
|
|
610
|
-
return (this.pushUntil(
|
|
611
|
-
this.pushSpaces(true) +
|
|
612
|
-
this.pushIndicators());
|
|
614
|
+
return ((yield* this.pushUntil(isNotAnchorChar)) +
|
|
615
|
+
(yield* this.pushSpaces(true)) +
|
|
616
|
+
(yield* this.pushIndicators()));
|
|
613
617
|
case ':':
|
|
614
618
|
case '?': // this is an error outside flow collections
|
|
615
619
|
case '-': // this is an error
|
|
616
620
|
if (isEmpty(this.charAt(1))) {
|
|
617
621
|
if (this.flowLevel === 0)
|
|
618
622
|
this.indentNext = this.indentValue + 1;
|
|
619
|
-
return (this.pushCount(1)
|
|
623
|
+
return ((yield* this.pushCount(1)) +
|
|
624
|
+
(yield* this.pushSpaces(true)) +
|
|
625
|
+
(yield* this.pushIndicators()));
|
|
620
626
|
}
|
|
621
627
|
}
|
|
622
628
|
return 0;
|
|
623
629
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
ch
|
|
629
|
-
|
|
630
|
+
*pushTag() {
|
|
631
|
+
if (this.charAt(1) === '<') {
|
|
632
|
+
let i = this.pos + 2;
|
|
633
|
+
let ch = this.buffer[i];
|
|
634
|
+
while (!isEmpty(ch) && ch !== '>')
|
|
635
|
+
ch = this.buffer[++i];
|
|
636
|
+
return yield* this.pushToIndex(ch === '>' ? i + 1 : i, false);
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
let i = this.pos + 1;
|
|
640
|
+
let ch = this.buffer[i];
|
|
641
|
+
while (ch) {
|
|
642
|
+
if (tagChars.includes(ch))
|
|
643
|
+
ch = this.buffer[++i];
|
|
644
|
+
else if (ch === '%' &&
|
|
645
|
+
hexDigits.includes(this.buffer[i + 1]) &&
|
|
646
|
+
hexDigits.includes(this.buffer[i + 2])) {
|
|
647
|
+
ch = this.buffer[(i += 3)];
|
|
648
|
+
}
|
|
649
|
+
else
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
return yield* this.pushToIndex(i, false);
|
|
653
|
+
}
|
|
630
654
|
}
|
|
631
|
-
pushNewline() {
|
|
655
|
+
*pushNewline() {
|
|
632
656
|
const ch = this.buffer[this.pos];
|
|
633
657
|
if (ch === '\n')
|
|
634
|
-
return this.pushCount(1);
|
|
658
|
+
return yield* this.pushCount(1);
|
|
635
659
|
else if (ch === '\r' && this.charAt(1) === '\n')
|
|
636
|
-
return this.pushCount(2);
|
|
660
|
+
return yield* this.pushCount(2);
|
|
637
661
|
else
|
|
638
662
|
return 0;
|
|
639
663
|
}
|
|
640
|
-
pushSpaces(allowTabs) {
|
|
664
|
+
*pushSpaces(allowTabs) {
|
|
641
665
|
let i = this.pos - 1;
|
|
642
666
|
let ch;
|
|
643
667
|
do {
|
|
@@ -645,17 +669,17 @@ class Lexer {
|
|
|
645
669
|
} while (ch === ' ' || (allowTabs && ch === '\t'));
|
|
646
670
|
const n = i - this.pos;
|
|
647
671
|
if (n > 0) {
|
|
648
|
-
this.
|
|
672
|
+
yield this.buffer.substr(this.pos, n);
|
|
649
673
|
this.pos = i;
|
|
650
674
|
}
|
|
651
675
|
return n;
|
|
652
676
|
}
|
|
653
|
-
pushUntil(test) {
|
|
677
|
+
*pushUntil(test) {
|
|
654
678
|
let i = this.pos;
|
|
655
679
|
let ch = this.buffer[i];
|
|
656
680
|
while (!test(ch))
|
|
657
681
|
ch = this.buffer[++i];
|
|
658
|
-
return this.pushToIndex(i, false);
|
|
682
|
+
return yield* this.pushToIndex(i, false);
|
|
659
683
|
}
|
|
660
684
|
}
|
|
661
685
|
|