phantom-pr 0.2.2 → 0.2.4
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.
- package/dist/cli.js +7 -0
- package/dist/cli.js.map +1 -1
- package/node_modules/ignore/LICENSE-MIT +21 -0
- package/node_modules/ignore/README.md +452 -0
- package/node_modules/ignore/index.d.ts +81 -0
- package/node_modules/ignore/index.js +784 -0
- package/node_modules/ignore/legacy.js +681 -0
- package/node_modules/ignore/package.json +87 -0
- package/node_modules/yaml/LICENSE +13 -0
- package/node_modules/yaml/README.md +172 -0
- package/node_modules/yaml/bin.mjs +11 -0
- package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
- package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
- package/node_modules/yaml/browser/dist/compose/compose-node.js +102 -0
- package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
- package/node_modules/yaml/browser/dist/compose/composer.js +217 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
- package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +223 -0
- package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
- package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
- package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
- package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
- package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
- package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
- package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
- package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
- package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
- package/node_modules/yaml/browser/dist/errors.js +57 -0
- package/node_modules/yaml/browser/dist/index.js +17 -0
- package/node_modules/yaml/browser/dist/log.js +11 -0
- package/node_modules/yaml/browser/dist/nodes/Alias.js +114 -0
- package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
- package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
- package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
- package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
- package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
- package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
- package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
- package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
- package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
- package/node_modules/yaml/browser/dist/parse/lexer.js +717 -0
- package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
- package/node_modules/yaml/browser/dist/parse/parser.js +967 -0
- package/node_modules/yaml/browser/dist/public-api.js +102 -0
- package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
- package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
- package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
- package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
- package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
- package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
- package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
- package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
- package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +64 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
- package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
- package/node_modules/yaml/browser/dist/stringify/stringify.js +128 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +143 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +24 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
- package/node_modules/yaml/browser/dist/util.js +11 -0
- package/node_modules/yaml/browser/dist/visit.js +233 -0
- package/node_modules/yaml/browser/index.js +5 -0
- package/node_modules/yaml/browser/package.json +3 -0
- package/node_modules/yaml/dist/cli.d.ts +8 -0
- package/node_modules/yaml/dist/cli.mjs +201 -0
- package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
- package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
- package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
- package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
- package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
- package/node_modules/yaml/dist/compose/compose-node.js +105 -0
- package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
- package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
- package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
- package/node_modules/yaml/dist/compose/composer.js +222 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
- package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +225 -0
- package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
- package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
- package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
- package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
- package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
- package/node_modules/yaml/dist/doc/Document.js +337 -0
- package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
- package/node_modules/yaml/dist/doc/anchors.js +76 -0
- package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
- package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
- package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
- package/node_modules/yaml/dist/doc/createNode.js +90 -0
- package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
- package/node_modules/yaml/dist/doc/directives.js +178 -0
- package/node_modules/yaml/dist/errors.d.ts +21 -0
- package/node_modules/yaml/dist/errors.js +62 -0
- package/node_modules/yaml/dist/index.d.ts +25 -0
- package/node_modules/yaml/dist/index.js +50 -0
- package/node_modules/yaml/dist/log.d.ts +3 -0
- package/node_modules/yaml/dist/log.js +19 -0
- package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/Alias.js +116 -0
- package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
- package/node_modules/yaml/dist/nodes/Collection.js +151 -0
- package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/Node.js +40 -0
- package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
- package/node_modules/yaml/dist/nodes/Pair.js +39 -0
- package/node_modules/yaml/dist/nodes/Scalar.d.ts +43 -0
- package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
- package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
- package/node_modules/yaml/dist/nodes/identity.js +53 -0
- package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/toJS.js +39 -0
- package/node_modules/yaml/dist/options.d.ts +344 -0
- package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
- package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
- package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
- package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
- package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
- package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
- package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
- package/node_modules/yaml/dist/parse/cst.js +112 -0
- package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
- package/node_modules/yaml/dist/parse/lexer.js +719 -0
- package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
- package/node_modules/yaml/dist/parse/line-counter.js +41 -0
- package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
- package/node_modules/yaml/dist/parse/parser.js +972 -0
- package/node_modules/yaml/dist/public-api.d.ts +44 -0
- package/node_modules/yaml/dist/public-api.js +107 -0
- package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
- package/node_modules/yaml/dist/schema/Schema.js +39 -0
- package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/map.js +19 -0
- package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
- package/node_modules/yaml/dist/schema/common/null.js +17 -0
- package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/seq.js +19 -0
- package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/string.js +16 -0
- package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/bool.js +21 -0
- package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/float.js +47 -0
- package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/int.js +42 -0
- package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/core/schema.js +25 -0
- package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
- package/node_modules/yaml/dist/schema/json/schema.js +64 -0
- package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
- package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
- package/node_modules/yaml/dist/schema/tags.js +99 -0
- package/node_modules/yaml/dist/schema/types.d.ts +92 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +68 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
- package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
- package/node_modules/yaml/dist/stringify/stringify.js +131 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.js +145 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.js +26 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
- package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
- package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
- package/node_modules/yaml/dist/test-events.d.ts +4 -0
- package/node_modules/yaml/dist/test-events.js +134 -0
- package/node_modules/yaml/dist/util.d.ts +16 -0
- package/node_modules/yaml/dist/util.js +28 -0
- package/node_modules/yaml/dist/visit.d.ts +102 -0
- package/node_modules/yaml/dist/visit.js +236 -0
- package/node_modules/yaml/package.json +97 -0
- package/node_modules/yaml/util.js +2 -0
- package/package.json +5 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { BlockMap, BlockSequence, CollectionItem, Document, FlowCollection } from './cst';
|
|
2
|
+
export type VisitPath = readonly ['key' | 'value', number][];
|
|
3
|
+
export 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) => BlockMap | BlockSequence | 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?.[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?.[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;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export { createScalarToken, resolveAsScalar, setScalarValue } from './cst-scalar';
|
|
2
|
+
export { stringify } from './cst-stringify';
|
|
3
|
+
export type { Visitor, VisitPath } from './cst-visit';
|
|
4
|
+
export { visit } from './cst-visit';
|
|
5
|
+
export interface SourceToken {
|
|
6
|
+
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';
|
|
7
|
+
offset: number;
|
|
8
|
+
indent: number;
|
|
9
|
+
source: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ErrorToken {
|
|
12
|
+
type: 'error';
|
|
13
|
+
offset: number;
|
|
14
|
+
source: string;
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Directive {
|
|
18
|
+
type: 'directive';
|
|
19
|
+
offset: number;
|
|
20
|
+
source: string;
|
|
21
|
+
}
|
|
22
|
+
export interface Document {
|
|
23
|
+
type: 'document';
|
|
24
|
+
offset: number;
|
|
25
|
+
start: SourceToken[];
|
|
26
|
+
value?: Token;
|
|
27
|
+
end?: SourceToken[];
|
|
28
|
+
}
|
|
29
|
+
export interface DocumentEnd {
|
|
30
|
+
type: 'doc-end';
|
|
31
|
+
offset: number;
|
|
32
|
+
source: string;
|
|
33
|
+
end?: SourceToken[];
|
|
34
|
+
}
|
|
35
|
+
export interface FlowScalar {
|
|
36
|
+
type: 'alias' | 'scalar' | 'single-quoted-scalar' | 'double-quoted-scalar';
|
|
37
|
+
offset: number;
|
|
38
|
+
indent: number;
|
|
39
|
+
source: string;
|
|
40
|
+
end?: SourceToken[];
|
|
41
|
+
}
|
|
42
|
+
export interface BlockScalar {
|
|
43
|
+
type: 'block-scalar';
|
|
44
|
+
offset: number;
|
|
45
|
+
indent: number;
|
|
46
|
+
props: Token[];
|
|
47
|
+
source: string;
|
|
48
|
+
}
|
|
49
|
+
export interface BlockMap {
|
|
50
|
+
type: 'block-map';
|
|
51
|
+
offset: number;
|
|
52
|
+
indent: number;
|
|
53
|
+
items: Array<{
|
|
54
|
+
start: SourceToken[];
|
|
55
|
+
explicitKey?: true;
|
|
56
|
+
key?: never;
|
|
57
|
+
sep?: never;
|
|
58
|
+
value?: never;
|
|
59
|
+
} | {
|
|
60
|
+
start: SourceToken[];
|
|
61
|
+
explicitKey?: true;
|
|
62
|
+
key: Token | null;
|
|
63
|
+
sep: SourceToken[];
|
|
64
|
+
value?: Token;
|
|
65
|
+
}>;
|
|
66
|
+
}
|
|
67
|
+
export interface BlockSequence {
|
|
68
|
+
type: 'block-seq';
|
|
69
|
+
offset: number;
|
|
70
|
+
indent: number;
|
|
71
|
+
items: Array<{
|
|
72
|
+
start: SourceToken[];
|
|
73
|
+
key?: never;
|
|
74
|
+
sep?: never;
|
|
75
|
+
value?: Token;
|
|
76
|
+
}>;
|
|
77
|
+
}
|
|
78
|
+
export type CollectionItem = {
|
|
79
|
+
start: SourceToken[];
|
|
80
|
+
key?: Token | null;
|
|
81
|
+
sep?: SourceToken[];
|
|
82
|
+
value?: Token;
|
|
83
|
+
};
|
|
84
|
+
export interface FlowCollection {
|
|
85
|
+
type: 'flow-collection';
|
|
86
|
+
offset: number;
|
|
87
|
+
indent: number;
|
|
88
|
+
start: SourceToken;
|
|
89
|
+
items: CollectionItem[];
|
|
90
|
+
end: SourceToken[];
|
|
91
|
+
}
|
|
92
|
+
export type Token = SourceToken | ErrorToken | Directive | Document | DocumentEnd | FlowScalar | BlockScalar | BlockMap | BlockSequence | FlowCollection;
|
|
93
|
+
export type TokenType = SourceToken['type'] | DocumentEnd['type'] | FlowScalar['type'];
|
|
94
|
+
/** The byte order mark */
|
|
95
|
+
export declare const BOM = "\uFEFF";
|
|
96
|
+
/** Start of doc-mode */
|
|
97
|
+
export declare const DOCUMENT = "\u0002";
|
|
98
|
+
/** Unexpected end of flow-mode */
|
|
99
|
+
export declare const FLOW_END = "\u0018";
|
|
100
|
+
/** Next token is a scalar value */
|
|
101
|
+
export declare const SCALAR = "\u001F";
|
|
102
|
+
/** @returns `true` if `token` is a flow or block collection */
|
|
103
|
+
export declare const isCollection: (token: Token | null | undefined) => token is BlockMap | BlockSequence | FlowCollection;
|
|
104
|
+
/** @returns `true` if `token` is a flow or block scalar; not an alias */
|
|
105
|
+
export declare const isScalar: (token: Token | null | undefined) => token is FlowScalar | BlockScalar;
|
|
106
|
+
/** Get a printable representation of a lexer token */
|
|
107
|
+
export declare function prettyToken(token: string): string;
|
|
108
|
+
/** Identify the type of a lexer token. May return `null` for unknown tokens. */
|
|
109
|
+
export declare function tokenType(source: string): TokenType | null;
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
|
|
7
|
+
/** The byte order mark */
|
|
8
|
+
const BOM = '\u{FEFF}';
|
|
9
|
+
/** Start of doc-mode */
|
|
10
|
+
const DOCUMENT = '\x02'; // C0: Start of Text
|
|
11
|
+
/** Unexpected end of flow-mode */
|
|
12
|
+
const FLOW_END = '\x18'; // C0: Cancel
|
|
13
|
+
/** Next token is a scalar value */
|
|
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');
|
|
23
|
+
/* istanbul ignore next */
|
|
24
|
+
/** Get a printable representation of a lexer token */
|
|
25
|
+
function prettyToken(token) {
|
|
26
|
+
switch (token) {
|
|
27
|
+
case BOM:
|
|
28
|
+
return '<BOM>';
|
|
29
|
+
case DOCUMENT:
|
|
30
|
+
return '<DOC>';
|
|
31
|
+
case FLOW_END:
|
|
32
|
+
return '<FLOW_END>';
|
|
33
|
+
case SCALAR:
|
|
34
|
+
return '<SCALAR>';
|
|
35
|
+
default:
|
|
36
|
+
return JSON.stringify(token);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Identify the type of a lexer token. May return `null` for unknown tokens. */
|
|
40
|
+
function tokenType(source) {
|
|
41
|
+
switch (source) {
|
|
42
|
+
case BOM:
|
|
43
|
+
return 'byte-order-mark';
|
|
44
|
+
case DOCUMENT:
|
|
45
|
+
return 'doc-mode';
|
|
46
|
+
case FLOW_END:
|
|
47
|
+
return 'flow-error-end';
|
|
48
|
+
case SCALAR:
|
|
49
|
+
return 'scalar';
|
|
50
|
+
case '---':
|
|
51
|
+
return 'doc-start';
|
|
52
|
+
case '...':
|
|
53
|
+
return 'doc-end';
|
|
54
|
+
case '':
|
|
55
|
+
case '\n':
|
|
56
|
+
case '\r\n':
|
|
57
|
+
return 'newline';
|
|
58
|
+
case '-':
|
|
59
|
+
return 'seq-item-ind';
|
|
60
|
+
case '?':
|
|
61
|
+
return 'explicit-key-ind';
|
|
62
|
+
case ':':
|
|
63
|
+
return 'map-value-ind';
|
|
64
|
+
case '{':
|
|
65
|
+
return 'flow-map-start';
|
|
66
|
+
case '}':
|
|
67
|
+
return 'flow-map-end';
|
|
68
|
+
case '[':
|
|
69
|
+
return 'flow-seq-start';
|
|
70
|
+
case ']':
|
|
71
|
+
return 'flow-seq-end';
|
|
72
|
+
case ',':
|
|
73
|
+
return 'comma';
|
|
74
|
+
}
|
|
75
|
+
switch (source[0]) {
|
|
76
|
+
case ' ':
|
|
77
|
+
case '\t':
|
|
78
|
+
return 'space';
|
|
79
|
+
case '#':
|
|
80
|
+
return 'comment';
|
|
81
|
+
case '%':
|
|
82
|
+
return 'directive-line';
|
|
83
|
+
case '*':
|
|
84
|
+
return 'alias';
|
|
85
|
+
case '&':
|
|
86
|
+
return 'anchor';
|
|
87
|
+
case '!':
|
|
88
|
+
return 'tag';
|
|
89
|
+
case "'":
|
|
90
|
+
return 'single-quoted-scalar';
|
|
91
|
+
case '"':
|
|
92
|
+
return 'double-quoted-scalar';
|
|
93
|
+
case '|':
|
|
94
|
+
case '>':
|
|
95
|
+
return 'block-scalar-header';
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
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;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits an input string into lexical tokens, i.e. smaller strings that are
|
|
3
|
+
* easily identifiable by `tokens.tokenType()`.
|
|
4
|
+
*
|
|
5
|
+
* Lexing starts always in a "stream" context. Incomplete input may be buffered
|
|
6
|
+
* until a complete token can be emitted.
|
|
7
|
+
*
|
|
8
|
+
* In addition to slices of the original input, the following control characters
|
|
9
|
+
* may also be emitted:
|
|
10
|
+
*
|
|
11
|
+
* - `\x02` (Start of Text): A document starts with the next token
|
|
12
|
+
* - `\x18` (Cancel): Unexpected end of flow-mode (indicates an error)
|
|
13
|
+
* - `\x1f` (Unit Separator): Next token is a scalar value
|
|
14
|
+
* - `\u{FEFF}` (Byte order mark): Emitted separately outside documents
|
|
15
|
+
*/
|
|
16
|
+
export declare class Lexer {
|
|
17
|
+
/**
|
|
18
|
+
* Flag indicating whether the end of the current buffer marks the end of
|
|
19
|
+
* all input
|
|
20
|
+
*/
|
|
21
|
+
private atEnd;
|
|
22
|
+
/**
|
|
23
|
+
* Explicit indent set in block scalar header, as an offset from the current
|
|
24
|
+
* minimum indent, so e.g. set to 1 from a header `|2+`. Set to -1 if not
|
|
25
|
+
* explicitly set.
|
|
26
|
+
*/
|
|
27
|
+
private blockScalarIndent;
|
|
28
|
+
/**
|
|
29
|
+
* Block scalars that include a + (keep) chomping indicator in their header
|
|
30
|
+
* include trailing empty lines, which are otherwise excluded from the
|
|
31
|
+
* scalar's contents.
|
|
32
|
+
*/
|
|
33
|
+
private blockScalarKeep;
|
|
34
|
+
/** Current input */
|
|
35
|
+
private buffer;
|
|
36
|
+
/**
|
|
37
|
+
* Flag noting whether the map value indicator : can immediately follow this
|
|
38
|
+
* node within a flow context.
|
|
39
|
+
*/
|
|
40
|
+
private flowKey;
|
|
41
|
+
/** Count of surrounding flow collection levels. */
|
|
42
|
+
private flowLevel;
|
|
43
|
+
/**
|
|
44
|
+
* Minimum level of indentation required for next lines to be parsed as a
|
|
45
|
+
* part of the current scalar value.
|
|
46
|
+
*/
|
|
47
|
+
private indentNext;
|
|
48
|
+
/** Indentation level of the current line. */
|
|
49
|
+
private indentValue;
|
|
50
|
+
/** Position of the next \n character. */
|
|
51
|
+
private lineEndPos;
|
|
52
|
+
/** Stores the state of the lexer if reaching the end of incpomplete input */
|
|
53
|
+
private next;
|
|
54
|
+
/** A pointer to `buffer`; the current position of the lexer. */
|
|
55
|
+
private pos;
|
|
56
|
+
/**
|
|
57
|
+
* Generate YAML tokens from the `source` string. If `incomplete`,
|
|
58
|
+
* a part of the last line may be left as a buffer for the next call.
|
|
59
|
+
*
|
|
60
|
+
* @returns A generator of lexical tokens
|
|
61
|
+
*/
|
|
62
|
+
lex(source: string, incomplete?: boolean): Generator<string, void>;
|
|
63
|
+
private atLineEnd;
|
|
64
|
+
private charAt;
|
|
65
|
+
private continueScalar;
|
|
66
|
+
private getLine;
|
|
67
|
+
private hasChars;
|
|
68
|
+
private setNext;
|
|
69
|
+
private peek;
|
|
70
|
+
private parseNext;
|
|
71
|
+
private parseStream;
|
|
72
|
+
private parseLineStart;
|
|
73
|
+
private parseBlockStart;
|
|
74
|
+
private parseDocument;
|
|
75
|
+
private parseFlowCollection;
|
|
76
|
+
private parseQuotedScalar;
|
|
77
|
+
private parseBlockScalarHeader;
|
|
78
|
+
private parseBlockScalar;
|
|
79
|
+
private parsePlainScalar;
|
|
80
|
+
private pushCount;
|
|
81
|
+
private pushToIndex;
|
|
82
|
+
private pushIndicators;
|
|
83
|
+
private pushTag;
|
|
84
|
+
private pushNewline;
|
|
85
|
+
private pushSpaces;
|
|
86
|
+
private pushUntil;
|
|
87
|
+
}
|