yaml 2.0.0-4 → 2.0.0-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/README.md +5 -5
  2. package/browser/dist/compose/compose-collection.js +12 -9
  3. package/browser/dist/compose/compose-doc.js +23 -6
  4. package/browser/dist/compose/compose-node.js +20 -17
  5. package/browser/dist/compose/compose-scalar.js +20 -23
  6. package/browser/dist/compose/composer.js +105 -76
  7. package/browser/dist/compose/resolve-block-map.js +38 -29
  8. package/browser/dist/compose/resolve-block-scalar.js +14 -17
  9. package/browser/dist/compose/resolve-block-seq.js +21 -17
  10. package/browser/dist/compose/resolve-end.js +6 -7
  11. package/browser/dist/compose/resolve-flow-collection.js +153 -199
  12. package/browser/dist/compose/resolve-flow-scalar.js +49 -25
  13. package/browser/dist/compose/resolve-props.js +47 -35
  14. package/browser/dist/compose/util-contains-newline.js +15 -12
  15. package/browser/dist/doc/Document.js +50 -99
  16. package/browser/dist/doc/anchors.js +72 -0
  17. package/browser/dist/doc/createNode.js +27 -17
  18. package/browser/dist/errors.js +16 -12
  19. package/browser/dist/index.js +3 -3
  20. package/browser/dist/nodes/Alias.js +51 -28
  21. package/browser/dist/nodes/Collection.js +5 -83
  22. package/browser/dist/nodes/Node.js +2 -1
  23. package/browser/dist/nodes/Pair.js +9 -232
  24. package/browser/dist/nodes/YAMLMap.js +8 -4
  25. package/browser/dist/nodes/YAMLSeq.js +7 -4
  26. package/browser/dist/nodes/addPairToJSMap.js +103 -0
  27. package/browser/dist/nodes/toJS.js +12 -10
  28. package/browser/dist/options.js +0 -2
  29. package/browser/dist/parse/cst-scalar.js +219 -0
  30. package/browser/dist/parse/cst-stringify.js +61 -0
  31. package/browser/dist/parse/cst-visit.js +97 -0
  32. package/{dist/parse/tokens.js → browser/dist/parse/cst.js} +12 -7
  33. package/browser/dist/parse/lexer.js +99 -105
  34. package/browser/dist/parse/parser.js +219 -144
  35. package/browser/dist/public-api.js +11 -14
  36. package/browser/dist/schema/Schema.js +23 -0
  37. package/browser/dist/{tags/failsafe → schema/common}/map.js +0 -0
  38. package/browser/dist/schema/common/null.js +13 -0
  39. package/browser/dist/{tags/failsafe → schema/common}/seq.js +1 -1
  40. package/browser/dist/{tags/failsafe → schema/common}/string.js +0 -0
  41. package/browser/dist/schema/core/bool.js +19 -0
  42. package/browser/dist/schema/core/float.js +40 -0
  43. package/browser/dist/schema/core/int.js +38 -0
  44. package/browser/dist/schema/core/schema.js +23 -0
  45. package/browser/dist/{tags/json.js → schema/json/schema.js} +5 -6
  46. package/browser/dist/schema/tags.js +79 -0
  47. package/browser/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
  48. package/browser/dist/schema/yaml-1.1/bool.js +26 -0
  49. package/browser/dist/schema/yaml-1.1/float.js +43 -0
  50. package/browser/dist/schema/yaml-1.1/int.js +71 -0
  51. package/browser/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
  52. package/browser/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
  53. package/browser/dist/schema/yaml-1.1/schema.js +37 -0
  54. package/browser/dist/{tags → schema}/yaml-1.1/set.js +0 -0
  55. package/browser/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
  56. package/browser/dist/stringify/addComment.js +1 -7
  57. package/browser/dist/stringify/stringify.js +8 -6
  58. package/browser/dist/stringify/stringifyCollection.js +108 -0
  59. package/browser/dist/stringify/stringifyDocument.js +61 -0
  60. package/browser/dist/stringify/stringifyPair.js +113 -0
  61. package/browser/dist/stringify/stringifyString.js +53 -52
  62. package/browser/dist/visit.js +20 -1
  63. package/dist/compose/compose-collection.d.ts +4 -4
  64. package/dist/compose/compose-collection.js +12 -9
  65. package/dist/compose/compose-doc.d.ts +4 -3
  66. package/dist/compose/compose-doc.js +23 -6
  67. package/dist/compose/compose-node.d.ts +15 -7
  68. package/dist/compose/compose-node.js +20 -17
  69. package/dist/compose/compose-scalar.d.ts +4 -3
  70. package/dist/compose/compose-scalar.js +19 -22
  71. package/dist/compose/composer.d.ts +28 -23
  72. package/dist/compose/composer.js +106 -77
  73. package/dist/compose/resolve-block-map.d.ts +4 -4
  74. package/dist/compose/resolve-block-map.js +38 -29
  75. package/dist/compose/resolve-block-scalar.d.ts +5 -3
  76. package/dist/compose/resolve-block-scalar.js +14 -17
  77. package/dist/compose/resolve-block-seq.d.ts +4 -4
  78. package/dist/compose/resolve-block-seq.js +21 -17
  79. package/dist/compose/resolve-end.d.ts +3 -2
  80. package/dist/compose/resolve-end.js +6 -7
  81. package/dist/compose/resolve-flow-collection.d.ts +4 -5
  82. package/dist/compose/resolve-flow-collection.js +152 -198
  83. package/dist/compose/resolve-flow-scalar.d.ts +5 -3
  84. package/dist/compose/resolve-flow-scalar.js +49 -25
  85. package/dist/compose/resolve-props.d.ts +17 -10
  86. package/dist/compose/resolve-props.js +47 -35
  87. package/dist/compose/util-contains-newline.d.ts +1 -1
  88. package/dist/compose/util-contains-newline.js +15 -12
  89. package/dist/compose/util-empty-scalar-position.d.ts +1 -1
  90. package/dist/doc/Document.d.ts +27 -15
  91. package/dist/doc/Document.js +48 -97
  92. package/dist/doc/anchors.d.ts +24 -0
  93. package/dist/doc/anchors.js +77 -0
  94. package/dist/doc/createNode.d.ts +8 -10
  95. package/dist/doc/createNode.js +26 -16
  96. package/dist/errors.d.ts +11 -8
  97. package/dist/errors.js +16 -12
  98. package/dist/index.d.ts +5 -3
  99. package/dist/index.js +3 -3
  100. package/dist/nodes/Alias.d.ts +19 -9
  101. package/dist/nodes/Alias.js +51 -28
  102. package/dist/nodes/Collection.d.ts +3 -17
  103. package/dist/nodes/Collection.js +4 -82
  104. package/dist/nodes/Node.d.ts +6 -4
  105. package/dist/nodes/Node.js +2 -0
  106. package/dist/nodes/Pair.d.ts +6 -11
  107. package/dist/nodes/Pair.js +8 -231
  108. package/dist/nodes/Scalar.d.ts +6 -3
  109. package/dist/nodes/YAMLMap.d.ts +3 -3
  110. package/dist/nodes/YAMLMap.js +8 -4
  111. package/dist/nodes/YAMLSeq.d.ts +3 -3
  112. package/dist/nodes/YAMLSeq.js +7 -4
  113. package/dist/nodes/addPairToJSMap.d.ts +3 -0
  114. package/dist/nodes/addPairToJSMap.js +105 -0
  115. package/dist/nodes/toJS.d.ts +4 -5
  116. package/dist/nodes/toJS.js +12 -10
  117. package/dist/options.d.ts +20 -26
  118. package/dist/options.js +0 -2
  119. package/dist/parse/cst-scalar.d.ts +58 -0
  120. package/dist/parse/cst-scalar.js +223 -0
  121. package/dist/parse/cst-stringify.d.ts +8 -0
  122. package/dist/parse/cst-stringify.js +63 -0
  123. package/dist/parse/cst-visit.d.ts +39 -0
  124. package/dist/parse/cst-visit.js +99 -0
  125. package/dist/parse/{tokens.d.ts → cst.d.ts} +23 -7
  126. package/{browser/dist/parse/tokens.js → dist/parse/cst.js} +27 -1
  127. package/dist/parse/lexer.d.ts +4 -13
  128. package/dist/parse/lexer.js +100 -106
  129. package/dist/parse/parser.d.ts +30 -24
  130. package/dist/parse/parser.js +221 -146
  131. package/dist/public-api.d.ts +7 -7
  132. package/dist/public-api.js +11 -14
  133. package/dist/{doc → schema}/Schema.d.ts +5 -3
  134. package/dist/schema/Schema.js +25 -0
  135. package/dist/{tags/failsafe → schema/common}/map.d.ts +0 -0
  136. package/dist/{tags/failsafe → schema/common}/map.js +0 -0
  137. package/dist/schema/common/null.d.ts +4 -0
  138. package/dist/schema/common/null.js +15 -0
  139. package/dist/{tags/failsafe → schema/common}/seq.d.ts +0 -0
  140. package/dist/{tags/failsafe → schema/common}/seq.js +1 -1
  141. package/dist/{tags/failsafe → schema/common}/string.d.ts +0 -0
  142. package/dist/{tags/failsafe → schema/common}/string.js +0 -0
  143. package/dist/schema/core/bool.d.ts +4 -0
  144. package/dist/schema/core/bool.js +21 -0
  145. package/dist/schema/core/float.d.ts +4 -0
  146. package/dist/schema/core/float.js +44 -0
  147. package/dist/schema/core/int.d.ts +4 -0
  148. package/dist/schema/core/int.js +42 -0
  149. package/dist/schema/core/schema.d.ts +1 -0
  150. package/dist/schema/core/schema.js +25 -0
  151. package/dist/schema/json/schema.d.ts +2 -0
  152. package/dist/{tags/json.js → schema/json/schema.js} +5 -6
  153. package/dist/schema/tags.d.ts +41 -0
  154. package/dist/schema/tags.js +82 -0
  155. package/dist/{tags → schema}/types.d.ts +3 -7
  156. package/dist/{tags → schema}/yaml-1.1/binary.d.ts +0 -0
  157. package/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
  158. package/dist/schema/yaml-1.1/bool.d.ts +7 -0
  159. package/dist/schema/yaml-1.1/bool.js +29 -0
  160. package/dist/schema/yaml-1.1/float.d.ts +4 -0
  161. package/dist/schema/yaml-1.1/float.js +47 -0
  162. package/dist/schema/yaml-1.1/int.d.ts +5 -0
  163. package/dist/schema/yaml-1.1/int.js +76 -0
  164. package/dist/{tags → schema}/yaml-1.1/omap.d.ts +0 -0
  165. package/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
  166. package/dist/{tags → schema}/yaml-1.1/pairs.d.ts +3 -2
  167. package/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
  168. package/dist/schema/yaml-1.1/schema.d.ts +1 -0
  169. package/dist/schema/yaml-1.1/schema.js +39 -0
  170. package/dist/{tags → schema}/yaml-1.1/set.d.ts +1 -1
  171. package/dist/{tags → schema}/yaml-1.1/set.js +0 -0
  172. package/dist/{tags → schema}/yaml-1.1/timestamp.d.ts +0 -0
  173. package/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
  174. package/dist/stringify/addComment.js +0 -7
  175. package/dist/stringify/stringify.d.ts +1 -2
  176. package/dist/stringify/stringify.js +8 -6
  177. package/dist/stringify/stringifyCollection.d.ts +21 -0
  178. package/dist/stringify/stringifyCollection.js +110 -0
  179. package/dist/stringify/stringifyDocument.d.ts +3 -0
  180. package/dist/stringify/stringifyDocument.js +63 -0
  181. package/dist/stringify/stringifyPair.d.ts +3 -0
  182. package/dist/stringify/stringifyPair.js +115 -0
  183. package/dist/stringify/stringifyString.js +53 -52
  184. package/dist/test-events.d.ts +1 -2
  185. package/dist/test-events.js +25 -12
  186. package/dist/util.d.ts +1 -1
  187. package/dist/visit.d.ts +10 -1
  188. package/dist/visit.js +20 -1
  189. package/package.json +4 -3
  190. package/browser/dist/doc/Anchors.js +0 -102
  191. package/browser/dist/doc/Schema.js +0 -27
  192. package/browser/dist/doc/getSchemaTags.js +0 -30
  193. package/browser/dist/tags/core.js +0 -109
  194. package/browser/dist/tags/failsafe/index.js +0 -7
  195. package/browser/dist/tags/index.js +0 -34
  196. package/browser/dist/tags/yaml-1.1/index.js +0 -152
  197. package/dist/doc/Anchors.d.ts +0 -36
  198. package/dist/doc/Anchors.js +0 -104
  199. package/dist/doc/Schema.js +0 -29
  200. package/dist/doc/getSchemaTags.d.ts +0 -3
  201. package/dist/doc/getSchemaTags.js +0 -32
  202. package/dist/tags/core.d.ts +0 -14
  203. package/dist/tags/core.js +0 -119
  204. package/dist/tags/failsafe/index.d.ts +0 -1
  205. package/dist/tags/failsafe/index.js +0 -9
  206. package/dist/tags/index.d.ts +0 -31
  207. package/dist/tags/index.js +0 -37
  208. package/dist/tags/json.d.ts +0 -2
  209. package/dist/tags/yaml-1.1/index.d.ts +0 -2
  210. package/dist/tags/yaml-1.1/index.js +0 -154
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Stringify a CST document, token, or collection item
5
+ *
6
+ * Fair warning: This applies no validation whatsoever, and
7
+ * simply concatenates the sources in their logical order.
8
+ */
9
+ const stringify = (cst) => 'type' in cst ? stringifyToken(cst) : stringifyItem(cst);
10
+ function stringifyToken(token) {
11
+ switch (token.type) {
12
+ case 'block-scalar': {
13
+ let res = '';
14
+ for (const tok of token.props)
15
+ res += stringifyToken(tok);
16
+ return res + token.source;
17
+ }
18
+ case 'block-map':
19
+ case 'block-seq': {
20
+ let res = '';
21
+ for (const item of token.items)
22
+ res += stringifyItem(item);
23
+ return res;
24
+ }
25
+ case 'flow-collection': {
26
+ let res = token.start.source;
27
+ for (const item of token.items)
28
+ res += stringifyItem(item);
29
+ for (const st of token.end)
30
+ res += st.source;
31
+ return res;
32
+ }
33
+ case 'document': {
34
+ let res = stringifyItem(token);
35
+ if (token.end)
36
+ for (const st of token.end)
37
+ res += st.source;
38
+ return res;
39
+ }
40
+ default: {
41
+ let res = token.source;
42
+ if ('end' in token && token.end)
43
+ for (const st of token.end)
44
+ res += st.source;
45
+ return res;
46
+ }
47
+ }
48
+ }
49
+ function stringifyItem({ start, key, sep, value }) {
50
+ let res = '';
51
+ for (const st of start)
52
+ res += st.source;
53
+ if (key)
54
+ res += stringifyToken(key);
55
+ if (sep)
56
+ for (const st of sep)
57
+ res += st.source;
58
+ if (value)
59
+ res += stringifyToken(value);
60
+ return res;
61
+ }
62
+
63
+ exports.stringify = stringify;
@@ -0,0 +1,39 @@
1
+ import type { CollectionItem, Document } from './cst.js';
2
+ export declare type VisitPath = readonly ['key' | 'value', number][];
3
+ export declare type Visitor = (item: CollectionItem, path: VisitPath) => number | symbol | Visitor | void;
4
+ /**
5
+ * Apply a visitor to a CST document or item.
6
+ *
7
+ * Walks through the tree (depth-first) starting from the root, calling a
8
+ * `visitor` function with two arguments when entering each item:
9
+ * - `item`: The current item, which included the following members:
10
+ * - `start: SourceToken[]` – Source tokens before the key or value,
11
+ * possibly including its anchor or tag.
12
+ * - `key?: Token | null` – Set for pair values. May then be `null`, if
13
+ * the key before the `:` separator is empty.
14
+ * - `sep?: SourceToken[]` – Source tokens between the key and the value,
15
+ * which should include the `:` map value indicator if `value` is set.
16
+ * - `value?: Token` – The value of a sequence item, or of a map pair.
17
+ * - `path`: The steps from the root to the current node, as an array of
18
+ * `['key' | 'value', number]` tuples.
19
+ *
20
+ * The return value of the visitor may be used to control the traversal:
21
+ * - `undefined` (default): Do nothing and continue
22
+ * - `visit.SKIP`: Do not visit the children of this token, continue with
23
+ * next sibling
24
+ * - `visit.BREAK`: Terminate traversal completely
25
+ * - `visit.REMOVE`: Remove the current item, then continue with the next one
26
+ * - `number`: Set the index of the next step. This is useful especially if
27
+ * the index of the current token has changed.
28
+ * - `function`: Define the next visitor for this item. After the original
29
+ * visitor is called on item entry, next visitors are called after handling
30
+ * a non-empty `key` and when exiting the item.
31
+ */
32
+ export declare function visit(cst: Document | CollectionItem, visitor: Visitor): void;
33
+ export declare namespace visit {
34
+ var BREAK: symbol;
35
+ var SKIP: symbol;
36
+ var REMOVE: symbol;
37
+ var itemAtPath: (cst: Document | CollectionItem, path: VisitPath) => CollectionItem | undefined;
38
+ var parentCollection: (cst: Document | CollectionItem, path: VisitPath) => import("./cst.js").BlockMap | import("./cst.js").BlockSequence | import("./cst.js").FlowCollection;
39
+ }
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ const BREAK = Symbol('break visit');
4
+ const SKIP = Symbol('skip children');
5
+ const REMOVE = Symbol('remove item');
6
+ /**
7
+ * Apply a visitor to a CST document or item.
8
+ *
9
+ * Walks through the tree (depth-first) starting from the root, calling a
10
+ * `visitor` function with two arguments when entering each item:
11
+ * - `item`: The current item, which included the following members:
12
+ * - `start: SourceToken[]` – Source tokens before the key or value,
13
+ * possibly including its anchor or tag.
14
+ * - `key?: Token | null` – Set for pair values. May then be `null`, if
15
+ * the key before the `:` separator is empty.
16
+ * - `sep?: SourceToken[]` – Source tokens between the key and the value,
17
+ * which should include the `:` map value indicator if `value` is set.
18
+ * - `value?: Token` – The value of a sequence item, or of a map pair.
19
+ * - `path`: The steps from the root to the current node, as an array of
20
+ * `['key' | 'value', number]` tuples.
21
+ *
22
+ * The return value of the visitor may be used to control the traversal:
23
+ * - `undefined` (default): Do nothing and continue
24
+ * - `visit.SKIP`: Do not visit the children of this token, continue with
25
+ * next sibling
26
+ * - `visit.BREAK`: Terminate traversal completely
27
+ * - `visit.REMOVE`: Remove the current item, then continue with the next one
28
+ * - `number`: Set the index of the next step. This is useful especially if
29
+ * the index of the current token has changed.
30
+ * - `function`: Define the next visitor for this item. After the original
31
+ * visitor is called on item entry, next visitors are called after handling
32
+ * a non-empty `key` and when exiting the item.
33
+ */
34
+ function visit(cst, visitor) {
35
+ if ('type' in cst && cst.type === 'document')
36
+ cst = { start: cst.start, value: cst.value };
37
+ _visit(Object.freeze([]), cst, visitor);
38
+ }
39
+ // Without the `as symbol` casts, TS declares these in the `visit`
40
+ // namespace using `var`, but then complains about that because
41
+ // `unique symbol` must be `const`.
42
+ /** Terminate visit traversal completely */
43
+ visit.BREAK = BREAK;
44
+ /** Do not visit the children of the current item */
45
+ visit.SKIP = SKIP;
46
+ /** Remove the current item */
47
+ visit.REMOVE = REMOVE;
48
+ /** Find the item at `path` from `cst` as the root */
49
+ visit.itemAtPath = (cst, path) => {
50
+ let item = cst;
51
+ for (const [field, index] of path) {
52
+ const tok = item && item[field];
53
+ if (tok && 'items' in tok) {
54
+ item = tok.items[index];
55
+ }
56
+ else
57
+ return undefined;
58
+ }
59
+ return item;
60
+ };
61
+ /**
62
+ * Get the immediate parent collection of the item at `path` from `cst` as the root.
63
+ *
64
+ * Throws an error if the collection is not found, which should never happen if the item itself exists.
65
+ */
66
+ visit.parentCollection = (cst, path) => {
67
+ const parent = visit.itemAtPath(cst, path.slice(0, -1));
68
+ const field = path[path.length - 1][0];
69
+ const coll = parent && parent[field];
70
+ if (coll && 'items' in coll)
71
+ return coll;
72
+ throw new Error('Parent collection not found');
73
+ };
74
+ function _visit(path, item, visitor) {
75
+ let ctrl = visitor(item, path);
76
+ if (typeof ctrl === 'symbol')
77
+ return ctrl;
78
+ for (const field of ['key', 'value']) {
79
+ const token = item[field];
80
+ if (token && 'items' in token) {
81
+ for (let i = 0; i < token.items.length; ++i) {
82
+ const ci = _visit(Object.freeze(path.concat([[field, i]])), token.items[i], visitor);
83
+ if (typeof ci === 'number')
84
+ i = ci - 1;
85
+ else if (ci === BREAK)
86
+ return BREAK;
87
+ else if (ci === REMOVE) {
88
+ token.items.splice(i, 1);
89
+ i -= 1;
90
+ }
91
+ }
92
+ if (typeof ctrl === 'function' && field === 'key')
93
+ ctrl = ctrl(item, path);
94
+ }
95
+ }
96
+ return typeof ctrl === 'function' ? ctrl(item, path) : ctrl;
97
+ }
98
+
99
+ exports.visit = visit;
@@ -1,17 +1,21 @@
1
- export declare type SourceTokenType = 'byte-order-mark' | 'doc-mode' | 'scalar' | 'doc-start' | 'doc-end' | 'space' | 'comment' | 'newline' | 'directive-line' | 'alias' | 'anchor' | 'tag' | 'seq-item-ind' | 'explicit-key-ind' | 'map-value-ind' | 'flow-map-start' | 'flow-map-end' | 'flow-seq-start' | 'flow-seq-end' | 'flow-error-end' | 'comma' | 'single-quoted-scalar' | 'double-quoted-scalar' | 'block-scalar-header';
1
+ export { createScalarToken, resolveAsScalar, setScalarValue } from './cst-scalar.js';
2
+ export { stringify } from './cst-stringify.js';
3
+ export { visit, Visitor, VisitPath } from './cst-visit.js';
2
4
  export interface SourceToken {
3
- type: Exclude<SourceTokenType, DocumentEnd['type'] | FlowScalar['type']>;
5
+ type: 'byte-order-mark' | 'doc-mode' | 'doc-start' | 'space' | 'comment' | 'newline' | 'directive-line' | 'anchor' | 'tag' | 'seq-item-ind' | 'explicit-key-ind' | 'map-value-ind' | 'flow-map-start' | 'flow-map-end' | 'flow-seq-start' | 'flow-seq-end' | 'flow-error-end' | 'comma' | 'block-scalar-header';
6
+ offset: number;
4
7
  indent: number;
5
8
  source: string;
6
9
  }
