yaml 2.0.0-5 → 2.0.0-9
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/browser/dist/compose/compose-doc.js +1 -1
- package/browser/dist/compose/compose-node.js +10 -1
- package/browser/dist/compose/compose-scalar.js +2 -1
- package/browser/dist/compose/composer.js +3 -2
- package/browser/dist/compose/resolve-block-map.js +15 -5
- package/browser/dist/compose/resolve-block-scalar.js +2 -2
- package/browser/dist/compose/resolve-block-seq.js +1 -1
- package/browser/dist/compose/resolve-end.js +2 -2
- package/browser/dist/compose/resolve-flow-collection.js +14 -6
- package/browser/dist/compose/resolve-flow-scalar.js +19 -7
- package/browser/dist/compose/resolve-props.js +30 -7
- package/browser/dist/compose/util-map-includes.js +17 -0
- package/browser/dist/doc/Document.js +26 -2
- package/browser/dist/doc/createNode.js +11 -5
- package/browser/dist/doc/directives.js +5 -0
- package/browser/dist/node_modules/tslib/tslib.es6.js +164 -0
- package/browser/dist/nodes/Collection.js +28 -15
- package/browser/dist/nodes/Node.js +7 -0
- package/browser/dist/nodes/Pair.js +9 -1
- package/browser/dist/nodes/addPairToJSMap.js +4 -3
- package/browser/dist/options.js +2 -0
- package/browser/dist/parse/cst-scalar.js +2 -6
- package/browser/dist/parse/lexer.js +64 -31
- package/browser/dist/parse/parser.js +53 -52
- package/browser/dist/schema/Schema.js +5 -0
- package/browser/dist/schema/tags.js +9 -5
- package/browser/dist/stringify/stringify.js +2 -1
- package/browser/dist/stringify/stringifyCollection.js +23 -9
- package/browser/dist/stringify/stringifyComment.js +14 -0
- package/browser/dist/stringify/stringifyDocument.js +8 -5
- package/browser/dist/stringify/stringifyPair.js +5 -7
- package/browser/dist/stringify/stringifyString.js +35 -34
- package/browser/dist/util.js +3 -0
- package/dist/compose/compose-doc.js +1 -1
- package/dist/compose/compose-node.js +10 -1
- package/dist/compose/compose-scalar.js +2 -1
- package/dist/compose/composer.js +3 -2
- package/dist/compose/resolve-block-map.d.ts +2 -1
- package/dist/compose/resolve-block-map.js +15 -5
- package/dist/compose/resolve-block-scalar.js +2 -2
- package/dist/compose/resolve-block-seq.js +1 -1
- package/dist/compose/resolve-end.js +2 -2
- package/dist/compose/resolve-flow-collection.js +14 -6
- package/dist/compose/resolve-flow-scalar.js +19 -7
- package/dist/compose/resolve-props.d.ts +3 -4
- package/dist/compose/resolve-props.js +30 -7
- package/dist/compose/util-map-includes.d.ts +4 -0
- package/dist/compose/util-map-includes.js +19 -0
- package/dist/doc/Document.d.ts +10 -2
- package/dist/doc/Document.js +25 -1
- package/dist/doc/createNode.d.ts +2 -1
- package/dist/doc/createNode.js +10 -4
- package/dist/doc/directives.d.ts +1 -0
- package/dist/doc/directives.js +5 -0
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/node_modules/tslib/tslib.es6.js +76 -0
- package/dist/nodes/Alias.d.ts +7 -3
- package/dist/nodes/Collection.d.ts +10 -4
- package/dist/nodes/Collection.js +27 -14
- package/dist/nodes/Node.d.ts +10 -3
- package/dist/nodes/Node.js +7 -0
- package/dist/nodes/Pair.d.ts +7 -2
- package/dist/nodes/Pair.js +8 -0
- package/dist/nodes/Scalar.d.ts +2 -0
- package/dist/nodes/YAMLMap.d.ts +2 -0
- package/dist/nodes/YAMLSeq.d.ts +2 -0
- package/dist/nodes/addPairToJSMap.js +3 -2
- package/dist/options.d.ts +40 -3
- package/dist/options.js +2 -0
- package/dist/parse/cst-scalar.d.ts +6 -0
- package/dist/parse/cst-scalar.js +2 -6
- package/dist/parse/lexer.d.ts +3 -1
- package/dist/parse/lexer.js +64 -31
- package/dist/parse/parser.d.ts +1 -0
- package/dist/parse/parser.js +53 -52
- package/dist/schema/Schema.d.ts +1 -0
- package/dist/schema/Schema.js +5 -0
- package/dist/schema/tags.js +9 -5
- package/dist/stringify/stringify.js +2 -1
- package/dist/stringify/stringifyCollection.d.ts +1 -1
- package/dist/stringify/stringifyCollection.js +24 -10
- package/dist/stringify/stringifyComment.d.ts +2 -0
- package/dist/stringify/{addComment.js → stringifyComment.js} +5 -1
- package/dist/stringify/stringifyDocument.js +9 -6
- package/dist/stringify/stringifyPair.js +9 -11
- package/dist/stringify/stringifyString.js +35 -34
- package/dist/test-events.d.ts +1 -1
- package/dist/util.d.ts +3 -0
- package/dist/util.js +6 -0
- package/package.json +9 -8
- package/util.d.ts +3 -0
- package/browser/dist/stringify/addComment.js +0 -11
- package/dist/stringify/addComment.d.ts +0 -2
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
/* global Reflect, Promise */
|
|
17
|
+
var extendStatics = function (d, b) {
|
|
18
|
+
extendStatics = Object.setPrototypeOf || {
|
|
19
|
+
__proto__: []
|
|
20
|
+
} instanceof Array && function (d, b) {
|
|
21
|
+
d.__proto__ = b;
|
|
22
|
+
} || function (d, b) {
|
|
23
|
+
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return extendStatics(d, b);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function __extends(d, b) {
|
|
30
|
+
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
31
|
+
extendStatics(d, b);
|
|
32
|
+
|
|
33
|
+
function __() {
|
|
34
|
+
this.constructor = d;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
38
|
+
}
|
|
39
|
+
function __generator(thisArg, body) {
|
|
40
|
+
var _ = {
|
|
41
|
+
label: 0,
|
|
42
|
+
sent: function () {
|
|
43
|
+
if (t[0] & 1) throw t[1];
|
|
44
|
+
return t[1];
|
|
45
|
+
},
|
|
46
|
+
trys: [],
|
|
47
|
+
ops: []
|
|
48
|
+
},
|
|
49
|
+
f,
|
|
50
|
+
y,
|
|
51
|
+
t,
|
|
52
|
+
g;
|
|
53
|
+
return g = {
|
|
54
|
+
next: verb(0),
|
|
55
|
+
"throw": verb(1),
|
|
56
|
+
"return": verb(2)
|
|
57
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
58
|
+
return this;
|
|
59
|
+
}), g;
|
|
60
|
+
|
|
61
|
+
function verb(n) {
|
|
62
|
+
return function (v) {
|
|
63
|
+
return step([n, v]);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function step(op) {
|
|
68
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
69
|
+
|
|
70
|
+
while (_) try {
|
|
71
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
72
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
73
|
+
|
|
74
|
+
switch (op[0]) {
|
|
75
|
+
case 0:
|
|
76
|
+
case 1:
|
|
77
|
+
t = op;
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case 4:
|
|
81
|
+
_.label++;
|
|
82
|
+
return {
|
|
83
|
+
value: op[1],
|
|
84
|
+
done: false
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
case 5:
|
|
88
|
+
_.label++;
|
|
89
|
+
y = op[1];
|
|
90
|
+
op = [0];
|
|
91
|
+
continue;
|
|
92
|
+
|
|
93
|
+
case 7:
|
|
94
|
+
op = _.ops.pop();
|
|
95
|
+
|
|
96
|
+
_.trys.pop();
|
|
97
|
+
|
|
98
|
+
continue;
|
|
99
|
+
|
|
100
|
+
default:
|
|
101
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
102
|
+
_ = 0;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
107
|
+
_.label = op[1];
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
112
|
+
_.label = t[1];
|
|
113
|
+
t = op;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (t && _.label < t[2]) {
|
|
118
|
+
_.label = t[2];
|
|
119
|
+
|
|
120
|
+
_.ops.push(op);
|
|
121
|
+
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (t[2]) _.ops.pop();
|
|
126
|
+
|
|
127
|
+
_.trys.pop();
|
|
128
|
+
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
op = body.call(thisArg, _);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
op = [6, e];
|
|
135
|
+
y = 0;
|
|
136
|
+
} finally {
|
|
137
|
+
f = t = 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (op[0] & 5) throw op[1];
|
|
141
|
+
return {
|
|
142
|
+
value: op[0] ? op[1] : void 0,
|
|
143
|
+
done: true
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function __values(o) {
|
|
148
|
+
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
149
|
+
m = s && o[s],
|
|
150
|
+
i = 0;
|
|
151
|
+
if (m) return m.call(o);
|
|
152
|
+
if (o && typeof o.length === "number") return {
|
|
153
|
+
next: function () {
|
|
154
|
+
if (o && i >= o.length) o = void 0;
|
|
155
|
+
return {
|
|
156
|
+
value: o && o[i++],
|
|
157
|
+
done: !o
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { __extends, __generator, __values };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createNode } from '../doc/createNode.js';
|
|
2
|
-
import { NodeBase, isCollection, isScalar
|
|
2
|
+
import { NodeBase, isNode, isPair, isCollection, isScalar } from './Node.js';
|
|
3
3
|
|
|
4
4
|
function collectionFromPath(schema, path, value) {
|
|
5
5
|
let v = value;
|
|
@@ -11,19 +11,14 @@ function collectionFromPath(schema, path, value) {
|
|
|
11
11
|
v = a;
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
|
-
|
|
15
|
-
Object.defineProperty(o, typeof k === 'symbol' ? k : String(k), {
|
|
16
|
-
value: v,
|
|
17
|
-
writable: true,
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true
|
|
20
|
-
});
|
|
21
|
-
v = o;
|
|
14
|
+
v = new Map([[k, v]]);
|
|
22
15
|
}
|
|
23
16
|
}
|
|
24
17
|
return createNode(v, undefined, {
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
aliasDuplicateObjects: false,
|
|
19
|
+
keepUndefined: false,
|
|
20
|
+
onAnchor: () => {
|
|
21
|
+
throw new Error('This should not happen, please report a bug.');
|
|
27
22
|
},
|
|
28
23
|
schema,
|
|
29
24
|
sourceObjects: new Map()
|
|
@@ -42,6 +37,20 @@ class Collection extends NodeBase {
|
|
|
42
37
|
writable: true
|
|
43
38
|
});
|
|
44
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a copy of this collection.
|
|
42
|
+
*
|
|
43
|
+
* @param schema - If defined, overwrites the original's schema
|
|
44
|
+
*/
|
|
45
|
+
clone(schema) {
|
|
46
|
+
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
47
|
+
if (schema)
|
|
48
|
+
copy.schema = schema;
|
|
49
|
+
copy.items = copy.items.map(it => isNode(it) || isPair(it) ? it.clone(schema) : it);
|
|
50
|
+
if (this.range)
|
|
51
|
+
copy.range = this.range.slice();
|
|
52
|
+
return copy;
|
|
53
|
+
}
|
|
45
54
|
/**
|
|
46
55
|
* Adds a value to the collection. For `!!map` and `!!omap` the value must
|
|
47
56
|
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
@@ -65,7 +74,8 @@ class Collection extends NodeBase {
|
|
|
65
74
|
* Removes a value from the collection.
|
|
66
75
|
* @returns `true` if the item was found and removed.
|
|
67
76
|
*/
|
|
68
|
-
deleteIn(
|
|
77
|
+
deleteIn(path) {
|
|
78
|
+
const [key, ...rest] = path;
|
|
69
79
|
if (rest.length === 0)
|
|
70
80
|
return this.delete(key);
|
|
71
81
|
const node = this.get(key, true);
|
|
@@ -79,7 +89,8 @@ class Collection extends NodeBase {
|
|
|
79
89
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
80
90
|
* `true` (collections are always returned intact).
|
|
81
91
|
*/
|
|
82
|
-
getIn(
|
|
92
|
+
getIn(path, keepScalar) {
|
|
93
|
+
const [key, ...rest] = path;
|
|
83
94
|
const node = this.get(key, true);
|
|
84
95
|
if (rest.length === 0)
|
|
85
96
|
return !keepScalar && isScalar(node) ? node.value : node;
|
|
@@ -103,7 +114,8 @@ class Collection extends NodeBase {
|
|
|
103
114
|
/**
|
|
104
115
|
* Checks if the collection includes a value with the key `key`.
|
|
105
116
|
*/
|
|
106
|
-
hasIn(
|
|
117
|
+
hasIn(path) {
|
|
118
|
+
const [key, ...rest] = path;
|
|
107
119
|
if (rest.length === 0)
|
|
108
120
|
return this.has(key);
|
|
109
121
|
const node = this.get(key, true);
|
|
@@ -113,7 +125,8 @@ class Collection extends NodeBase {
|
|
|
113
125
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
114
126
|
* boolean to add/remove the item from the set.
|
|
115
127
|
*/
|
|
116
|
-
setIn(
|
|
128
|
+
setIn(path, value) {
|
|
129
|
+
const [key, ...rest] = path;
|
|
117
130
|
if (rest.length === 0) {
|
|
118
131
|
this.set(key, value);
|
|
119
132
|
}
|
|
@@ -36,6 +36,13 @@ class NodeBase {
|
|
|
36
36
|
constructor(type) {
|
|
37
37
|
Object.defineProperty(this, NODE_TYPE, { value: type });
|
|
38
38
|
}
|
|
39
|
+
/** Create a copy of this node. */
|
|
40
|
+
clone() {
|
|
41
|
+
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
42
|
+
if (this.range)
|
|
43
|
+
copy.range = this.range.slice();
|
|
44
|
+
return copy;
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
export { ALIAS, DOC, MAP, NODE_TYPE, NodeBase, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createNode } from '../doc/createNode.js';
|
|
2
2
|
import { stringifyPair } from '../stringify/stringifyPair.js';
|
|
3
3
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
4
|
-
import { NODE_TYPE, PAIR } from './Node.js';
|
|
4
|
+
import { NODE_TYPE, PAIR, isNode } from './Node.js';
|
|
5
5
|
|
|
6
6
|
function createPair(key, value, ctx) {
|
|
7
7
|
const k = createNode(key, undefined, ctx);
|
|
@@ -14,6 +14,14 @@ class Pair {
|
|
|
14
14
|
this.key = key;
|
|
15
15
|
this.value = value;
|
|
16
16
|
}
|
|
17
|
+
clone(schema) {
|
|
18
|
+
let { key, value } = this;
|
|
19
|
+
if (isNode(key))
|
|
20
|
+
key = key.clone(schema);
|
|
21
|
+
if (isNode(value))
|
|
22
|
+
value = value.clone(schema);
|
|
23
|
+
return new Pair(key, value);
|
|
24
|
+
}
|
|
17
25
|
toJSON(_, ctx) {
|
|
18
26
|
const pair = ctx && ctx.mapAsMap ? new Map() : {};
|
|
19
27
|
return addPairToJSMap(ctx, pair, this);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { warn } from '../log.js';
|
|
2
2
|
import { createStringifyContext } from '../stringify/stringify.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isAlias, isSeq, isScalar, isMap, isNode } from './Node.js';
|
|
4
4
|
import { Scalar } from './Scalar.js';
|
|
5
5
|
import { toJS } from './toJS.js';
|
|
6
6
|
|
|
7
7
|
const MERGE_KEY = '<<';
|
|
8
8
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
9
9
|
if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
|
|
10
|
+
value = isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
10
11
|
if (isSeq(value))
|
|
11
12
|
for (const it of value.items)
|
|
12
13
|
mergeToJSMap(ctx, map, it);
|
|
@@ -52,9 +53,9 @@ const isMergeKey = (key) => key === MERGE_KEY ||
|
|
|
52
53
|
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
53
54
|
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
54
55
|
function mergeToJSMap(ctx, map, value) {
|
|
55
|
-
const source = ctx && isAlias(value) ? value.resolve(ctx.doc) :
|
|
56
|
+
const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
56
57
|
if (!isMap(source))
|
|
57
|
-
throw new Error('Merge sources must be map aliases');
|
|
58
|
+
throw new Error('Merge sources must be maps or map aliases');
|
|
58
59
|
const srcMap = source.toJSON(null, ctx, Map);
|
|
59
60
|
for (const [key, value] of srcMap) {
|
|
60
61
|
if (map instanceof Map) {
|
package/browser/dist/options.js
CHANGED
|
@@ -3,10 +3,6 @@ import { resolveFlowScalar } from '../compose/resolve-flow-scalar.js';
|
|
|
3
3
|
import { YAMLParseError } from '../errors.js';
|
|
4
4
|
import { stringifyString } from '../stringify/stringifyString.js';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
|
|
8
|
-
* Otherwise, return `null`.
|
|
9
|
-
*/
|
|
10
6
|
function resolveAsScalar(token, strict = true, onError) {
|
|
11
7
|
if (token) {
|
|
12
8
|
const _onError = (pos, code, message) => {
|
|
@@ -48,7 +44,7 @@ function createScalarToken(value, context) {
|
|
|
48
44
|
implicitKey,
|
|
49
45
|
indent: indent > 0 ? ' '.repeat(indent) : '',
|
|
50
46
|
inFlow,
|
|
51
|
-
options: { lineWidth: -1 }
|
|
47
|
+
options: { blockQuote: true, lineWidth: -1 }
|
|
52
48
|
});
|
|
53
49
|
const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
|
|
54
50
|
{ type: 'newline', offset: -1, indent, source: '\n' }
|
|
@@ -117,7 +113,7 @@ function setScalarValue(token, value, context = {}) {
|
|
|
117
113
|
implicitKey: implicitKey || indent === null,
|
|
118
114
|
indent: indent !== null && indent > 0 ? ' '.repeat(indent) : '',
|
|
119
115
|
inFlow,
|
|
120
|
-
options: { lineWidth: -1 }
|
|
116
|
+
options: { blockQuote: true, lineWidth: -1 }
|
|
121
117
|
});
|
|
122
118
|
switch (source[0]) {
|
|
123
119
|
case '|':
|
|
@@ -79,9 +79,11 @@ function isEmpty(ch) {
|
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
82
|
+
const hexDigits = '0123456789ABCDEFabcdef'.split('');
|
|
83
|
+
const tagChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()".split('');
|
|
84
|
+
const invalidFlowScalarChars = ',[]{}'.split('');
|
|
85
|
+
const invalidAnchorChars = ' ,[]{}\n\r\t'.split('');
|
|
86
|
+
const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.includes(ch);
|
|
85
87
|
/**
|
|
86
88
|
* Splits an input string into lexical tokens, i.e. smaller strings that are
|
|
87
89
|
* easily identifiable by `tokens.tokenType()`.
|
|
@@ -132,6 +134,8 @@ class Lexer {
|
|
|
132
134
|
this.indentNext = 0;
|
|
133
135
|
/** Indentation level of the current line. */
|
|
134
136
|
this.indentValue = 0;
|
|
137
|
+
/** Position of the next \n character. */
|
|
138
|
+
this.lineEndPos = null;
|
|
135
139
|
/** Stores the state of the lexer if reaching the end of incpomplete input */
|
|
136
140
|
this.next = null;
|
|
137
141
|
/** A pointer to `buffer`; the current position of the lexer. */
|
|
@@ -144,8 +148,10 @@ class Lexer {
|
|
|
144
148
|
* @returns A generator of lexical tokens
|
|
145
149
|
*/
|
|
146
150
|
*lex(source, incomplete = false) {
|
|
147
|
-
if (source)
|
|
151
|
+
if (source) {
|
|
148
152
|
this.buffer = this.buffer ? this.buffer + source : source;
|
|
153
|
+
this.lineEndPos = null;
|
|
154
|
+
}
|
|
149
155
|
this.atEnd = !incomplete;
|
|
150
156
|
let next = this.next || 'stream';
|
|
151
157
|
while (next && (incomplete || this.hasChars(1)))
|
|
@@ -188,7 +194,11 @@ class Lexer {
|
|
|
188
194
|
return offset;
|
|
189
195
|
}
|
|
190
196
|
getLine() {
|
|
191
|
-
let end = this.
|
|
197
|
+
let end = this.lineEndPos;
|
|
198
|
+
if (typeof end !== 'number' || (end !== -1 && end < this.pos)) {
|
|
199
|
+
end = this.buffer.indexOf('\n', this.pos);
|
|
200
|
+
this.lineEndPos = end;
|
|
201
|
+
}
|
|
192
202
|
if (end === -1)
|
|
193
203
|
return this.atEnd ? this.buffer.substring(this.pos) : null;
|
|
194
204
|
if (this.buffer[end - 1] === '\r')
|
|
@@ -201,6 +211,7 @@ class Lexer {
|
|
|
201
211
|
setNext(state) {
|
|
202
212
|
this.buffer = this.buffer.substring(this.pos);
|
|
203
213
|
this.pos = 0;
|
|
214
|
+
this.lineEndPos = null;
|
|
204
215
|
this.next = state;
|
|
205
216
|
return null;
|
|
206
217
|
}
|
|
@@ -325,7 +336,7 @@ class Lexer {
|
|
|
325
336
|
yield* this.pushCount(1);
|
|
326
337
|
return 'doc';
|
|
327
338
|
case '*':
|
|
328
|
-
yield* this.pushUntil(
|
|
339
|
+
yield* this.pushUntil(isNotAnchorChar);
|
|
329
340
|
return 'doc';
|
|
330
341
|
case '"':
|
|
331
342
|
case "'":
|
|
@@ -353,7 +364,7 @@ class Lexer {
|
|
|
353
364
|
const line = this.getLine();
|
|
354
365
|
if (line === null)
|
|
355
366
|
return this.setNext('flow');
|
|
356
|
-
if ((indent !== -1 && indent < this.indentNext) ||
|
|
367
|
+
if ((indent !== -1 && indent < this.indentNext && line[0] !== '#') ||
|
|
357
368
|
(indent === 0 &&
|
|
358
369
|
(line.startsWith('---') || line.startsWith('...')) &&
|
|
359
370
|
isEmpty(line[3]))) {
|
|
@@ -371,8 +382,11 @@ class Lexer {
|
|
|
371
382
|
}
|
|
372
383
|
}
|
|
373
384
|
let n = 0;
|
|
374
|
-
while (line[n] === ',')
|
|
375
|
-
n +=
|
|
385
|
+
while (line[n] === ',') {
|
|
386
|
+
n += yield* this.pushCount(1);
|
|
387
|
+
n += yield* this.pushSpaces(true);
|
|
388
|
+
this.flowKey = false;
|
|
389
|
+
}
|
|
376
390
|
n += yield* this.pushIndicators();
|
|
377
391
|
switch (line[n]) {
|
|
378
392
|
case undefined:
|
|
@@ -393,7 +407,7 @@ class Lexer {
|
|
|
393
407
|
this.flowLevel -= 1;
|
|
394
408
|
return this.flowLevel ? 'flow' : 'doc';
|
|
395
409
|
case '*':
|
|
396
|
-
yield* this.pushUntil(
|
|
410
|
+
yield* this.pushUntil(isNotAnchorChar);
|
|
397
411
|
return 'flow';
|
|
398
412
|
case '"':
|
|
399
413
|
case "'":
|
|
@@ -431,17 +445,19 @@ class Lexer {
|
|
|
431
445
|
end = this.buffer.indexOf('"', end + 1);
|
|
432
446
|
}
|
|
433
447
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
448
|
+
// Only looking for newlines within the quotes
|
|
449
|
+
const qb = this.buffer.substring(0, end);
|
|
450
|
+
let nl = qb.indexOf('\n', this.pos);
|
|
451
|
+
if (nl !== -1) {
|
|
452
|
+
while (nl !== -1) {
|
|
437
453
|
const cs = this.continueScalar(nl + 1);
|
|
438
454
|
if (cs === -1)
|
|
439
455
|
break;
|
|
440
|
-
nl =
|
|
456
|
+
nl = qb.indexOf('\n', cs);
|
|
441
457
|
}
|
|
442
|
-
if (nl !== -1
|
|
458
|
+
if (nl !== -1) {
|
|
443
459
|
// this is an error caused by an unexpected unindent
|
|
444
|
-
end = nl - 1;
|
|
460
|
+
end = nl - (qb[nl - 1] === '\r' ? 2 : 1);
|
|
445
461
|
}
|
|
446
462
|
}
|
|
447
463
|
if (end === -1) {
|
|
@@ -541,17 +557,18 @@ class Lexer {
|
|
|
541
557
|
end = i;
|
|
542
558
|
}
|
|
543
559
|
else if (isEmpty(ch)) {
|
|
544
|
-
|
|
545
|
-
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
|
|
546
|
-
break;
|
|
560
|
+
let next = this.buffer[i + 1];
|
|
547
561
|
if (ch === '\r') {
|
|
548
562
|
if (next === '\n') {
|
|
549
563
|
i += 1;
|
|
550
564
|
ch = '\n';
|
|
565
|
+
next = this.buffer[i + 1];
|
|
551
566
|
}
|
|
552
567
|
else
|
|
553
568
|
end = i;
|
|
554
569
|
}
|
|
570
|
+
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
|
|
571
|
+
break;
|
|
555
572
|
if (ch === '\n') {
|
|
556
573
|
const cs = this.continueScalar(i + 1);
|
|
557
574
|
if (cs === -1)
|
|
@@ -593,13 +610,11 @@ class Lexer {
|
|
|
593
610
|
*pushIndicators() {
|
|
594
611
|
switch (this.charAt(0)) {
|
|
595
612
|
case '!':
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
(yield* this.pushIndicators()));
|
|
600
|
-
// fallthrough
|
|
613
|
+
return ((yield* this.pushTag()) +
|
|
614
|
+
(yield* this.pushSpaces(true)) +
|
|
615
|
+
(yield* this.pushIndicators()));
|
|
601
616
|
case '&':
|
|
602
|
-
return ((yield* this.pushUntil(
|
|
617
|
+
return ((yield* this.pushUntil(isNotAnchorChar)) +
|
|
603
618
|
(yield* this.pushSpaces(true)) +
|
|
604
619
|
(yield* this.pushIndicators()));
|
|
605
620
|
case ':':
|
|
@@ -615,12 +630,30 @@ class Lexer {
|
|
|
615
630
|
}
|
|
616
631
|
return 0;
|
|
617
632
|
}
|
|
618
|
-
*
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
ch
|
|
623
|
-
|
|
633
|
+
*pushTag() {
|
|
634
|
+
if (this.charAt(1) === '<') {
|
|
635
|
+
let i = this.pos + 2;
|
|
636
|
+
let ch = this.buffer[i];
|
|
637
|
+
while (!isEmpty(ch) && ch !== '>')
|
|
638
|
+
ch = this.buffer[++i];
|
|
639
|
+
return yield* this.pushToIndex(ch === '>' ? i + 1 : i, false);
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
let i = this.pos + 1;
|
|
643
|
+
let ch = this.buffer[i];
|
|
644
|
+
while (ch) {
|
|
645
|
+
if (tagChars.includes(ch))
|
|
646
|
+
ch = this.buffer[++i];
|
|
647
|
+
else if (ch === '%' &&
|
|
648
|
+
hexDigits.includes(this.buffer[i + 1]) &&
|
|
649
|
+
hexDigits.includes(this.buffer[i + 2])) {
|
|
650
|
+
ch = this.buffer[(i += 3)];
|
|
651
|
+
}
|
|
652
|
+
else
|
|
653
|
+
break;
|
|
654
|
+
}
|
|
655
|
+
return yield* this.pushToIndex(i, false);
|
|
656
|
+
}
|
|
624
657
|
}
|
|
625
658
|
*pushNewline() {
|
|
626
659
|
const ch = this.buffer[this.pos];
|