yaml 2.0.0-4 → 2.0.0-5

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.
Files changed (210) hide show
  1. package/README.md +5 -5
  2. package/browser/dist/compose/compose-collection.js +12 -9
  3. package/browser/dist/compose/compose-doc.js +23 -6
  4. package/browser/dist/compose/compose-node.js +20 -17
  5. package/browser/dist/compose/compose-scalar.js +20 -23
  6. package/browser/dist/compose/composer.js +105 -76
  7. package/browser/dist/compose/resolve-block-map.js +38 -29
  8. package/browser/dist/compose/resolve-block-scalar.js +14 -17
  9. package/browser/dist/compose/resolve-block-seq.js +21 -17
  10. package/browser/dist/compose/resolve-end.js +6 -7
  11. package/browser/dist/compose/resolve-flow-collection.js +153 -199
  12. package/browser/dist/compose/resolve-flow-scalar.js +49 -25
  13. package/browser/dist/compose/resolve-props.js +47 -35
  14. package/browser/dist/compose/util-contains-newline.js +15 -12
  15. package/browser/dist/doc/Document.js +50 -99
  16. package/browser/dist/doc/anchors.js +72 -0
  17. package/browser/dist/doc/createNode.js +27 -17
  18. package/browser/dist/errors.js +16 -12
  19. package/browser/dist/index.js +3 -3
  20. package/browser/dist/nodes/Alias.js +51 -28
  21. package/browser/dist/nodes/Collection.js +5 -83
  22. package/browser/dist/nodes/Node.js +2 -1
  23. package/browser/dist/nodes/Pair.js +9 -232
  24. package/browser/dist/nodes/YAMLMap.js +8 -4
  25. package/browser/dist/nodes/YAMLSeq.js +7 -4
  26. package/browser/dist/nodes/addPairToJSMap.js +103 -0
  27. package/browser/dist/nodes/toJS.js +12 -10
  28. package/browser/dist/options.js +0 -2
  29. package/browser/dist/parse/cst-scalar.js +219 -0
  30. package/browser/dist/parse/cst-stringify.js +61 -0
  31. package/browser/dist/parse/cst-visit.js +97 -0
  32. package/{dist/parse/tokens.js → browser/dist/parse/cst.js} +12 -7
  33. package/browser/dist/parse/lexer.js +99 -105
  34. package/browser/dist/parse/parser.js +219 -144
  35. package/browser/dist/public-api.js +11 -14
  36. package/browser/dist/schema/Schema.js +23 -0
  37. package/browser/dist/{tags/failsafe → schema/common}/map.js +0 -0
  38. package/browser/dist/schema/common/null.js +13 -0
  39. package/browser/dist/{tags/failsafe → schema/common}/seq.js +1 -1
  40. package/browser/dist/{tags/failsafe → schema/common}/string.js +0 -0
  41. package/browser/dist/schema/core/bool.js +19 -0
  42. package/browser/dist/schema/core/float.js +40 -0
  43. package/browser/dist/schema/core/int.js +38 -0
  44. package/browser/dist/schema/core/schema.js +23 -0
  45. package/browser/dist/{tags/json.js → schema/json/schema.js} +5 -6
  46. package/browser/dist/schema/tags.js +79 -0
  47. package/browser/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
  48. package/browser/dist/schema/yaml-1.1/bool.js +26 -0
  49. package/browser/dist/schema/yaml-1.1/float.js +43 -0
  50. package/browser/dist/schema/yaml-1.1/int.js +71 -0
  51. package/browser/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
  52. package/browser/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
  53. package/browser/dist/schema/yaml-1.1/schema.js +37 -0
  54. package/browser/dist/{tags → schema}/yaml-1.1/set.js +0 -0
  55. package/browser/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
  56. package/browser/dist/stringify/addComment.js +1 -7
  57. package/browser/dist/stringify/stringify.js +8 -6
  58. package/browser/dist/stringify/stringifyCollection.js +108 -0
  59. package/browser/dist/stringify/stringifyDocument.js +61 -0
  60. package/browser/dist/stringify/stringifyPair.js +113 -0
  61. package/browser/dist/stringify/stringifyString.js +53 -52
  62. package/browser/dist/visit.js +20 -1
  63. package/dist/compose/compose-collection.d.ts +4 -4
  64. package/dist/compose/compose-collection.js +12 -9
  65. package/dist/compose/compose-doc.d.ts +4 -3
  66. package/dist/compose/compose-doc.js +23 -6
  67. package/dist/compose/compose-node.d.ts +15 -7
  68. package/dist/compose/compose-node.js +20 -17
  69. package/dist/compose/compose-scalar.d.ts +4 -3
  70. package/dist/compose/compose-scalar.js +19 -22
  71. package/dist/compose/composer.d.ts +28 -23
  72. package/dist/compose/composer.js +106 -77
  73. package/dist/compose/resolve-block-map.d.ts +4 -4
  74. package/dist/compose/resolve-block-map.js +38 -29
  75. package/dist/compose/resolve-block-scalar.d.ts +5 -3
  76. package/dist/compose/resolve-block-scalar.js +14 -17
  77. package/dist/compose/resolve-block-seq.d.ts +4 -4
  78. package/dist/compose/resolve-block-seq.js +21 -17
  79. package/dist/compose/resolve-end.d.ts +3 -2
  80. package/dist/compose/resolve-end.js +6 -7
  81. package/dist/compose/resolve-flow-collection.d.ts +4 -5
  82. package/dist/compose/resolve-flow-collection.js +152 -198
  83. package/dist/compose/resolve-flow-scalar.d.ts +5 -3
  84. package/dist/compose/resolve-flow-scalar.js +49 -25
  85. package/dist/compose/resolve-props.d.ts +17 -10
  86. package/dist/compose/resolve-props.js +47 -35
  87. package/dist/compose/util-contains-newline.d.ts +1 -1
  88. package/dist/compose/util-contains-newline.js +15 -12
  89. package/dist/compose/util-empty-scalar-position.d.ts +1 -1
  90. package/dist/doc/Document.d.ts +27 -15
  91. package/dist/doc/Document.js +48 -97
  92. package/dist/doc/anchors.d.ts +24 -0
  93. package/dist/doc/anchors.js +77 -0
  94. package/dist/doc/createNode.d.ts +8 -10
  95. package/dist/doc/createNode.js +26 -16
  96. package/dist/errors.d.ts +11 -8
  97. package/dist/errors.js +16 -12
  98. package/dist/index.d.ts +5 -3
  99. package/dist/index.js +3 -3
  100. package/dist/nodes/Alias.d.ts +19 -9
  101. package/dist/nodes/Alias.js +51 -28
  102. package/dist/nodes/Collection.d.ts +3 -17
  103. package/dist/nodes/Collection.js +4 -82
  104. package/dist/nodes/Node.d.ts +6 -4
  105. package/dist/nodes/Node.js +2 -0
  106. package/dist/nodes/Pair.d.ts +6 -11
  107. package/dist/nodes/Pair.js +8 -231
  108. package/dist/nodes/Scalar.d.ts +6 -3
  109. package/dist/nodes/YAMLMap.d.ts +3 -3
  110. package/dist/nodes/YAMLMap.js +8 -4
  111. package/dist/nodes/YAMLSeq.d.ts +3 -3
  112. package/dist/nodes/YAMLSeq.js +7 -4
  113. package/dist/nodes/addPairToJSMap.d.ts +3 -0
  114. package/dist/nodes/addPairToJSMap.js +105 -0
  115. package/dist/nodes/toJS.d.ts +4 -5
  116. package/dist/nodes/toJS.js +12 -10
  117. package/dist/options.d.ts +20 -26
  118. package/dist/options.js +0 -2
  119. package/dist/parse/cst-scalar.d.ts +58 -0
  120. package/dist/parse/cst-scalar.js +223 -0
  121. package/dist/parse/cst-stringify.d.ts +8 -0
  122. package/dist/parse/cst-stringify.js +63 -0
  123. package/dist/parse/cst-visit.d.ts +39 -0
  124. package/dist/parse/cst-visit.js +99 -0
  125. package/dist/parse/{tokens.d.ts → cst.d.ts} +23 -7
  126. package/{browser/dist/parse/tokens.js → dist/parse/cst.js} +27 -1
  127. package/dist/parse/lexer.d.ts +4 -13
  128. package/dist/parse/lexer.js +100 -106
  129. package/dist/parse/parser.d.ts +30 -24
  130. package/dist/parse/parser.js +221 -146
  131. package/dist/public-api.d.ts +7 -7
  132. package/dist/public-api.js +11 -14
  133. package/dist/{doc → schema}/Schema.d.ts +5 -3
  134. package/dist/schema/Schema.js +25 -0
  135. package/dist/{tags/failsafe → schema/common}/map.d.ts +0 -0
  136. package/dist/{tags/failsafe → schema/common}/map.js +0 -0
  137. package/dist/schema/common/null.d.ts +4 -0
  138. package/dist/schema/common/null.js +15 -0
  139. package/dist/{tags/failsafe → schema/common}/seq.d.ts +0 -0
  140. package/dist/{tags/failsafe → schema/common}/seq.js +1 -1
  141. package/dist/{tags/failsafe → schema/common}/string.d.ts +0 -0
  142. package/dist/{tags/failsafe → schema/common}/string.js +0 -0
  143. package/dist/schema/core/bool.d.ts +4 -0
  144. package/dist/schema/core/bool.js +21 -0
  145. package/dist/schema/core/float.d.ts +4 -0
  146. package/dist/schema/core/float.js +44 -0
  147. package/dist/schema/core/int.d.ts +4 -0
  148. package/dist/schema/core/int.js +42 -0
  149. package/dist/schema/core/schema.d.ts +1 -0
  150. package/dist/schema/core/schema.js +25 -0
  151. package/dist/schema/json/schema.d.ts +2 -0
  152. package/dist/{tags/json.js → schema/json/schema.js} +5 -6
  153. package/dist/schema/tags.d.ts +41 -0
  154. package/dist/schema/tags.js +82 -0
  155. package/dist/{tags → schema}/types.d.ts +3 -7
  156. package/dist/{tags → schema}/yaml-1.1/binary.d.ts +0 -0
  157. package/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
  158. package/dist/schema/yaml-1.1/bool.d.ts +7 -0
  159. package/dist/schema/yaml-1.1/bool.js +29 -0
  160. package/dist/schema/yaml-1.1/float.d.ts +4 -0
  161. package/dist/schema/yaml-1.1/float.js +47 -0
  162. package/dist/schema/yaml-1.1/int.d.ts +5 -0
  163. package/dist/schema/yaml-1.1/int.js +76 -0
  164. package/dist/{tags → schema}/yaml-1.1/omap.d.ts +0 -0
  165. package/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
  166. package/dist/{tags → schema}/yaml-1.1/pairs.d.ts +3 -2
  167. package/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
  168. package/dist/schema/yaml-1.1/schema.d.ts +1 -0
  169. package/dist/schema/yaml-1.1/schema.js +39 -0
  170. package/dist/{tags → schema}/yaml-1.1/set.d.ts +1 -1
  171. package/dist/{tags → schema}/yaml-1.1/set.js +0 -0
  172. package/dist/{tags → schema}/yaml-1.1/timestamp.d.ts +0 -0
  173. package/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
  174. package/dist/stringify/addComment.js +0 -7
  175. package/dist/stringify/stringify.d.ts +1 -2
  176. package/dist/stringify/stringify.js +8 -6
  177. package/dist/stringify/stringifyCollection.d.ts +21 -0
  178. package/dist/stringify/stringifyCollection.js +110 -0
  179. package/dist/stringify/stringifyDocument.d.ts +3 -0
  180. package/dist/stringify/stringifyDocument.js +63 -0
  181. package/dist/stringify/stringifyPair.d.ts +3 -0
  182. package/dist/stringify/stringifyPair.js +115 -0
  183. package/dist/stringify/stringifyString.js +53 -52
  184. package/dist/test-events.d.ts +1 -2
  185. package/dist/test-events.js +25 -12
  186. package/dist/util.d.ts +1 -1
  187. package/dist/visit.d.ts +10 -1
  188. package/dist/visit.js +20 -1
  189. package/package.json +4 -3
  190. package/browser/dist/doc/Anchors.js +0 -102
  191. package/browser/dist/doc/Schema.js +0 -27
  192. package/browser/dist/doc/getSchemaTags.js +0 -30
  193. package/browser/dist/tags/core.js +0 -109
  194. package/browser/dist/tags/failsafe/index.js +0 -7
  195. package/browser/dist/tags/index.js +0 -34
  196. package/browser/dist/tags/yaml-1.1/index.js +0 -152
  197. package/dist/doc/Anchors.d.ts +0 -36
  198. package/dist/doc/Anchors.js +0 -104
  199. package/dist/doc/Schema.js +0 -29
  200. package/dist/doc/getSchemaTags.d.ts +0 -3
  201. package/dist/doc/getSchemaTags.js +0 -32
  202. package/dist/tags/core.d.ts +0 -14
  203. package/dist/tags/core.js +0 -119
  204. package/dist/tags/failsafe/index.d.ts +0 -1
  205. package/dist/tags/failsafe/index.js +0 -9
  206. package/dist/tags/index.d.ts +0 -31
  207. package/dist/tags/index.js +0 -37
  208. package/dist/tags/json.d.ts +0 -2
  209. package/dist/tags/yaml-1.1/index.d.ts +0 -2
  210. package/dist/tags/yaml-1.1/index.js +0 -154