7
10
  export interface ErrorToken {
8
11
  type: 'error';
9
- offset?: number;
12
+ offset: number;
10
13
  source: string;
11
14
  message: string;
12
15
  }
13
16
  export interface Directive {
14
17
  type: 'directive';
18
+ offset: number;
15
19
  source: string;
16
20
  }
17
21
  export interface Document {
@@ -39,7 +43,7 @@ export interface BlockScalar {
39
43
  offset: number;
40
44
  indent: number;
41
45
  props: Token[];
42
- source?: string;
46
+ source: string;
43
47
  }
44
48
  export interface BlockMap {
45
49
  type: 'block-map';
@@ -63,19 +67,27 @@ export interface BlockSequence {
63
67
  indent: number;
64
68
  items: Array<{
65
69
  start: SourceToken[];
66
- value?: Token;
70
+ key?: never;
67
71
  sep?: never;
72
+ value?: Token;
68
73
  }>;
69
74
  }
75
+ export declare type CollectionItem = {
76
+ start: SourceToken[];
77
+ key?: Token | null;
78
+ sep?: SourceToken[];
79
+ value?: Token;
80
+ };
70
81
  export interface FlowCollection {
71
82
  type: 'flow-collection';
72
83
  offset: number;
73
84
  indent: number;
74
85
  start: SourceToken;
75
- items: Array<Token>;
86
+ items: CollectionItem[];
76
87
  end: SourceToken[];
77
88
  }
78
89
  export declare type Token = SourceToken | ErrorToken | Directive | Document | DocumentEnd | FlowScalar | BlockScalar | BlockMap | BlockSequence | FlowCollection;
90
+ export declare type TokenType = SourceToken['type'] | DocumentEnd['type'] | FlowScalar['type'];
79
91
  /** The byte order mark */
80
92
  export declare const BOM = "\uFEFF";
81
93
  /** Start of doc-mode */
@@ -84,7 +96,11 @@ export declare const DOCUMENT = "\u0002";
84
96
  export declare const FLOW_END = "\u0018";
85
97
  /** Next token is a scalar value */
86
98
  export declare const SCALAR = "\u001F";
99
+ /** @returns `true` if `token` is a flow or block collection */
100
+ export declare const isCollection: (token: Token | null | undefined) => token is BlockMap | BlockSequence | FlowCollection;
101
+ /** @returns `true` if `token` is a flow or block scalar; not an alias */
102
+ export declare const isScalar: (token: Token | null | undefined) => token is BlockScalar | FlowScalar;
87
103
  /** Get a printable representation of a lexer token */
88
104
  export declare function prettyToken(token: string): string;
89
105
  /** Identify the type of a lexer token. May return `null` for unknown tokens. */
90
- export declare function tokenType(source: string): SourceTokenType | null;
106
+ export declare function tokenType(source: string): TokenType | null;
@@ -1,3 +1,9 @@
1
+ 'use strict';
2
+
3
+ var cstScalar = require('./cst-scalar.js');
4
+ var cstStringify = require('./cst-stringify.js');
5
+ var cstVisit = require('./cst-visit.js');
6
+
1
7
  /** The byte order mark */
2
8
  const BOM = '\u{FEFF}';
3
9
  /** Start of doc-mode */
@@ -6,6 +12,14 @@ const DOCUMENT = '\x02'; // C0: Start of Text
6
12
  const FLOW_END = '\x18'; // C0: Cancel
7
13
  /** Next token is a scalar value */
8
14
  const SCALAR = '\x1f'; // C0: Unit Separator
15
+ /** @returns `true` if `token` is a flow or block collection */
16
+ const isCollection = (token) => !!token && 'items' in token;
17
+ /** @returns `true` if `token` is a flow or block scalar; not an alias */
18
+ const isScalar = (token) => !!token &&
19
+ (token.type === 'scalar' ||
20
+ token.type === 'single-quoted-scalar' ||
21
+ token.type === 'double-quoted-scalar' ||
22
+ token.type === 'block-scalar');
9
23
  /* istanbul ignore next */
10
24
  /** Get a printable representation of a lexer token */
11
25
  function prettyToken(token) {
@@ -83,4 +97,16 @@ function tokenType(source) {
83
97
  return null;
84
98
  }
85
99
 
86
- export { BOM, DOCUMENT, FLOW_END, SCALAR, prettyToken, tokenType };
100
+ exports.createScalarToken = cstScalar.createScalarToken;
101
+ exports.resolveAsScalar = cstScalar.resolveAsScalar;
102
+ exports.setScalarValue = cstScalar.setScalarValue;
103
+ exports.stringify = cstStringify.stringify;
104
+ exports.visit = cstVisit.visit;
105
+ exports.BOM = BOM;
106
+ exports.DOCUMENT = DOCUMENT;
107
+ exports.FLOW_END = FLOW_END;
108
+ exports.SCALAR = SCALAR;
109
+ exports.isCollection = isCollection;
110
+ exports.isScalar = isScalar;
111
+ exports.prettyToken = prettyToken;
112
+ exports.tokenType = tokenType;
@@ -14,7 +14,6 @@
14
14
  * - `\u{FEFF}` (Byte order mark): Emitted separately outside documents
15
15
  */
16
16
  export declare class Lexer {
17
- private push;
18
17
  /**
19
18
  * Flag indicating whether the end of the current buffer marks the end of
20
19
  * all input
@@ -53,20 +52,12 @@ export declare class Lexer {
53
52
  /** A pointer to `buffer`; the current position of the lexer. */
54
53
  private pos;
55
54
  /**
56
- * Define/initialise a YAML lexer. `push` will be called separately with each
57
- * token when `lex()` is passed an input string.
55
+ * Generate YAML tokens from the `source` string. If `incomplete`,
56
+ * a part of the last line may be left as a buffer for the next call.
58
57
  *
59
- * @public
58
+ * @returns A generator of lexical tokens
60
59
  */
61
- constructor(push: (token: string) => void);
62
- /**
63
- * Read YAML tokens from the `source` string, calling the callback
64
- * defined in the constructor for each one. If `incomplete`, a part
65
- * of the last line may be left as a buffer for the next call.
66
- *
67
- * @public
68
- */
69
- lex(source: string, incomplete: boolean): void;
60
+ lex(source: string, incomplete?: boolean): Generator<string, void, unknown>;
70
61
  private atLineEnd;
71
62
  private charAt;
72
63
  private continueScalar;