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
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
var Scalar = require('../nodes/Scalar.js');
|
|
4
4
|
|
|
5
5
|
function resolveBlockScalar(scalar, strict, onError) {
|
|
6
|
+
const start = scalar.offset;
|
|
6
7
|
const header = parseBlockScalarHeader(scalar, strict, onError);
|
|
7
8
|
if (!header)
|
|
8
|
-
return { value: '', type: null, comment: '',
|
|
9
|
+
return { value: '', type: null, comment: '', range: [start, start, start] };
|
|
9
10
|
const type = header.mode === '>' ? Scalar.Scalar.BLOCK_FOLDED : Scalar.Scalar.BLOCK_LITERAL;
|
|
10
11
|
const lines = scalar.source ? splitLines(scalar.source) : [];
|
|
11
12
|
// determine the end of content & start of chomping
|
|
@@ -20,10 +21,10 @@ function resolveBlockScalar(scalar, strict, onError) {
|
|
|
20
21
|
// shortcut for empty contents
|
|
21
22
|
if (!scalar.source || chompStart === 0) {
|
|
22
23
|
const value = header.chomp === '+' ? lines.map(line => line[0]).join('\n') : '';
|
|
23
|
-
let
|
|
24
|
+
let end = start + header.length;
|
|
24
25
|
if (scalar.source)
|
|
25
|
-
|
|
26
|
-
return { value, type, comment: header.comment,
|
|
26
|
+
end += scalar.source.length;
|
|
27
|
+
return { value, type, comment: header.comment, range: [start, end, end] };
|
|
27
28
|
}
|
|
28
29
|
// find the indentation level to trim from start
|
|
29
30
|
let trimIndent = scalar.indent + header.indent;
|
|
@@ -38,7 +39,7 @@ function resolveBlockScalar(scalar, strict, onError) {
|
|
|
38
39
|
else {
|
|
39
40
|
if (indent.length < trimIndent) {
|
|
40
41
|
const message = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
|
|
41
|
-
onError(offset + indent.length, message);
|
|
42
|
+
onError(offset + indent.length, 'MISSING_CHAR', message);
|
|
42
43
|
}
|
|
43
44
|
if (header.indent === 0)
|
|
44
45
|
trimIndent = indent.length;
|
|
@@ -65,7 +66,7 @@ function resolveBlockScalar(scalar, strict, onError) {
|
|
|
65
66
|
? 'explicit indentation indicator'
|
|
66
67
|
: 'first line';
|
|
67
68
|
const message = `Block scalar lines must not be less indented than their ${src}`;
|
|
68
|
-
onError(offset - content.length - (crlf ? 2 : 1), message);
|
|
69
|
+
onError(offset - content.length - (crlf ? 2 : 1), 'BAD_INDENT', message);
|
|
69
70
|
indent = '';
|
|
70
71
|
}
|
|
71
72
|
if (type === Scalar.Scalar.BLOCK_LITERAL) {
|
|
@@ -107,17 +108,13 @@ function resolveBlockScalar(scalar, strict, onError) {
|
|
|
107
108
|
default:
|
|
108
109
|
value += '\n';
|
|
109
110
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
type,
|
|
113
|
-
comment: header.comment,
|
|
114
|
-
length: header.length + scalar.source.length
|
|
115
|
-
};
|
|
111
|
+
const end = start + header.length + scalar.source.length;
|
|
112
|
+
return { value, type, comment: header.comment, range: [start, end, end] };
|
|
116
113
|
}
|
|
117
114
|
function parseBlockScalarHeader({ offset, props }, strict, onError) {
|
|
118
115
|
/* istanbul ignore if should not happen */
|
|
119
116
|
if (props[0].type !== 'block-scalar-header') {
|
|
120
|
-
onError(
|
|
117
|
+
onError(props[0], 'IMPOSSIBLE', 'Block scalar header not found');
|
|
121
118
|
return null;
|
|
122
119
|
}
|
|
123
120
|
const { source } = props[0];
|
|
@@ -138,7 +135,7 @@ function parseBlockScalarHeader({ offset, props }, strict, onError) {
|
|
|
138
135
|
}
|
|
139
136
|
}
|
|
140
137
|
if (error !== -1)
|
|
141
|
-
onError(error, `Block scalar header includes extra characters: ${source}`);
|
|
138
|
+
onError(error, 'UNEXPECTED_TOKEN', `Block scalar header includes extra characters: ${source}`);
|
|
142
139
|
let hasSpace = false;
|
|
143
140
|
let comment = '';
|
|
144
141
|
let length = source.length;
|
|
@@ -154,19 +151,19 @@ function parseBlockScalarHeader({ offset, props }, strict, onError) {
|
|
|
154
151
|
case 'comment':
|
|
155
152
|
if (strict && !hasSpace) {
|
|
156
153
|
const message = 'Comments must be separated from other tokens by white space characters';
|
|
157
|
-
onError(
|
|
154
|
+
onError(token, 'MISSING_CHAR', message);
|
|
158
155
|
}
|
|
159
156
|
length += token.source.length;
|
|
160
157
|
comment = token.source.substring(1);
|
|
161
158
|
break;
|
|
162
159
|
case 'error':
|
|
163
|
-
onError(
|
|
160
|
+
onError(token, 'UNEXPECTED_TOKEN', token.message);
|
|
164
161
|
length += token.source.length;
|
|
165
162
|
break;
|
|
166
163
|
/* istanbul ignore next should not happen */
|
|
167
164
|
default: {
|
|
168
165
|
const message = `Unexpected token in block scalar header: ${token.type}`;
|
|
169
|
-
onError(
|
|
166
|
+
onError(token, 'UNEXPECTED_TOKEN', message);
|
|
170
167
|
const ts = token.source;
|
|
171
168
|
if (ts && typeof ts === 'string')
|
|
172
169
|
length += ts.length;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Document } from '../doc/Document.js';
|
|
2
1
|
import { YAMLSeq } from '../nodes/YAMLSeq.js';
|
|
3
|
-
import type { BlockSequence } from '../parse/
|
|
4
|
-
import type { ComposeNode } from './compose-node.js';
|
|
5
|
-
|
|
2
|
+
import type { BlockSequence } from '../parse/cst.js';
|
|
3
|
+
import type { ComposeContext, ComposeNode } from './compose-node.js';
|
|
4
|
+
import type { ComposeErrorHandler } from './composer.js';
|
|
5
|
+
export declare function resolveBlockSeq({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bs: BlockSequence, onError: ComposeErrorHandler): YAMLSeq.Parsed<import("../index.js").ParsedNode>;
|
|
@@ -3,20 +3,24 @@
|
|
|
3
3
|
var YAMLSeq = require('../nodes/YAMLSeq.js');
|
|
4
4
|
var resolveProps = require('./resolve-props.js');
|
|
5
5
|
|
|
6
|
-
function resolveBlockSeq({ composeNode, composeEmptyNode },
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
|
|
7
|
+
const seq = new YAMLSeq.YAMLSeq(ctx.schema);
|
|
8
|
+
let offset = bs.offset;
|
|
9
|
+
for (const { start, value } of bs.items) {
|
|
10
|
+
const props = resolveProps.resolveProps(start, {
|
|
11
|
+
indicator: 'seq-item-ind',
|
|
12
|
+
next: value,
|
|
13
|
+
offset,
|
|
14
|
+
onError,
|
|
15
|
+
startOnNewline: true
|
|
16
|
+
});
|
|
17
|
+
offset = props.end;
|
|
14
18
|
if (!props.found) {
|
|
15
|
-
if (props.anchor || props.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
if (props.anchor || props.tag || value) {
|
|
20
|
+
if (value && value.type === 'block-seq')
|
|
21
|
+
onError(offset, 'BAD_INDENT', 'All sequence items must start at the same column');
|
|
22
|
+
else
|
|
23
|
+
onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
|
|
20
24
|
}
|
|
21
25
|
else {
|
|
22
26
|
// TODO: assert being at last item?
|
|
@@ -26,12 +30,12 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, doc, { items, offset
|
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
const node = value
|
|
29
|
-
? composeNode(
|
|
30
|
-
: composeEmptyNode(
|
|
31
|
-
offset = node.range[
|
|
33
|
+
? composeNode(ctx, value, props, onError)
|
|
34
|
+
: composeEmptyNode(ctx, offset, start, null, props, onError);
|
|
35
|
+
offset = node.range[2];
|
|
32
36
|
seq.items.push(node);
|
|
33
37
|
}
|
|
34
|
-
seq.range = [
|
|
38
|
+
seq.range = [bs.offset, offset, offset];
|
|
35
39
|
return seq;
|
|
36
40
|
}
|
|
37
41
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { SourceToken } from '../parse/
|
|
2
|
-
|
|
1
|
+
import type { SourceToken } from '../parse/cst.js';
|
|
2
|
+
import type { ComposeErrorHandler } from './composer.js';
|
|
3
|
+
export declare function resolveEnd(end: SourceToken[] | undefined, offset: number, reqSpace: boolean, onError: ComposeErrorHandler): {
|
|
3
4
|
comment: string;
|
|
4
5
|
offset: number;
|
|
5
6
|
};
|
|
@@ -4,32 +4,31 @@ function resolveEnd(end, offset, reqSpace, onError) {
|
|
|
4
4
|
let comment = '';
|
|
5
5
|
if (end) {
|
|
6
6
|
let hasSpace = false;
|
|
7
|
-
let hasComment = false;
|
|
8
7
|
let sep = '';
|
|
9
|
-
for (const
|
|
8
|
+
for (const token of end) {
|
|
9
|
+
const { source, type } = token;
|
|
10
10
|
switch (type) {
|
|
11
11
|
case 'space':
|
|
12
12
|
hasSpace = true;
|
|
13
13
|
break;
|
|
14
14
|
case 'comment': {
|
|
15
15
|
if (reqSpace && !hasSpace)
|
|
16
|
-
onError(
|
|
17
|
-
const cb = source.substring(1);
|
|
18
|
-
if (!
|
|
16
|
+
onError(token, 'MISSING_CHAR', 'Comments must be separated from other tokens by white space characters');
|
|
17
|
+
const cb = source.substring(1) || ' ';
|
|
18
|
+
if (!comment)
|
|
19
19
|
comment = cb;
|
|
20
20
|
else
|
|
21
21
|
comment += sep + cb;
|
|
22
|
-
hasComment = true;
|
|
23
22
|
sep = '';
|
|
24
23
|
break;
|
|
25
24
|
}
|
|
26
25
|
case 'newline':
|
|
27
|
-
if (
|
|
26
|
+
if (comment)
|
|
28
27
|
sep += source;
|
|
29
28
|
hasSpace = true;
|
|
30
29
|
break;
|
|
31
30
|
default:
|
|
32
|
-
onError(
|
|
31
|
+
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${type} at node end`);
|
|
33
32
|
}
|
|
34
33
|
offset += source.length;
|
|
35
34
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Document } from '../doc/Document.js';
|
|
2
|
-
import { ParsedNode } from '../nodes/Node.js';
|
|
3
1
|
import { YAMLMap } from '../nodes/YAMLMap.js';
|
|
4
2
|
import { YAMLSeq } from '../nodes/YAMLSeq.js';
|
|
5
|
-
import type { FlowCollection } from '../parse/
|
|
6
|
-
import type { ComposeNode } from './compose-node.js';
|
|
7
|
-
|
|
3
|
+
import type { FlowCollection } from '../parse/cst.js';
|
|
4
|
+
import type { ComposeContext, ComposeNode } from './compose-node.js';
|
|
5
|
+
import type { ComposeErrorHandler } from './composer.js';
|
|
6
|
+
export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../nodes/Node.js").ParsedNode, import("../nodes/Node.js").ParsedNode | null> | YAMLSeq.Parsed<import("../nodes/Node.js").ParsedNode>;
|
|
@@ -5,227 +5,186 @@ var Pair = require('../nodes/Pair.js');
|
|
|
5
5
|
var YAMLMap = require('../nodes/YAMLMap.js');
|
|
6
6
|
var YAMLSeq = require('../nodes/YAMLSeq.js');
|
|
7
7
|
var resolveEnd = require('./resolve-end.js');
|
|
8
|
+
var resolveProps = require('./resolve-props.js');
|
|
8
9
|
var utilContainsNewline = require('./util-contains-newline.js');
|
|
10
|
+
var utilMapIncludes = require('./util-map-includes.js');
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
const blockMsg = 'Block collections are not allowed within flow collections';
|
|
13
|
+
const isBlock = (token) => token && (token.type === 'block-map' || token.type === 'block-seq');
|
|
14
|
+
function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError) {
|
|
11
15
|
const isMap = fc.start.source === '{';
|
|
12
|
-
const
|
|
16
|
+
const fcName = isMap ? 'flow map' : 'flow sequence';
|
|
17
|
+
const coll = isMap
|
|
18
|
+
? new YAMLMap.YAMLMap(ctx.schema)
|
|
19
|
+
: new YAMLSeq.YAMLSeq(ctx.schema);
|
|
13
20
|
coll.flow = true;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (value) {
|
|
43
|
-
if (hasComment)
|
|
44
|
-
value.comment = comment;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
value = composeEmptyNode(doc, offset, fc.items, pos, getProps(), onError);
|
|
21
|
+
let offset = fc.offset;
|
|
22
|
+
for (let i = 0; i < fc.items.length; ++i) {
|
|
23
|
+
const { start, key, sep, value } = fc.items[i];
|
|
24
|
+
const props = resolveProps.resolveProps(start, {
|
|
25
|
+
flow: fcName,
|
|
26
|
+
indicator: 'explicit-key-ind',
|
|
27
|
+
next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
|
|
28
|
+
offset,
|
|
29
|
+
onError,
|
|
30
|
+
startOnNewline: false
|
|
31
|
+
});
|
|
32
|
+
if (!props.found) {
|
|
33
|
+
if (!props.anchor && !props.tag && !sep && !value) {
|
|
34
|
+
if (i === 0 && props.comma)
|
|
35
|
+
onError(props.comma, 'UNEXPECTED_TOKEN', `Unexpected , in ${fcName}`);
|
|
36
|
+
else if (i < fc.items.length - 1)
|
|
37
|
+
onError(props.start, 'UNEXPECTED_TOKEN', `Unexpected empty item in ${fcName}`);
|
|
38
|
+
if (props.comment) {
|
|
39
|
+
if (coll.comment)
|
|
40
|
+
coll.comment += '\n' + props.comment;
|
|
41
|
+
else
|
|
42
|
+
coll.comment = props.comment;
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (!isMap && ctx.options.strict && utilContainsNewline.containsNewline(key))
|
|
47
|
+
onError(key, // checked by containsNewline()
|
|
48
|
+
'MULTILINE_IMPLICIT_KEY', 'Implicit keys of flow sequence pairs need to be on a single line');
|
|
48
49
|
}
|
|
49
|
-
if (
|
|
50
|
-
|
|
50
|
+
if (i === 0) {
|
|
51
|
+
if (props.comma)
|
|
52
|
+
onError(props.comma, 'UNEXPECTED_TOKEN', `Unexpected , in ${fcName}`);
|
|
51
53
|
}
|
|
52
54
|
else {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
switch (token.type) {
|
|
68
|
-
case 'space':
|
|
69
|
-
hasSpace = true;
|
|
70
|
-
break;
|
|
71
|
-
case 'comment': {
|
|
72
|
-
if (doc.options.strict && !hasSpace)
|
|
73
|
-
onError(offset, 'Comments must be separated from other tokens by white space characters');
|
|
74
|
-
const cb = token.source.substring(1);
|
|
75
|
-
if (!hasComment)
|
|
76
|
-
comment = cb;
|
|
77
|
-
else
|
|
78
|
-
comment += newlines + cb;
|
|
79
|
-
atLineStart = false;
|
|
80
|
-
hasComment = true;
|
|
81
|
-
newlines = '';
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case 'newline':
|
|
85
|
-
if (atLineStart && !hasComment)
|
|
86
|
-
spaceBefore = true;
|
|
87
|
-
if (atValueEnd) {
|
|
88
|
-
if (hasComment) {
|
|
89
|
-
let node = coll.items[coll.items.length - 1];
|
|
90
|
-
if (Node.isPair(node))
|
|
91
|
-
node = node.value || node.key;
|
|
92
|
-
/* istanbul ignore else should not happen */
|
|
93
|
-
if (Node.isNode(node))
|
|
94
|
-
node.comment = comment;
|
|
95
|
-
else
|
|
96
|
-
onError(offset, 'Error adding trailing comment to node');
|
|
97
|
-
comment = '';
|
|
98
|
-
hasComment = false;
|
|
55
|
+
if (!props.comma)
|
|
56
|
+
onError(props.start, 'MISSING_CHAR', `Missing , between ${fcName} items`);
|
|
57
|
+
if (props.comment) {
|
|
58
|
+
let prevItemComment = '';
|
|
59
|
+
loop: for (const st of start) {
|
|
60
|
+
switch (st.type) {
|
|
61
|
+
case 'comma':
|
|
62
|
+
case 'space':
|
|
63
|
+
break;
|
|
64
|
+
case 'comment':
|
|
65
|
+
prevItemComment = st.source.substring(1);
|
|
66
|
+
break loop;
|
|
67
|
+
default:
|
|
68
|
+
break loop;
|
|
99
69
|
}
|
|
100
|
-
atValueEnd = false;
|
|
101
70
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
|
|
71
|
+
if (prevItemComment) {
|
|
72
|
+
let prev = coll.items[coll.items.length - 1];
|
|
73
|
+
if (Node.isPair(prev))
|
|
74
|
+
prev = prev.value || prev.key;
|
|
75
|
+
if (prev.comment)
|
|
76
|
+
prev.comment += '\n' + prevItemComment;
|
|
77
|
+
else
|
|
78
|
+
prev.comment = prevItemComment;
|
|
79
|
+
props.comment = props.comment.substring(prevItemComment.length + 1);
|
|
106
80
|
}
|
|
107
|
-
atLineStart = true;
|
|
108
|
-
hasSpace = true;
|
|
109
|
-
break;
|
|
110
|
-
case 'anchor':
|
|
111
|
-
if (anchor)
|
|
112
|
-
onError(offset, 'A node can have at most one anchor');
|
|
113
|
-
anchor = token.source.substring(1);
|
|
114
|
-
atLineStart = false;
|
|
115
|
-
atValueEnd = false;
|
|
116
|
-
hasSpace = false;
|
|
117
|
-
break;
|
|
118
|
-
case 'tag': {
|
|
119
|
-
if (tagName)
|
|
120
|
-
onError(offset, 'A node can have at most one tag');
|
|
121
|
-
const tn = doc.directives.tagName(token.source, m => onError(offset, m));
|
|
122
|
-
if (tn)
|
|
123
|
-
tagName = tn;
|
|
124
|
-
atLineStart = false;
|
|
125
|
-
atValueEnd = false;
|
|
126
|
-
hasSpace = false;
|
|
127
|
-
break;
|
|
128
81
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
82
|
+
}
|
|
83
|
+
if (!isMap && !sep && !props.found) {
|
|
84
|
+
// item is a value in a seq
|
|
85
|
+
// → key & sep are empty, start does not include ? or :
|
|
86
|
+
const valueNode = value
|
|
87
|
+
? composeNode(ctx, value, props, onError)
|
|
88
|
+
: composeEmptyNode(ctx, props.end, sep, null, props, onError);
|
|
89
|
+
coll.items.push(valueNode);
|
|
90
|
+
offset = valueNode.range[2];
|
|
91
|
+
if (isBlock(value))
|
|
92
|
+
onError(valueNode.range, 'BLOCK_IN_FLOW', blockMsg);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// item is a key+value pair
|
|
96
|
+
// key value
|
|
97
|
+
const keyStart = props.end;
|
|
98
|
+
const keyNode = key
|
|
99
|
+
? composeNode(ctx, key, props, onError)
|
|
100
|
+
: composeEmptyNode(ctx, keyStart, start, null, props, onError);
|
|
101
|
+
if (isBlock(key))
|
|
102
|
+
onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
|
|
103
|
+
// value properties
|
|
104
|
+
const valueProps = resolveProps.resolveProps(sep || [], {
|
|
105
|
+
flow: fcName,
|
|
106
|
+
indicator: 'map-value-ind',
|
|
107
|
+
next: value,
|
|
108
|
+
offset: keyNode.range[2],
|
|
109
|
+
onError,
|
|
110
|
+
startOnNewline: false
|
|
111
|
+
});
|
|
112
|
+
if (valueProps.found) {
|
|
113
|
+
if (!isMap && !props.found && ctx.options.strict) {
|
|
114
|
+
if (sep)
|
|
115
|
+
for (const st of sep) {
|
|
116
|
+
if (st === valueProps.found)
|
|
117
|
+
break;
|
|
118
|
+
if (st.type === 'newline') {
|
|
119
|
+
onError(st, 'MULTILINE_IMPLICIT_KEY', 'Implicit keys of flow sequence pairs need to be on a single line');
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
161
122
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
value = null;
|
|
123
|
+
if (props.start < valueProps.found.offset - 1024)
|
|
124
|
+
onError(valueProps.found, 'KEY_OVER_1024_CHARS', 'The : indicator must be at most 1024 chars after the start of an implicit flow sequence key');
|
|
165
125
|
}
|
|
166
|
-
else {
|
|
167
|
-
key = composeEmptyNode(doc, offset, fc.items, i, getProps(), onError);
|
|
168
|
-
}
|
|
169
|
-
if (hasComment) {
|
|
170
|
-
key.comment = comment;
|
|
171
|
-
comment = '';
|
|
172
|
-
hasComment = false;
|
|
173
|
-
}
|
|
174
|
-
atExplicitKey = false;
|
|
175
|
-
atValueEnd = false;
|
|
176
|
-
hasSpace = false;
|
|
177
|
-
break;
|
|
178
126
|
}
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
|
|
127
|
+
else if (value) {
|
|
128
|
+
if ('source' in value && value.source && value.source[0] === ':')
|
|
129
|
+
onError(value, 'MISSING_CHAR', `Missing space after : in ${fcName}`);
|
|
182
130
|
else
|
|
183
|
-
onError(
|
|
184
|
-
key = null;
|
|
185
|
-
value = null;
|
|
186
|
-
atExplicitKey = false;
|
|
187
|
-
atValueEnd = true;
|
|
188
|
-
hasSpace = false;
|
|
189
|
-
nlAfterValueInSeq = false;
|
|
190
|
-
seqKeyToken = null;
|
|
191
|
-
break;
|
|
192
|
-
case 'block-map':
|
|
193
|
-
case 'block-seq':
|
|
194
|
-
onError(offset, 'Block collections are not allowed within flow collections');
|
|
195
|
-
// fallthrough
|
|
196
|
-
default: {
|
|
197
|
-
if (value)
|
|
198
|
-
onError(offset, 'Missing , between flow collection items');
|
|
199
|
-
if (!isMap && !key && !atExplicitKey)
|
|
200
|
-
seqKeyToken = token;
|
|
201
|
-
value = composeNode(doc, token, getProps(), onError);
|
|
202
|
-
offset = value.range[1];
|
|
203
|
-
atLineStart = false;
|
|
204
|
-
isSourceToken = false;
|
|
205
|
-
atValueEnd = false;
|
|
206
|
-
hasSpace = false;
|
|
131
|
+
onError(valueProps.start, 'MISSING_CHAR', `Missing , or : between ${fcName} items`);
|
|
207
132
|
}
|
|
133
|
+
// value value
|
|
134
|
+
const valueNode = value
|
|
135
|
+
? composeNode(ctx, value, valueProps, onError)
|
|
136
|
+
: valueProps.found
|
|
137
|
+
? composeEmptyNode(ctx, valueProps.end, sep, null, valueProps, onError)
|
|
138
|
+
: null;
|
|
139
|
+
if (valueNode) {
|
|
140
|
+
if (isBlock(value))
|
|
141
|
+
onError(valueNode.range, 'BLOCK_IN_FLOW', blockMsg);
|
|
142
|
+
}
|
|
143
|
+
else if (valueProps.comment) {
|
|
144
|
+
if (keyNode.comment)
|
|
145
|
+
keyNode.comment += '\n' + valueProps.comment;
|
|
146
|
+
else
|
|
147
|
+
keyNode.comment = valueProps.comment;
|
|
148
|
+
}
|
|
149
|
+
const pair = new Pair.Pair(keyNode, valueNode);
|
|
150
|
+
if (isMap) {
|
|
151
|
+
const map = coll;
|
|
152
|
+
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
153
|
+
onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
|
|
154
|
+
map.items.push(pair);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const map = new YAMLMap.YAMLMap(ctx.schema);
|
|
158
|
+
map.flow = true;
|
|
159
|
+
map.items.push(pair);
|
|
160
|
+
coll.items.push(map);
|
|
161
|
+
}
|
|
162
|
+
offset = valueNode ? valueNode.range[2] : valueProps.end;
|
|
208
163
|
}
|
|
209
|
-
if (isSourceToken)
|
|
210
|
-
offset += token.source.length;
|
|
211
164
|
}
|
|
212
|
-
if (key || value || anchor || tagName || atExplicitKey)
|
|
213
|
-
addItem(fc.items.length);
|
|
214
165
|
const expectedEnd = isMap ? '}' : ']';
|
|
215
166
|
const [ce, ...ee] = fc.end;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
167
|
+
let cePos = offset;
|
|
168
|
+
if (ce && ce.source === expectedEnd)
|
|
169
|
+
cePos = ce.offset + ce.source.length;
|
|
170
|
+
else {
|
|
171
|
+
onError(offset + 1, 'MISSING_CHAR', `Expected ${fcName} to end with ${expectedEnd}`);
|
|
172
|
+
if (ce && ce.source.length !== 1)
|
|
173
|
+
ee.unshift(ce);
|
|
219
174
|
}
|
|
220
|
-
if (ce)
|
|
221
|
-
offset += ce.source.length;
|
|
222
175
|
if (ee.length > 0) {
|
|
223
|
-
const end = resolveEnd.resolveEnd(ee,
|
|
224
|
-
if (end.comment)
|
|
225
|
-
coll.comment
|
|
226
|
-
|
|
176
|
+
const end = resolveEnd.resolveEnd(ee, cePos, ctx.options.strict, onError);
|
|
177
|
+
if (end.comment) {
|
|
178
|
+
if (coll.comment)
|
|
179
|
+
coll.comment += '\n' + end.comment;
|
|
180
|
+
else
|
|
181
|
+
coll.comment = end.comment;
|
|
182
|
+
}
|
|
183
|
+
coll.range = [fc.offset, cePos, end.offset];
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
coll.range = [fc.offset, cePos, cePos];
|
|
227
187
|
}
|
|
228
|
-
coll.range = [fc.offset, offset];
|
|
229
188
|
return coll;
|
|
230
189
|
}
|
|
231
190
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { Range } from '../nodes/Node.js';
|
|
1
2
|
import { Scalar } from '../nodes/Scalar.js';
|
|
2
|
-
import type { FlowScalar } from '../parse/
|
|
3
|
-
|
|
3
|
+
import type { FlowScalar } from '../parse/cst.js';
|
|
4
|
+
import type { ComposeErrorHandler } from './composer.js';
|
|
5
|
+
export declare function resolveFlowScalar(scalar: FlowScalar, strict: boolean, onError: ComposeErrorHandler): {
|
|
4
6
|
value: string;
|
|
5
7
|
type: Scalar.PLAIN | Scalar.QUOTE_DOUBLE | Scalar.QUOTE_SINGLE | null;
|
|
6
8
|
comment: string;
|
|
7
|
-
|
|
9
|
+
range: Range;
|
|
8
10
|
};
|