yaml 2.0.0-4 → 2.0.0-8
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/README.md +5 -5
- package/browser/dist/compose/compose-collection.js +12 -9
- package/browser/dist/compose/compose-doc.js +23 -6
- package/browser/dist/compose/compose-node.js +27 -17
- package/browser/dist/compose/compose-scalar.js +21 -23
- package/browser/dist/compose/composer.js +108 -78
- package/browser/dist/compose/resolve-block-map.js +41 -29
- package/browser/dist/compose/resolve-block-scalar.js +14 -17
- package/browser/dist/compose/resolve-block-seq.js +21 -17
- package/browser/dist/compose/resolve-end.js +7 -8
- package/browser/dist/compose/resolve-flow-collection.js +158 -199
- package/browser/dist/compose/resolve-flow-scalar.js +62 -26
- package/browser/dist/compose/resolve-props.js +72 -37
- package/browser/dist/compose/util-contains-newline.js +15 -12
- package/browser/dist/compose/util-map-includes.js +17 -0
- package/browser/dist/doc/Document.js +74 -99
- package/browser/dist/doc/anchors.js +72 -0
- package/browser/dist/doc/createNode.js +35 -19
- package/browser/dist/doc/directives.js +5 -0
- package/browser/dist/errors.js +16 -12
- package/browser/dist/index.js +3 -3
- package/browser/dist/nodes/Alias.js +51 -28
- package/browser/dist/nodes/Collection.js +23 -92
- package/browser/dist/nodes/Node.js +9 -1
- package/browser/dist/nodes/Pair.js +16 -231
- package/browser/dist/nodes/YAMLMap.js +8 -4
- package/browser/dist/nodes/YAMLSeq.js +7 -4
- package/browser/dist/nodes/addPairToJSMap.js +103 -0
- package/browser/dist/nodes/toJS.js +12 -10
- package/browser/dist/options.js +1 -2
- package/browser/dist/parse/cst-scalar.js +219 -0
- package/browser/dist/parse/cst-stringify.js +61 -0
- package/browser/dist/parse/cst-visit.js +97 -0
- package/{dist/parse/tokens.js → browser/dist/parse/cst.js} +12 -7
- package/browser/dist/parse/lexer.js +149 -125
- package/browser/dist/parse/parser.js +272 -196
- package/browser/dist/public-api.js +11 -14
- package/browser/dist/schema/Schema.js +28 -0
- package/browser/dist/{tags/failsafe → schema/common}/map.js +0 -0
- package/browser/dist/schema/common/null.js +13 -0
- package/browser/dist/{tags/failsafe → schema/common}/seq.js +1 -1
- package/browser/dist/{tags/failsafe → schema/common}/string.js +0 -0
- package/browser/dist/schema/core/bool.js +19 -0
- package/browser/dist/schema/core/float.js +40 -0
- package/browser/dist/schema/core/int.js +38 -0
- package/browser/dist/schema/core/schema.js +23 -0
- package/browser/dist/{tags/json.js → schema/json/schema.js} +5 -6
- package/browser/dist/schema/tags.js +79 -0
- package/browser/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
- package/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/browser/dist/schema/yaml-1.1/float.js +43 -0
- package/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/browser/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
- package/browser/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
- package/browser/dist/schema/yaml-1.1/schema.js +37 -0
- package/browser/dist/{tags → schema}/yaml-1.1/set.js +0 -0
- package/browser/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
- package/browser/dist/stringify/stringify.js +8 -6
- package/browser/dist/stringify/stringifyCollection.js +122 -0
- package/browser/dist/stringify/stringifyComment.js +14 -0
- package/browser/dist/stringify/stringifyDocument.js +64 -0
- package/browser/dist/stringify/stringifyPair.js +111 -0
- package/browser/dist/stringify/stringifyString.js +53 -52
- package/browser/dist/visit.js +20 -1
- package/dist/compose/compose-collection.d.ts +4 -4
- package/dist/compose/compose-collection.js +12 -9
- package/dist/compose/compose-doc.d.ts +4 -3
- package/dist/compose/compose-doc.js +23 -6
- package/dist/compose/compose-node.d.ts +15 -7
- package/dist/compose/compose-node.js +27 -17
- package/dist/compose/compose-scalar.d.ts +4 -3
- package/dist/compose/compose-scalar.js +20 -22
- package/dist/compose/composer.d.ts +28 -23
- package/dist/compose/composer.js +109 -79
- package/dist/compose/resolve-block-map.d.ts +5 -4
- package/dist/compose/resolve-block-map.js +41 -29
- package/dist/compose/resolve-block-scalar.d.ts +5 -3
- package/dist/compose/resolve-block-scalar.js +14 -17
- package/dist/compose/resolve-block-seq.d.ts +4 -4
- package/dist/compose/resolve-block-seq.js +21 -17
- package/dist/compose/resolve-end.d.ts +3 -2
- package/dist/compose/resolve-end.js +7 -8
- package/dist/compose/resolve-flow-collection.d.ts +4 -5
- package/dist/compose/resolve-flow-collection.js +157 -198
- package/dist/compose/resolve-flow-scalar.d.ts +5 -3
- package/dist/compose/resolve-flow-scalar.js +62 -26
- package/dist/compose/resolve-props.d.ts +16 -10
- package/dist/compose/resolve-props.js +72 -37
- package/dist/compose/util-contains-newline.d.ts +1 -1
- package/dist/compose/util-contains-newline.js +15 -12
- package/dist/compose/util-empty-scalar-position.d.ts +1 -1
- 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 +35 -15
- package/dist/doc/Document.js +72 -97
- package/dist/doc/anchors.d.ts +24 -0
- package/dist/doc/anchors.js +77 -0
- package/dist/doc/createNode.d.ts +10 -11
- package/dist/doc/createNode.js +34 -18
- package/dist/doc/directives.d.ts +1 -0
- package/dist/doc/directives.js +5 -0
- package/dist/errors.d.ts +11 -8
- package/dist/errors.js +16 -12
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -3
- package/dist/nodes/Alias.d.ts +19 -9
- package/dist/nodes/Alias.js +51 -28
- package/dist/nodes/Collection.d.ts +9 -17
- package/dist/nodes/Collection.js +22 -91
- package/dist/nodes/Node.d.ts +10 -4
- package/dist/nodes/Node.js +9 -0
- package/dist/nodes/Pair.d.ts +10 -13
- package/dist/nodes/Pair.js +15 -230
- package/dist/nodes/Scalar.d.ts +6 -3
- package/dist/nodes/YAMLMap.d.ts +3 -3
- package/dist/nodes/YAMLMap.js +8 -4
- package/dist/nodes/YAMLSeq.d.ts +3 -3
- package/dist/nodes/YAMLSeq.js +7 -4
- package/dist/nodes/addPairToJSMap.d.ts +3 -0
- package/dist/nodes/addPairToJSMap.js +105 -0
- package/dist/nodes/toJS.d.ts +4 -5
- package/dist/nodes/toJS.js +12 -10
- package/dist/options.d.ts +41 -25
- package/dist/options.js +1 -2
- package/dist/parse/cst-scalar.d.ts +58 -0
- package/dist/parse/cst-scalar.js +223 -0
- package/dist/parse/cst-stringify.d.ts +8 -0
- package/dist/parse/cst-stringify.js +63 -0
- package/dist/parse/cst-visit.d.ts +39 -0
- package/dist/parse/cst-visit.js +99 -0
- package/dist/parse/{tokens.d.ts → cst.d.ts} +23 -7
- package/{browser/dist/parse/tokens.js → dist/parse/cst.js} +27 -1
- package/dist/parse/lexer.d.ts +7 -14
- package/dist/parse/lexer.js +150 -126
- package/dist/parse/parser.d.ts +31 -24
- package/dist/parse/parser.js +274 -198
- package/dist/public-api.d.ts +7 -7
- package/dist/public-api.js +11 -14
- package/dist/{doc → schema}/Schema.d.ts +6 -3
- package/dist/schema/Schema.js +30 -0
- package/dist/{tags/failsafe → schema/common}/map.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/map.js +0 -0
- package/dist/schema/common/null.d.ts +4 -0
- package/dist/schema/common/null.js +15 -0
- package/dist/{tags/failsafe → schema/common}/seq.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/seq.js +1 -1
- package/dist/{tags/failsafe → schema/common}/string.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/string.js +0 -0
- package/dist/schema/core/bool.d.ts +4 -0
- package/dist/schema/core/bool.js +21 -0
- package/dist/schema/core/float.d.ts +4 -0
- package/dist/schema/core/float.js +44 -0
- package/dist/schema/core/int.d.ts +4 -0
- package/dist/schema/core/int.js +42 -0
- package/dist/schema/core/schema.d.ts +1 -0
- package/dist/schema/core/schema.js +25 -0
- package/dist/schema/json/schema.d.ts +2 -0
- package/dist/{tags/json.js → schema/json/schema.js} +5 -6
- package/dist/schema/tags.d.ts +41 -0
- package/dist/schema/tags.js +82 -0
- package/dist/{tags → schema}/types.d.ts +3 -7
- package/dist/{tags → schema}/yaml-1.1/binary.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
- package/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/dist/schema/yaml-1.1/bool.js +29 -0
- package/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/dist/schema/yaml-1.1/float.js +47 -0
- package/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/dist/schema/yaml-1.1/int.js +76 -0
- package/dist/{tags → schema}/yaml-1.1/omap.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
- package/dist/{tags → schema}/yaml-1.1/pairs.d.ts +3 -2
- package/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
- package/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/dist/schema/yaml-1.1/schema.js +39 -0
- package/dist/{tags → schema}/yaml-1.1/set.d.ts +1 -1
- package/dist/{tags → schema}/yaml-1.1/set.js +0 -0
- package/dist/{tags → schema}/yaml-1.1/timestamp.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
- package/dist/stringify/stringify.d.ts +1 -2
- package/dist/stringify/stringify.js +8 -6
- package/dist/stringify/stringifyCollection.d.ts +21 -0
- package/dist/stringify/stringifyCollection.js +124 -0
- package/dist/stringify/stringifyComment.d.ts +2 -0
- package/dist/stringify/stringifyComment.js +17 -0
- package/dist/stringify/stringifyDocument.d.ts +3 -0
- package/dist/stringify/stringifyDocument.js +66 -0
- package/dist/stringify/stringifyPair.d.ts +3 -0
- package/dist/stringify/stringifyPair.js +113 -0
- package/dist/stringify/stringifyString.js +53 -52
- package/dist/test-events.d.ts +1 -2
- package/dist/test-events.js +25 -12
- package/dist/util.d.ts +1 -1
- package/dist/visit.d.ts +10 -1
- package/dist/visit.js +20 -1
- package/package.json +9 -8
- package/browser/dist/doc/Anchors.js +0 -102
- package/browser/dist/doc/Schema.js +0 -27
- package/browser/dist/doc/getSchemaTags.js +0 -30
- package/browser/dist/stringify/addComment.js +0 -17
- package/browser/dist/tags/core.js +0 -109
- package/browser/dist/tags/failsafe/index.js +0 -7
- package/browser/dist/tags/index.js +0 -34
- package/browser/dist/tags/yaml-1.1/index.js +0 -152
- package/dist/doc/Anchors.d.ts +0 -36
- package/dist/doc/Anchors.js +0 -104
- package/dist/doc/Schema.js +0 -29
- package/dist/doc/getSchemaTags.d.ts +0 -3
- package/dist/doc/getSchemaTags.js +0 -32
- package/dist/stringify/addComment.d.ts +0 -2
- package/dist/stringify/addComment.js +0 -20
- package/dist/tags/core.d.ts +0 -14
- package/dist/tags/core.js +0 -119
- package/dist/tags/failsafe/index.d.ts +0 -1
- package/dist/tags/failsafe/index.js +0 -9
- package/dist/tags/index.d.ts +0 -31
- package/dist/tags/index.js +0 -37
- package/dist/tags/json.d.ts +0 -2
- package/dist/tags/yaml-1.1/index.d.ts +0 -2
- package/dist/tags/yaml-1.1/index.js +0 -154
|
@@ -2,26 +2,31 @@ import { Pair } from '../nodes/Pair.js';
|
|
|
2
2
|
import { YAMLMap } from '../nodes/YAMLMap.js';
|
|
3
3
|
import { resolveProps } from './resolve-props.js';
|
|
4
4
|
import { containsNewline } from './util-contains-newline.js';
|
|
5
|
+
import { mapIncludes } from './util-map-includes.js';
|
|
5
6
|
|
|
6
7
|
const startColMsg = 'All mapping items must start at the same column';
|
|
7
|
-
function resolveBlockMap({ composeNode, composeEmptyNode },
|
|
8
|
+
function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
8
9
|
var _a;
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
doc.anchors.setAnchor(map, anchor);
|
|
13
|
-
for (const { start, key, sep, value } of items) {
|
|
10
|
+
const map = new YAMLMap(ctx.schema);
|
|
11
|
+
let offset = bm.offset;
|
|
12
|
+
for (const { start, key, sep, value } of bm.items) {
|
|
14
13
|
// key properties
|
|
15
|
-
const keyProps = resolveProps(
|
|
14
|
+
const keyProps = resolveProps(start, {
|
|
15
|
+
indicator: 'explicit-key-ind',
|
|
16
|
+
next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
|
|
17
|
+
offset,
|
|
18
|
+
onError,
|
|
19
|
+
startOnNewline: true
|
|
20
|
+
});
|
|
16
21
|
const implicitKey = !keyProps.found;
|
|
17
22
|
if (implicitKey) {
|
|
18
23
|
if (key) {
|
|
19
24
|
if (key.type === 'block-seq')
|
|
20
|
-
onError(offset, 'A block sequence may not be used as an implicit map key');
|
|
21
|
-
else if ('indent' in key && key.indent !== indent)
|
|
22
|
-
onError(offset, startColMsg);
|
|
25
|
+
onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'A block sequence may not be used as an implicit map key');
|
|
26
|
+
else if ('indent' in key && key.indent !== bm.indent)
|
|
27
|
+
onError(offset, 'BAD_INDENT', startColMsg);
|
|
23
28
|
}
|
|
24
|
-
if (!keyProps.anchor && !keyProps.
|
|
29
|
+
if (!keyProps.anchor && !keyProps.tag && !sep) {
|
|
25
30
|
// TODO: assert being at last item?
|
|
26
31
|
if (keyProps.comment) {
|
|
27
32
|
if (map.comment)
|
|
@@ -32,39 +37,46 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, doc, { indent, items
|
|
|
32
37
|
continue;
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
|
-
else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== indent)
|
|
36
|
-
onError(offset, startColMsg);
|
|
37
|
-
offset += keyProps.length;
|
|
40
|
+
else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent)
|
|
41
|
+
onError(offset, 'BAD_INDENT', startColMsg);
|
|
38
42
|
if (implicitKey && containsNewline(key))
|
|
39
|
-
onError(
|
|
43
|
+
onError(key, // checked by containsNewline()
|
|
44
|
+
'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
|
|
40
45
|
// key value
|
|
41
|
-
const keyStart =
|
|
46
|
+
const keyStart = keyProps.end;
|
|
42
47
|
const keyNode = key
|
|
43
|
-
? composeNode(
|
|
44
|
-
: composeEmptyNode(
|
|
45
|
-
|
|
48
|
+
? composeNode(ctx, key, keyProps, onError)
|
|
49
|
+
: composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
|
|
50
|
+
if (mapIncludes(ctx, map.items, keyNode))
|
|
51
|
+
onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
|
|
46
52
|
// value properties
|
|
47
|
-
const valueProps = resolveProps(
|
|
48
|
-
|
|
53
|
+
const valueProps = resolveProps(sep || [], {
|
|
54
|
+
indicator: 'map-value-ind',
|
|
55
|
+
next: value,
|
|
56
|
+
offset: keyNode.range[2],
|
|
57
|
+
onError,
|
|
58
|
+
startOnNewline: !key || key.type === 'block-scalar'
|
|
59
|
+
});
|
|
60
|
+
offset = valueProps.end;
|
|
49
61
|
if (valueProps.found) {
|
|
50
62
|
if (implicitKey) {
|
|
51
63
|
if ((value === null || value === void 0 ? void 0 : value.type) === 'block-map' && !valueProps.hasNewline)
|
|
52
|
-
onError(offset, 'Nested mappings are not allowed in compact mappings');
|
|
53
|
-
if (
|
|
64
|
+
onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');
|
|
65
|
+
if (ctx.options.strict &&
|
|
54
66
|
keyProps.start < valueProps.found.offset - 1024)
|
|
55
|
-
onError(
|
|
67
|
+
onError(keyNode.range, 'KEY_OVER_1024_CHARS', 'The : indicator must be at most 1024 chars after the start of an implicit block mapping key');
|
|
56
68
|
}
|
|
57
69
|
// value value
|
|
58
70
|
const valueNode = value
|
|
59
|
-
? composeNode(
|
|
60
|
-
: composeEmptyNode(
|
|
61
|
-
offset = valueNode.range[
|
|
71
|
+
? composeNode(ctx, value, valueProps, onError)
|
|
72
|
+
: composeEmptyNode(ctx, offset, sep, null, valueProps, onError);
|
|
73
|
+
offset = valueNode.range[2];
|
|
62
74
|
map.items.push(new Pair(keyNode, valueNode));
|
|
63
75
|
}
|
|
64
76
|
else {
|
|
65
77
|
// key with no value
|
|
66
78
|
if (implicitKey)
|
|
67
|
-
onError(
|
|
79
|
+
onError(keyNode.range, 'MISSING_CHAR', 'Implicit map keys need to be followed by map values');
|
|
68
80
|
if (valueProps.comment) {
|
|
69
81
|
if (keyNode.comment)
|
|
70
82
|
keyNode.comment += '\n' + valueProps.comment;
|
|
@@ -74,7 +86,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, doc, { indent, items
|
|
|
74
86
|
map.items.push(new Pair(keyNode));
|
|
75
87
|
}
|
|
76
88
|
}
|
|
77
|
-
map.range = [
|
|
89
|
+
map.range = [bm.offset, offset, offset];
|
|
78
90
|
return map;
|
|
79
91
|
}
|
|
80
92
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Scalar } from '../nodes/Scalar.js';
|
|
2
2
|
|
|
3
3
|
function resolveBlockScalar(scalar, strict, onError) {
|
|
4
|
+
const start = scalar.offset;
|
|
4
5
|
const header = parseBlockScalarHeader(scalar, strict, onError);
|
|
5
6
|
if (!header)
|
|
6
|
-
return { value: '', type: null, comment: '',
|
|
7
|
+
return { value: '', type: null, comment: '', range: [start, start, start] };
|
|
7
8
|
const type = header.mode === '>' ? Scalar.BLOCK_FOLDED : Scalar.BLOCK_LITERAL;
|
|
8
9
|
const lines = scalar.source ? splitLines(scalar.source) : [];
|
|
9
10
|
// determine the end of content & start of chomping
|
|
@@ -18,10 +19,10 @@ function resolveBlockScalar(scalar, strict, onError) {
|
|
|
18
19
|
// shortcut for empty contents
|
|
19
20
|
if (!scalar.source || chompStart === 0) {
|
|
20
21
|
const value = header.chomp === '+' ? lines.map(line => line[0]).join('\n') : '';
|
|
21
|
-
let
|
|
22
|
+
let end = start + header.length;
|
|
22
23
|
if (scalar.source)
|
|
23
|
-
|
|
24
|
-
return { value, type, comment: header.comment,
|
|
24
|
+
end += scalar.source.length;
|
|
25
|
+
return { value, type, comment: header.comment, range: [start, end, end] };
|
|
25
26
|
}
|
|
26
27
|
// find the indentation level to trim from start
|
|
27
28
|
let trimIndent = scalar.indent + header.indent;
|
|
@@ -36,7 +37,7 @@ function resolveBlockScalar(scalar, strict, onError) {
|
|
|
36
37
|
else {
|
|
37
38
|
if (indent.length < trimIndent) {
|
|
38
39
|
const message = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
|
|
39
|
-
onError(offset + indent.length, message);
|
|
40
|
+
onError(offset + indent.length, 'MISSING_CHAR', message);
|
|
40
41
|
}
|
|
41
42
|
if (header.indent === 0)
|
|
42
43
|
trimIndent = indent.length;
|
|
@@ -63,7 +64,7 @@ function resolveBlockScalar(scalar, strict, onError) {
|
|
|
63
64
|
? 'explicit indentation indicator'
|
|
64
65
|
: 'first line';
|
|
65
66
|
const message = `Block scalar lines must not be less indented than their ${src}`;
|
|
66
|
-
onError(offset - content.length - (crlf ? 2 : 1), message);
|
|
67
|
+
onError(offset - content.length - (crlf ? 2 : 1), 'BAD_INDENT', message);
|
|
67
68
|
indent = '';
|
|
68
69
|
}
|
|
69
70
|
if (type === Scalar.BLOCK_LITERAL) {
|
|
@@ -105,17 +106,13 @@ function resolveBlockScalar(scalar, strict, onError) {
|
|
|
105
106
|
default:
|
|
106
107
|
value += '\n';
|
|
107
108
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
type,
|
|
111
|
-
comment: header.comment,
|
|
112
|
-
length: header.length + scalar.source.length
|
|
113
|
-
};
|
|
109
|
+
const end = start + header.length + scalar.source.length;
|
|
110
|
+
return { value, type, comment: header.comment, range: [start, end, end] };
|
|
114
111
|
}
|
|
115
112
|
function parseBlockScalarHeader({ offset, props }, strict, onError) {
|
|
116
113
|
/* istanbul ignore if should not happen */
|
|
117
114
|
if (props[0].type !== 'block-scalar-header') {
|
|
118
|
-
onError(
|
|
115
|
+
onError(props[0], 'IMPOSSIBLE', 'Block scalar header not found');
|
|
119
116
|
return null;
|
|
120
117
|
}
|
|
121
118
|
const { source } = props[0];
|
|
@@ -136,7 +133,7 @@ function parseBlockScalarHeader({ offset, props }, strict, onError) {
|
|
|
136
133
|
}
|
|
137
134
|
}
|
|
138
135
|
if (error !== -1)
|
|
139
|
-
onError(error, `Block scalar header includes extra characters: ${source}`);
|
|
136
|
+
onError(error, 'UNEXPECTED_TOKEN', `Block scalar header includes extra characters: ${source}`);
|
|
140
137
|
let hasSpace = false;
|
|
141
138
|
let comment = '';
|
|
142
139
|
let length = source.length;
|
|
@@ -152,19 +149,19 @@ function parseBlockScalarHeader({ offset, props }, strict, onError) {
|
|
|
152
149
|
case 'comment':
|
|
153
150
|
if (strict && !hasSpace) {
|
|
154
151
|
const message = 'Comments must be separated from other tokens by white space characters';
|
|
155
|
-
onError(
|
|
152
|
+
onError(token, 'MISSING_CHAR', message);
|
|
156
153
|
}
|
|
157
154
|
length += token.source.length;
|
|
158
155
|
comment = token.source.substring(1);
|
|
159
156
|
break;
|
|
160
157
|
case 'error':
|
|
161
|
-
onError(
|
|
158
|
+
onError(token, 'UNEXPECTED_TOKEN', token.message);
|
|
162
159
|
length += token.source.length;
|
|
163
160
|
break;
|
|
164
161
|
/* istanbul ignore next should not happen */
|
|
165
162
|
default: {
|
|
166
163
|
const message = `Unexpected token in block scalar header: ${token.type}`;
|
|
167
|
-
onError(
|
|
164
|
+
onError(token, 'UNEXPECTED_TOKEN', message);
|
|
168
165
|
const ts = token.source;
|
|
169
166
|
if (ts && typeof ts === 'string')
|
|
170
167
|
length += ts.length;
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { YAMLSeq } from '../nodes/YAMLSeq.js';
|
|
2
2
|
import { resolveProps } from './resolve-props.js';
|
|
3
3
|
|
|
4
|
-
function resolveBlockSeq({ composeNode, composeEmptyNode },
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
|
|
5
|
+
const seq = new YAMLSeq(ctx.schema);
|
|
6
|
+
let offset = bs.offset;
|
|
7
|
+
for (const { start, value } of bs.items) {
|
|
8
|
+
const props = resolveProps(start, {
|
|
9
|
+
indicator: 'seq-item-ind',
|
|
10
|
+
next: value,
|
|
11
|
+
offset,
|
|
12
|
+
onError,
|
|
13
|
+
startOnNewline: true
|
|
14
|
+
});
|
|
15
|
+
offset = props.end;
|
|
12
16
|
if (!props.found) {
|
|
13
|
-
if (props.anchor || props.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
if (props.anchor || props.tag || value) {
|
|
18
|
+
if (value && value.type === 'block-seq')
|
|
19
|
+
onError(offset, 'BAD_INDENT', 'All sequence items must start at the same column');
|
|
20
|
+
else
|
|
21
|
+
onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
|
|
18
22
|
}
|
|
19
23
|
else {
|
|
20
24
|
// TODO: assert being at last item?
|
|
@@ -24,12 +28,12 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, doc, { items, offset
|
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
const node = value
|
|
27
|
-
? composeNode(
|
|
28
|
-
: composeEmptyNode(
|
|
29
|
-
offset = node.range[
|
|
31
|
+
? composeNode(ctx, value, props, onError)
|
|
32
|
+
: composeEmptyNode(ctx, offset, start, null, props, onError);
|
|
33
|
+
offset = node.range[2];
|
|
30
34
|
seq.items.push(node);
|
|
31
35
|
}
|
|
32
|
-
seq.range = [
|
|
36
|
+
seq.range = [bs.offset, offset, offset];
|
|
33
37
|
return seq;
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -2,32 +2,31 @@ function resolveEnd(end, offset, reqSpace, onError) {
|
|
|
2
2
|
let comment = '';
|
|
3
3
|
if (end) {
|
|
4
4
|
let hasSpace = false;
|
|
5
|
-
let hasComment = false;
|
|
6
5
|
let sep = '';
|
|
7
|
-
for (const
|
|
6
|
+
for (const token of end) {
|
|
7
|
+
const { source, type } = token;
|
|
8
8
|
switch (type) {
|
|
9
9
|
case 'space':
|
|
10
10
|
hasSpace = true;
|
|
11
11
|
break;
|
|
12
12
|
case 'comment': {
|
|
13
13
|
if (reqSpace && !hasSpace)
|
|
14
|
-
onError(
|
|
15
|
-
const cb = source.substring(1);
|
|
16
|
-
if (!
|
|
14
|
+
onError(token, 'MISSING_CHAR', 'Comments must be separated from other tokens by white space characters');
|
|
15
|
+
const cb = source.substring(1) || ' ';
|
|
16
|
+
if (!comment)
|
|
17
17
|
comment = cb;
|
|
18
18
|
else
|
|
19
19
|
comment += sep + cb;
|
|
20
|
-
hasComment = true;
|
|
21
20
|
sep = '';
|
|
22
21
|
break;
|
|
23
22
|
}
|
|
24
23
|
case 'newline':
|
|
25
|
-
if (
|
|
24
|
+
if (comment)
|
|
26
25
|
sep += source;
|
|
27
26
|
hasSpace = true;
|
|
28
27
|
break;
|
|
29
28
|
default:
|
|
30
|
-
onError(
|
|
29
|
+
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${type} at node end`);
|
|
31
30
|
}
|
|
32
31
|
offset += source.length;
|
|
33
32
|
}
|