yaml 2.0.0-3 → 2.0.0-7

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 (345) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +46 -26
  3. package/browser/dist/compose/compose-collection.js +59 -0
  4. package/browser/dist/compose/compose-doc.js +39 -0
  5. package/browser/dist/compose/compose-node.js +79 -0
  6. package/browser/dist/compose/compose-scalar.js +74 -0
  7. package/browser/dist/compose/composer.js +219 -0
  8. package/browser/dist/compose/resolve-block-map.js +93 -0
  9. package/browser/dist/compose/resolve-block-scalar.js +185 -0
  10. package/browser/dist/compose/resolve-block-seq.js +40 -0
  11. package/browser/dist/compose/resolve-end.js +37 -0
  12. package/browser/dist/compose/resolve-flow-collection.js +189 -0
  13. package/browser/dist/compose/resolve-flow-scalar.js +217 -0
  14. package/browser/dist/compose/resolve-props.js +126 -0
  15. package/browser/dist/compose/util-contains-newline.js +34 -0
  16. package/browser/dist/compose/util-empty-scalar-position.js +27 -0
  17. package/browser/dist/compose/util-map-includes.js +17 -0
  18. package/browser/dist/doc/Document.js +251 -348
  19. package/browser/dist/doc/anchors.js +72 -0
  20. package/browser/dist/doc/applyReviver.js +41 -28
  21. package/browser/dist/doc/createNode.js +75 -55
  22. package/browser/dist/doc/directives.js +161 -0
  23. package/browser/dist/errors.js +50 -72
  24. package/browser/dist/index.js +16 -72
  25. package/browser/dist/log.js +11 -7
  26. package/browser/dist/nodes/Alias.js +94 -0
  27. package/browser/dist/nodes/Collection.js +133 -0
  28. package/browser/dist/nodes/Node.js +41 -0
  29. package/browser/dist/nodes/Pair.js +28 -0
  30. package/browser/dist/nodes/Scalar.js +23 -0
  31. package/browser/dist/nodes/YAMLMap.js +116 -0
  32. package/browser/dist/nodes/YAMLSeq.js +105 -0
  33. package/browser/dist/nodes/addPairToJSMap.js +103 -0
  34. package/browser/dist/nodes/toJS.js +35 -0
  35. package/browser/dist/options.js +14 -95
  36. package/browser/dist/parse/cst-scalar.js +219 -0
  37. package/browser/dist/parse/cst-stringify.js +61 -0
  38. package/browser/dist/parse/cst-visit.js +97 -0
  39. package/browser/dist/parse/cst.js +98 -0
  40. package/browser/dist/parse/lexer.js +674 -0
  41. package/browser/dist/parse/line-counter.js +39 -0
  42. package/browser/dist/parse/parser.js +876 -0
  43. package/browser/dist/public-api.js +101 -0
  44. package/browser/dist/schema/Schema.js +23 -0
  45. package/browser/dist/schema/common/map.js +42 -0
  46. package/browser/dist/schema/common/null.js +13 -0
  47. package/browser/dist/schema/common/seq.js +33 -0
  48. package/browser/dist/schema/common/string.js +14 -0
  49. package/browser/dist/schema/core/bool.js +19 -0
  50. package/browser/dist/schema/core/float.js +40 -0
  51. package/browser/dist/schema/core/int.js +38 -0
  52. package/browser/dist/schema/core/schema.js +23 -0
  53. package/browser/dist/schema/json/schema.js +62 -0
  54. package/browser/dist/schema/tags.js +79 -0
  55. package/browser/dist/schema/yaml-1.1/binary.js +66 -0
  56. package/browser/dist/schema/yaml-1.1/bool.js +26 -0
  57. package/browser/dist/schema/yaml-1.1/float.js +43 -0
  58. package/browser/dist/schema/yaml-1.1/int.js +71 -0
  59. package/browser/dist/schema/yaml-1.1/omap.js +73 -0
  60. package/browser/dist/schema/yaml-1.1/pairs.js +77 -0
  61. package/browser/dist/schema/yaml-1.1/schema.js +37 -0
  62. package/browser/dist/schema/yaml-1.1/set.js +87 -0
  63. package/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  64. package/browser/dist/stringify/foldFlowLines.js +121 -139
  65. package/browser/dist/stringify/stringify.js +87 -72
  66. package/browser/dist/stringify/stringifyCollection.js +122 -0
  67. package/browser/dist/stringify/stringifyComment.js +14 -0
  68. package/browser/dist/stringify/stringifyDocument.js +64 -0
  69. package/browser/dist/stringify/stringifyNumber.js +20 -23
  70. package/browser/dist/stringify/stringifyPair.js +111 -0
  71. package/browser/dist/stringify/stringifyString.js +295 -322
  72. package/browser/dist/util.js +4 -4
  73. package/browser/dist/visit.js +134 -71
  74. package/browser/index.js +4 -1
  75. package/dist/compose/compose-collection.d.ts +5 -0
  76. package/dist/compose/compose-collection.js +61 -0
  77. package/dist/compose/compose-doc.d.ts +6 -0
  78. package/dist/compose/compose-doc.js +41 -0
  79. package/dist/compose/compose-node.d.ts +25 -0
  80. package/dist/compose/compose-node.js +82 -0
  81. package/dist/compose/compose-scalar.d.ts +5 -0
  82. package/dist/compose/compose-scalar.js +76 -0
  83. package/dist/compose/composer.d.ts +62 -0
  84. package/dist/compose/composer.js +223 -0
  85. package/dist/compose/resolve-block-map.d.ts +6 -0
  86. package/dist/compose/resolve-block-map.js +95 -0
  87. package/dist/compose/resolve-block-scalar.d.ts +10 -0
  88. package/dist/compose/resolve-block-scalar.js +187 -0
  89. package/dist/compose/resolve-block-seq.d.ts +5 -0
  90. package/dist/compose/resolve-block-seq.js +42 -0
  91. package/dist/compose/resolve-end.d.ts +6 -0
  92. package/dist/compose/resolve-end.js +39 -0
  93. package/dist/compose/resolve-flow-collection.d.ts +6 -0
  94. package/dist/compose/resolve-flow-collection.js +191 -0
  95. package/dist/compose/resolve-flow-scalar.d.ts +10 -0
  96. package/dist/compose/resolve-flow-scalar.js +219 -0
  97. package/dist/compose/resolve-props.d.ts +21 -0
  98. package/dist/compose/resolve-props.js +128 -0
  99. package/dist/compose/util-contains-newline.d.ts +2 -0
  100. package/dist/compose/util-contains-newline.js +36 -0
  101. package/dist/compose/util-empty-scalar-position.d.ts +2 -0
  102. package/dist/compose/util-empty-scalar-position.js +29 -0
  103. package/dist/compose/util-map-includes.d.ts +4 -0
  104. package/dist/compose/util-map-includes.js +19 -0
  105. package/dist/doc/Document.d.ts +130 -0
  106. package/dist/doc/Document.js +250 -347
  107. package/dist/doc/anchors.d.ts +24 -0
  108. package/dist/doc/anchors.js +77 -0
  109. package/dist/doc/applyReviver.d.ts +9 -0
  110. package/dist/doc/applyReviver.js +41 -28
  111. package/dist/doc/createNode.d.ts +16 -0
  112. package/dist/doc/createNode.js +75 -55
  113. package/dist/doc/directives.d.ts +46 -0
  114. package/dist/doc/directives.js +163 -0
  115. package/dist/errors.d.ts +21 -0
  116. package/dist/errors.js +51 -74
  117. package/dist/index.d.ts +19 -0
  118. package/dist/index.js +39 -70
  119. package/dist/log.d.ts +3 -0
  120. package/dist/log.js +11 -6
  121. package/dist/nodes/Alias.d.ts +24 -0
  122. package/dist/nodes/Alias.js +96 -0
  123. package/dist/nodes/Collection.d.ts +67 -0
  124. package/dist/nodes/Collection.js +137 -0
  125. package/dist/nodes/Node.d.ts +48 -0
  126. package/dist/nodes/Node.js +59 -0
  127. package/dist/nodes/Pair.d.ts +16 -0
  128. package/dist/nodes/Pair.js +31 -0
  129. package/dist/nodes/Scalar.d.ts +40 -0
  130. package/dist/nodes/Scalar.js +26 -0
  131. package/dist/nodes/YAMLMap.d.ts +39 -0
  132. package/dist/nodes/YAMLMap.js +119 -0
  133. package/dist/nodes/YAMLSeq.d.ts +53 -0
  134. package/dist/nodes/YAMLSeq.js +107 -0
  135. package/dist/nodes/addPairToJSMap.d.ts +3 -0
  136. package/dist/nodes/addPairToJSMap.js +105 -0
  137. package/dist/nodes/toJS.d.ts +30 -0
  138. package/dist/nodes/toJS.js +37 -0
  139. package/dist/options.d.ts +278 -0
  140. package/dist/options.js +13 -96
  141. package/dist/parse/cst-scalar.d.ts +58 -0
  142. package/dist/parse/cst-scalar.js +223 -0
  143. package/dist/parse/cst-stringify.d.ts +8 -0
  144. package/dist/parse/cst-stringify.js +63 -0
  145. package/dist/parse/cst-visit.d.ts +39 -0
  146. package/dist/parse/cst-visit.js +99 -0
  147. package/dist/parse/cst.d.ts +106 -0
  148. package/dist/parse/cst.js +112 -0
  149. package/dist/parse/lexer.d.ts +85 -0
  150. package/dist/parse/lexer.js +676 -0
  151. package/dist/parse/line-counter.d.ts +22 -0
  152. package/dist/parse/line-counter.js +41 -0
  153. package/dist/parse/parser.d.ts +84 -0
  154. package/dist/parse/parser.js +880 -0
  155. package/dist/public-api.d.ts +43 -0
  156. package/dist/public-api.js +106 -0
  157. package/dist/schema/Schema.d.ts +16 -0
  158. package/dist/schema/Schema.js +25 -0
  159. package/dist/schema/common/map.d.ts +2 -0
  160. package/dist/schema/common/map.js +44 -0
  161. package/dist/schema/common/null.d.ts +4 -0
  162. package/dist/schema/common/null.js +15 -0
  163. package/dist/schema/common/seq.d.ts +2 -0
  164. package/dist/schema/common/seq.js +35 -0
  165. package/dist/schema/common/string.d.ts +2 -0
  166. package/dist/schema/common/string.js +16 -0
  167. package/dist/schema/core/bool.d.ts +4 -0
  168. package/dist/schema/core/bool.js +21 -0
  169. package/dist/schema/core/float.d.ts +4 -0
  170. package/dist/schema/core/float.js +44 -0
  171. package/dist/schema/core/int.d.ts +4 -0
  172. package/dist/schema/core/int.js +42 -0
  173. package/dist/schema/core/schema.d.ts +1 -0
  174. package/dist/schema/core/schema.js +25 -0
  175. package/dist/schema/json/schema.d.ts +2 -0
  176. package/dist/schema/json/schema.js +64 -0
  177. package/dist/schema/tags.d.ts +41 -0
  178. package/dist/schema/tags.js +82 -0
  179. package/dist/schema/types.d.ts +82 -0
  180. package/dist/schema/yaml-1.1/binary.d.ts +2 -0
  181. package/dist/schema/yaml-1.1/binary.js +68 -0
  182. package/dist/schema/yaml-1.1/bool.d.ts +7 -0
  183. package/dist/schema/yaml-1.1/bool.js +29 -0
  184. package/dist/schema/yaml-1.1/float.d.ts +4 -0
  185. package/dist/schema/yaml-1.1/float.js +47 -0
  186. package/dist/schema/yaml-1.1/int.d.ts +5 -0
  187. package/dist/schema/yaml-1.1/int.js +76 -0
  188. package/dist/schema/yaml-1.1/omap.d.ts +21 -0
  189. package/dist/schema/yaml-1.1/omap.js +76 -0
  190. package/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  191. package/dist/schema/yaml-1.1/pairs.js +81 -0
  192. package/dist/schema/yaml-1.1/schema.d.ts +1 -0
  193. package/dist/schema/yaml-1.1/schema.js +39 -0
  194. package/dist/schema/yaml-1.1/set.d.ts +22 -0
  195. package/dist/schema/yaml-1.1/set.js +90 -0
  196. package/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  197. package/dist/schema/yaml-1.1/timestamp.js +105 -0
  198. package/dist/stringify/foldFlowLines.d.ts +34 -0
  199. package/dist/stringify/foldFlowLines.js +121 -139
  200. package/dist/stringify/stringify.d.ts +18 -0
  201. package/dist/stringify/stringify.js +87 -71
  202. package/dist/stringify/stringifyCollection.d.ts +21 -0
  203. package/dist/stringify/stringifyCollection.js +124 -0
  204. package/dist/stringify/stringifyComment.d.ts +2 -0
  205. package/dist/stringify/stringifyComment.js +17 -0
  206. package/dist/stringify/stringifyDocument.d.ts +3 -0
  207. package/dist/stringify/stringifyDocument.js +66 -0
  208. package/dist/stringify/stringifyNumber.d.ts +2 -0
  209. package/dist/stringify/stringifyNumber.js +20 -23
  210. package/dist/stringify/stringifyPair.d.ts +3 -0
  211. package/dist/stringify/stringifyPair.js +113 -0
  212. package/dist/stringify/stringifyString.d.ts +3 -0
  213. package/dist/stringify/stringifyString.js +295 -322
  214. package/dist/test-events.d.ts +4 -0
  215. package/dist/test-events.js +124 -148
  216. package/dist/util.d.ts +6 -0
  217. package/dist/util.js +9 -12
  218. package/dist/visit.d.ts +63 -0
  219. package/dist/visit.js +134 -71
  220. package/package.json +31 -39
  221. package/util.js +2 -14
  222. package/browser/dist/_virtual/_rollupPluginBabelHelpers.js +0 -16
  223. package/browser/dist/ast/Alias.js +0 -95
  224. package/browser/dist/ast/Collection.js +0 -192
  225. package/browser/dist/ast/Merge.js +0 -71
  226. package/browser/dist/ast/Node.js +0 -3
  227. package/browser/dist/ast/Pair.js +0 -200
  228. package/browser/dist/ast/Scalar.js +0 -21
  229. package/browser/dist/ast/YAMLMap.js +0 -91
  230. package/browser/dist/ast/YAMLSeq.js +0 -67
  231. package/browser/dist/ast/toJS.js +0 -29
  232. package/browser/dist/constants.js +0 -40
  233. package/browser/dist/cst/Alias.js +0 -26
  234. package/browser/dist/cst/BlankLine.js +0 -34
  235. package/browser/dist/cst/BlockValue.js +0 -240
  236. package/browser/dist/cst/Collection.js +0 -259
  237. package/browser/dist/cst/CollectionItem.js +0 -123
  238. package/browser/dist/cst/Comment.js +0 -27
  239. package/browser/dist/cst/Directive.js +0 -53
  240. package/browser/dist/cst/Document.js +0 -262
  241. package/browser/dist/cst/FlowCollection.js +0 -201
  242. package/browser/dist/cst/Node.js +0 -355
  243. package/browser/dist/cst/ParseContext.js +0 -234
  244. package/browser/dist/cst/PlainValue.js +0 -171
  245. package/browser/dist/cst/QuoteDouble.js +0 -224
  246. package/browser/dist/cst/QuoteSingle.js +0 -100
  247. package/browser/dist/cst/Range.js +0 -56
  248. package/browser/dist/cst/parse.js +0 -46
  249. package/browser/dist/cst/source-utils.js +0 -169
  250. package/browser/dist/doc/Anchors.js +0 -115
  251. package/browser/dist/doc/Schema.js +0 -34
  252. package/browser/dist/doc/getSchemaTags.js +0 -33
  253. package/browser/dist/doc/listTagNames.js +0 -27
  254. package/browser/dist/doc/parseContents.js +0 -60
  255. package/browser/dist/doc/parseDirectives.js +0 -107
  256. package/browser/dist/resolve/collection-utils.js +0 -86
  257. package/browser/dist/resolve/resolveMap.js +0 -315
  258. package/browser/dist/resolve/resolveNode.js +0 -173
  259. package/browser/dist/resolve/resolveScalar.js +0 -20
  260. package/browser/dist/resolve/resolveSeq.js +0 -170
  261. package/browser/dist/resolve/resolveTag.js +0 -107
  262. package/browser/dist/resolve/resolveTagName.js +0 -87
  263. package/browser/dist/stringify/addComment.js +0 -10
  264. package/browser/dist/stringify/stringifyTag.js +0 -28
  265. package/browser/dist/tags/core.js +0 -128
  266. package/browser/dist/tags/failsafe/index.js +0 -7
  267. package/browser/dist/tags/failsafe/map.js +0 -37
  268. package/browser/dist/tags/failsafe/seq.js +0 -34
  269. package/browser/dist/tags/failsafe/string.js +0 -20
  270. package/browser/dist/tags/index.js +0 -39
  271. package/browser/dist/tags/json.js +0 -62
  272. package/browser/dist/tags/options.js +0 -31
  273. package/browser/dist/tags/yaml-1.1/binary.js +0 -83
  274. package/browser/dist/tags/yaml-1.1/index.js +0 -174
  275. package/browser/dist/tags/yaml-1.1/omap.js +0 -86
  276. package/browser/dist/tags/yaml-1.1/pairs.js +0 -62
  277. package/browser/dist/tags/yaml-1.1/set.js +0 -78
  278. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -101
  279. package/browser/dist/types.js +0 -10
  280. package/cst.d.ts +0 -185
  281. package/dist/_virtual/_rollupPluginBabelHelpers.js +0 -18
  282. package/dist/ast/Alias.js +0 -97
  283. package/dist/ast/Collection.js +0 -196
  284. package/dist/ast/Merge.js +0 -74
  285. package/dist/ast/Node.js +0 -5
  286. package/dist/ast/Pair.js +0 -203
  287. package/dist/ast/Scalar.js +0 -24
  288. package/dist/ast/YAMLMap.js +0 -94
  289. package/dist/ast/YAMLSeq.js +0 -69
  290. package/dist/ast/toJS.js +0 -31
  291. package/dist/constants.js +0 -46
  292. package/dist/cst/Alias.js +0 -28
  293. package/dist/cst/BlankLine.js +0 -36
  294. package/dist/cst/BlockValue.js +0 -243
  295. package/dist/cst/Collection.js +0 -262
  296. package/dist/cst/CollectionItem.js +0 -125
  297. package/dist/cst/Comment.js +0 -29
  298. package/dist/cst/Directive.js +0 -55
  299. package/dist/cst/Document.js +0 -264
  300. package/dist/cst/FlowCollection.js +0 -203
  301. package/dist/cst/Node.js +0 -357
  302. package/dist/cst/ParseContext.js +0 -236
  303. package/dist/cst/PlainValue.js +0 -173
  304. package/dist/cst/QuoteDouble.js +0 -226
  305. package/dist/cst/QuoteSingle.js +0 -102
  306. package/dist/cst/Range.js +0 -58
  307. package/dist/cst/parse.js +0 -48
  308. package/dist/cst/source-utils.js +0 -173
  309. package/dist/doc/Anchors.js +0 -117
  310. package/dist/doc/Schema.js +0 -36
  311. package/dist/doc/getSchemaTags.js +0 -35
  312. package/dist/doc/listTagNames.js +0 -29
  313. package/dist/doc/parseContents.js +0 -62
  314. package/dist/doc/parseDirectives.js +0 -109
  315. package/dist/resolve/collection-utils.js +0 -91
  316. package/dist/resolve/resolveMap.js +0 -317
  317. package/dist/resolve/resolveNode.js +0 -175
  318. package/dist/resolve/resolveScalar.js +0 -22
  319. package/dist/resolve/resolveSeq.js +0 -172
  320. package/dist/resolve/resolveTag.js +0 -109
  321. package/dist/resolve/resolveTagName.js +0 -89
  322. package/dist/stringify/addComment.js +0 -13
  323. package/dist/stringify/stringifyTag.js +0 -30
  324. package/dist/tags/core.js +0 -138
  325. package/dist/tags/failsafe/index.js +0 -9
  326. package/dist/tags/failsafe/map.js +0 -39
  327. package/dist/tags/failsafe/seq.js +0 -36
  328. package/dist/tags/failsafe/string.js +0 -22
  329. package/dist/tags/index.js +0 -42
  330. package/dist/tags/json.js +0 -64
  331. package/dist/tags/options.js +0 -37
  332. package/dist/tags/yaml-1.1/binary.js +0 -85
  333. package/dist/tags/yaml-1.1/index.js +0 -176
  334. package/dist/tags/yaml-1.1/omap.js +0 -89
  335. package/dist/tags/yaml-1.1/pairs.js +0 -66
  336. package/dist/tags/yaml-1.1/set.js +0 -81
  337. package/dist/tags/yaml-1.1/timestamp.js +0 -105
  338. package/dist/types.js +0 -29
  339. package/index.d.ts +0 -519
  340. package/index.js +0 -1
  341. package/types.d.ts +0 -379
  342. package/types.js +0 -17
  343. package/types.mjs +0 -17
  344. package/util.d.ts +0 -76
  345. package/util.mjs +0 -15
