yaml 2.0.0-2 → 2.0.0-6

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