@@ -1,4 +1,4 @@
1
- import { BOM, DOCUMENT, FLOW_END, SCALAR } from './tokens.js';
1
+ import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.js';
2
2
 
3
3
  /*
4
4
  START -> stream
@@ -98,13 +98,7 @@ const isNotIdentifierChar = (ch) => !ch || invalidIdentifierChars.includes(ch);
98
98
  * - `\u{FEFF}` (Byte order mark): Emitted separately outside documents
99
99
  */
100
100
  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) {
101
+ constructor() {
108
102
  /**
109
103
  * Flag indicating whether the end of the current buffer marks the end of
110
104
  * all input
@@ -142,22 +136,20 @@ class Lexer {
142
136
  this.next = null;
143
137
  /** A pointer to `buffer`; the current position of the lexer. */
144
138
  this.pos = 0;
145
- this.push = push;
146
139
  }
147
140
  /**
148
- * Read YAML tokens from the `source` string, calling the callback
149
- * defined in the constructor for each one. If `incomplete`, a part
150
- * of the last line may be left as a buffer for the next call.
141
+ * Generate YAML tokens from the `source` string. If `incomplete`,
142
+ * a part of the last line may be left as a buffer for the next call.
151
143
  *
152
- * @public
144
+ * @returns A generator of lexical tokens
153
145
  */
154
- lex(source, incomplete) {
146
+ *lex(source, incomplete = false) {
155
147
  if (source)
156
148
  this.buffer = this.buffer ? this.buffer + source : source;
157
149
  this.atEnd = !incomplete;
158
150
  let next = this.next || 'stream';
159
151
  while (next && (incomplete || this.hasChars(1)))
160
- next = this.parseNext(next);
152
+ next = yield* this.parseNext(next);
161
153
  }
162
154
  atLineEnd() {
163
155
  let i = this.pos;
@@ -215,32 +207,32 @@ class Lexer {
215
207
  peek(n) {
216
208
  return this.buffer.substr(this.pos, n);
217
209
  }
218
- parseNext(next) {
210
+ *parseNext(next) {
219
211
  switch (next) {
220
212
  case 'stream':
221
- return this.parseStream();
213
+ return yield* this.parseStream();
222
214
  case 'line-start':
223
- return this.parseLineStart();
215
+ return yield* this.parseLineStart();
224
216
  case 'block-start':
225
- return this.parseBlockStart();
217
+ return yield* this.parseBlockStart();
226
218
  case 'doc':
227
- return this.parseDocument();
219
+ return yield* this.parseDocument();
228
220
  case 'flow':
229
- return this.parseFlowCollection();
221
+ return yield* this.parseFlowCollection();
230
222
  case 'quoted-scalar':
231
- return this.parseQuotedScalar();
223
+ return yield* this.parseQuotedScalar();
232
224
  case 'block-scalar':
233
- return this.parseBlockScalar();
225
+ return yield* this.parseBlockScalar();
234
226
  case 'plain-scalar':
235
- return this.parsePlainScalar();
227
+ return yield* this.parsePlainScalar();
236
228
  }
237
229
  }
238
- parseStream() {
230
+ *parseStream() {
239
231
  let line = this.getLine();
240
232
  if (line === null)
241
233
  return this.setNext('stream');
242
234
  if (line[0] === BOM) {
243
- this.pushCount(1);
235
+ yield* this.pushCount(1);
244
236
  line = line.substring(1);
245
237
  }
246
238
  if (line[0] === '%') {
@@ -258,21 +250,21 @@ class Lexer {
258
250
  else
259
251
  break;
260
252
  }
261
- const n = this.pushCount(dirEnd) + this.pushSpaces(true);
262
- this.pushCount(line.length - n); // possible comment
253
+ const n = (yield* this.pushCount(dirEnd)) + (yield* this.pushSpaces(true));
254
+ yield* this.pushCount(line.length - n); // possible comment
263
255
  this.pushNewline();
264
256
  return 'stream';
265
257
  }
266
258
  if (this.atLineEnd()) {
267
- const sp = this.pushSpaces(true);
268
- this.pushCount(line.length - sp);
269
- this.pushNewline();
259
+ const sp = yield* this.pushSpaces(true);
260
+ yield* this.pushCount(line.length - sp);
261
+ yield* this.pushNewline();
270
262
  return 'stream';
271
263
  }
272
- this.push(DOCUMENT);
273
- return this.parseLineStart();
264
+ yield DOCUMENT;
265
+ return yield* this.parseLineStart();
274
266
  }
275
- parseLineStart() {
267
+ *parseLineStart() {
276
268
  const ch = this.charAt(0);
277
269
  if (!ch && !this.atEnd)
278
270
  return this.setNext('line-start');
@@ -281,80 +273,80 @@ class Lexer {
281
273
  return this.setNext('line-start');
282
274
  const s = this.peek(3);
283
275
  if (s === '---' && isEmpty(this.charAt(3))) {
284
- this.pushCount(3);
276
+ yield* this.pushCount(3);
285
277
  this.indentValue = 0;
286
278
  this.indentNext = 0;
287
279
  return 'doc';
288
280
  }
289
281
  else if (s === '...' && isEmpty(this.charAt(3))) {
290
- this.pushCount(3);
282
+ yield* this.pushCount(3);
291
283
  return 'stream';
292
284
  }
293
285
  }
294
- this.indentValue = this.pushSpaces(false);
286
+ this.indentValue = yield* this.pushSpaces(false);
295
287
  if (this.indentNext > this.indentValue && !isEmpty(this.charAt(1)))
296
288
  this.indentNext = this.indentValue;
297
- return this.parseBlockStart();
289
+ return yield* this.parseBlockStart();
298
290
  }
299
- parseBlockStart() {
291
+ *parseBlockStart() {
300
292
  const [ch0, ch1] = this.peek(2);
301
293
  if (!ch1 && !this.atEnd)
302
294
  return this.setNext('block-start');
303
295
  if ((ch0 === '-' || ch0 === '?' || ch0 === ':') && isEmpty(ch1)) {
304
- const n = this.pushCount(1) + this.pushSpaces(true);
296
+ const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
305
297
  this.indentNext = this.indentValue + 1;
306
298
  this.indentValue += n;
307
- return this.parseBlockStart();
299
+ return yield* this.parseBlockStart();
308
300
  }
309
301
  return 'doc';
310
302
  }
311
- parseDocument() {
312
- this.pushSpaces(true);
303
+ *parseDocument() {
304
+ yield* this.pushSpaces(true);
313
305
  const line = this.getLine();
314
306
  if (line === null)
315
307
  return this.setNext('doc');
316
- let n = this.pushIndicators();
308
+ let n = yield* this.pushIndicators();
317
309
  switch (line[n]) {
318
310
  case '#':
319
- this.pushCount(line.length - n);
311
+ yield* this.pushCount(line.length - n);
320
312
  // fallthrough
321
313
  case undefined:
322
- this.pushNewline();
323
- return this.parseLineStart();
314
+ yield* this.pushNewline();
315
+ return yield* this.parseLineStart();
324
316
  case '{':
325
317
  case '[':
326
- this.pushCount(1);
318
+ yield* this.pushCount(1);
327
319
  this.flowKey = false;
328
320
  this.flowLevel = 1;
329
321
  return 'flow';
330
322
  case '}':
331
323
  case ']':
332
324
  // this is an error
333
- this.pushCount(1);
325
+ yield* this.pushCount(1);
334
326
  return 'doc';
335
327
  case '*':
336
- this.pushUntil(isNotIdentifierChar);
328
+ yield* this.pushUntil(isNotIdentifierChar);
337
329
  return 'doc';
338
330
  case '"':
339
331
  case "'":
340
- return this.parseQuotedScalar();
332
+ return yield* this.parseQuotedScalar();
341
333
  case '|':
342
334
  case '>':
343
- n += this.parseBlockScalarHeader();
344
- n += this.pushSpaces(true);
345
- this.pushCount(line.length - n);
346
- this.pushNewline();
347
- return this.parseBlockScalar();
335
+ n += yield* this.parseBlockScalarHeader();
336
+ n += yield* this.pushSpaces(true);
337
+ yield* this.pushCount(line.length - n);
338
+ yield* this.pushNewline();
339
+ return yield* this.parseBlockScalar();
348
340
  default:
349
- return this.parsePlainScalar();
341
+ return yield* this.parsePlainScalar();
350
342
  }
351
343
  }
352
- parseFlowCollection() {
344
+ *parseFlowCollection() {
353
345
  let nl, sp;
354
346
  let indent = -1;
355
347
  do {
356
- nl = this.pushNewline();
357
- sp = this.pushSpaces(true);
348
+ nl = yield* this.pushNewline();
349
+ sp = yield* this.pushSpaces(true);
358
350
  if (nl > 0)
359
351
  this.indentValue = indent = sp;
360
352
  } while (nl + sp > 0);
@@ -374,54 +366,54 @@ class Lexer {
374
366
  if (!atFlowEndMarker) {
375
367
  // this is an error
376
368
  this.flowLevel = 0;
377
- this.push(FLOW_END);
378
- return this.parseLineStart();
369
+ yield FLOW_END;
370
+ return yield* this.parseLineStart();
379
371
  }
380
372
  }
381
373
  let n = 0;
382
374
  while (line[n] === ',')
383
- n += this.pushCount(1) + this.pushSpaces(true);
384
- n += this.pushIndicators();
375
+ n += (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
376
+ n += yield* this.pushIndicators();
385
377
  switch (line[n]) {
386
378
  case undefined:
387
379
  return 'flow';
388
380
  case '#':
389
- this.pushCount(line.length - n);
381
+ yield* this.pushCount(line.length - n);
390
382
  return 'flow';
391
383
  case '{':
392
384
  case '[':
393
- this.pushCount(1);
385
+ yield* this.pushCount(1);
394
386
  this.flowKey = false;
395
387
  this.flowLevel += 1;
396
388
  return 'flow';
397
389
  case '}':
398
390
  case ']':
399
- this.pushCount(1);
391
+ yield* this.pushCount(1);
400
392
  this.flowKey = true;
401
393
  this.flowLevel -= 1;
402
394
  return this.flowLevel ? 'flow' : 'doc';
403
395
  case '*':
404
- this.pushUntil(isNotIdentifierChar);
396
+ yield* this.pushUntil(isNotIdentifierChar);
405
397
  return 'flow';
406
398
  case '"':
407
399
  case "'":
408
400
  this.flowKey = true;
409
- return this.parseQuotedScalar();
401
+ return yield* this.parseQuotedScalar();
410
402
  case ':': {
411
403
  const next = this.charAt(1);
412
404
  if (this.flowKey || isEmpty(next) || next === ',') {
413
- this.pushCount(1);
414
- this.pushSpaces(true);
405
+ yield* this.pushCount(1);
406
+ yield* this.pushSpaces(true);
415
407
  return 'flow';
416
408
  }
417
409
  }
418
410
  // fallthrough
419
411
  default:
420
412
  this.flowKey = false;
421
- return this.parsePlainScalar();
413
+ return yield* this.parsePlainScalar();
422
414
  }
423
415
  }
424
- parseQuotedScalar() {
416
+ *parseQuotedScalar() {
425
417
  const quote = this.charAt(0);
426
418
  let end = this.buffer.indexOf(quote, this.pos + 1);
427
419
  if (quote === "'") {
@@ -457,10 +449,10 @@ class Lexer {
457
449
  return this.setNext('quoted-scalar');
458
450
  end = this.buffer.length;
459
451
  }
460
- this.pushToIndex(end + 1, false);
452
+ yield* this.pushToIndex(end + 1, false);
461
453
  return this.flowLevel ? 'flow' : 'doc';
462
454
  }
463
- parseBlockScalarHeader() {
455
+ *parseBlockScalarHeader() {
464
456
  this.blockScalarIndent = -1;
465
457
  this.blockScalarKeep = false;
466
458
  let i = this.pos;
@@ -473,9 +465,9 @@ class Lexer {
473
465
  else if (ch !== '-')
474
466
  break;
475
467
  }
476
- return this.pushUntil(ch => isEmpty(ch) || ch === '#');
468
+ return yield* this.pushUntil(ch => isEmpty(ch) || ch === '#');
477
469
  }
478
- parseBlockScalar() {
470
+ *parseBlockScalar() {
479
471
  let nl = this.pos - 1; // may be -1 if this.pos === 0
480
472
  let indent = 0;
481
473
  let ch;
@@ -532,11 +524,11 @@ class Lexer {
532
524
  break;
533
525
  } while (true);
534
526
  }
535
- this.push(SCALAR);
536
- this.pushToIndex(nl + 1, true);
537
- return this.parseLineStart();
527
+ yield SCALAR;
528
+ yield* this.pushToIndex(nl + 1, true);
529
+ return yield* this.parseLineStart();
538
530
  }
539
- parsePlainScalar() {
531
+ *parsePlainScalar() {
540
532
  const inFlow = this.flowLevel > 0;
541
533
  let end = this.pos - 1;
542
534
  let i = this.pos - 1;
@@ -575,69 +567,71 @@ class Lexer {
575
567
  }
576
568
  if (!ch && !this.atEnd)
577
569
  return this.setNext('plain-scalar');
578
- this.push(SCALAR);
579
- this.pushToIndex(end + 1, true);
570
+ yield SCALAR;
571
+ yield* this.pushToIndex(end + 1, true);
580
572
  return inFlow ? 'flow' : 'doc';
581
573
  }
582
- pushCount(n) {
574
+ *pushCount(n) {
583
575
  if (n > 0) {
584
- this.push(this.buffer.substr(this.pos, n));
576
+ yield this.buffer.substr(this.pos, n);
585
577
  this.pos += n;
586
578
  return n;
587
579
  }
588
580
  return 0;
589
581
  }
590
- pushToIndex(i, allowEmpty) {
582
+ *pushToIndex(i, allowEmpty) {
591
583
  const s = this.buffer.slice(this.pos, i);
592
584
  if (s) {
593
- this.push(s);
585
+ yield s;
594
586
  this.pos += s.length;
595
587
  return s.length;
596
588
  }
597
589
  else if (allowEmpty)
598
- this.push('');
590
+ yield '';
599
591
  return 0;
600
592
  }
601
- pushIndicators() {
593
+ *pushIndicators() {
602
594
  switch (this.charAt(0)) {
603
595
  case '!':
604
596
  if (this.charAt(1) === '<')
605
- return (this.pushVerbatimTag() +
606
- this.pushSpaces(true) +
607
- this.pushIndicators());
597
+ return ((yield* this.pushVerbatimTag()) +
598
+ (yield* this.pushSpaces(true)) +
599
+ (yield* this.pushIndicators()));
608
600
  // fallthrough
609
601
  case '&':
610
- return (this.pushUntil(isNotIdentifierChar) +
611
- this.pushSpaces(true) +
612
- this.pushIndicators());
602
+ return ((yield* this.pushUntil(isNotIdentifierChar)) +
603
+ (yield* this.pushSpaces(true)) +
604
+ (yield* this.pushIndicators()));
613
605
  case ':':
614
606
  case '?': // this is an error outside flow collections
615
607
  case '-': // this is an error
616
608
  if (isEmpty(this.charAt(1))) {
617
609
  if (this.flowLevel === 0)
618
610
  this.indentNext = this.indentValue + 1;
619
- return (this.pushCount(1) + this.pushSpaces(true) + this.pushIndicators());
611
+ return ((yield* this.pushCount(1)) +
612
+ (yield* this.pushSpaces(true)) +
613
+ (yield* this.pushIndicators()));
620
614
  }
621
615
  }
622
616
  return 0;
623
617
  }
624
- pushVerbatimTag() {
618
+ *pushVerbatimTag() {
625
619
  let i = this.pos + 2;
626
620
  let ch = this.buffer[i];
627
621
  while (!isEmpty(ch) && ch !== '>')
628
622
  ch = this.buffer[++i];
629
- return this.pushToIndex(ch === '>' ? i + 1 : i, false);
623
+ return yield* this.pushToIndex(ch === '>' ? i + 1 : i, false);
630
624
  }
631
- pushNewline() {
625
+ *pushNewline() {
632
626
  const ch = this.buffer[this.pos];
633
627
  if (ch === '\n')
634
- return this.pushCount(1);
628
+ return yield* this.pushCount(1);
635
629
  else if (ch === '\r' && this.charAt(1) === '\n')
636
- return this.pushCount(2);
630
+ return yield* this.pushCount(2);
637
631
  else
638
632
  return 0;
639
633
  }
640
- pushSpaces(allowTabs) {
634
+ *pushSpaces(allowTabs) {
641
635
  let i = this.pos - 1;
642
636
  let ch;
643
637
  do {
@@ -645,17 +639,17 @@ class Lexer {
645
639
  } while (ch === ' ' || (allowTabs && ch === '\t'));
646
640
  const n = i - this.pos;
647
641
  if (n > 0) {
648
- this.push(this.buffer.substr(this.pos, n));
642
+ yield this.buffer.substr(this.pos, n);
649
643
  this.pos = i;
650
644
  }
651
645
  return n;
652
646
  }
653
- pushUntil(test) {
647
+ *pushUntil(test) {
654
648
  let i = this.pos;
655
649
  let ch = this.buffer[i];
656
650
  while (!test(ch))
657
651
  ch = this.buffer[++i];
658
- return this.pushToIndex(i, false);
652
+ return yield* this.pushToIndex(i, false);
659
653
  }
660
654
  }
661
655