@@ -0,0 +1,876 @@
1
+ import { tokenType } from './cst.js';
2
+ import { Lexer } from './lexer.js';
3
+
4
+ function includesToken(list, type) {
5
+ for (let i = 0; i < list.length; ++i)
6
+ if (list[i].type === type)
7
+ return true;
8
+ return false;
9
+ }
10
+ function includesNonEmpty(list) {
11
+ for (let i = 0; i < list.length; ++i) {
12
+ switch (list[i].type) {
13
+ case 'space':
14
+ case 'comment':
15
+ case 'newline':
16
+ break;
17
+ default:
18
+ return true;
19
+ }
20
+ }
21
+ return false;
22
+ }
23
+ function isFlowToken(token) {
24
+ switch (token === null || token === void 0 ? void 0 : token.type) {
25
+ case 'alias':
26
+ case 'scalar':
27
+ case 'single-quoted-scalar':
28
+ case 'double-quoted-scalar':
29
+ case 'flow-collection':
30
+ return true;
31
+ default:
32
+ return false;
33
+ }
34
+ }
35
+ function getPrevProps(parent) {
36
+ switch (parent.type) {
37
+ case 'document':
38
+ return parent.start;
39
+ case 'block-map': {
40
+ const it = parent.items[parent.items.length - 1];
41
+ return it.sep || it.start;
42
+ }
43
+ case 'block-seq':
44
+ return parent.items[parent.items.length - 1].start;
45
+ /* istanbul ignore next should not happen */
46
+ default:
47
+ return [];
48
+ }
49
+ }
50
+ /** Note: May modify input array */
51
+ function getFirstKeyStartProps(prev) {
52
+ var _a;
53
+ if (prev.length === 0)
54
+ return [];
55
+ let i = prev.length;
56
+ loop: while (--i >= 0) {
57
+ switch (prev[i].type) {
58
+ case 'doc-start':
59
+ case 'explicit-key-ind':
60
+ case 'map-value-ind':
61
+ case 'seq-item-ind':
62
+ case 'newline':
63
+ break loop;
64
+ }
65
+ }
66
+ while (((_a = prev[++i]) === null || _a === void 0 ? void 0 : _a.type) === 'space') {
67
+ /* loop */
68
+ }
69
+ return prev.splice(i, prev.length);
70
+ }
71
+ function fixFlowSeqItems(fc) {
72
+ if (fc.start.type === 'flow-seq-start') {
73
+ for (const it of fc.items) {
74
+ if (it.sep &&
75
+ !it.value &&
76
+ !includesToken(it.start, 'explicit-key-ind') &&
77
+ !includesToken(it.sep, 'map-value-ind')) {
78
+ if (it.key)
79
+ it.value = it.key;
80
+ delete it.key;
81
+ if (isFlowToken(it.value)) {
82
+ if (it.value.end)
83
+ Array.prototype.push.apply(it.value.end, it.sep);
84
+ else
85
+ it.value.end = it.sep;
86
+ }
87
+ else
88
+ Array.prototype.push.apply(it.start, it.sep);
89
+ delete it.sep;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ /**
95
+ * A YAML concrete syntax tree (CST) parser
96
+ *
97
+ * ```ts
98
+ * const src: string = ...
99
+ * for (const token of new Parser().parse(src)) {
100
+ * // token: Token
101
+ * }
102
+ * ```
103
+ *
104
+ * To use the parser with a user-provided lexer:
105
+ *
106
+ * ```ts
107
+ * function* parse(source: string, lexer: Lexer) {
108
+ * const parser = new Parser()
109
+ * for (const lexeme of lexer.lex(source))
110
+ * yield* parser.next(lexeme)
111
+ * yield* parser.end()
112
+ * }
113
+ *
114
+ * const src: string = ...
115
+ * const lexer = new Lexer()
116
+ * for (const token of parse(src, lexer)) {
117
+ * // token: Token
118
+ * }
119
+ * ```
120
+ */
121
+ class Parser {
122
+ /**
123
+ * @param onNewLine - If defined, called separately with the start position of
124
+ * each new line (in `parse()`, including the start of input).
125
+ */
126
+ constructor(onNewLine) {
127
+ /** If true, space and sequence indicators count as indentation */
128
+ this.atNewLine = true;
129
+ /** If true, next token is a scalar value */
130
+ this.atScalar = false;
131
+ /** Current indentation level */
132
+ this.indent = 0;
133
+ /** Current offset since the start of parsing */
134
+ this.offset = 0;
135
+ /** On the same line with a block map key */
136
+ this.onKeyLine = false;
137
+ /** Top indicates the node that's currently being built */
138
+ this.stack = [];
139
+ /** The source of the current token, set in parse() */
140
+ this.source = '';
141
+ /** The type of the current token, set in parse() */
142
+ this.type = '';
143
+ // Must be defined after `next()`
144
+ this.lexer = new Lexer();
145
+ this.onNewLine = onNewLine;
146
+ }
147
+ /**
148
+ * Parse `source` as a YAML stream.
149
+ * If `incomplete`, a part of the last line may be left as a buffer for the next call.
150
+ *
151
+ * Errors are not thrown, but yielded as `{ type: 'error', message }` tokens.
152
+ *
153
+ * @returns A generator of tokens representing each directive, document, and other structure.
154
+ */
155
+ *parse(source, incomplete = false) {
156
+ if (this.onNewLine && this.offset === 0)
157
+ this.onNewLine(0);
158
+ for (const lexeme of this.lexer.lex(source, incomplete))
159
+ yield* this.next(lexeme);
160
+ if (!incomplete)
161
+ yield* this.end();
162
+ }
163
+ /**
164
+ * Advance the parser by the `source` of one lexical token.
165
+ */
166
+ *next(source) {
167
+ this.source = source;
168
+ if (this.atScalar) {
169
+ this.atScalar = false;
170
+ yield* this.step();
171
+ this.offset += source.length;
172
+ return;
173
+ }
174
+ const type = tokenType(source);
175
+ if (!type) {
176
+ const message = `Not a YAML token: ${source}`;
177
+ yield* this.pop({ type: 'error', offset: this.offset, message, source });
178
+ this.offset += source.length;
179
+ }
180
+ else if (type === 'scalar') {
181
+ this.atNewLine = false;
182
+ this.atScalar = true;
183
+ this.type = 'scalar';
184
+ }
185
+ else {
186
+ this.type = type;
187
+ yield* this.step();
188
+ switch (type) {
189
+ case 'newline':
190
+ this.atNewLine = true;
191
+ this.indent = 0;
192
+ if (this.onNewLine)
193
+ this.onNewLine(this.offset + source.length);
194
+ break;
195
+ case 'space':
196
+ if (this.atNewLine && source[0] === ' ')
197
+ this.indent += source.length;
198
+ break;
199
+ case 'explicit-key-ind':
200
+ case 'map-value-ind':
201
+ case 'seq-item-ind':
202
+ if (this.atNewLine)
203
+ this.indent += source.length;
204
+ break;
205
+ case 'doc-mode':
206
+ return;
207
+ default:
208
+ this.atNewLine = false;
209
+ }
210
+ this.offset += source.length;
211
+ }
212
+ }
213
+ /** Call at end of input to push out any remaining constructions */
214
+ *end() {
215
+ while (this.stack.length > 0)
216
+ yield* this.pop();
217
+ }
218
+ get sourceToken() {
219
+ const st = {
220
+ type: this.type,
221
+ offset: this.offset,
222
+ indent: this.indent,
223
+ source: this.source
224
+ };
225
+ return st;
226
+ }
227
+ *step() {
228
+ const top = this.peek(1);
229
+ if (this.type === 'doc-end' && (!top || top.type !== 'doc-end')) {
230
+ while (this.stack.length > 0)
231
+ yield* this.pop();
232
+ this.stack.push({
233
+ type: 'doc-end',
234
+ offset: this.offset,
235
+ source: this.source
236
+ });
237
+ return;
238
+ }
239
+ if (!top)
240
+ return yield* this.stream();
241
+ switch (top.type) {
242
+ case 'document':
243
+ return yield* this.document(top);
244
+ case 'alias':
245
+ case 'scalar':
246
+ case 'single-quoted-scalar':
247
+ case 'double-quoted-scalar':
248
+ return yield* this.scalar(top);
249
+ case 'block-scalar':
250
+ return yield* this.blockScalar(top);
251
+ case 'block-map':
252
+ return yield* this.blockMap(top);
253
+ case 'block-seq':
254
+ return yield* this.blockSequence(top);
255
+ case 'flow-collection':
256
+ return yield* this.flowCollection(top);
257
+ case 'doc-end':
258
+ return yield* this.documentEnd(top);
259
+ }
260
+ /* istanbul ignore next should not happen */
261
+ yield* this.pop();
262
+ }
263
+ peek(n) {
264
+ return this.stack[this.stack.length - n];
265
+ }
266
+ *pop(error) {
267
+ const token = error || this.stack.pop();
268
+ /* istanbul ignore if should not happen */
269
+ if (!token) {
270
+ const message = 'Tried to pop an empty stack';
271
+ yield { type: 'error', offset: this.offset, source: '', message };
272
+ }
273
+ else if (this.stack.length === 0) {
274
+ yield token;
275
+ }
276
+ else {
277
+ const top = this.peek(1);
278
+ // For these, parent indent is needed instead of own
279
+ if (token.type === 'block-scalar' || token.type === 'flow-collection')
280
+ token.indent = 'indent' in top ? top.indent : -1;
281
+ if (token.type === 'flow-collection')
282
+ fixFlowSeqItems(token);
283
+ switch (top.type) {
284
+ case 'document':
285
+ top.value = token;
286
+ break;
287
+ case 'block-scalar':
288
+ top.props.push(token); // error
289
+ break;
290
+ case 'block-map': {
291
+ const it = top.items[top.items.length - 1];
292
+ if (it.value) {
293
+ top.items.push({ start: [], key: token, sep: [] });
294
+ this.onKeyLine = true;
295
+ return;
296
+ }
297
+ else if (it.sep) {
298
+ it.value = token;
299
+ }
300
+ else {
301
+ Object.assign(it, { key: token, sep: [] });
302
+ this.onKeyLine = !includesToken(it.start, 'explicit-key-ind');
303
+ return;
304
+ }
305
+ break;
306
+ }
307
+ case 'block-seq': {
308
+ const it = top.items[top.items.length - 1];
309
+ if (it.value)
310
+ top.items.push({ start: [], value: token });
311
+ else
312
+ it.value = token;
313
+ break;
314
+ }
315
+ case 'flow-collection': {
316
+ const it = top.items[top.items.length - 1];
317
+ if (!it || it.value)
318
+ top.items.push({ start: [], key: token, sep: [] });
319
+ else if (it.sep)
320
+ it.value = token;
321
+ else
322
+ Object.assign(it, { key: token, sep: [] });
323
+ return;
324
+ }
325
+ /* istanbul ignore next should not happen */
326
+ default:
327
+ yield* this.pop();
328
+ yield* this.pop(token);
329
+ }
330
+ if ((top.type === 'document' ||
331
+ top.type === 'block-map' ||
332
+ top.type === 'block-seq') &&
333
+ (token.type === 'block-map' || token.type === 'block-seq')) {
334
+ const last = token.items[token.items.length - 1];
335
+ if (last &&
336
+ !last.sep &&
337
+ !last.value &&
338
+ last.start.length > 0 &&
339
+ !includesNonEmpty(last.start) &&
340
+ (token.indent === 0 ||
341
+ last.start.every(st => st.type !== 'comment' || st.indent < token.indent))) {
342
+ if (top.type === 'document')
343
+ top.end = last.start;
344
+ else
345
+ top.items.push({ start: last.start });
346
+ token.items.splice(-1, 1);
347
+ }
348
+ }
349
+ }
350
+ }
351
+ *stream() {
352
+ switch (this.type) {
353
+ case 'directive-line':
354
+ yield { type: 'directive', offset: this.offset, source: this.source };
355
+ return;
356
+ case 'byte-order-mark':
357
+ case 'space':
358
+ case 'comment':
359
+ case 'newline':
360
+ yield this.sourceToken;
361
+ return;
362
+ case 'doc-mode':
363
+ case 'doc-start': {
364
+ const doc = {
365
+ type: 'document',
366
+ offset: this.offset,
367
+ start: []
368
+ };
369
+ if (this.type === 'doc-start')
370
+ doc.start.push(this.sourceToken);
371
+ this.stack.push(doc);
372
+ return;
373
+ }
374
+ }
375
+ yield {
376
+ type: 'error',
377
+ offset: this.offset,
378
+ message: `Unexpected ${this.type} token in YAML stream`,
379
+ source: this.source
380
+ };
381
+ }
382
+ *document(doc) {
383
+ if (doc.value)
384
+ return yield* this.lineEnd(doc);
385
+ switch (this.type) {
386
+ case 'doc-start': {
387
+ if (includesNonEmpty(doc.start)) {
388
+ yield* this.pop();
389
+ yield* this.step();
390
+ }
391
+ else
392
+ doc.start.push(this.sourceToken);
393
+ return;
394
+ }
395
+ case 'anchor':
396
+ case 'tag':
397
+ case 'space':
398
+ case 'comment':
399
+ case 'newline':
400
+ doc.start.push(this.sourceToken);
401
+ return;
402
+ }
403
+ const bv = this.startBlockValue(doc);
404
+ if (bv)
405
+ this.stack.push(bv);
406
+ else {
407
+ yield {
408
+ type: 'error',
409
+ offset: this.offset,
410
+ message: `Unexpected ${this.type} token in YAML document`,
411
+ source: this.source
412
+ };
413
+ }
414
+ }
415
+ *scalar(scalar) {
416
+ if (this.type === 'map-value-ind') {
417
+ const prev = getPrevProps(this.peek(2));
418
+ const start = getFirstKeyStartProps(prev);
419
+ let sep;
420
+ if (scalar.end) {
421
+ sep = scalar.end;
422
+ sep.push(this.sourceToken);
423
+ delete scalar.end;
424
+ }
425
+ else
426
+ sep = [this.sourceToken];
427
+ const map = {
428
+ type: 'block-map',
429
+ offset: scalar.offset,
430
+ indent: scalar.indent,
431
+ items: [{ start, key: scalar, sep }]
432
+ };
433
+ this.onKeyLine = true;
434
+ this.stack[this.stack.length - 1] = map;
435
+ }
436
+ else
437
+ yield* this.lineEnd(scalar);
438
+ }
439
+ *blockScalar(scalar) {
440
+ switch (this.type) {
441
+ case 'space':
442
+ case 'comment':
443
+ case 'newline':
444
+ scalar.props.push(this.sourceToken);
445
+ return;
446
+ case 'scalar':
447
+ scalar.source = this.source;
448
+ // block-scalar source includes trailing newline
449
+ this.atNewLine = true;
450
+ this.indent = 0;
451
+ if (this.onNewLine) {
452
+ let nl = this.source.indexOf('\n') + 1;
453
+ while (nl !== 0) {
454
+ this.onNewLine(this.offset + nl);
455
+ nl = this.source.indexOf('\n', nl) + 1;
456
+ }
457
+ }
458
+ yield* this.pop();
459
+ break;
460
+ /* istanbul ignore next should not happen */
461
+ default:
462
+ yield* this.pop();
463
+ yield* this.step();
464
+ }
465
+ }
466
+ *blockMap(map) {
467
+ var _a;
468
+ const it = map.items[map.items.length - 1];
469
+ // it.sep is true-ish if pair already has key or : separator
470
+ switch (this.type) {
471
+ case 'newline':
472
+ this.onKeyLine = false;
473
+ if (it.value) {
474
+ const end = 'end' in it.value ? it.value.end : undefined;
475
+ const last = Array.isArray(end) ? end[end.length - 1] : undefined;
476
+ if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
477
+ end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
478
+ else
479
+ map.items.push({ start: [this.sourceToken] });
480
+ }
481
+ else if (it.sep)
482
+ it.sep.push(this.sourceToken);
483
+ else
484
+ it.start.push(this.sourceToken);
485
+ return;
486
+ case 'space':
487
+ case 'comment':
488
+ if (it.value)
489
+ map.items.push({ start: [this.sourceToken] });
490
+ else if (it.sep)
491
+ it.sep.push(this.sourceToken);
492
+ else {
493
+ if (this.atIndentedComment(it.start, map.indent)) {
494
+ const prev = map.items[map.items.length - 2];
495
+ const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
496
+ if (Array.isArray(end)) {
497
+ Array.prototype.push.apply(end, it.start);
498
+ end.push(this.sourceToken);
499
+ map.items.pop();
500
+ return;
501
+ }
502
+ }
503
+ it.start.push(this.sourceToken);
504
+ }
505
+ return;
506
+ }
507
+ if (this.indent >= map.indent) {
508
+ const atNextItem = !this.onKeyLine &&
509
+ this.indent === map.indent &&
510
+ (it.sep || includesNonEmpty(it.start));
511
+ switch (this.type) {
512
+ case 'anchor':
513
+ case 'tag':
514
+ if (atNextItem || it.value) {
515
+ map.items.push({ start: [this.sourceToken] });
516
+ this.onKeyLine = true;
517
+ }
518
+ else if (it.sep)
519
+ it.sep.push(this.sourceToken);
520
+ else
521
+ it.start.push(this.sourceToken);
522
+ return;
523
+ case 'explicit-key-ind':
524
+ if (!it.sep && !includesToken(it.start, 'explicit-key-ind'))
525
+ it.start.push(this.sourceToken);
526
+ else if (atNextItem || it.value)
527
+ map.items.push({ start: [this.sourceToken] });
528
+ else
529
+ this.stack.push({
530
+ type: 'block-map',
531
+ offset: this.offset,
532
+ indent: this.indent,
533
+ items: [{ start: [this.sourceToken] }]
534
+ });
535
+ this.onKeyLine = true;
536
+ return;
537
+ case 'map-value-ind':
538
+ if (!it.sep)
539
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
540
+ else if (it.value ||
541
+ (atNextItem && !includesToken(it.start, 'explicit-key-ind')))
542
+ map.items.push({ start: [], key: null, sep: [this.sourceToken] });
543
+ else if (includesToken(it.sep, 'map-value-ind'))
544
+ this.stack.push({
545
+ type: 'block-map',
546
+ offset: this.offset,
547
+ indent: this.indent,
548
+ items: [{ start: [], key: null, sep: [this.sourceToken] }]
549
+ });
550
+ else if (includesToken(it.start, 'explicit-key-ind') &&
551
+ isFlowToken(it.key) &&
552
+ !includesToken(it.sep, 'newline')) {
553
+ const start = getFirstKeyStartProps(it.start);
554
+ const key = it.key;
555
+ const sep = it.sep;
556
+ sep.push(this.sourceToken);
557
+ // @ts-ignore type guard is wrong here
558
+ delete it.key, delete it.sep;
559
+ this.stack.push({
560
+ type: 'block-map',
561
+ offset: this.offset,
562
+ indent: this.indent,
563
+ items: [{ start, key, sep }]
564
+ });
565
+ }
566
+ else
567
+ it.sep.push(this.sourceToken);
568
+ this.onKeyLine = true;
569
+ return;
570
+ case 'alias':
571
+ case 'scalar':
572
+ case 'single-quoted-scalar':
573
+ case 'double-quoted-scalar': {
574
+ const fs = this.flowScalar(this.type);
575
+ if (atNextItem || it.value) {
576
+ map.items.push({ start: [], key: fs, sep: [] });
577
+ this.onKeyLine = true;
578
+ }
579
+ else if (it.sep) {
580
+ this.stack.push(fs);
581
+ }
582
+ else {
583
+ Object.assign(it, { key: fs, sep: [] });
584
+ this.onKeyLine = true;
585
+ }
586
+ return;
587
+ }
588
+ default: {
589
+ const bv = this.startBlockValue(map);
590
+ if (bv) {
591
+ if (atNextItem &&
592
+ bv.type !== 'block-seq' &&
593
+ includesToken(it.start, 'explicit-key-ind'))
594
+ map.items.push({ start: [] });
595
+ this.stack.push(bv);
596
+ return;
597
+ }
598
+ }
599
+ }
600
+ }
601
+ yield* this.pop();
602
+ yield* this.step();
603
+ }
604
+ *blockSequence(seq) {
605
+ var _a;
606
+ const it = seq.items[seq.items.length - 1];
607
+ switch (this.type) {
608
+ case 'newline':
609
+ if (it.value) {
610
+ const end = 'end' in it.value ? it.value.end : undefined;
611
+ const last = Array.isArray(end) ? end[end.length - 1] : undefined;
612
+ if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
613
+ end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
614
+ else
615
+ seq.items.push({ start: [this.sourceToken] });
616
+ }
617
+ else
618
+ it.start.push(this.sourceToken);
619
+ return;
620
+ case 'space':
621
+ case 'comment':
622
+ if (it.value)
623
+ seq.items.push({ start: [this.sourceToken] });
624
+ else {
625
+ if (this.atIndentedComment(it.start, seq.indent)) {
626
+ const prev = seq.items[seq.items.length - 2];
627
+ const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
628
+ if (Array.isArray(end)) {
629
+ Array.prototype.push.apply(end, it.start);
630
+ end.push(this.sourceToken);
631
+ seq.items.pop();
632
+ return;
633
+ }
634
+ }
635
+ it.start.push(this.sourceToken);
636
+ }
637
+ return;
638
+ case 'anchor':
639
+ case 'tag':
640
+ if (it.value || this.indent <= seq.indent)
641
+ break;
642
+ it.start.push(this.sourceToken);
643
+ return;
644
+ case 'seq-item-ind':
645
+ if (this.indent !== seq.indent)
646
+ break;
647
+ if (it.value || includesToken(it.start, 'seq-item-ind'))
648
+ seq.items.push({ start: [this.sourceToken] });
649
+ else
650
+ it.start.push(this.sourceToken);
651
+ return;
652
+ }
653
+ if (this.indent > seq.indent) {
654
+ const bv = this.startBlockValue(seq);
655
+ if (bv) {
656
+ this.stack.push(bv);
657
+ return;
658
+ }
659
+ }
660
+ yield* this.pop();
661
+ yield* this.step();
662
+ }
663
+ *flowCollection(fc) {
664
+ const it = fc.items[fc.items.length - 1];
665
+ if (this.type === 'flow-error-end') {
666
+ let top;
667
+ do {
668
+ yield* this.pop();
669
+ top = this.peek(1);
670
+ } while (top && top.type === 'flow-collection');
671
+ }
672
+ else if (fc.end.length === 0) {
673
+ switch (this.type) {
674
+ case 'comma':
675
+ case 'explicit-key-ind':
676
+ if (!it || it.sep)
677
+ fc.items.push({ start: [this.sourceToken] });
678
+ else
679
+ it.start.push(this.sourceToken);
680
+ return;
681
+ case 'map-value-ind':
682
+ if (!it || it.value)
683
+ fc.items.push({ start: [], key: null, sep: [this.sourceToken] });
684
+ else if (it.sep)
685
+ it.sep.push(this.sourceToken);
686
+ else
687
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
688
+ return;
689
+ case 'space':
690
+ case 'comment':
691
+ case 'newline':
692
+ case 'anchor':
693
+ case 'tag':
694
+ if (!it || it.value)
695
+ fc.items.push({ start: [this.sourceToken] });
696
+ else if (it.sep)
697
+ it.sep.push(this.sourceToken);
698
+ else
699
+ it.start.push(this.sourceToken);
700
+ return;
701
+ case 'alias':
702
+ case 'scalar':
703
+ case 'single-quoted-scalar':
704
+ case 'double-quoted-scalar': {
705
+ const fs = this.flowScalar(this.type);
706
+ if (!it || it.value)
707
+ fc.items.push({ start: [], key: fs, sep: [] });
708
+ else if (it.sep)
709
+ this.stack.push(fs);
710
+ else
711
+ Object.assign(it, { key: fs, sep: [] });
712
+ return;
713
+ }
714
+ case 'flow-map-end':
715
+ case 'flow-seq-end':
716
+ fc.end.push(this.sourceToken);
717
+ return;
718
+ }
719
+ const bv = this.startBlockValue(fc);
720
+ /* istanbul ignore else should not happen */
721
+ if (bv)
722
+ this.stack.push(bv);
723
+ else {
724
+ yield* this.pop();
725
+ yield* this.step();
726
+ }
727
+ }
728
+ else {
729
+ const parent = this.peek(2);
730
+ if (parent.type === 'block-map' &&
731
+ (this.type === 'map-value-ind' ||
732
+ (this.type === 'newline' &&
733
+ !parent.items[parent.items.length - 1].sep))) {
734
+ yield* this.pop();
735
+ yield* this.step();
736
+ }
737
+ else if (this.type === 'map-value-ind' &&
738
+ parent.type !== 'flow-collection') {
739
+ const prev = getPrevProps(parent);
740
+ const start = getFirstKeyStartProps(prev);
741
+ fixFlowSeqItems(fc);
742
+ const sep = fc.end.splice(1, fc.end.length);
743
+ sep.push(this.sourceToken);
744
+ const map = {
745
+ type: 'block-map',
746
+ offset: fc.offset,
747
+ indent: fc.indent,
748
+ items: [{ start, key: fc, sep }]
749
+ };
750
+ this.onKeyLine = true;
751
+ this.stack[this.stack.length - 1] = map;
752
+ }
753
+ else {
754
+ yield* this.lineEnd(fc);
755
+ }
756
+ }
757
+ }
758
+ flowScalar(type) {
759
+ if (this.onNewLine) {
760
+ let nl = this.source.indexOf('\n') + 1;
761
+ while (nl !== 0) {
762
+ this.onNewLine(this.offset + nl);
763
+ nl = this.source.indexOf('\n', nl) + 1;
764
+ }
765
+ }
766
+ return {
767
+ type,
768
+ offset: this.offset,
769
+ indent: this.indent,
770
+ source: this.source
771
+ };
772
+ }
773
+ startBlockValue(parent) {
774
+ switch (this.type) {
775
+ case 'alias':
776
+ case 'scalar':
777
+ case 'single-quoted-scalar':
778
+ case 'double-quoted-scalar':
779
+ return this.flowScalar(this.type);
780
+ case 'block-scalar-header':
781
+ return {
782
+ type: 'block-scalar',
783
+ offset: this.offset,
784
+ indent: this.indent,
785
+ props: [this.sourceToken],
786
+ source: ''
787
+ };
788
+ case 'flow-map-start':
789
+ case 'flow-seq-start':
790
+ return {
791
+ type: 'flow-collection',
792
+ offset: this.offset,
793
+ indent: this.indent,
794
+ start: this.sourceToken,
795
+ items: [],
796
+ end: []
797
+ };
798
+ case 'seq-item-ind':
799
+ return {
800
+ type: 'block-seq',
801
+ offset: this.offset,
802
+ indent: this.indent,
803
+ items: [{ start: [this.sourceToken] }]
804
+ };
805
+ case 'explicit-key-ind': {
806
+ this.onKeyLine = true;
807
+ const prev = getPrevProps(parent);
808
+ const start = getFirstKeyStartProps(prev);
809
+ start.push(this.sourceToken);
810
+ return {
811
+ type: 'block-map',
812
+ offset: this.offset,
813
+ indent: this.indent,
814
+ items: [{ start }]
815
+ };
816
+ }
817
+ case 'map-value-ind': {
818
+ this.onKeyLine = true;
819
+ const prev = getPrevProps(parent);
820
+ const start = getFirstKeyStartProps(prev);
821
+ return {
822
+ type: 'block-map',
823
+ offset: this.offset,
824
+ indent: this.indent,
825
+ items: [{ start, key: null, sep: [this.sourceToken] }]
826
+ };
827
+ }
828
+ }
829
+ return null;
830
+ }
831
+ atIndentedComment(start, indent) {
832
+ if (this.type !== 'comment')
833
+ return false;
834
+ if (this.indent <= indent)
835
+ return false;
836
+ return start.every(st => st.type === 'newline' || st.type === 'space');
837
+ }
838
+ *documentEnd(docEnd) {
839
+ if (this.type !== 'doc-mode') {
840
+ if (docEnd.end)
841
+ docEnd.end.push(this.sourceToken);
842
+ else
843
+ docEnd.end = [this.sourceToken];
844
+ if (this.type === 'newline')
845
+ yield* this.pop();
846
+ }
847
+ }
848
+ *lineEnd(token) {
849
+ switch (this.type) {
850
+ case 'comma':
851
+ case 'doc-start':
852
+ case 'doc-end':
853
+ case 'flow-seq-end':
854
+ case 'flow-map-end':
855
+ case 'map-value-ind':
856
+ yield* this.pop();
857
+ yield* this.step();
858
+ break;
859
+ case 'newline':
860
+ this.onKeyLine = false;
861
+ // fallthrough
862
+ case 'space':
863
+ case 'comment':
864
+ default:
865
+ // all other values are errors
866
+ if (token.end)
867
+ token.end.push(this.sourceToken);
868
+ else
869
+ token.end = [this.sourceToken];
870
+ if (this.type === 'newline')
871
+ yield* this.pop();
872
+ }
873
+ }
874
+ }
875
+
876
+ export { Parser };