fumadocs-openapi 10.6.8 → 10.7.0
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/css/generated/shared.css +0 -1
- package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/general/create-limiter.js +43 -0
- package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/object/is-object.js +26 -0
- package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/object/prevent-pollution.js +33 -0
- package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/queue/queue.js +106 -0
- package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/string/generate-hash.js +120 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/bundle.js +346 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/fetch-urls/index.js +73 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/node.js +3 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/parse-yaml/index.js +1 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/read-files/index.js +51 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/value-generator.js +88 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/convert-to-local-ref.js +24 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/escape-json-pointer.js +11 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-schemas.js +44 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-segments-from-path.js +10 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-value-by-path.js +42 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-file-path.js +23 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-http-url.js +23 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-json-object.js +28 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-yaml.js +21 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/normalize.js +26 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/resolve-reference-path.js +30 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/set-value-at-path.js +70 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/to-relative-path.js +33 -0
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/unescape-json-pointer.js +12 -0
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/2.0-to-3.0/upgrade-from-two-to-three.js +487 -0
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js +95 -0
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js +59 -0
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/helpers/traverse.js +25 -0
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/upgrade.js +15 -0
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.js +19 -0
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +430 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-collection.js +50 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-doc.js +39 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-node.js +85 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-scalar.js +57 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/composer.js +193 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-block-map.js +82 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +173 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +40 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-end.js +36 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +153 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +204 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-props.js +105 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-contains-newline.js +27 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +25 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +10 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-map-includes.js +10 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/Document.js +277 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/anchors.js +57 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/applyReviver.js +38 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/createNode.js +61 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/directives.js +163 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/errors.js +48 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/index.js +16 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/log.js +6 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Alias.js +91 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Collection.js +117 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Node.js +32 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Pair.js +29 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/YAMLMap.js +106 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +104 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +49 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/identity.js +33 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/toJS.js +35 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/cst-scalar.js +3 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/cst-visit.js +89 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/cst.js +40 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/lexer.js +517 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/line-counter.js +45 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/parser.js +852 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/public-api.js +44 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/Schema.js +27 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/map.js +16 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/null.js +13 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/seq.js +16 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/bool.js +17 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/float.js +38 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/int.js +37 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/json/schema.js +61 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/tags.js +81 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +44 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +24 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +41 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +70 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +36 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +60 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +56 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +65 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +79 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +111 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringify.js +105 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +116 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyComment.js +16 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +59 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +19 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyPair.js +95 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyString.js +222 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/visit.js +187 -0
- package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/index.js +16 -0
- package/dist/scalar/client.js +1 -1
- package/dist/utils/document/process.js +5 -3
- package/package.json +16 -16
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/cst-visit.js
|
|
2
|
+
const BREAK = Symbol("break visit");
|
|
3
|
+
const SKIP = Symbol("skip children");
|
|
4
|
+
const REMOVE = Symbol("remove item");
|
|
5
|
+
/**
|
|
6
|
+
* Apply a visitor to a CST document or item.
|
|
7
|
+
*
|
|
8
|
+
* Walks through the tree (depth-first) starting from the root, calling a
|
|
9
|
+
* `visitor` function with two arguments when entering each item:
|
|
10
|
+
* - `item`: The current item, which included the following members:
|
|
11
|
+
* - `start: SourceToken[]` – Source tokens before the key or value,
|
|
12
|
+
* possibly including its anchor or tag.
|
|
13
|
+
* - `key?: Token | null` – Set for pair values. May then be `null`, if
|
|
14
|
+
* the key before the `:` separator is empty.
|
|
15
|
+
* - `sep?: SourceToken[]` – Source tokens between the key and the value,
|
|
16
|
+
* which should include the `:` map value indicator if `value` is set.
|
|
17
|
+
* - `value?: Token` – The value of a sequence item, or of a map pair.
|
|
18
|
+
* - `path`: The steps from the root to the current node, as an array of
|
|
19
|
+
* `['key' | 'value', number]` tuples.
|
|
20
|
+
*
|
|
21
|
+
* The return value of the visitor may be used to control the traversal:
|
|
22
|
+
* - `undefined` (default): Do nothing and continue
|
|
23
|
+
* - `visit.SKIP`: Do not visit the children of this token, continue with
|
|
24
|
+
* next sibling
|
|
25
|
+
* - `visit.BREAK`: Terminate traversal completely
|
|
26
|
+
* - `visit.REMOVE`: Remove the current item, then continue with the next one
|
|
27
|
+
* - `number`: Set the index of the next step. This is useful especially if
|
|
28
|
+
* the index of the current token has changed.
|
|
29
|
+
* - `function`: Define the next visitor for this item. After the original
|
|
30
|
+
* visitor is called on item entry, next visitors are called after handling
|
|
31
|
+
* a non-empty `key` and when exiting the item.
|
|
32
|
+
*/
|
|
33
|
+
function visit(cst, visitor) {
|
|
34
|
+
if ("type" in cst && cst.type === "document") cst = {
|
|
35
|
+
start: cst.start,
|
|
36
|
+
value: cst.value
|
|
37
|
+
};
|
|
38
|
+
_visit(Object.freeze([]), cst, visitor);
|
|
39
|
+
}
|
|
40
|
+
/** Terminate visit traversal completely */
|
|
41
|
+
visit.BREAK = BREAK;
|
|
42
|
+
/** Do not visit the children of the current item */
|
|
43
|
+
visit.SKIP = SKIP;
|
|
44
|
+
/** Remove the current item */
|
|
45
|
+
visit.REMOVE = REMOVE;
|
|
46
|
+
/** Find the item at `path` from `cst` as the root */
|
|
47
|
+
visit.itemAtPath = (cst, path) => {
|
|
48
|
+
let item = cst;
|
|
49
|
+
for (const [field, index] of path) {
|
|
50
|
+
const tok = item?.[field];
|
|
51
|
+
if (tok && "items" in tok) item = tok.items[index];
|
|
52
|
+
else return void 0;
|
|
53
|
+
}
|
|
54
|
+
return item;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Get the immediate parent collection of the item at `path` from `cst` as the root.
|
|
58
|
+
*
|
|
59
|
+
* Throws an error if the collection is not found, which should never happen if the item itself exists.
|
|
60
|
+
*/
|
|
61
|
+
visit.parentCollection = (cst, path) => {
|
|
62
|
+
const parent = visit.itemAtPath(cst, path.slice(0, -1));
|
|
63
|
+
const field = path[path.length - 1][0];
|
|
64
|
+
const coll = parent?.[field];
|
|
65
|
+
if (coll && "items" in coll) return coll;
|
|
66
|
+
throw new Error("Parent collection not found");
|
|
67
|
+
};
|
|
68
|
+
function _visit(path, item, visitor) {
|
|
69
|
+
let ctrl = visitor(item, path);
|
|
70
|
+
if (typeof ctrl === "symbol") return ctrl;
|
|
71
|
+
for (const field of ["key", "value"]) {
|
|
72
|
+
const token = item[field];
|
|
73
|
+
if (token && "items" in token) {
|
|
74
|
+
for (let i = 0; i < token.items.length; ++i) {
|
|
75
|
+
const ci = _visit(Object.freeze(path.concat([[field, i]])), token.items[i], visitor);
|
|
76
|
+
if (typeof ci === "number") i = ci - 1;
|
|
77
|
+
else if (ci === BREAK) return BREAK;
|
|
78
|
+
else if (ci === REMOVE) {
|
|
79
|
+
token.items.splice(i, 1);
|
|
80
|
+
i -= 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (typeof ctrl === "function" && field === "key") ctrl = ctrl(item, path);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return typeof ctrl === "function" ? ctrl(item, path) : ctrl;
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { visit };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import "./cst-scalar.js";
|
|
2
|
+
import "./cst-visit.js";
|
|
3
|
+
/** Identify the type of a lexer token. May return `null` for unknown tokens. */
|
|
4
|
+
function tokenType(source) {
|
|
5
|
+
switch (source) {
|
|
6
|
+
case "": return "byte-order-mark";
|
|
7
|
+
case "": return "doc-mode";
|
|
8
|
+
case "": return "flow-error-end";
|
|
9
|
+
case "": return "scalar";
|
|
10
|
+
case "---": return "doc-start";
|
|
11
|
+
case "...": return "doc-end";
|
|
12
|
+
case "":
|
|
13
|
+
case "\n":
|
|
14
|
+
case "\r\n": return "newline";
|
|
15
|
+
case "-": return "seq-item-ind";
|
|
16
|
+
case "?": return "explicit-key-ind";
|
|
17
|
+
case ":": return "map-value-ind";
|
|
18
|
+
case "{": return "flow-map-start";
|
|
19
|
+
case "}": return "flow-map-end";
|
|
20
|
+
case "[": return "flow-seq-start";
|
|
21
|
+
case "]": return "flow-seq-end";
|
|
22
|
+
case ",": return "comma";
|
|
23
|
+
}
|
|
24
|
+
switch (source[0]) {
|
|
25
|
+
case " ":
|
|
26
|
+
case " ": return "space";
|
|
27
|
+
case "#": return "comment";
|
|
28
|
+
case "%": return "directive-line";
|
|
29
|
+
case "*": return "alias";
|
|
30
|
+
case "&": return "anchor";
|
|
31
|
+
case "!": return "tag";
|
|
32
|
+
case "'": return "single-quoted-scalar";
|
|
33
|
+
case "\"": return "double-quoted-scalar";
|
|
34
|
+
case "|":
|
|
35
|
+
case ">": return "block-scalar-header";
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { tokenType };
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import "./cst.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/lexer.js
|
|
3
|
+
function isEmpty(ch) {
|
|
4
|
+
switch (ch) {
|
|
5
|
+
case void 0:
|
|
6
|
+
case " ":
|
|
7
|
+
case "\n":
|
|
8
|
+
case "\r":
|
|
9
|
+
case " ": return true;
|
|
10
|
+
default: return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const hexDigits = /* @__PURE__ */ new Set("0123456789ABCDEFabcdef");
|
|
14
|
+
const tagChars = /* @__PURE__ */ new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()");
|
|
15
|
+
const flowIndicatorChars = /* @__PURE__ */ new Set(",[]{}");
|
|
16
|
+
const invalidAnchorChars = /* @__PURE__ */ new Set(" ,[]{}\n\r ");
|
|
17
|
+
const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.has(ch);
|
|
18
|
+
/**
|
|
19
|
+
* Splits an input string into lexical tokens, i.e. smaller strings that are
|
|
20
|
+
* easily identifiable by `tokens.tokenType()`.
|
|
21
|
+
*
|
|
22
|
+
* Lexing starts always in a "stream" context. Incomplete input may be buffered
|
|
23
|
+
* until a complete token can be emitted.
|
|
24
|
+
*
|
|
25
|
+
* In addition to slices of the original input, the following control characters
|
|
26
|
+
* may also be emitted:
|
|
27
|
+
*
|
|
28
|
+
* - `\x02` (Start of Text): A document starts with the next token
|
|
29
|
+
* - `\x18` (Cancel): Unexpected end of flow-mode (indicates an error)
|
|
30
|
+
* - `\x1f` (Unit Separator): Next token is a scalar value
|
|
31
|
+
* - `\u{FEFF}` (Byte order mark): Emitted separately outside documents
|
|
32
|
+
*/
|
|
33
|
+
var Lexer = class {
|
|
34
|
+
constructor() {
|
|
35
|
+
/**
|
|
36
|
+
* Flag indicating whether the end of the current buffer marks the end of
|
|
37
|
+
* all input
|
|
38
|
+
*/
|
|
39
|
+
this.atEnd = false;
|
|
40
|
+
/**
|
|
41
|
+
* Explicit indent set in block scalar header, as an offset from the current
|
|
42
|
+
* minimum indent, so e.g. set to 1 from a header `|2+`. Set to -1 if not
|
|
43
|
+
* explicitly set.
|
|
44
|
+
*/
|
|
45
|
+
this.blockScalarIndent = -1;
|
|
46
|
+
/**
|
|
47
|
+
* Block scalars that include a + (keep) chomping indicator in their header
|
|
48
|
+
* include trailing empty lines, which are otherwise excluded from the
|
|
49
|
+
* scalar's contents.
|
|
50
|
+
*/
|
|
51
|
+
this.blockScalarKeep = false;
|
|
52
|
+
/** Current input */
|
|
53
|
+
this.buffer = "";
|
|
54
|
+
/**
|
|
55
|
+
* Flag noting whether the map value indicator : can immediately follow this
|
|
56
|
+
* node within a flow context.
|
|
57
|
+
*/
|
|
58
|
+
this.flowKey = false;
|
|
59
|
+
/** Count of surrounding flow collection levels. */
|
|
60
|
+
this.flowLevel = 0;
|
|
61
|
+
/**
|
|
62
|
+
* Minimum level of indentation required for next lines to be parsed as a
|
|
63
|
+
* part of the current scalar value.
|
|
64
|
+
*/
|
|
65
|
+
this.indentNext = 0;
|
|
66
|
+
/** Indentation level of the current line. */
|
|
67
|
+
this.indentValue = 0;
|
|
68
|
+
/** Position of the next \n character. */
|
|
69
|
+
this.lineEndPos = null;
|
|
70
|
+
/** Stores the state of the lexer if reaching the end of incpomplete input */
|
|
71
|
+
this.next = null;
|
|
72
|
+
/** A pointer to `buffer`; the current position of the lexer. */
|
|
73
|
+
this.pos = 0;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Generate YAML tokens from the `source` string. If `incomplete`,
|
|
77
|
+
* a part of the last line may be left as a buffer for the next call.
|
|
78
|
+
*
|
|
79
|
+
* @returns A generator of lexical tokens
|
|
80
|
+
*/
|
|
81
|
+
*lex(source, incomplete = false) {
|
|
82
|
+
if (source) {
|
|
83
|
+
if (typeof source !== "string") throw TypeError("source is not a string");
|
|
84
|
+
this.buffer = this.buffer ? this.buffer + source : source;
|
|
85
|
+
this.lineEndPos = null;
|
|
86
|
+
}
|
|
87
|
+
this.atEnd = !incomplete;
|
|
88
|
+
let next = this.next ?? "stream";
|
|
89
|
+
while (next && (incomplete || this.hasChars(1))) next = yield* this.parseNext(next);
|
|
90
|
+
}
|
|
91
|
+
atLineEnd() {
|
|
92
|
+
let i = this.pos;
|
|
93
|
+
let ch = this.buffer[i];
|
|
94
|
+
while (ch === " " || ch === " ") ch = this.buffer[++i];
|
|
95
|
+
if (!ch || ch === "#" || ch === "\n") return true;
|
|
96
|
+
if (ch === "\r") return this.buffer[i + 1] === "\n";
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
charAt(n) {
|
|
100
|
+
return this.buffer[this.pos + n];
|
|
101
|
+
}
|
|
102
|
+
continueScalar(offset) {
|
|
103
|
+
let ch = this.buffer[offset];
|
|
104
|
+
if (this.indentNext > 0) {
|
|
105
|
+
let indent = 0;
|
|
106
|
+
while (ch === " ") ch = this.buffer[++indent + offset];
|
|
107
|
+
if (ch === "\r") {
|
|
108
|
+
const next = this.buffer[indent + offset + 1];
|
|
109
|
+
if (next === "\n" || !next && !this.atEnd) return offset + indent + 1;
|
|
110
|
+
}
|
|
111
|
+
return ch === "\n" || indent >= this.indentNext || !ch && !this.atEnd ? offset + indent : -1;
|
|
112
|
+
}
|
|
113
|
+
if (ch === "-" || ch === ".") {
|
|
114
|
+
const dt = this.buffer.substr(offset, 3);
|
|
115
|
+
if ((dt === "---" || dt === "...") && isEmpty(this.buffer[offset + 3])) return -1;
|
|
116
|
+
}
|
|
117
|
+
return offset;
|
|
118
|
+
}
|
|
119
|
+
getLine() {
|
|
120
|
+
let end = this.lineEndPos;
|
|
121
|
+
if (typeof end !== "number" || end !== -1 && end < this.pos) {
|
|
122
|
+
end = this.buffer.indexOf("\n", this.pos);
|
|
123
|
+
this.lineEndPos = end;
|
|
124
|
+
}
|
|
125
|
+
if (end === -1) return this.atEnd ? this.buffer.substring(this.pos) : null;
|
|
126
|
+
if (this.buffer[end - 1] === "\r") end -= 1;
|
|
127
|
+
return this.buffer.substring(this.pos, end);
|
|
128
|
+
}
|
|
129
|
+
hasChars(n) {
|
|
130
|
+
return this.pos + n <= this.buffer.length;
|
|
131
|
+
}
|
|
132
|
+
setNext(state) {
|
|
133
|
+
this.buffer = this.buffer.substring(this.pos);
|
|
134
|
+
this.pos = 0;
|
|
135
|
+
this.lineEndPos = null;
|
|
136
|
+
this.next = state;
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
peek(n) {
|
|
140
|
+
return this.buffer.substr(this.pos, n);
|
|
141
|
+
}
|
|
142
|
+
*parseNext(next) {
|
|
143
|
+
switch (next) {
|
|
144
|
+
case "stream": return yield* this.parseStream();
|
|
145
|
+
case "line-start": return yield* this.parseLineStart();
|
|
146
|
+
case "block-start": return yield* this.parseBlockStart();
|
|
147
|
+
case "doc": return yield* this.parseDocument();
|
|
148
|
+
case "flow": return yield* this.parseFlowCollection();
|
|
149
|
+
case "quoted-scalar": return yield* this.parseQuotedScalar();
|
|
150
|
+
case "block-scalar": return yield* this.parseBlockScalar();
|
|
151
|
+
case "plain-scalar": return yield* this.parsePlainScalar();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
*parseStream() {
|
|
155
|
+
let line = this.getLine();
|
|
156
|
+
if (line === null) return this.setNext("stream");
|
|
157
|
+
if (line[0] === "") {
|
|
158
|
+
yield* this.pushCount(1);
|
|
159
|
+
line = line.substring(1);
|
|
160
|
+
}
|
|
161
|
+
if (line[0] === "%") {
|
|
162
|
+
let dirEnd = line.length;
|
|
163
|
+
let cs = line.indexOf("#");
|
|
164
|
+
while (cs !== -1) {
|
|
165
|
+
const ch = line[cs - 1];
|
|
166
|
+
if (ch === " " || ch === " ") {
|
|
167
|
+
dirEnd = cs - 1;
|
|
168
|
+
break;
|
|
169
|
+
} else cs = line.indexOf("#", cs + 1);
|
|
170
|
+
}
|
|
171
|
+
while (true) {
|
|
172
|
+
const ch = line[dirEnd - 1];
|
|
173
|
+
if (ch === " " || ch === " ") dirEnd -= 1;
|
|
174
|
+
else break;
|
|
175
|
+
}
|
|
176
|
+
const n = (yield* this.pushCount(dirEnd)) + (yield* this.pushSpaces(true));
|
|
177
|
+
yield* this.pushCount(line.length - n);
|
|
178
|
+
this.pushNewline();
|
|
179
|
+
return "stream";
|
|
180
|
+
}
|
|
181
|
+
if (this.atLineEnd()) {
|
|
182
|
+
const sp = yield* this.pushSpaces(true);
|
|
183
|
+
yield* this.pushCount(line.length - sp);
|
|
184
|
+
yield* this.pushNewline();
|
|
185
|
+
return "stream";
|
|
186
|
+
}
|
|
187
|
+
yield "";
|
|
188
|
+
return yield* this.parseLineStart();
|
|
189
|
+
}
|
|
190
|
+
*parseLineStart() {
|
|
191
|
+
const ch = this.charAt(0);
|
|
192
|
+
if (!ch && !this.atEnd) return this.setNext("line-start");
|
|
193
|
+
if (ch === "-" || ch === ".") {
|
|
194
|
+
if (!this.atEnd && !this.hasChars(4)) return this.setNext("line-start");
|
|
195
|
+
const s = this.peek(3);
|
|
196
|
+
if ((s === "---" || s === "...") && isEmpty(this.charAt(3))) {
|
|
197
|
+
yield* this.pushCount(3);
|
|
198
|
+
this.indentValue = 0;
|
|
199
|
+
this.indentNext = 0;
|
|
200
|
+
return s === "---" ? "doc" : "stream";
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
this.indentValue = yield* this.pushSpaces(false);
|
|
204
|
+
if (this.indentNext > this.indentValue && !isEmpty(this.charAt(1))) this.indentNext = this.indentValue;
|
|
205
|
+
return yield* this.parseBlockStart();
|
|
206
|
+
}
|
|
207
|
+
*parseBlockStart() {
|
|
208
|
+
const [ch0, ch1] = this.peek(2);
|
|
209
|
+
if (!ch1 && !this.atEnd) return this.setNext("block-start");
|
|
210
|
+
if ((ch0 === "-" || ch0 === "?" || ch0 === ":") && isEmpty(ch1)) {
|
|
211
|
+
const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
|
|
212
|
+
this.indentNext = this.indentValue + 1;
|
|
213
|
+
this.indentValue += n;
|
|
214
|
+
return yield* this.parseBlockStart();
|
|
215
|
+
}
|
|
216
|
+
return "doc";
|
|
217
|
+
}
|
|
218
|
+
*parseDocument() {
|
|
219
|
+
yield* this.pushSpaces(true);
|
|
220
|
+
const line = this.getLine();
|
|
221
|
+
if (line === null) return this.setNext("doc");
|
|
222
|
+
let n = yield* this.pushIndicators();
|
|
223
|
+
switch (line[n]) {
|
|
224
|
+
case "#": yield* this.pushCount(line.length - n);
|
|
225
|
+
case void 0:
|
|
226
|
+
yield* this.pushNewline();
|
|
227
|
+
return yield* this.parseLineStart();
|
|
228
|
+
case "{":
|
|
229
|
+
case "[":
|
|
230
|
+
yield* this.pushCount(1);
|
|
231
|
+
this.flowKey = false;
|
|
232
|
+
this.flowLevel = 1;
|
|
233
|
+
return "flow";
|
|
234
|
+
case "}":
|
|
235
|
+
case "]":
|
|
236
|
+
yield* this.pushCount(1);
|
|
237
|
+
return "doc";
|
|
238
|
+
case "*":
|
|
239
|
+
yield* this.pushUntil(isNotAnchorChar);
|
|
240
|
+
return "doc";
|
|
241
|
+
case "\"":
|
|
242
|
+
case "'": return yield* this.parseQuotedScalar();
|
|
243
|
+
case "|":
|
|
244
|
+
case ">":
|
|
245
|
+
n += yield* this.parseBlockScalarHeader();
|
|
246
|
+
n += yield* this.pushSpaces(true);
|
|
247
|
+
yield* this.pushCount(line.length - n);
|
|
248
|
+
yield* this.pushNewline();
|
|
249
|
+
return yield* this.parseBlockScalar();
|
|
250
|
+
default: return yield* this.parsePlainScalar();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
*parseFlowCollection() {
|
|
254
|
+
let nl, sp;
|
|
255
|
+
let indent = -1;
|
|
256
|
+
do {
|
|
257
|
+
nl = yield* this.pushNewline();
|
|
258
|
+
if (nl > 0) {
|
|
259
|
+
sp = yield* this.pushSpaces(false);
|
|
260
|
+
this.indentValue = indent = sp;
|
|
261
|
+
} else sp = 0;
|
|
262
|
+
sp += yield* this.pushSpaces(true);
|
|
263
|
+
} while (nl + sp > 0);
|
|
264
|
+
const line = this.getLine();
|
|
265
|
+
if (line === null) return this.setNext("flow");
|
|
266
|
+
if (indent !== -1 && indent < this.indentNext && line[0] !== "#" || indent === 0 && (line.startsWith("---") || line.startsWith("...")) && isEmpty(line[3])) {
|
|
267
|
+
if (!(indent === this.indentNext - 1 && this.flowLevel === 1 && (line[0] === "]" || line[0] === "}"))) {
|
|
268
|
+
this.flowLevel = 0;
|
|
269
|
+
yield "";
|
|
270
|
+
return yield* this.parseLineStart();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
let n = 0;
|
|
274
|
+
while (line[n] === ",") {
|
|
275
|
+
n += yield* this.pushCount(1);
|
|
276
|
+
n += yield* this.pushSpaces(true);
|
|
277
|
+
this.flowKey = false;
|
|
278
|
+
}
|
|
279
|
+
n += yield* this.pushIndicators();
|
|
280
|
+
switch (line[n]) {
|
|
281
|
+
case void 0: return "flow";
|
|
282
|
+
case "#":
|
|
283
|
+
yield* this.pushCount(line.length - n);
|
|
284
|
+
return "flow";
|
|
285
|
+
case "{":
|
|
286
|
+
case "[":
|
|
287
|
+
yield* this.pushCount(1);
|
|
288
|
+
this.flowKey = false;
|
|
289
|
+
this.flowLevel += 1;
|
|
290
|
+
return "flow";
|
|
291
|
+
case "}":
|
|
292
|
+
case "]":
|
|
293
|
+
yield* this.pushCount(1);
|
|
294
|
+
this.flowKey = true;
|
|
295
|
+
this.flowLevel -= 1;
|
|
296
|
+
return this.flowLevel ? "flow" : "doc";
|
|
297
|
+
case "*":
|
|
298
|
+
yield* this.pushUntil(isNotAnchorChar);
|
|
299
|
+
return "flow";
|
|
300
|
+
case "\"":
|
|
301
|
+
case "'":
|
|
302
|
+
this.flowKey = true;
|
|
303
|
+
return yield* this.parseQuotedScalar();
|
|
304
|
+
case ":": {
|
|
305
|
+
const next = this.charAt(1);
|
|
306
|
+
if (this.flowKey || isEmpty(next) || next === ",") {
|
|
307
|
+
this.flowKey = false;
|
|
308
|
+
yield* this.pushCount(1);
|
|
309
|
+
yield* this.pushSpaces(true);
|
|
310
|
+
return "flow";
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
default:
|
|
314
|
+
this.flowKey = false;
|
|
315
|
+
return yield* this.parsePlainScalar();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
*parseQuotedScalar() {
|
|
319
|
+
const quote = this.charAt(0);
|
|
320
|
+
let end = this.buffer.indexOf(quote, this.pos + 1);
|
|
321
|
+
if (quote === "'") while (end !== -1 && this.buffer[end + 1] === "'") end = this.buffer.indexOf("'", end + 2);
|
|
322
|
+
else while (end !== -1) {
|
|
323
|
+
let n = 0;
|
|
324
|
+
while (this.buffer[end - 1 - n] === "\\") n += 1;
|
|
325
|
+
if (n % 2 === 0) break;
|
|
326
|
+
end = this.buffer.indexOf("\"", end + 1);
|
|
327
|
+
}
|
|
328
|
+
const qb = this.buffer.substring(0, end);
|
|
329
|
+
let nl = qb.indexOf("\n", this.pos);
|
|
330
|
+
if (nl !== -1) {
|
|
331
|
+
while (nl !== -1) {
|
|
332
|
+
const cs = this.continueScalar(nl + 1);
|
|
333
|
+
if (cs === -1) break;
|
|
334
|
+
nl = qb.indexOf("\n", cs);
|
|
335
|
+
}
|
|
336
|
+
if (nl !== -1) end = nl - (qb[nl - 1] === "\r" ? 2 : 1);
|
|
337
|
+
}
|
|
338
|
+
if (end === -1) {
|
|
339
|
+
if (!this.atEnd) return this.setNext("quoted-scalar");
|
|
340
|
+
end = this.buffer.length;
|
|
341
|
+
}
|
|
342
|
+
yield* this.pushToIndex(end + 1, false);
|
|
343
|
+
return this.flowLevel ? "flow" : "doc";
|
|
344
|
+
}
|
|
345
|
+
*parseBlockScalarHeader() {
|
|
346
|
+
this.blockScalarIndent = -1;
|
|
347
|
+
this.blockScalarKeep = false;
|
|
348
|
+
let i = this.pos;
|
|
349
|
+
while (true) {
|
|
350
|
+
const ch = this.buffer[++i];
|
|
351
|
+
if (ch === "+") this.blockScalarKeep = true;
|
|
352
|
+
else if (ch > "0" && ch <= "9") this.blockScalarIndent = Number(ch) - 1;
|
|
353
|
+
else if (ch !== "-") break;
|
|
354
|
+
}
|
|
355
|
+
return yield* this.pushUntil((ch) => isEmpty(ch) || ch === "#");
|
|
356
|
+
}
|
|
357
|
+
*parseBlockScalar() {
|
|
358
|
+
let nl = this.pos - 1;
|
|
359
|
+
let indent = 0;
|
|
360
|
+
let ch;
|
|
361
|
+
loop: for (let i = this.pos; ch = this.buffer[i]; ++i) switch (ch) {
|
|
362
|
+
case " ":
|
|
363
|
+
indent += 1;
|
|
364
|
+
break;
|
|
365
|
+
case "\n":
|
|
366
|
+
nl = i;
|
|
367
|
+
indent = 0;
|
|
368
|
+
break;
|
|
369
|
+
case "\r": {
|
|
370
|
+
const next = this.buffer[i + 1];
|
|
371
|
+
if (!next && !this.atEnd) return this.setNext("block-scalar");
|
|
372
|
+
if (next === "\n") break;
|
|
373
|
+
}
|
|
374
|
+
default: break loop;
|
|
375
|
+
}
|
|
376
|
+
if (!ch && !this.atEnd) return this.setNext("block-scalar");
|
|
377
|
+
if (indent >= this.indentNext) {
|
|
378
|
+
if (this.blockScalarIndent === -1) this.indentNext = indent;
|
|
379
|
+
else this.indentNext = this.blockScalarIndent + (this.indentNext === 0 ? 1 : this.indentNext);
|
|
380
|
+
do {
|
|
381
|
+
const cs = this.continueScalar(nl + 1);
|
|
382
|
+
if (cs === -1) break;
|
|
383
|
+
nl = this.buffer.indexOf("\n", cs);
|
|
384
|
+
} while (nl !== -1);
|
|
385
|
+
if (nl === -1) {
|
|
386
|
+
if (!this.atEnd) return this.setNext("block-scalar");
|
|
387
|
+
nl = this.buffer.length;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
let i = nl + 1;
|
|
391
|
+
ch = this.buffer[i];
|
|
392
|
+
while (ch === " ") ch = this.buffer[++i];
|
|
393
|
+
if (ch === " ") {
|
|
394
|
+
while (ch === " " || ch === " " || ch === "\r" || ch === "\n") ch = this.buffer[++i];
|
|
395
|
+
nl = i - 1;
|
|
396
|
+
} else if (!this.blockScalarKeep) do {
|
|
397
|
+
let i = nl - 1;
|
|
398
|
+
let ch = this.buffer[i];
|
|
399
|
+
if (ch === "\r") ch = this.buffer[--i];
|
|
400
|
+
const lastChar = i;
|
|
401
|
+
while (ch === " ") ch = this.buffer[--i];
|
|
402
|
+
if (ch === "\n" && i >= this.pos && i + 1 + indent > lastChar) nl = i;
|
|
403
|
+
else break;
|
|
404
|
+
} while (true);
|
|
405
|
+
yield "";
|
|
406
|
+
yield* this.pushToIndex(nl + 1, true);
|
|
407
|
+
return yield* this.parseLineStart();
|
|
408
|
+
}
|
|
409
|
+
*parsePlainScalar() {
|
|
410
|
+
const inFlow = this.flowLevel > 0;
|
|
411
|
+
let end = this.pos - 1;
|
|
412
|
+
let i = this.pos - 1;
|
|
413
|
+
let ch;
|
|
414
|
+
while (ch = this.buffer[++i]) if (ch === ":") {
|
|
415
|
+
const next = this.buffer[i + 1];
|
|
416
|
+
if (isEmpty(next) || inFlow && flowIndicatorChars.has(next)) break;
|
|
417
|
+
end = i;
|
|
418
|
+
} else if (isEmpty(ch)) {
|
|
419
|
+
let next = this.buffer[i + 1];
|
|
420
|
+
if (ch === "\r") if (next === "\n") {
|
|
421
|
+
i += 1;
|
|
422
|
+
ch = "\n";
|
|
423
|
+
next = this.buffer[i + 1];
|
|
424
|
+
} else end = i;
|
|
425
|
+
if (next === "#" || inFlow && flowIndicatorChars.has(next)) break;
|
|
426
|
+
if (ch === "\n") {
|
|
427
|
+
const cs = this.continueScalar(i + 1);
|
|
428
|
+
if (cs === -1) break;
|
|
429
|
+
i = Math.max(i, cs - 2);
|
|
430
|
+
}
|
|
431
|
+
} else {
|
|
432
|
+
if (inFlow && flowIndicatorChars.has(ch)) break;
|
|
433
|
+
end = i;
|
|
434
|
+
}
|
|
435
|
+
if (!ch && !this.atEnd) return this.setNext("plain-scalar");
|
|
436
|
+
yield "";
|
|
437
|
+
yield* this.pushToIndex(end + 1, true);
|
|
438
|
+
return inFlow ? "flow" : "doc";
|
|
439
|
+
}
|
|
440
|
+
*pushCount(n) {
|
|
441
|
+
if (n > 0) {
|
|
442
|
+
yield this.buffer.substr(this.pos, n);
|
|
443
|
+
this.pos += n;
|
|
444
|
+
return n;
|
|
445
|
+
}
|
|
446
|
+
return 0;
|
|
447
|
+
}
|
|
448
|
+
*pushToIndex(i, allowEmpty) {
|
|
449
|
+
const s = this.buffer.slice(this.pos, i);
|
|
450
|
+
if (s) {
|
|
451
|
+
yield s;
|
|
452
|
+
this.pos += s.length;
|
|
453
|
+
return s.length;
|
|
454
|
+
} else if (allowEmpty) yield "";
|
|
455
|
+
return 0;
|
|
456
|
+
}
|
|
457
|
+
*pushIndicators() {
|
|
458
|
+
switch (this.charAt(0)) {
|
|
459
|
+
case "!": return (yield* this.pushTag()) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
|
|
460
|
+
case "&": return (yield* this.pushUntil(isNotAnchorChar)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
|
|
461
|
+
case "-":
|
|
462
|
+
case "?":
|
|
463
|
+
case ":": {
|
|
464
|
+
const inFlow = this.flowLevel > 0;
|
|
465
|
+
const ch1 = this.charAt(1);
|
|
466
|
+
if (isEmpty(ch1) || inFlow && flowIndicatorChars.has(ch1)) {
|
|
467
|
+
if (!inFlow) this.indentNext = this.indentValue + 1;
|
|
468
|
+
else if (this.flowKey) this.flowKey = false;
|
|
469
|
+
return (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)) + (yield* this.pushIndicators());
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return 0;
|
|
474
|
+
}
|
|
475
|
+
*pushTag() {
|
|
476
|
+
if (this.charAt(1) === "<") {
|
|
477
|
+
let i = this.pos + 2;
|
|
478
|
+
let ch = this.buffer[i];
|
|
479
|
+
while (!isEmpty(ch) && ch !== ">") ch = this.buffer[++i];
|
|
480
|
+
return yield* this.pushToIndex(ch === ">" ? i + 1 : i, false);
|
|
481
|
+
} else {
|
|
482
|
+
let i = this.pos + 1;
|
|
483
|
+
let ch = this.buffer[i];
|
|
484
|
+
while (ch) if (tagChars.has(ch)) ch = this.buffer[++i];
|
|
485
|
+
else if (ch === "%" && hexDigits.has(this.buffer[i + 1]) && hexDigits.has(this.buffer[i + 2])) ch = this.buffer[i += 3];
|
|
486
|
+
else break;
|
|
487
|
+
return yield* this.pushToIndex(i, false);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
*pushNewline() {
|
|
491
|
+
const ch = this.buffer[this.pos];
|
|
492
|
+
if (ch === "\n") return yield* this.pushCount(1);
|
|
493
|
+
else if (ch === "\r" && this.charAt(1) === "\n") return yield* this.pushCount(2);
|
|
494
|
+
else return 0;
|
|
495
|
+
}
|
|
496
|
+
*pushSpaces(allowTabs) {
|
|
497
|
+
let i = this.pos - 1;
|
|
498
|
+
let ch;
|
|
499
|
+
do
|
|
500
|
+
ch = this.buffer[++i];
|
|
501
|
+
while (ch === " " || allowTabs && ch === " ");
|
|
502
|
+
const n = i - this.pos;
|
|
503
|
+
if (n > 0) {
|
|
504
|
+
yield this.buffer.substr(this.pos, n);
|
|
505
|
+
this.pos = i;
|
|
506
|
+
}
|
|
507
|
+
return n;
|
|
508
|
+
}
|
|
509
|
+
*pushUntil(test) {
|
|
510
|
+
let i = this.pos;
|
|
511
|
+
let ch = this.buffer[i];
|
|
512
|
+
while (!test(ch)) ch = this.buffer[++i];
|
|
513
|
+
return yield* this.pushToIndex(i, false);
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
//#endregion
|
|
517
|
+
export { Lexer };
|
package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/line-counter.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/line-counter.js
|
|
2
|
+
/**
|
|
3
|
+
* Tracks newlines during parsing in order to provide an efficient API for
|
|
4
|
+
* determining the one-indexed `{ line, col }` position for any offset
|
|
5
|
+
* within the input.
|
|
6
|
+
*/
|
|
7
|
+
var LineCounter = class {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.lineStarts = [];
|
|
10
|
+
/**
|
|
11
|
+
* Should be called in ascending order. Otherwise, call
|
|
12
|
+
* `lineCounter.lineStarts.sort()` before calling `linePos()`.
|
|
13
|
+
*/
|
|
14
|
+
this.addNewLine = (offset) => this.lineStarts.push(offset);
|
|
15
|
+
/**
|
|
16
|
+
* Performs a binary search and returns the 1-indexed { line, col }
|
|
17
|
+
* position of `offset`. If `line === 0`, `addNewLine` has never been
|
|
18
|
+
* called or `offset` is before the first known newline.
|
|
19
|
+
*/
|
|
20
|
+
this.linePos = (offset) => {
|
|
21
|
+
let low = 0;
|
|
22
|
+
let high = this.lineStarts.length;
|
|
23
|
+
while (low < high) {
|
|
24
|
+
const mid = low + high >> 1;
|
|
25
|
+
if (this.lineStarts[mid] < offset) low = mid + 1;
|
|
26
|
+
else high = mid;
|
|
27
|
+
}
|
|
28
|
+
if (this.lineStarts[low] === offset) return {
|
|
29
|
+
line: low + 1,
|
|
30
|
+
col: 1
|
|
31
|
+
};
|
|
32
|
+
if (low === 0) return {
|
|
33
|
+
line: 0,
|
|
34
|
+
col: offset
|
|
35
|
+
};
|
|
36
|
+
const start = this.lineStarts[low - 1];
|
|
37
|
+
return {
|
|
38
|
+
line: low,
|
|
39
|
+
col: offset - start + 1
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { LineCounter };
|