cdklabs-projen-project-types 0.0.2

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