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,701 @@
1
+ import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.js';
2
+
3
+ /*
4
+ START -> stream
5
+
6
+ stream
7
+ directive -> line-end -> stream
8
+ indent + line-end -> stream
9
+ [else] -> line-start
10
+
11
+ line-end
12
+ comment -> line-end
13
+ newline -> .
14
+ input-end -> END
15
+
16
+ line-start
17
+ doc-start -> doc
18
+ doc-end -> stream
19
+ [else] -> indent -> block-start
20
+
21
+ block-start
22
+ seq-item-start -> block-start
23
+ explicit-key-start -> block-start
24
+ map-value-start -> block-start
25
+ [else] -> doc
26
+
27
+ doc
28
+ line-end -> line-start
29
+ spaces -> doc
30
+ anchor -> doc
31
+ tag -> doc
32
+ flow-start -> flow -> doc
33
+ flow-end -> error -> doc
34
+ seq-item-start -> error -> doc
35
+ explicit-key-start -> error -> doc
36
+ map-value-start -> doc
37
+ alias -> doc
38
+ quote-start -> quoted-scalar -> doc
39
+ block-scalar-header -> line-end -> block-scalar(min) -> line-start
40
+ [else] -> plain-scalar(false, min) -> doc
41
+
42
+ flow
43
+ line-end -> flow
44
+ spaces -> flow
45
+ anchor -> flow
46
+ tag -> flow
47
+ flow-start -> flow -> flow
48
+ flow-end -> .
49
+ seq-item-start -> error -> flow
50
+ explicit-key-start -> flow
51
+ map-value-start -> flow
52
+ alias -> flow
53
+ quote-start -> quoted-scalar -> flow
54
+ comma -> flow
55
+ [else] -> plain-scalar(true, 0) -> flow
56
+
57
+ quoted-scalar
58
+ quote-end -> .
59
+ [else] -> quoted-scalar
60
+
61
+ block-scalar(min)
62
+ newline + peek(indent < min) -> .
63
+ [else] -> block-scalar(min)
64
+
65
+ plain-scalar(is-flow, min)
66
+ scalar-end(is-flow) -> .
67
+ peek(newline + (indent < min)) -> .
68
+ [else] -> plain-scalar(min)
69
+ */
70
+ function isEmpty(ch) {
71
+ switch (ch) {
72
+ case undefined:
73
+ case ' ':
74
+ case '\n':
75
+ case '\r':
76
+ case '\t':
77
+ return true;
78
+ default:
79
+ return false;
80
+ }
81
+ }
82
+ const hexDigits = '0123456789ABCDEFabcdef'.split('');
83
+ const tagChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()".split('');
84
+ const invalidFlowScalarChars = ',[]{}'.split('');
85
+ const invalidAnchorChars = ' ,[]{}\n\r\t'.split('');
86
+ const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.includes(ch);
87
+ /**
88
+ * Splits an input string into lexical tokens, i.e. smaller strings that are
89
+ * easily identifiable by `tokens.tokenType()`.
90
+ *
91
+ * Lexing starts always in a "stream" context. Incomplete input may be buffered
92
+ * until a complete token can be emitted.
93
+ *
94
+ * In addition to slices of the original input, the following control characters
95
+ * may also be emitted:
96
+ *
97
+ * - `\x02` (Start of Text): A document starts with the next token
98
+ * - `\x18` (Cancel): Unexpected end of flow-mode (indicates an error)
99
+ * - `\x1f` (Unit Separator): Next token is a scalar value
100
+ * - `\u{FEFF}` (Byte order mark): Emitted separately outside documents
101
+ */
102
+ class Lexer {
103
+ constructor() {
104
+ /**
105
+ * Flag indicating whether the end of the current buffer marks the end of
106
+ * all input
107
+ */
108
+ this.atEnd = false;
109
+ /**
110
+ * Explicit indent set in block scalar header, as an offset from the current
111
+ * minimum indent, so e.g. set to 1 from a header `|2+`. Set to -1 if not
112
+ * explicitly set.
113
+ */
114
+ this.blockScalarIndent = -1;
115
+ /**
116
+ * Block scalars that include a + (keep) chomping indicator in their header
117
+ * include trailing empty lines, which are otherwise excluded from the
118
+ * scalar's contents.
119
+ */
120
+ this.blockScalarKeep = false;
121
+ /** Current input */
122
+ this.buffer = '';
123
+ /**
124
+ * Flag noting whether the map value indicator : can immediately follow this
125
+ * node within a flow context.
126
+ */
127
+ this.flowKey = false;
128
+ /** Count of surrounding flow collection levels. */
129
+ this.flowLevel = 0;
130
+ /**
131
+ * Minimum level of indentation required for next lines to be parsed as a
132
+ * part of the current scalar value.
133
+ */
134
+ this.indentNext = 0;
135
+ /** Indentation level of the current line. */
136
+ this.indentValue = 0;
137
+ /** Position of the next \n character. */
138
+ this.lineEndPos = null;
139
+ /** Stores the state of the lexer if reaching the end of incpomplete input */
140
+ this.next = null;
141
+ /** A pointer to `buffer`; the current position of the lexer. */
142
+ this.pos = 0;
143
+ }
144
+ /**
145
+ * Generate YAML tokens from the `source` string. If `incomplete`,
146
+ * a part of the last line may be left as a buffer for the next call.
147
+ *
148
+ * @returns A generator of lexical tokens
149
+ */
150
+ *lex(source, incomplete = false) {
151
+ if (source) {
152
+ this.buffer = this.buffer ? this.buffer + source : source;
153
+ this.lineEndPos = null;
154
+ }
155
+ this.atEnd = !incomplete;
156
+ let next = this.next ?? 'stream';
157
+ while (next && (incomplete || this.hasChars(1)))
158
+ next = yield* this.parseNext(next);
159
+ }
160
+ atLineEnd() {
161
+ let i = this.pos;
162
+ let ch = this.buffer[i];
163
+ while (ch === ' ' || ch === '\t')
164
+ ch = this.buffer[++i];
165
+ if (!ch || ch === '#' || ch === '\n')
166
+ return true;
167
+ if (ch === '\r')
168
+ return this.buffer[i + 1] === '\n';
169
+ return false;
170
+ }
171
+ charAt(n) {
172
+ return this.buffer[this.pos + n];
173
+ }
174
+ continueScalar(offset) {
175
+ let ch = this.buffer[offset];
176
+ if (this.indentNext > 0) {
177
+ let indent = 0;
178
+ while (ch === ' ')
179
+ ch = this.buffer[++indent + offset];
180
+ if (ch === '\r') {
181
+ const next = this.buffer[indent + offset + 1];
182
+ if (next === '\n' || (!next && !this.atEnd))
183
+ return offset + indent + 1;
184
+ }
185
+ return ch === '\n' || indent >= this.indentNext || (!ch && !this.atEnd)
186
+ ? offset + indent
187
+ : -1;
188
+ }
189
+ if (ch === '-' || ch === '.') {
190
+ const dt = this.buffer.substr(offset, 3);
191
+ if ((dt === '---' || dt === '...') && isEmpty(this.buffer[offset + 3]))
192
+ return -1;
193
+ }
194
+ return offset;
195
+ }
196
+ getLine() {
197
+ let end = this.lineEndPos;
198
+ if (typeof end !== 'number' || (end !== -1 && end < this.pos)) {
199
+ end = this.buffer.indexOf('\n', this.pos);
200
+ this.lineEndPos = end;
201
+ }
202
+ if (end === -1)
203
+ return this.atEnd ? this.buffer.substring(this.pos) : null;
204
+ if (this.buffer[end - 1] === '\r')
205
+ end -= 1;
206
+ return this.buffer.substring(this.pos, end);
207
+ }
208
+ hasChars(n) {
209
+ return this.pos + n <= this.buffer.length;
210
+ }
211
+ setNext(state) {
212
+ this.buffer = this.buffer.substring(this.pos);
213
+ this.pos = 0;
214
+ this.lineEndPos = null;
215
+ this.next = state;
216
+ return null;
217
+ }
218
+ peek(n) {
219
+ return this.buffer.substr(this.pos, n);
220
+ }
221
+ *parseNext(next) {
222
+ switch (next) {
223
+ case 'stream':
224
+ return yield* this.parseStream();
225
+ case 'line-start':
226
+ return yield* this.parseLineStart();
227
+ case 'block-start':
228
+ return yield* this.parseBlockStart();
229
+ case 'doc':
230
+ return yield* this.parseDocument();
231
+ case 'flow':
232
+ return yield* this.parseFlowCollection();
233
+ case 'quoted-scalar':
234
+ return yield* this.parseQuotedScalar();
235
+ case 'block-scalar':
236
+ return yield* this.parseBlockScalar();
237
+ case 'plain-scalar':
238
+ return yield* this.parsePlainScalar();
239
+ }
240
+ }
241
+ *parseStream() {
242
+ let line = this.getLine();
243
+ if (line === null)
244
+ return this.setNext('stream');
245
+ if (line[0] === BOM) {
246
+ yield* this.pushCount(1);
247
+ line = line.substring(1);
248
+ }
249
+ if (line[0] === '%') {
250
+ let dirEnd = line.length;
251
+ const cs = line.indexOf('#');
252
+ if (cs !== -1) {
253
+ const ch = line[cs - 1];
254
+ if (ch === ' ' || ch === '\t')
255
+ dirEnd = cs - 1;
256
+ }
257
+ while (true) {
258
+ const ch = line[dirEnd - 1];
259
+ if (ch === ' ' || ch === '\t')
260
+ dirEnd -= 1;
261
+ else
262
+ break;
263
+ }
264
+ const n = (yield* this.pushCount(dirEnd)) + (yield* this.pushSpaces(true));
265
+ yield* this.pushCount(line.length - n); // possible comment
266
+ this.pushNewline();
267
+ return 'stream';
268
+ }
269
+ if (this.atLineEnd()) {
270
+ const sp = yield* this.pushSpaces(true);
271
+ yield* this.pushCount(line.length - sp);
272
+ yield* this.pushNewline();
273
+ return 'stream';
274
+ }
275
+ yield DOCUMENT;
276
+ return yield* this.parseLineStart();
277
+ }
278
+ *parseLineStart() {
279
+ const ch = this.charAt(0);
280
+ if (!ch && !this.atEnd)
281
+ return this.setNext('line-start');
282
+ if (ch === '-' || ch === '.') {
283
+ if (!this.atEnd && !this.hasChars(4))
284
+ return this.setNext('line-start');
285
+ const s = this.peek(3);
286
+ if (s === '---' && isEmpty(this.charAt(3))) {
287
+ yield* this.pushCount(3);
288
+ this.indentValue = 0;
289
+ this.indentNext = 0;
290
+ return 'doc';
291
+ }
292
+ else if (s === '...' && isEmpty(this.charAt(3))) {
293
+ yield* this.pushCount(3);
294
+ return 'stream';
295
+ }
296
+ }
297
+ this.indentValue = yield* this.pushSpaces(false);
298
+ if (this.indentNext > this.indentValue && !isEmpty(this.charAt(1)))
299
+ this.indentNext = this.indentValue;
300
+ return yield* this.parseBlockStart();
301
+ }
302
+ *parseBlockStart() {
303
+ const [ch0, ch1] = this.peek(2);
304
+ if (!ch1 && !this.atEnd)
305
+ return this.setNext('block-start');
306
+ if ((ch0 === '-' || ch0 === '?' || ch0 === ':') && isEmpty(ch1)) {
307
+ const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
308
+ this.indentNext = this.indentValue + 1;
309
+ this.indentValue += n;
310
+ return yield* this.parseBlockStart();
311
+ }
312
+ return 'doc';
313
+ }
314
+ *parseDocument() {
315
+ yield* this.pushSpaces(true);
316
+ const line = this.getLine();
317
+ if (line === null)
318
+ return this.setNext('doc');
319
+ let n = yield* this.pushIndicators();
320
+ switch (line[n]) {
321
+ case '#':
322
+ yield* this.pushCount(line.length - n);
323
+ // fallthrough
324
+ case undefined:
325
+ yield* this.pushNewline();
326
+ return yield* this.parseLineStart();
327
+ case '{':
328
+ case '[':
329
+ yield* this.pushCount(1);
330
+ this.flowKey = false;
331
+ this.flowLevel = 1;
332
+ return 'flow';
333
+ case '}':
334
+ case ']':
335
+ // this is an error
336
+ yield* this.pushCount(1);
337
+ return 'doc';
338
+ case '*':
339
+ yield* this.pushUntil(isNotAnchorChar);
340
+ return 'doc';
341
+ case '"':
342
+ case "'":
343
+ return yield* this.parseQuotedScalar();
344
+ case '|':
345
+ case '>':
346
+ n += yield* this.parseBlockScalarHeader();
347
+ n += yield* this.pushSpaces(true);
348
+ yield* this.pushCount(line.length - n);
349
+ yield* this.pushNewline();
350
+ return yield* this.parseBlockScalar();
351
+ default:
352
+ return yield* this.parsePlainScalar();
353
+ }
354
+ }
355
+ *parseFlowCollection() {
356
+ let nl, sp;
357
+ let indent = -1;
358
+ do {
359
+ nl = yield* this.pushNewline();
360
+ if (nl > 0) {
361
+ sp = yield* this.pushSpaces(false);
362
+ this.indentValue = indent = sp;
363
+ }
364
+ else {
365
+ sp = 0;
366
+ }
367
+ sp += yield* this.pushSpaces(true);
368
+ } while (nl + sp > 0);
369
+ const line = this.getLine();
370
+ if (line === null)
371
+ return this.setNext('flow');
372
+ if ((indent !== -1 && indent < this.indentNext && line[0] !== '#') ||
373
+ (indent === 0 &&
374
+ (line.startsWith('---') || line.startsWith('...')) &&
375
+ isEmpty(line[3]))) {
376
+ // Allowing for the terminal ] or } at the same (rather than greater)
377
+ // indent level as the initial [ or { is technically invalid, but
378
+ // failing here would be surprising to users.
379
+ const atFlowEndMarker = indent === this.indentNext - 1 &&
380
+ this.flowLevel === 1 &&
381
+ (line[0] === ']' || line[0] === '}');
382
+ if (!atFlowEndMarker) {
383
+ // this is an error
384
+ this.flowLevel = 0;
385
+ yield FLOW_END;
386
+ return yield* this.parseLineStart();
387
+ }
388
+ }
389
+ let n = 0;
390
+ while (line[n] === ',') {
391
+ n += yield* this.pushCount(1);
392
+ n += yield* this.pushSpaces(true);
393
+ this.flowKey = false;
394
+ }
395
+ n += yield* this.pushIndicators();
396
+ switch (line[n]) {
397
+ case undefined:
398
+ return 'flow';
399
+ case '#':
400
+ yield* this.pushCount(line.length - n);
401
+ return 'flow';
402
+ case '{':
403
+ case '[':
404
+ yield* this.pushCount(1);
405
+ this.flowKey = false;
406
+ this.flowLevel += 1;
407
+ return 'flow';
408
+ case '}':
409
+ case ']':
410
+ yield* this.pushCount(1);
411
+ this.flowKey = true;
412
+ this.flowLevel -= 1;
413
+ return this.flowLevel ? 'flow' : 'doc';
414
+ case '*':
415
+ yield* this.pushUntil(isNotAnchorChar);
416
+ return 'flow';
417
+ case '"':
418
+ case "'":
419
+ this.flowKey = true;
420
+ return yield* this.parseQuotedScalar();
421
+ case ':': {
422
+ const next = this.charAt(1);
423
+ if (this.flowKey || isEmpty(next) || next === ',') {
424
+ this.flowKey = false;
425
+ yield* this.pushCount(1);
426
+ yield* this.pushSpaces(true);
427
+ return 'flow';
428
+ }
429
+ }
430
+ // fallthrough
431
+ default:
432
+ this.flowKey = false;
433
+ return yield* this.parsePlainScalar();
434
+ }
435
+ }
436
+ *parseQuotedScalar() {
437
+ const quote = this.charAt(0);
438
+ let end = this.buffer.indexOf(quote, this.pos + 1);
439
+ if (quote === "'") {
440
+ while (end !== -1 && this.buffer[end + 1] === "'")
441
+ end = this.buffer.indexOf("'", end + 2);
442
+ }
443
+ else {
444
+ // double-quote
445
+ while (end !== -1) {
446
+ let n = 0;
447
+ while (this.buffer[end - 1 - n] === '\\')
448
+ n += 1;
449
+ if (n % 2 === 0)
450
+ break;
451
+ end = this.buffer.indexOf('"', end + 1);
452
+ }
453
+ }
454
+ // Only looking for newlines within the quotes
455
+ const qb = this.buffer.substring(0, end);
456
+ let nl = qb.indexOf('\n', this.pos);
457
+ if (nl !== -1) {
458
+ while (nl !== -1) {
459
+ const cs = this.continueScalar(nl + 1);
460
+ if (cs === -1)
461
+ break;
462
+ nl = qb.indexOf('\n', cs);
463
+ }
464
+ if (nl !== -1) {
465
+ // this is an error caused by an unexpected unindent
466
+ end = nl - (qb[nl - 1] === '\r' ? 2 : 1);
467
+ }
468
+ }
469
+ if (end === -1) {
470
+ if (!this.atEnd)
471
+ return this.setNext('quoted-scalar');
472
+ end = this.buffer.length;
473
+ }
474
+ yield* this.pushToIndex(end + 1, false);
475
+ return this.flowLevel ? 'flow' : 'doc';
476
+ }
477
+ *parseBlockScalarHeader() {
478
+ this.blockScalarIndent = -1;
479
+ this.blockScalarKeep = false;
480
+ let i = this.pos;
481
+ while (true) {
482
+ const ch = this.buffer[++i];
483
+ if (ch === '+')
484
+ this.blockScalarKeep = true;
485
+ else if (ch > '0' && ch <= '9')
486
+ this.blockScalarIndent = Number(ch) - 1;
487
+ else if (ch !== '-')
488
+ break;
489
+ }
490
+ return yield* this.pushUntil(ch => isEmpty(ch) || ch === '#');
491
+ }
492
+ *parseBlockScalar() {
493
+ let nl = this.pos - 1; // may be -1 if this.pos === 0
494
+ let indent = 0;
495
+ let ch;
496
+ loop: for (let i = this.pos; (ch = this.buffer[i]); ++i) {
497
+ switch (ch) {
498
+ case ' ':
499
+ indent += 1;
500
+ break;
501
+ case '\n':
502
+ nl = i;
503
+ indent = 0;
504
+ break;
505
+ case '\r': {
506
+ const next = this.buffer[i + 1];
507
+ if (!next && !this.atEnd)
508
+ return this.setNext('block-scalar');
509
+ if (next === '\n')
510
+ break;
511
+ } // fallthrough
512
+ default:
513
+ break loop;
514
+ }
515
+ }
516
+ if (!ch && !this.atEnd)
517
+ return this.setNext('block-scalar');
518
+ if (indent >= this.indentNext) {
519
+ if (this.blockScalarIndent === -1)
520
+ this.indentNext = indent;
521
+ else
522
+ this.indentNext += this.blockScalarIndent;
523
+ do {
524
+ const cs = this.continueScalar(nl + 1);
525
+ if (cs === -1)
526
+ break;
527
+ nl = this.buffer.indexOf('\n', cs);
528
+ } while (nl !== -1);
529
+ if (nl === -1) {
530
+ if (!this.atEnd)
531
+ return this.setNext('block-scalar');
532
+ nl = this.buffer.length;
533
+ }
534
+ }
535
+ if (!this.blockScalarKeep) {
536
+ do {
537
+ let i = nl - 1;
538
+ let ch = this.buffer[i];
539
+ if (ch === '\r')
540
+ ch = this.buffer[--i];
541
+ const lastChar = i; // Drop the line if last char not more indented
542
+ while (ch === ' ' || ch === '\t')
543
+ ch = this.buffer[--i];
544
+ if (ch === '\n' && i >= this.pos && i + 1 + indent > lastChar)
545
+ nl = i;
546
+ else
547
+ break;
548
+ } while (true);
549
+ }
550
+ yield SCALAR;
551
+ yield* this.pushToIndex(nl + 1, true);
552
+ return yield* this.parseLineStart();
553
+ }
554
+ *parsePlainScalar() {
555
+ const inFlow = this.flowLevel > 0;
556
+ let end = this.pos - 1;
557
+ let i = this.pos - 1;
558
+ let ch;
559
+ while ((ch = this.buffer[++i])) {
560
+ if (ch === ':') {
561
+ const next = this.buffer[i + 1];
562
+ if (isEmpty(next) || (inFlow && next === ','))
563
+ break;
564
+ end = i;
565
+ }
566
+ else if (isEmpty(ch)) {
567
+ let next = this.buffer[i + 1];
568
+ if (ch === '\r') {
569
+ if (next === '\n') {
570
+ i += 1;
571
+ ch = '\n';
572
+ next = this.buffer[i + 1];
573
+ }
574
+ else
575
+ end = i;
576
+ }
577
+ if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
578
+ break;
579
+ if (ch === '\n') {
580
+ const cs = this.continueScalar(i + 1);
581
+ if (cs === -1)
582
+ break;
583
+ i = Math.max(i, cs - 2); // to advance, but still account for ' #'
584
+ }
585
+ }
586
+ else {
587
+ if (inFlow && invalidFlowScalarChars.includes(ch))
588
+ break;
589
+ end = i;
590
+ }
591
+ }
592
+ if (!ch && !this.atEnd)
593
+ return this.setNext('plain-scalar');
594
+ yield SCALAR;
595
+ yield* this.pushToIndex(end + 1, true);
596
+ return inFlow ? 'flow' : 'doc';
597
+ }
598
+ *pushCount(n) {
599
+ if (n > 0) {
600
+ yield this.buffer.substr(this.pos, n);
601
+ this.pos += n;
602
+ return n;
603
+ }
604
+ return 0;
605
+ }
606
+ *pushToIndex(i, allowEmpty) {
607
+ const s = this.buffer.slice(this.pos, i);
608
+ if (s) {
609
+ yield s;
610
+ this.pos += s.length;
611
+ return s.length;
612
+ }
613
+ else if (allowEmpty)
614
+ yield '';
615
+ return 0;
616
+ }
617
+ *pushIndicators() {
618
+ switch (this.charAt(0)) {
619
+ case '!':
620
+ return ((yield* this.pushTag()) +
621
+ (yield* this.pushSpaces(true)) +
622
+ (yield* this.pushIndicators()));
623
+ case '&':
624
+ return ((yield* this.pushUntil(isNotAnchorChar)) +
625
+ (yield* this.pushSpaces(true)) +
626
+ (yield* this.pushIndicators()));
627
+ case '-': // this is an error
628
+ case '?': // this is an error outside flow collections
629
+ case ':': {
630
+ const inFlow = this.flowLevel > 0;
631
+ const ch1 = this.charAt(1);
632
+ if (isEmpty(ch1) || (inFlow && invalidFlowScalarChars.includes(ch1))) {
633
+ if (!inFlow)
634
+ this.indentNext = this.indentValue + 1;
635
+ else if (this.flowKey)
636
+ this.flowKey = false;
637
+ return ((yield* this.pushCount(1)) +
638
+ (yield* this.pushSpaces(true)) +
639
+ (yield* this.pushIndicators()));
640
+ }
641
+ }
642
+ }
643
+ return 0;
644
+ }
645
+ *pushTag() {
646
+ if (this.charAt(1) === '<') {
647
+ let i = this.pos + 2;
648
+ let ch = this.buffer[i];
649
+ while (!isEmpty(ch) && ch !== '>')
650
+ ch = this.buffer[++i];
651
+ return yield* this.pushToIndex(ch === '>' ? i + 1 : i, false);
652
+ }
653
+ else {
654
+ let i = this.pos + 1;
655
+ let ch = this.buffer[i];
656
+ while (ch) {
657
+ if (tagChars.includes(ch))
658
+ ch = this.buffer[++i];
659
+ else if (ch === '%' &&
660
+ hexDigits.includes(this.buffer[i + 1]) &&
661
+ hexDigits.includes(this.buffer[i + 2])) {
662
+ ch = this.buffer[(i += 3)];
663
+ }
664
+ else
665
+ break;
666
+ }
667
+ return yield* this.pushToIndex(i, false);
668
+ }
669
+ }
670
+ *pushNewline() {
671
+ const ch = this.buffer[this.pos];
672
+ if (ch === '\n')
673
+ return yield* this.pushCount(1);
674
+ else if (ch === '\r' && this.charAt(1) === '\n')
675
+ return yield* this.pushCount(2);
676
+ else
677
+ return 0;
678
+ }
679
+ *pushSpaces(allowTabs) {
680
+ let i = this.pos - 1;
681
+ let ch;
682
+ do {
683
+ ch = this.buffer[++i];
684
+ } while (ch === ' ' || (allowTabs && ch === '\t'));
685
+ const n = i - this.pos;
686
+ if (n > 0) {
687
+ yield this.buffer.substr(this.pos, n);
688
+ this.pos = i;
689
+ }
690
+ return n;
691
+ }
692
+ *pushUntil(test) {
693
+ let i = this.pos;
694
+ let ch = this.buffer[i];
695
+ while (!test(ch))
696
+ ch = this.buffer[++i];
697
+ return yield* this.pushToIndex(i, false);
698
+ }
699
+ }
700
+
701
+ export { Lexer };