@amritk/nish-aarch64-linux 0.35.0 → 0.36.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/INSTALL.md +6 -1
- package/bin/nish +0 -0
- package/docs/AI.md +9 -2
- package/package.json +1 -1
- package/runtime/nish.d.ts +4612 -430
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/base64.ts +34 -5
- package/std/bytes.ts +256 -40
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +235 -27
- package/std/net/http1-server.ts +343 -85
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +246 -96
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +723 -103
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +228 -44
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +489 -171
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +205 -35
- package/std/sync/shm.ts +194 -16
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/yaml.ts
CHANGED
|
@@ -65,7 +65,9 @@ export const YAML_PAIR: i32 = 5
|
|
|
65
65
|
|
|
66
66
|
/** A plain scalar, or a node with no style of its own (an alias, a pair). */
|
|
67
67
|
export const YAML_PLAIN: i32 = 0
|
|
68
|
+
/** A `'...'` scalar. */
|
|
68
69
|
export const YAML_SINGLE_QUOTED: i32 = 1
|
|
70
|
+
/** A `"..."` scalar, the one style with escapes. */
|
|
69
71
|
export const YAML_DOUBLE_QUOTED: i32 = 2
|
|
70
72
|
/** A `|` block scalar. */
|
|
71
73
|
export const YAML_LITERAL: i32 = 3
|
|
@@ -78,44 +80,99 @@ export const YAML_BLOCK: i32 = 6
|
|
|
78
80
|
|
|
79
81
|
/** A scalar's core-schema type, from `type`; `-1` for a node that is not a scalar. */
|
|
80
82
|
export const YAML_NULL: i32 = 0
|
|
83
|
+
/** `true` or `false`. */
|
|
81
84
|
export const YAML_BOOL: i32 = 1
|
|
85
|
+
/** An integer: decimal, `0o` octal or `0x` hex. */
|
|
82
86
|
export const YAML_INT: i32 = 2
|
|
87
|
+
/** A number with a fraction or exponent, an infinity (`.inf`, `-.inf`) or not-a-number (`.nan`). */
|
|
83
88
|
export const YAML_FLOAT: i32 = 3
|
|
89
|
+
/** Every other scalar; a quoted or block scalar is one unless a `!!` core tag that fits its text says otherwise. */
|
|
84
90
|
export const YAML_STRING: i32 = 4
|
|
85
91
|
|
|
86
92
|
// ---- Diagnostic codes ---------------------------------------------------------
|
|
87
93
|
|
|
94
|
+
/** Warning: an anchor or alias name ends in `:`, which YAML reads as part of the name. */
|
|
88
95
|
export const YAML_ERR_AMBIGUOUS_ANCHOR_NAME: i32 = 1
|
|
96
|
+
/** An anchor or alias whose name is empty or runs on into a flow indicator. */
|
|
89
97
|
export const YAML_ERR_BAD_ANCHOR: i32 = 2
|
|
98
|
+
/** A block scalar header that is not `|` or `>` with at most one indentation digit and one chomping indicator. */
|
|
90
99
|
export const YAML_ERR_BAD_BLOCK_HEADER: i32 = 3
|
|
100
|
+
/** A `#` that no whitespace precedes, so it cannot start a comment. */
|
|
91
101
|
export const YAML_ERR_BAD_COMMENT: i32 = 4
|
|
102
|
+
/**
|
|
103
|
+
* A `%YAML` directive with a bad version or content after it; as a warning, a
|
|
104
|
+
* `%TAG` directive missing its handle or prefix.
|
|
105
|
+
*/
|
|
92
106
|
export const YAML_ERR_BAD_DIRECTIVE: i32 = 5
|
|
107
|
+
/**
|
|
108
|
+
* A double-quoted escape that is not one: an unknown letter, the wrong count of
|
|
109
|
+
* hex digits, or a code point past U+10FFFF.
|
|
110
|
+
*/
|
|
93
111
|
export const YAML_ERR_BAD_ESCAPE: i32 = 6
|
|
112
|
+
/** An implicit key that does not fit on one line, or runs more than 1024 bytes before its `:`. */
|
|
94
113
|
export const YAML_ERR_BAD_IMPLICIT_KEY: i32 = 7
|
|
114
|
+
/**
|
|
115
|
+
* A quoted scalar or flow collection continued on a line not indented deeper
|
|
116
|
+
* than its parent, or a block scalar whose leading blank line is indented
|
|
117
|
+
* deeper than its first content line.
|
|
118
|
+
*/
|
|
95
119
|
export const YAML_ERR_BAD_INDENT: i32 = 8
|
|
120
|
+
/** A `<<` merge whose value is not a map, an alias to one, or a sequence of those. */
|
|
96
121
|
export const YAML_ERR_BAD_MERGE: i32 = 9
|
|
122
|
+
/**
|
|
123
|
+
* A node with two anchors or two tags, an alias with an anchor or tag, or node properties written before a `?`
|
|
124
|
+
* explicit key indicator on its line.
|
|
125
|
+
*/
|
|
97
126
|
export const YAML_ERR_BAD_PROPERTY: i32 = 10
|
|
127
|
+
/** A plain scalar that holds `: `, which only a key may. */
|
|
98
128
|
export const YAML_ERR_BAD_SCALAR_CONTENT: i32 = 11
|
|
129
|
+
/** A plain scalar that starts with an indicator character, or a flow entry that starts with `-`. */
|
|
99
130
|
export const YAML_ERR_BAD_SCALAR_START: i32 = 12
|
|
131
|
+
/** A tag that is empty or not well formed. */
|
|
100
132
|
export const YAML_ERR_BAD_TAG: i32 = 13
|
|
133
|
+
/**
|
|
134
|
+
* Warning: a `!!` core tag on the wrong kind of node (`!!map` on a scalar, say),
|
|
135
|
+
* which only warns, or a scalar whose text its `!!int`, `!!float`, `!!bool` or
|
|
136
|
+
* `!!null` tag cannot read, which is kept as a string.
|
|
137
|
+
*/
|
|
101
138
|
export const YAML_ERR_BAD_TAG_VALUE: i32 = 14
|
|
139
|
+
/** Collections nested deeper than `maxDepth`; the parse stops there. */
|
|
102
140
|
export const YAML_ERR_DEPTH_LIMIT: i32 = 15
|
|
141
|
+
/** A second `%YAML` directive in one document; as a warning, a `%TAG` handle declared twice. */
|
|
103
142
|
export const YAML_ERR_DUPLICATE_DIRECTIVE: i32 = 16
|
|
143
|
+
/** A map that repeats a key, when `uniqueKeys` asks for the check. */
|
|
104
144
|
export const YAML_ERR_DUPLICATE_KEY: i32 = 17
|
|
145
|
+
/** Warning: the stream has more documents than the first, which `firstDocumentOnly` left unread. */
|
|
105
146
|
export const YAML_ERR_MULTIPLE_DOCUMENTS: i32 = 18
|
|
147
|
+
/** An alias inside the node its anchor names. */
|
|
106
148
|
export const YAML_ERR_RECURSIVE_ALIAS: i32 = 19
|
|
149
|
+
/** A tab used to indent; YAML indents with spaces only. */
|
|
107
150
|
export const YAML_ERR_TAB_INDENT: i32 = 20
|
|
151
|
+
/** A `,` in a flow collection with no entry before it. */
|
|
108
152
|
export const YAML_ERR_UNEXPECTED_COMMA: i32 = 21
|
|
153
|
+
/** Text where no node may start, such as after the end of a node or a document marker inside a flow collection. */
|
|
109
154
|
export const YAML_ERR_UNEXPECTED_CONTENT: i32 = 22
|
|
155
|
+
/** A directive that no `...` precedes or no `---` follows. */
|
|
110
156
|
export const YAML_ERR_UNEXPECTED_DIRECTIVE: i32 = 23
|
|
157
|
+
/** Warning: a directive other than `%YAML` and `%TAG`; it is skipped. */
|
|
111
158
|
export const YAML_ERR_UNKNOWN_DIRECTIVE: i32 = 24
|
|
159
|
+
/** A tag whose handle no `%TAG` directive declared. */
|
|
112
160
|
export const YAML_ERR_UNKNOWN_TAG_HANDLE: i32 = 25
|
|
161
|
+
/** An alias with no anchor of that name before it. */
|
|
113
162
|
export const YAML_ERR_UNRESOLVED_ALIAS: i32 = 26
|
|
163
|
+
/** Warning: a `%YAML` version other than 1.2; the document is parsed as 1.2. */
|
|
114
164
|
export const YAML_ERR_UNSUPPORTED_YAML_VERSION: i32 = 27
|
|
165
|
+
/** A flow collection with no closing `]` or `}`. */
|
|
115
166
|
export const YAML_ERR_UNTERMINATED_FLOW: i32 = 28
|
|
167
|
+
/** A quoted scalar with no closing quote. */
|
|
116
168
|
export const YAML_ERR_UNTERMINATED_QUOTE: i32 = 29
|
|
117
169
|
|
|
118
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* The name of a diagnostic code, for a message or a log line.
|
|
172
|
+
*
|
|
173
|
+
* @param code A `YAML_ERR_*` code, such as `YAML_ERR_DUPLICATE_KEY`.
|
|
174
|
+
* @returns The code's name without its prefix, such as `"DUPLICATE_KEY"`, or `""` for a number that is not a code.
|
|
175
|
+
*/
|
|
119
176
|
export const yamlErrorName = (code: i32): string => {
|
|
120
177
|
const names: string[] = [
|
|
121
178
|
"",
|
|
@@ -236,8 +293,9 @@ export class YamlOptions {
|
|
|
236
293
|
// ---- The stream ----------------------------------------------------------------
|
|
237
294
|
|
|
238
295
|
/**
|
|
239
|
-
* Every document, node and diagnostic one parse found.
|
|
240
|
-
*
|
|
296
|
+
* Every document, node and diagnostic one parse found. A member marked
|
|
297
|
+
* `@internal` is the parser's working state, public only so that the parser
|
|
298
|
+
* and the walkers can fill and read it; use the others.
|
|
241
299
|
*
|
|
242
300
|
* A read never panics: a handle that names no node (`-1`, or one past the
|
|
243
301
|
* stream), or a read that does not fit the node's kind (`count` of a scalar,
|
|
@@ -248,71 +306,124 @@ export class YamlStream {
|
|
|
248
306
|
/** The text the stream was parsed from; every offset is into it. */
|
|
249
307
|
source: string
|
|
250
308
|
/** Per node: the first byte of its source, and one past its last. */
|
|
251
|
-
starts: i32[]
|
|
252
|
-
ends: i32[]
|
|
309
|
+
private starts: i32[]
|
|
310
|
+
private ends: i32[]
|
|
253
311
|
/**
|
|
254
312
|
* Per node, by kind: a collection's first child in `kids` and its child
|
|
255
313
|
* count; a pair's key and value; an alias's target and `-1`; a scalar's body
|
|
256
314
|
* (the bytes inside its quotes, or a block scalar's lines).
|
|
315
|
+
* @internal Used by `yamlDecode` and `YamlParser`.
|
|
257
316
|
*/
|
|
258
317
|
firsts: i32[]
|
|
318
|
+
/** @internal Used by `yamlDecode` and `YamlParser`. */
|
|
259
319
|
counts: i32[]
|
|
260
320
|
/**
|
|
261
321
|
* Per node: a block scalar's content indent, whether it was written, and its
|
|
262
322
|
* chomping, as `(indent + 1) * 8 + explicit * 4 + chomp`.
|
|
323
|
+
* @internal Used by `yamlDecode` and `YamlParser`.
|
|
263
324
|
*/
|
|
264
325
|
extras: i32[]
|
|
265
|
-
/**
|
|
326
|
+
/**
|
|
327
|
+
* Per node: its properties' slot, or `-1`.
|
|
328
|
+
* @internal Used by `YamlParser`.
|
|
329
|
+
*/
|
|
266
330
|
props: i32[]
|
|
267
331
|
/** Every collection's children, one collection after another. */
|
|
268
|
-
kids: i32[]
|
|
269
|
-
/**
|
|
332
|
+
private kids: i32[]
|
|
333
|
+
/**
|
|
334
|
+
* Per property slot: the anchor's name (after `&`), the tag as written, and the anchor table entry.
|
|
335
|
+
* @internal Used by `YamlParser`.
|
|
336
|
+
*/
|
|
270
337
|
propAnchorStarts: i32[]
|
|
338
|
+
/** @internal Used by `YamlParser`. */
|
|
271
339
|
propAnchorEnds: i32[]
|
|
340
|
+
/** @internal Used by `YamlParser`. */
|
|
272
341
|
propTagStarts: i32[]
|
|
342
|
+
/** @internal Used by `YamlParser`. */
|
|
273
343
|
propTagEnds: i32[]
|
|
344
|
+
/** @internal Used by `YamlParser`. */
|
|
274
345
|
propStarts: i32[]
|
|
346
|
+
/** @internal Used by `YamlParser`. */
|
|
275
347
|
propEnds: i32[]
|
|
348
|
+
/** @internal Used by `YamlParser`. */
|
|
276
349
|
propEntries: i32[]
|
|
277
|
-
/**
|
|
350
|
+
/**
|
|
351
|
+
* Per property slot: the resolved tag, with `tag:yaml.org,2002:` stripped, or `""`.
|
|
352
|
+
* @internal Used by `YamlParser`.
|
|
353
|
+
*/
|
|
278
354
|
propTags: string[]
|
|
279
|
-
/**
|
|
355
|
+
/**
|
|
356
|
+
* Per diagnostic: its code, range, document and message, and whether it is a warning.
|
|
357
|
+
* @internal Used by `YamlParser`.
|
|
358
|
+
*/
|
|
280
359
|
diagCodes: i32[]
|
|
281
|
-
diagStarts: i32[]
|
|
282
|
-
diagEnds: i32[]
|
|
360
|
+
private diagStarts: i32[]
|
|
361
|
+
private diagEnds: i32[]
|
|
362
|
+
/** @internal Used by `YamlParser`. */
|
|
283
363
|
diagDocuments: i32[]
|
|
284
|
-
diagMessages: string[]
|
|
285
|
-
diagWarnings: boolean[]
|
|
286
|
-
/**
|
|
364
|
+
private diagMessages: string[]
|
|
365
|
+
private diagWarnings: boolean[]
|
|
366
|
+
/**
|
|
367
|
+
* Per document: its root node and its range.
|
|
368
|
+
* @internal Used by `YamlParser`.
|
|
369
|
+
*/
|
|
287
370
|
docRoots: i32[]
|
|
371
|
+
/** @internal Used by `YamlParser`. */
|
|
288
372
|
docStarts: i32[]
|
|
373
|
+
/** @internal Used by `YamlParser`. */
|
|
289
374
|
docEnds: i32[]
|
|
290
|
-
/**
|
|
375
|
+
/**
|
|
376
|
+
* Per comment kept: its range, from the `#`.
|
|
377
|
+
* @internal Used by `YamlParser`.
|
|
378
|
+
*/
|
|
291
379
|
commentStarts: i32[]
|
|
380
|
+
/** @internal Used by `YamlParser`. */
|
|
292
381
|
commentEnds: i32[]
|
|
293
382
|
/**
|
|
294
383
|
* Per node: the path step whose merge search last went through it, as
|
|
295
384
|
* `mergeStep` numbers them; grown to the node count by the first search, so
|
|
296
385
|
* a search marks a map searched in one store.
|
|
386
|
+
* @internal Used by `YamlPathWalker`.
|
|
297
387
|
*/
|
|
298
388
|
mergeStamps: i32[]
|
|
299
|
-
/**
|
|
389
|
+
/**
|
|
390
|
+
* Per node: its `YAML_*` kind, style and core-schema type (`YAML_UNRESOLVED` until read).
|
|
391
|
+
* @internal Used by `YamlJsonLoader` in yaml-json.ts.
|
|
392
|
+
*/
|
|
300
393
|
kinds: u8[]
|
|
301
|
-
styles: u8[]
|
|
394
|
+
private styles: u8[]
|
|
395
|
+
/** @internal Used by `YamlParser`. */
|
|
302
396
|
types: u8[]
|
|
303
397
|
|
|
304
398
|
/** How many nodes the arrays have room for, and how many are in use. */
|
|
305
|
-
cap: i32 = 0
|
|
399
|
+
private cap: i32 = 0
|
|
400
|
+
/** @internal Used by `YamlPathWalker`. */
|
|
306
401
|
top: i32 = 0
|
|
307
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* How many slots of `kids` are in use.
|
|
404
|
+
* @internal Used by `YamlParser`.
|
|
405
|
+
*/
|
|
308
406
|
kidTop: i32 = 0
|
|
407
|
+
/** How many of the diagnostics are errors; the same as `errorCount()`. */
|
|
309
408
|
errors: i32 = 0
|
|
409
|
+
/** How many of the diagnostics are warnings; the same as `warningCount()`. */
|
|
310
410
|
warnings: i32 = 0
|
|
311
|
-
/**
|
|
411
|
+
/**
|
|
412
|
+
* How many path steps have searched merge keys; the stamp of the latest.
|
|
413
|
+
* @internal Used by `YamlPathWalker`.
|
|
414
|
+
*/
|
|
312
415
|
mergeStep: i32 = 0
|
|
313
|
-
/**
|
|
416
|
+
/**
|
|
417
|
+
* Whether a plain `<<` key is a merge key, as `YamlOptions.merge` said; paths follow merge keys while it is.
|
|
418
|
+
*/
|
|
314
419
|
merge: boolean = true
|
|
315
420
|
|
|
421
|
+
/**
|
|
422
|
+
* An empty stream over `text`, for the parser to fill; get a parsed one from
|
|
423
|
+
* `parseYaml`.
|
|
424
|
+
*
|
|
425
|
+
* @param text The YAML source every node and diagnostic range points into.
|
|
426
|
+
*/
|
|
316
427
|
constructor(text: string) {
|
|
317
428
|
this.source = text
|
|
318
429
|
const room: i32 = toI32(text.length) / 8 + 16
|
|
@@ -351,57 +462,109 @@ export class YamlStream {
|
|
|
351
462
|
|
|
352
463
|
// ---- Documents ---------------------------------------------------------------
|
|
353
464
|
|
|
354
|
-
/**
|
|
465
|
+
/**
|
|
466
|
+
* How many documents the stream holds.
|
|
467
|
+
*
|
|
468
|
+
* @returns `0` for an empty text, and always `1` under `firstDocumentOnly`.
|
|
469
|
+
*/
|
|
355
470
|
documentCount(): i32 {
|
|
356
471
|
return toI32(this.docRoots.length)
|
|
357
472
|
}
|
|
358
473
|
|
|
359
|
-
/**
|
|
474
|
+
/**
|
|
475
|
+
* Document `d`'s root node.
|
|
476
|
+
*
|
|
477
|
+
* @param d The document's index, from 0.
|
|
478
|
+
* @returns The root node, or `-1` for a document that is not there.
|
|
479
|
+
*/
|
|
360
480
|
documentRoot(d: i32): i32 {
|
|
361
481
|
return yamlAt(this.docRoots, d)
|
|
362
482
|
}
|
|
363
483
|
|
|
364
|
-
/**
|
|
484
|
+
/**
|
|
485
|
+
* Where document `d` starts.
|
|
486
|
+
*
|
|
487
|
+
* @param d The document's index, from 0.
|
|
488
|
+
* @returns The byte offset of its first byte (its `---`, if it has one), or `-1` for a document that is not there.
|
|
489
|
+
*/
|
|
365
490
|
documentStart(d: i32): i32 {
|
|
366
491
|
return yamlAt(this.docStarts, d)
|
|
367
492
|
}
|
|
368
493
|
|
|
369
|
-
/**
|
|
494
|
+
/**
|
|
495
|
+
* Where document `d` ends.
|
|
496
|
+
*
|
|
497
|
+
* @param d The document's index, from 0.
|
|
498
|
+
* @returns The byte offset one past its last byte (through its `...`, if it has one), or `-1` for
|
|
499
|
+
* a document that is not there.
|
|
500
|
+
*/
|
|
370
501
|
documentEnd(d: i32): i32 {
|
|
371
502
|
return yamlAt(this.docEnds, d)
|
|
372
503
|
}
|
|
373
504
|
|
|
374
505
|
// ---- Nodes -------------------------------------------------------------------
|
|
375
506
|
|
|
376
|
-
/**
|
|
507
|
+
/**
|
|
508
|
+
* What node `n` is.
|
|
509
|
+
*
|
|
510
|
+
* @param n A node handle, such as a `documentRoot` or a `child`.
|
|
511
|
+
* @returns `YAML_SCALAR`, `YAML_MAP`, `YAML_SEQ`, `YAML_ALIAS` or `YAML_PAIR`, or `0` for `-1`
|
|
512
|
+
* and any handle that is not a node.
|
|
513
|
+
*/
|
|
377
514
|
kind(n: i32): i32 {
|
|
378
515
|
const kinds: u8[] = this.kinds
|
|
379
516
|
return n >= 0 && n < this.top && n < toI32(kinds.length) ? toI32(kinds[n]) : 0
|
|
380
517
|
}
|
|
381
518
|
|
|
382
|
-
/**
|
|
519
|
+
/**
|
|
520
|
+
* How node `n` is written.
|
|
521
|
+
*
|
|
522
|
+
* @param n A node handle.
|
|
523
|
+
* @returns `YAML_PLAIN`, a quoted or block-scalar style, `YAML_FLOW` or `YAML_BLOCK`.
|
|
524
|
+
*/
|
|
383
525
|
style(n: i32): i32 {
|
|
384
526
|
const styles: u8[] = this.styles
|
|
385
527
|
return n >= 0 && n < this.top && n < toI32(styles.length) ? toI32(styles[n]) : 0
|
|
386
528
|
}
|
|
387
529
|
|
|
388
|
-
/**
|
|
530
|
+
/**
|
|
531
|
+
* Where node `n`'s source starts, its anchor and tag not included.
|
|
532
|
+
*
|
|
533
|
+
* @param n A node handle.
|
|
534
|
+
* @returns The byte offset of its first byte, or `-1` for a handle that is not a node.
|
|
535
|
+
*/
|
|
389
536
|
start(n: i32): i32 {
|
|
390
537
|
return n < this.top ? yamlAt(this.starts, n) : -1
|
|
391
538
|
}
|
|
392
539
|
|
|
393
|
-
/**
|
|
540
|
+
/**
|
|
541
|
+
* Where node `n`'s source ends.
|
|
542
|
+
*
|
|
543
|
+
* @param n A node handle.
|
|
544
|
+
* @returns The byte offset one past its last byte, or `-1` for a handle that is not a node.
|
|
545
|
+
*/
|
|
394
546
|
end(n: i32): i32 {
|
|
395
547
|
return n < this.top ? yamlAt(this.ends, n) : -1
|
|
396
548
|
}
|
|
397
549
|
|
|
398
|
-
/**
|
|
550
|
+
/**
|
|
551
|
+
* How many children node `n` has.
|
|
552
|
+
*
|
|
553
|
+
* @param n A node handle.
|
|
554
|
+
* @returns A map's pair count or a seq's item count; `0` for any other node.
|
|
555
|
+
*/
|
|
399
556
|
count(n: i32): i32 {
|
|
400
557
|
const k: i32 = this.kind(n)
|
|
401
558
|
return k === YAML_MAP || k === YAML_SEQ ? yamlAt(this.counts, n) : 0
|
|
402
559
|
}
|
|
403
560
|
|
|
404
|
-
/**
|
|
561
|
+
/**
|
|
562
|
+
* One child of a map or a seq.
|
|
563
|
+
*
|
|
564
|
+
* @param n The map or seq.
|
|
565
|
+
* @param i The child's position, from 0.
|
|
566
|
+
* @returns The `i`th pair of a map or item of a seq, or `-1` past the last child.
|
|
567
|
+
*/
|
|
405
568
|
child(n: i32, i: i32): i32 {
|
|
406
569
|
if (i < 0 || i >= this.count(n)) {
|
|
407
570
|
return -1
|
|
@@ -409,27 +572,52 @@ export class YamlStream {
|
|
|
409
572
|
return yamlAt(this.kids, yamlAt(this.firsts, n) + i)
|
|
410
573
|
}
|
|
411
574
|
|
|
412
|
-
/**
|
|
575
|
+
/**
|
|
576
|
+
* A pair's key.
|
|
577
|
+
*
|
|
578
|
+
* @param pair A `YAML_PAIR` node, a child of a map.
|
|
579
|
+
* @returns The key node, or `-1` for a node that is not a pair.
|
|
580
|
+
*/
|
|
413
581
|
key(pair: i32): i32 {
|
|
414
582
|
return this.kind(pair) === YAML_PAIR ? yamlAt(this.firsts, pair) : -1
|
|
415
583
|
}
|
|
416
584
|
|
|
417
|
-
/**
|
|
585
|
+
/**
|
|
586
|
+
* A pair's value.
|
|
587
|
+
*
|
|
588
|
+
* @param pair A `YAML_PAIR` node, a child of a map.
|
|
589
|
+
* @returns The value node, or `-1` for an empty value (`a:`, which reads as null) and any node that is not a pair.
|
|
590
|
+
*/
|
|
418
591
|
value(pair: i32): i32 {
|
|
419
592
|
return this.kind(pair) === YAML_PAIR ? yamlAt(this.counts, pair) : -1
|
|
420
593
|
}
|
|
421
594
|
|
|
422
|
-
/**
|
|
595
|
+
/**
|
|
596
|
+
* The node an alias names.
|
|
597
|
+
*
|
|
598
|
+
* @param n An alias node.
|
|
599
|
+
* @returns The anchored node, or `-1` for an alias with no anchor and any node that is not an alias.
|
|
600
|
+
*/
|
|
423
601
|
target(n: i32): i32 {
|
|
424
602
|
return this.kind(n) === YAML_ALIAS ? yamlAt(this.firsts, n) : -1
|
|
425
603
|
}
|
|
426
604
|
|
|
427
|
-
/**
|
|
605
|
+
/**
|
|
606
|
+
* Node `n` with an alias followed.
|
|
607
|
+
*
|
|
608
|
+
* @param n A node handle.
|
|
609
|
+
* @returns The node an alias names, or `n` itself when it is not an alias.
|
|
610
|
+
*/
|
|
428
611
|
resolved(n: i32): i32 {
|
|
429
612
|
return this.kind(n) === YAML_ALIAS ? yamlAt(this.firsts, n) : n
|
|
430
613
|
}
|
|
431
614
|
|
|
432
|
-
/**
|
|
615
|
+
/**
|
|
616
|
+
* Node `n`'s anchor name.
|
|
617
|
+
*
|
|
618
|
+
* @param n A node handle.
|
|
619
|
+
* @returns The name without its `&`, or `""` for a node with no anchor.
|
|
620
|
+
*/
|
|
433
621
|
anchor(n: i32): string {
|
|
434
622
|
const slot: i32 = n < this.top ? yamlAt(this.props, n) : -1
|
|
435
623
|
if (slot < 0) {
|
|
@@ -440,9 +628,12 @@ export class YamlStream {
|
|
|
440
628
|
}
|
|
441
629
|
|
|
442
630
|
/**
|
|
443
|
-
* Node `n`'s tag, resolved
|
|
444
|
-
*
|
|
445
|
-
*
|
|
631
|
+
* Node `n`'s tag, resolved.
|
|
632
|
+
*
|
|
633
|
+
* @param n A node handle.
|
|
634
|
+
* @returns `"int"` for `!!int` (the `tag:yaml.org,2002:` prefix stripped), `"!local"` for
|
|
635
|
+
* `!local`, `"!"` for the non-specific `!`, a `%TAG` handle's prefix joined to its suffix, or
|
|
636
|
+
* `""` for an untagged node.
|
|
446
637
|
*/
|
|
447
638
|
tag(n: i32): string {
|
|
448
639
|
const slot: i32 = n < this.top ? yamlAt(this.props, n) : -1
|
|
@@ -452,10 +643,12 @@ export class YamlStream {
|
|
|
452
643
|
|
|
453
644
|
/**
|
|
454
645
|
* A scalar's text, decoded: quotes and escapes undone, lines folded, a block
|
|
455
|
-
* scalar's indentation and chomping applied.
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
646
|
+
* scalar's indentation and chomping applied. A `\u` surrogate pair is one
|
|
647
|
+
* character; a lone surrogate escape is kept as its three bytes, which are
|
|
648
|
+
* not UTF-8. Decoded on every call; keep the result.
|
|
649
|
+
*
|
|
650
|
+
* @param n A scalar, or an alias to one.
|
|
651
|
+
* @returns The decoded text; an alias answers its target's, and any other node `""`.
|
|
459
652
|
*/
|
|
460
653
|
text(n: i32): string {
|
|
461
654
|
const at: i32 = this.resolved(n)
|
|
@@ -466,10 +659,14 @@ export class YamlStream {
|
|
|
466
659
|
}
|
|
467
660
|
|
|
468
661
|
/**
|
|
469
|
-
* A scalar's core-schema type
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
662
|
+
* A scalar's core-schema type. Untagged, a plain scalar is typed from its
|
|
663
|
+
* text and a quoted or block scalar is a string. Under a `!!null`, `!!bool` or
|
|
664
|
+
* `!!int` tag it is that type when its text (decoded, for a quoted or block
|
|
665
|
+
* scalar) reads as one, and a string otherwise; under `!!float` an int or
|
|
666
|
+
* float text is a float. Any other tag, `!!str` included, makes it a string.
|
|
667
|
+
*
|
|
668
|
+
* @param n A scalar, or an alias to one.
|
|
669
|
+
* @returns `YAML_NULL`, `YAML_BOOL`, `YAML_INT`, `YAML_FLOAT` or `YAML_STRING`; `-1` for a collection.
|
|
473
670
|
*/
|
|
474
671
|
type(n: i32): i32 {
|
|
475
672
|
const at: i32 = this.resolved(n)
|
|
@@ -488,7 +685,12 @@ export class YamlStream {
|
|
|
488
685
|
return resolvedType
|
|
489
686
|
}
|
|
490
687
|
|
|
491
|
-
/**
|
|
688
|
+
/**
|
|
689
|
+
* A boolean scalar's value.
|
|
690
|
+
*
|
|
691
|
+
* @param n A scalar, or an alias to one.
|
|
692
|
+
* @returns Whether it is the boolean `true`; `false` for anything that is not a `YAML_BOOL`.
|
|
693
|
+
*/
|
|
492
694
|
boolValue(n: i32): boolean {
|
|
493
695
|
if (this.type(n) !== YAML_BOOL) {
|
|
494
696
|
return false
|
|
@@ -501,7 +703,12 @@ export class YamlStream {
|
|
|
501
703
|
return code === 116 || code === 84
|
|
502
704
|
}
|
|
503
705
|
|
|
504
|
-
/**
|
|
706
|
+
/**
|
|
707
|
+
* An integer scalar's value.
|
|
708
|
+
*
|
|
709
|
+
* @param n A scalar, or an alias to one.
|
|
710
|
+
* @returns The value of a `YAML_INT`, wrapped past 64 bits; `0` for anything else.
|
|
711
|
+
*/
|
|
505
712
|
intValue(n: i32): i64 {
|
|
506
713
|
if (this.type(n) !== YAML_INT) {
|
|
507
714
|
return toI64(0)
|
|
@@ -514,7 +721,12 @@ export class YamlStream {
|
|
|
514
721
|
return yamlParseInt(decoded, 0, toI32(decoded.length))
|
|
515
722
|
}
|
|
516
723
|
|
|
517
|
-
/**
|
|
724
|
+
/**
|
|
725
|
+
* A number scalar's value.
|
|
726
|
+
*
|
|
727
|
+
* @param n A scalar, or an alias to one.
|
|
728
|
+
* @returns The value of a `YAML_FLOAT` or `YAML_INT` as an `f64`; `0` for anything else.
|
|
729
|
+
*/
|
|
518
730
|
floatValue(n: i32): f64 {
|
|
519
731
|
const t: i32 = this.type(n)
|
|
520
732
|
const at: i32 = this.resolved(n)
|
|
@@ -533,72 +745,136 @@ export class YamlStream {
|
|
|
533
745
|
|
|
534
746
|
// ---- Diagnostics -------------------------------------------------------------
|
|
535
747
|
|
|
536
|
-
/**
|
|
748
|
+
/**
|
|
749
|
+
* How many diagnostics the parse found, errors and warnings, in order of
|
|
750
|
+
* where they start.
|
|
751
|
+
*
|
|
752
|
+
* @returns The count; diagnostics are numbered from 0 below it.
|
|
753
|
+
*/
|
|
537
754
|
diagnosticCount(): i32 {
|
|
538
755
|
return toI32(this.diagCodes.length)
|
|
539
756
|
}
|
|
540
757
|
|
|
541
|
-
/**
|
|
758
|
+
/**
|
|
759
|
+
* How many of the diagnostics are errors.
|
|
760
|
+
*
|
|
761
|
+
* @returns The count: `0` for a valid stream.
|
|
762
|
+
*/
|
|
542
763
|
errorCount(): i32 {
|
|
543
764
|
return this.errors
|
|
544
765
|
}
|
|
545
766
|
|
|
546
|
-
/**
|
|
767
|
+
/**
|
|
768
|
+
* How many of the diagnostics are warnings.
|
|
769
|
+
*
|
|
770
|
+
* @returns The count; a warning does not make the stream invalid.
|
|
771
|
+
*/
|
|
547
772
|
warningCount(): i32 {
|
|
548
773
|
return this.warnings
|
|
549
774
|
}
|
|
550
775
|
|
|
551
|
-
/**
|
|
776
|
+
/**
|
|
777
|
+
* What diagnostic `i` is about.
|
|
778
|
+
*
|
|
779
|
+
* @param i The diagnostic's index, from 0.
|
|
780
|
+
* @returns Its `YAML_ERR_*` code, or `0` for an index past the last.
|
|
781
|
+
*/
|
|
552
782
|
diagnosticCode(i: i32): i32 {
|
|
553
783
|
const code: i32 = i < 0 ? 0 : yamlAt(this.diagCodes, i)
|
|
554
784
|
return code < 0 ? 0 : code
|
|
555
785
|
}
|
|
556
786
|
|
|
557
|
-
/**
|
|
787
|
+
/**
|
|
788
|
+
* Whether diagnostic `i` is a warning rather than an error.
|
|
789
|
+
*
|
|
790
|
+
* @param i The diagnostic's index, from 0.
|
|
791
|
+
* @returns `true` for a warning; `false` for an error and for an index past the last.
|
|
792
|
+
*/
|
|
558
793
|
diagnosticIsWarning(i: i32): boolean {
|
|
559
794
|
const warnings: boolean[] = this.diagWarnings
|
|
560
795
|
return i >= 0 && i < toI32(warnings.length) ? warnings[i] : false
|
|
561
796
|
}
|
|
562
797
|
|
|
563
|
-
/**
|
|
798
|
+
/**
|
|
799
|
+
* Where diagnostic `i`'s range starts.
|
|
800
|
+
*
|
|
801
|
+
* @param i The diagnostic's index, from 0.
|
|
802
|
+
* @returns The byte offset of the first byte it is about, or `-1` for an index past the last.
|
|
803
|
+
*/
|
|
564
804
|
diagnosticStart(i: i32): i32 {
|
|
565
805
|
return yamlAt(this.diagStarts, i)
|
|
566
806
|
}
|
|
567
807
|
|
|
568
|
-
/**
|
|
808
|
+
/**
|
|
809
|
+
* Where diagnostic `i`'s range ends.
|
|
810
|
+
*
|
|
811
|
+
* @param i The diagnostic's index, from 0.
|
|
812
|
+
* @returns The byte offset one past the last byte it is about, the same as its start for a point,
|
|
813
|
+
* or `-1` for an index past the last.
|
|
814
|
+
*/
|
|
569
815
|
diagnosticEnd(i: i32): i32 {
|
|
570
816
|
return yamlAt(this.diagEnds, i)
|
|
571
817
|
}
|
|
572
818
|
|
|
573
|
-
/**
|
|
819
|
+
/**
|
|
820
|
+
* Diagnostic `i`'s message, for a person.
|
|
821
|
+
*
|
|
822
|
+
* @param i The diagnostic's index, from 0.
|
|
823
|
+
* @returns A sentence such as `Map key "a" is duplicated` (a capital first, as other YAML tooling
|
|
824
|
+
* spells them), or `""` for an index past the last.
|
|
825
|
+
*/
|
|
574
826
|
diagnosticMessage(i: i32): string {
|
|
575
827
|
const messages: string[] = this.diagMessages
|
|
576
828
|
return i >= 0 && i < toI32(messages.length) ? messages[i] : ""
|
|
577
829
|
}
|
|
578
830
|
|
|
579
|
-
/**
|
|
831
|
+
/**
|
|
832
|
+
* The document diagnostic `i` was found in.
|
|
833
|
+
*
|
|
834
|
+
* @param i The diagnostic's index, from 0.
|
|
835
|
+
* @returns The document's index, or `-1` for an index past the last.
|
|
836
|
+
*/
|
|
580
837
|
diagnosticDocument(i: i32): i32 {
|
|
581
838
|
return yamlAt(this.diagDocuments, i)
|
|
582
839
|
}
|
|
583
840
|
|
|
584
841
|
// ---- Comments ----------------------------------------------------------------
|
|
585
842
|
|
|
586
|
-
/**
|
|
843
|
+
/**
|
|
844
|
+
* How many comments the stream kept.
|
|
845
|
+
*
|
|
846
|
+
* @returns The count: `0` unless `keepComments` was set.
|
|
847
|
+
*/
|
|
587
848
|
commentCount(): i32 {
|
|
588
849
|
return toI32(this.commentStarts.length)
|
|
589
850
|
}
|
|
590
851
|
|
|
591
|
-
/**
|
|
852
|
+
/**
|
|
853
|
+
* Where comment `i` starts.
|
|
854
|
+
*
|
|
855
|
+
* @param i The comment's index, from 0, in source order.
|
|
856
|
+
* @returns The byte offset of its `#`, or `-1` for an index past the last.
|
|
857
|
+
*/
|
|
592
858
|
commentStart(i: i32): i32 {
|
|
593
859
|
return yamlAt(this.commentStarts, i)
|
|
594
860
|
}
|
|
595
861
|
|
|
596
|
-
/**
|
|
862
|
+
/**
|
|
863
|
+
* Where comment `i` ends.
|
|
864
|
+
*
|
|
865
|
+
* @param i The comment's index, from 0, in source order.
|
|
866
|
+
* @returns The byte offset one past its last byte, before its line break, or `-1` for an index past the last.
|
|
867
|
+
*/
|
|
597
868
|
commentEnd(i: i32): i32 {
|
|
598
869
|
return yamlAt(this.commentEnds, i)
|
|
599
870
|
}
|
|
600
871
|
|
|
601
|
-
/**
|
|
872
|
+
/**
|
|
873
|
+
* Comment `i`'s text.
|
|
874
|
+
*
|
|
875
|
+
* @param i The comment's index, from 0, in source order.
|
|
876
|
+
* @returns The text after its `#`, or `""` for an index past the last.
|
|
877
|
+
*/
|
|
602
878
|
comment(i: i32): string {
|
|
603
879
|
const from: i32 = this.commentStart(i)
|
|
604
880
|
return from < 0 ? "" : this.source.substring(from + 1, this.commentEnd(i))
|
|
@@ -606,7 +882,10 @@ export class YamlStream {
|
|
|
606
882
|
|
|
607
883
|
// ---- Building ----------------------------------------------------------------
|
|
608
884
|
|
|
609
|
-
/**
|
|
885
|
+
/**
|
|
886
|
+
* A new node of `kind` and `style` over `[start, end)`, its other fields empty.
|
|
887
|
+
* @internal Called by `YamlParser`.
|
|
888
|
+
*/
|
|
610
889
|
newNode(kind: i32, style: i32, start: i32, end: i32): i32 {
|
|
611
890
|
if (this.top >= this.cap) {
|
|
612
891
|
this.grow()
|
|
@@ -625,8 +904,8 @@ export class YamlStream {
|
|
|
625
904
|
return n
|
|
626
905
|
}
|
|
627
906
|
|
|
628
|
-
/**
|
|
629
|
-
grow(): void {
|
|
907
|
+
/** Doubles every node array together. */
|
|
908
|
+
private grow(): void {
|
|
630
909
|
const room: i32 = this.cap * 2
|
|
631
910
|
this.starts = yamlRoomI32(this.starts, room)
|
|
632
911
|
this.ends = yamlRoomI32(this.ends, room)
|
|
@@ -640,7 +919,10 @@ export class YamlStream {
|
|
|
640
919
|
this.cap = room
|
|
641
920
|
}
|
|
642
921
|
|
|
643
|
-
/**
|
|
922
|
+
/**
|
|
923
|
+
* Appends `n` to `kids`, growing it by doubling; answers its slot.
|
|
924
|
+
* @internal Called by `YamlParser`.
|
|
925
|
+
*/
|
|
644
926
|
pushKid(n: i32): i32 {
|
|
645
927
|
const slot: i32 = this.kidTop
|
|
646
928
|
this.kids = yamlRoomI32(this.kids, slot + 1)
|
|
@@ -649,7 +931,10 @@ export class YamlStream {
|
|
|
649
931
|
return slot
|
|
650
932
|
}
|
|
651
933
|
|
|
652
|
-
/**
|
|
934
|
+
/**
|
|
935
|
+
* Records a diagnostic.
|
|
936
|
+
* @internal Called by `YamlParser`.
|
|
937
|
+
*/
|
|
653
938
|
report(code: i32, warning: boolean, message: string, start: i32, end: i32, document: i32): void {
|
|
654
939
|
this.diagCodes.push(code)
|
|
655
940
|
this.diagWarnings.push(warning)
|
|
@@ -664,7 +949,10 @@ export class YamlStream {
|
|
|
664
949
|
}
|
|
665
950
|
}
|
|
666
951
|
|
|
667
|
-
/**
|
|
952
|
+
/**
|
|
953
|
+
* A new, empty property slot.
|
|
954
|
+
* @internal Called by `YamlParser`.
|
|
955
|
+
*/
|
|
668
956
|
newProps(): i32 {
|
|
669
957
|
const slot: i32 = toI32(this.propTags.length)
|
|
670
958
|
this.propAnchorStarts.push(YAML_NONE)
|
|
@@ -678,7 +966,10 @@ export class YamlStream {
|
|
|
678
966
|
return slot
|
|
679
967
|
}
|
|
680
968
|
|
|
681
|
-
/**
|
|
969
|
+
/**
|
|
970
|
+
* Sorts the diagnostics by start, keeping the order of those that start together.
|
|
971
|
+
* @internal Called by `parseYamlWith`.
|
|
972
|
+
*/
|
|
682
973
|
sortDiagnostics(): void {
|
|
683
974
|
const count: i32 = toI32(this.diagCodes.length)
|
|
684
975
|
let i: i32 = 1
|
|
@@ -713,8 +1004,8 @@ export class YamlStream {
|
|
|
713
1004
|
}
|
|
714
1005
|
}
|
|
715
1006
|
|
|
716
|
-
/**
|
|
717
|
-
moveDiagnostic(from: i32, to: i32): void {
|
|
1007
|
+
/** Copies diagnostic `from` over diagnostic `to`. */
|
|
1008
|
+
private moveDiagnostic(from: i32, to: i32): void {
|
|
718
1009
|
yamlPut(this.diagCodes, to, yamlAt(this.diagCodes, from))
|
|
719
1010
|
yamlPut(this.diagStarts, to, yamlAt(this.diagStarts, from))
|
|
720
1011
|
yamlPut(this.diagEnds, to, yamlAt(this.diagEnds, from))
|
|
@@ -856,7 +1147,8 @@ const yamlLineEnd = (text: string, from: i32, to: i32): i32 => {
|
|
|
856
1147
|
|
|
857
1148
|
/** The bytes a scalar decodes to, collected before they become one string. */
|
|
858
1149
|
class YamlBuffer {
|
|
859
|
-
bytes: u8[]
|
|
1150
|
+
private bytes: u8[]
|
|
1151
|
+
/** @internal Used by `yamlDecodeFlow`. */
|
|
860
1152
|
count: i32 = 0
|
|
861
1153
|
|
|
862
1154
|
constructor(room: i32) {
|
|
@@ -864,7 +1156,10 @@ class YamlBuffer {
|
|
|
864
1156
|
this.bytes = new Array<u8>(room > least ? room : least)
|
|
865
1157
|
}
|
|
866
1158
|
|
|
867
|
-
/**
|
|
1159
|
+
/**
|
|
1160
|
+
* Appends one byte.
|
|
1161
|
+
* @internal Called by `yamlDecodeFlow`, `yamlDecodeEscape` and `yamlDecodeBlock`.
|
|
1162
|
+
*/
|
|
868
1163
|
push(code: i32): void {
|
|
869
1164
|
if (this.count >= toI32(this.bytes.length)) {
|
|
870
1165
|
this.bytes = yamlRoomU8(this.bytes, this.count + 1)
|
|
@@ -873,7 +1168,10 @@ class YamlBuffer {
|
|
|
873
1168
|
this.count += 1
|
|
874
1169
|
}
|
|
875
1170
|
|
|
876
|
-
/**
|
|
1171
|
+
/**
|
|
1172
|
+
* Appends `count` copies of `code`.
|
|
1173
|
+
* @internal Called by `yamlDecodeFlow` and `yamlDecodeBlock`.
|
|
1174
|
+
*/
|
|
877
1175
|
repeat(code: i32, count: i32): void {
|
|
878
1176
|
let i: i32 = 0
|
|
879
1177
|
while (i < count) {
|
|
@@ -882,7 +1180,10 @@ class YamlBuffer {
|
|
|
882
1180
|
}
|
|
883
1181
|
}
|
|
884
1182
|
|
|
885
|
-
/**
|
|
1183
|
+
/**
|
|
1184
|
+
* Appends `text[from, to)`.
|
|
1185
|
+
* @internal Called by `yamlDecodeFlow` and `yamlDecodeBlock`.
|
|
1186
|
+
*/
|
|
886
1187
|
copy(text: string, from: i32, to: i32): void {
|
|
887
1188
|
let i: i32 = from
|
|
888
1189
|
while (i < to) {
|
|
@@ -891,7 +1192,10 @@ class YamlBuffer {
|
|
|
891
1192
|
}
|
|
892
1193
|
}
|
|
893
1194
|
|
|
894
|
-
/**
|
|
1195
|
+
/**
|
|
1196
|
+
* Appends code point `cp` as UTF-8.
|
|
1197
|
+
* @internal Called by `yamlDecodeEscape`.
|
|
1198
|
+
*/
|
|
895
1199
|
codePoint(cp: i32): void {
|
|
896
1200
|
const six: i32 = 6
|
|
897
1201
|
const low: i32 = 63
|
|
@@ -918,7 +1222,10 @@ class YamlBuffer {
|
|
|
918
1222
|
this.push(continuation + (cp & low))
|
|
919
1223
|
}
|
|
920
1224
|
|
|
921
|
-
/**
|
|
1225
|
+
/**
|
|
1226
|
+
* Drops trailing spaces and tabs, but none at or below `floor`.
|
|
1227
|
+
* @internal Called by `yamlDecodeFlow`.
|
|
1228
|
+
*/
|
|
922
1229
|
trimBlanks(floor: i32): void {
|
|
923
1230
|
const bytes: u8[] = this.bytes
|
|
924
1231
|
while (this.count > floor) {
|
|
@@ -931,7 +1238,10 @@ class YamlBuffer {
|
|
|
931
1238
|
}
|
|
932
1239
|
}
|
|
933
1240
|
|
|
934
|
-
/**
|
|
1241
|
+
/**
|
|
1242
|
+
* The bytes as a string.
|
|
1243
|
+
* @internal Called by `yamlDecodeFlow` and `yamlDecodeBlock`.
|
|
1244
|
+
*/
|
|
935
1245
|
text(): string {
|
|
936
1246
|
return String.fromBytes(this.bytes, 0, this.count)
|
|
937
1247
|
}
|
|
@@ -1484,51 +1794,56 @@ const yamlEscapeKind = (code: i32): i32 => {
|
|
|
1484
1794
|
|
|
1485
1795
|
/** One parse in progress: the cursor, the anchors in scope and the document's directives. */
|
|
1486
1796
|
class YamlParser {
|
|
1797
|
+
/** @internal Used by `parseYamlWith`. */
|
|
1487
1798
|
stream: YamlStream
|
|
1488
|
-
text: string
|
|
1799
|
+
private text: string
|
|
1489
1800
|
/** The anchors defined so far in this document: each name's range and its node, searched from the end. */
|
|
1490
|
-
anchorStarts: i32[]
|
|
1491
|
-
anchorEnds: i32[]
|
|
1492
|
-
anchorNodes: i32[]
|
|
1801
|
+
private anchorStarts: i32[]
|
|
1802
|
+
private anchorEnds: i32[]
|
|
1803
|
+
private anchorNodes: i32[]
|
|
1493
1804
|
/** The anchors whose node is still being read, so an alias to one is recursive. */
|
|
1494
|
-
pendingStarts: i32[]
|
|
1495
|
-
pendingEnds: i32[]
|
|
1805
|
+
private pendingStarts: i32[]
|
|
1806
|
+
private pendingEnds: i32[]
|
|
1496
1807
|
/** The `%TAG` handles this document declared, and their prefixes. */
|
|
1497
|
-
handleNames: string[]
|
|
1498
|
-
handlePrefixes: string[]
|
|
1808
|
+
private handleNames: string[]
|
|
1809
|
+
private handlePrefixes: string[]
|
|
1499
1810
|
/** The children of every collection still open, innermost last. */
|
|
1500
|
-
scratch: i32[]
|
|
1811
|
+
private scratch: i32[]
|
|
1501
1812
|
/** Hash sets for the duplicate check of maps past YAML_PAIRWISE_KEYS pairs, reused as maps nest and end. */
|
|
1502
|
-
keySets: YamlKeySet[]
|
|
1503
|
-
pos: i32 = 0
|
|
1504
|
-
len: i32 = 0
|
|
1505
|
-
depth: i32 = 0
|
|
1813
|
+
private keySets: YamlKeySet[]
|
|
1814
|
+
private pos: i32 = 0
|
|
1815
|
+
private len: i32 = 0
|
|
1816
|
+
private depth: i32 = 0
|
|
1506
1817
|
/** Whether `DEPTH_LIMIT` cut the text short, so the collections it left open are not reported. */
|
|
1507
|
-
depthHit: boolean = false
|
|
1508
|
-
maxDepth: i32 = 1000
|
|
1509
|
-
doc: i32 = 0
|
|
1818
|
+
private depthHit: boolean = false
|
|
1819
|
+
private maxDepth: i32 = 1000
|
|
1820
|
+
private doc: i32 = 0
|
|
1510
1821
|
/** The indent a flow collection's continuation lines must pass. */
|
|
1511
|
-
flowIndent: i32 = -1
|
|
1512
|
-
tabReportedAt: i32 = -1
|
|
1513
|
-
commentWatermark: i32 = 0
|
|
1514
|
-
anchorTop: i32 = 0
|
|
1515
|
-
pendingTop: i32 = 0
|
|
1516
|
-
scratchTop: i32 = 0
|
|
1517
|
-
keySetTop: i32 = 0
|
|
1822
|
+
private flowIndent: i32 = -1
|
|
1823
|
+
private tabReportedAt: i32 = -1
|
|
1824
|
+
private commentWatermark: i32 = 0
|
|
1825
|
+
private anchorTop: i32 = 0
|
|
1826
|
+
private pendingTop: i32 = 0
|
|
1827
|
+
private scratchTop: i32 = 0
|
|
1828
|
+
private keySetTop: i32 = 0
|
|
1518
1829
|
/** The last error's range, so one mistake is not reported twice. */
|
|
1519
|
-
lastErrStart: i32 = -1
|
|
1520
|
-
lastErrEnd: i32 = -1
|
|
1830
|
+
private lastErrStart: i32 = -1
|
|
1831
|
+
private lastErrEnd: i32 = -1
|
|
1521
1832
|
/** What `peekLine` found: the next content line's indent and first byte. */
|
|
1522
|
-
lineIndent: i32 = 0
|
|
1523
|
-
lineContent: i32 = 0
|
|
1833
|
+
private lineIndent: i32 = 0
|
|
1834
|
+
private lineContent: i32 = 0
|
|
1524
1835
|
/** Where the current document's `---` is, or `-1` when it has none. */
|
|
1525
|
-
markerAt: i32 = -1
|
|
1526
|
-
flowIndentReported: boolean = false
|
|
1527
|
-
uniqueKeys: boolean = true
|
|
1528
|
-
keepComments: boolean = false
|
|
1836
|
+
private markerAt: i32 = -1
|
|
1837
|
+
private flowIndentReported: boolean = false
|
|
1838
|
+
private uniqueKeys: boolean = true
|
|
1839
|
+
private keepComments: boolean = false
|
|
1840
|
+
/**
|
|
1841
|
+
* Whether only the first document is parsed, as `firstDocumentOnly` said.
|
|
1842
|
+
* @internal Nothing reads it.
|
|
1843
|
+
*/
|
|
1529
1844
|
firstOnly: boolean = false
|
|
1530
|
-
yamlDirective: boolean = false
|
|
1531
|
-
lineEof: boolean = false
|
|
1845
|
+
private yamlDirective: boolean = false
|
|
1846
|
+
private lineEof: boolean = false
|
|
1532
1847
|
|
|
1533
1848
|
constructor(text: string, options: YamlOptions) {
|
|
1534
1849
|
this.stream = new YamlStream(text)
|
|
@@ -1552,41 +1867,41 @@ class YamlParser {
|
|
|
1552
1867
|
|
|
1553
1868
|
// ---- Reporting and bytes -------------------------------------------------------
|
|
1554
1869
|
|
|
1555
|
-
/**
|
|
1556
|
-
error(code: i32, message: string, start: i32, end: i32): void {
|
|
1870
|
+
/** Records an error over `[start, end)`. */
|
|
1871
|
+
private error(code: i32, message: string, start: i32, end: i32): void {
|
|
1557
1872
|
this.stream.report(code, false, message, start, end, this.doc)
|
|
1558
1873
|
this.lastErrStart = start
|
|
1559
1874
|
this.lastErrEnd = end < start ? start : end
|
|
1560
1875
|
}
|
|
1561
1876
|
|
|
1562
|
-
/**
|
|
1563
|
-
warn(code: i32, message: string, start: i32, end: i32): void {
|
|
1877
|
+
/** Records a warning over `[start, end)`. */
|
|
1878
|
+
private warn(code: i32, message: string, start: i32, end: i32): void {
|
|
1564
1879
|
this.stream.report(code, true, message, start, end, this.doc)
|
|
1565
1880
|
}
|
|
1566
1881
|
|
|
1567
|
-
/**
|
|
1568
|
-
at(i: i32): i32 {
|
|
1882
|
+
/** The byte at `i`, or `-1` outside the text. */
|
|
1883
|
+
private at(i: i32): i32 {
|
|
1569
1884
|
return yamlByte(this.text, i)
|
|
1570
1885
|
}
|
|
1571
1886
|
|
|
1572
|
-
/**
|
|
1573
|
-
isSeqEntryDash(i: i32): boolean {
|
|
1887
|
+
/** Whether `i` holds a `-` that starts a block sequence entry. */
|
|
1888
|
+
private isSeqEntryDash(i: i32): boolean {
|
|
1574
1889
|
return this.at(i) === YAML_DASH && yamlIsWs(this.at(i + 1))
|
|
1575
1890
|
}
|
|
1576
1891
|
|
|
1577
|
-
/**
|
|
1578
|
-
crossesLine(from: i32, to: i32): boolean {
|
|
1892
|
+
/** Whether `[from, to)` holds a line break. */
|
|
1893
|
+
private crossesLine(from: i32, to: i32): boolean {
|
|
1579
1894
|
return from < to && yamlLineEnd(this.text, from, to) < to
|
|
1580
1895
|
}
|
|
1581
1896
|
|
|
1582
|
-
/**
|
|
1583
|
-
nextLineStart(from: i32): i32 {
|
|
1897
|
+
/** The start of the line after the one `from` is on, or the end of the text. */
|
|
1898
|
+
private nextLineStart(from: i32): i32 {
|
|
1584
1899
|
const e: i32 = yamlLineEnd(this.text, from, this.len)
|
|
1585
1900
|
return e >= this.len ? this.len : yamlAfterBreak(this.text, e)
|
|
1586
1901
|
}
|
|
1587
1902
|
|
|
1588
|
-
/**
|
|
1589
|
-
isDocMarker(i: i32): boolean {
|
|
1903
|
+
/** Whether `i` starts a `---` or `...` marker. */
|
|
1904
|
+
private isDocMarker(i: i32): boolean {
|
|
1590
1905
|
const c: i32 = this.at(i)
|
|
1591
1906
|
return (
|
|
1592
1907
|
(c === YAML_DASH || c === YAML_DOT) &&
|
|
@@ -1596,8 +1911,8 @@ class YamlParser {
|
|
|
1596
1911
|
)
|
|
1597
1912
|
}
|
|
1598
1913
|
|
|
1599
|
-
/**
|
|
1600
|
-
plainLineEnd(from: i32): i32 {
|
|
1914
|
+
/** The end of `[from, …)` before any trailing blanks and a comment, on its line. */
|
|
1915
|
+
private plainLineEnd(from: i32): i32 {
|
|
1601
1916
|
let i: i32 = from
|
|
1602
1917
|
let lastNonSpace: i32 = from
|
|
1603
1918
|
while (i < this.len) {
|
|
@@ -1616,8 +1931,8 @@ class YamlParser {
|
|
|
1616
1931
|
return lastNonSpace
|
|
1617
1932
|
}
|
|
1618
1933
|
|
|
1619
|
-
/**
|
|
1620
|
-
tokenEnd(from: i32): i32 {
|
|
1934
|
+
/** The end of a token: the next blank, break or end of text. */
|
|
1935
|
+
private tokenEnd(from: i32): i32 {
|
|
1621
1936
|
let i: i32 = from
|
|
1622
1937
|
while (i < this.len && !yamlIsWs(this.at(i))) {
|
|
1623
1938
|
i += 1
|
|
@@ -1626,10 +1941,10 @@ class YamlParser {
|
|
|
1626
1941
|
}
|
|
1627
1942
|
|
|
1628
1943
|
/**
|
|
1629
|
-
*
|
|
1944
|
+
* The end of an anchor or tag token; in flow, a flow indicator ends
|
|
1630
1945
|
* it too, except in a verbatim tag, `!<…>`, which runs to its `>`.
|
|
1631
1946
|
*/
|
|
1632
|
-
propTokenEnd(from: i32, flow: boolean): i32 {
|
|
1947
|
+
private propTokenEnd(from: i32, flow: boolean): i32 {
|
|
1633
1948
|
let i: i32 = from
|
|
1634
1949
|
if (this.at(from - 1) === YAML_BANG && this.at(from) === YAML_LT) {
|
|
1635
1950
|
while (i < this.len && !yamlIsWs(this.at(i))) {
|
|
@@ -1653,10 +1968,10 @@ class YamlParser {
|
|
|
1653
1968
|
// ---- Lines and comments ----------------------------------------------------------
|
|
1654
1969
|
|
|
1655
1970
|
/**
|
|
1656
|
-
*
|
|
1971
|
+
* Moves to the start of the next line with content, past blank and
|
|
1657
1972
|
* comment lines, and sets `lineEof`, `lineIndent` and `lineContent`.
|
|
1658
1973
|
*/
|
|
1659
|
-
peekLine(minIndent: i32): void {
|
|
1974
|
+
private peekLine(minIndent: i32): void {
|
|
1660
1975
|
let p: i32 = this.pos
|
|
1661
1976
|
while (p < this.len) {
|
|
1662
1977
|
let i: i32 = p
|
|
@@ -1703,23 +2018,23 @@ class YamlParser {
|
|
|
1703
2018
|
this.lineContent = this.len
|
|
1704
2019
|
}
|
|
1705
2020
|
|
|
1706
|
-
/**
|
|
1707
|
-
setLine(start: i32, indent: i32, content: i32): void {
|
|
2021
|
+
/** The line `peekLine` found. */
|
|
2022
|
+
private setLine(start: i32, indent: i32, content: i32): void {
|
|
1708
2023
|
this.pos = start
|
|
1709
2024
|
this.lineEof = false
|
|
1710
2025
|
this.lineIndent = indent
|
|
1711
2026
|
this.lineContent = content
|
|
1712
2027
|
}
|
|
1713
2028
|
|
|
1714
|
-
/**
|
|
1715
|
-
skipInlineSpaces(): void {
|
|
2029
|
+
/** Steps past spaces and tabs. */
|
|
2030
|
+
private skipInlineSpaces(): void {
|
|
1716
2031
|
while (yamlIsBlank(this.at(this.pos))) {
|
|
1717
2032
|
this.pos += 1
|
|
1718
2033
|
}
|
|
1719
2034
|
}
|
|
1720
2035
|
|
|
1721
|
-
/**
|
|
1722
|
-
skipIndicatorSeparation(): void {
|
|
2036
|
+
/** Steps past the spaces after an indicator, reporting a tab that indents a compact node. */
|
|
2037
|
+
private skipIndicatorSeparation(): void {
|
|
1723
2038
|
while (this.at(this.pos) === YAML_SPACE) {
|
|
1724
2039
|
this.pos += 1
|
|
1725
2040
|
}
|
|
@@ -1741,8 +2056,8 @@ class YamlParser {
|
|
|
1741
2056
|
}
|
|
1742
2057
|
}
|
|
1743
2058
|
|
|
1744
|
-
/**
|
|
1745
|
-
recordComment(hash: i32): void {
|
|
2059
|
+
/** Keeps the comment that starts at `hash`, when comments are kept. */
|
|
2060
|
+
private recordComment(hash: i32): void {
|
|
1746
2061
|
if (!this.keepComments || hash < this.commentWatermark) {
|
|
1747
2062
|
return
|
|
1748
2063
|
}
|
|
@@ -1752,8 +2067,8 @@ class YamlParser {
|
|
|
1752
2067
|
this.stream.commentEnds.push(end)
|
|
1753
2068
|
}
|
|
1754
2069
|
|
|
1755
|
-
/**
|
|
1756
|
-
recordTrailingComment(): void {
|
|
2070
|
+
/** Keeps a comment after the content on this line, if there is one. */
|
|
2071
|
+
private recordTrailingComment(): void {
|
|
1757
2072
|
if (!this.keepComments) {
|
|
1758
2073
|
return
|
|
1759
2074
|
}
|
|
@@ -1770,8 +2085,8 @@ class YamlParser {
|
|
|
1770
2085
|
this.recordComment(i)
|
|
1771
2086
|
}
|
|
1772
2087
|
|
|
1773
|
-
/**
|
|
1774
|
-
recordLineComment(from: i32): void {
|
|
2088
|
+
/** Keeps the first comment on the line from `from`, if there is one. */
|
|
2089
|
+
private recordLineComment(from: i32): void {
|
|
1775
2090
|
if (!this.keepComments) {
|
|
1776
2091
|
return
|
|
1777
2092
|
}
|
|
@@ -1789,27 +2104,27 @@ class YamlParser {
|
|
|
1789
2104
|
}
|
|
1790
2105
|
}
|
|
1791
2106
|
|
|
1792
|
-
/**
|
|
1793
|
-
atLineEnd(): boolean {
|
|
2107
|
+
/** Whether the cursor is at the end of the text, a break or a comment. */
|
|
2108
|
+
private atLineEnd(): boolean {
|
|
1794
2109
|
const c: i32 = this.at(this.pos)
|
|
1795
2110
|
return c < 0 || yamlIsBreak(c) || c === YAML_HASH
|
|
1796
2111
|
}
|
|
1797
2112
|
|
|
1798
|
-
/**
|
|
1799
|
-
finishLine(): void {
|
|
2113
|
+
/** Moves past the rest of this line, keeping its comment. */
|
|
2114
|
+
private finishLine(): void {
|
|
1800
2115
|
this.recordTrailingComment()
|
|
1801
2116
|
this.pos = this.nextLineStart(this.pos)
|
|
1802
2117
|
}
|
|
1803
2118
|
|
|
1804
|
-
/**
|
|
1805
|
-
finishLineIfMidLine(): void {
|
|
2119
|
+
/** `finishLine`, unless the cursor is already at the start of a line. */
|
|
2120
|
+
private finishLineIfMidLine(): void {
|
|
1806
2121
|
if (this.pos > 0 && this.pos < this.len && !yamlIsBreak(this.at(this.pos - 1))) {
|
|
1807
2122
|
this.finishLine()
|
|
1808
2123
|
}
|
|
1809
2124
|
}
|
|
1810
2125
|
|
|
1811
|
-
/**
|
|
1812
|
-
checkTrailingContent(): void {
|
|
2126
|
+
/** Reports what follows a node on its line, if it is neither a comment nor nothing. */
|
|
2127
|
+
private checkTrailingContent(): void {
|
|
1813
2128
|
const c: i32 = this.at(this.pos)
|
|
1814
2129
|
if (c < 0 || yamlIsBreak(c)) {
|
|
1815
2130
|
return
|
|
@@ -1843,8 +2158,8 @@ class YamlParser {
|
|
|
1843
2158
|
|
|
1844
2159
|
// ---- Tags and properties ---------------------------------------------------------
|
|
1845
2160
|
|
|
1846
|
-
/**
|
|
1847
|
-
resolveTag(start: i32, end: i32): string {
|
|
2161
|
+
/** The tag written at `[start, end)`, resolved against this document's handles. */
|
|
2162
|
+
private resolveTag(start: i32, end: i32): string {
|
|
1848
2163
|
const written: string = this.text.substring(start, end)
|
|
1849
2164
|
if (end - start === 1) {
|
|
1850
2165
|
return "!"
|
|
@@ -1904,8 +2219,8 @@ class YamlParser {
|
|
|
1904
2219
|
return written
|
|
1905
2220
|
}
|
|
1906
2221
|
|
|
1907
|
-
/**
|
|
1908
|
-
reportBadAnchorName(what: string, start: i32, end: i32): void {
|
|
2222
|
+
/** Reports an anchor or alias name that is empty or runs into a flow indicator. */
|
|
2223
|
+
private reportBadAnchorName(what: string, start: i32, end: i32): void {
|
|
1909
2224
|
if (end === start + 1) {
|
|
1910
2225
|
this.error(YAML_ERR_BAD_ANCHOR, `${what} name cannot be empty`, start, end)
|
|
1911
2226
|
return
|
|
@@ -1920,8 +2235,8 @@ class YamlParser {
|
|
|
1920
2235
|
)
|
|
1921
2236
|
}
|
|
1922
2237
|
|
|
1923
|
-
/**
|
|
1924
|
-
checkAmbiguousName(what: string, start: i32, end: i32): void {
|
|
2238
|
+
/** Warns about an anchor or alias name `[start + 1, end)` that ends in `:`. */
|
|
2239
|
+
private checkAmbiguousName(what: string, start: i32, end: i32): void {
|
|
1925
2240
|
if (end <= start + 1 || this.at(end - 1) !== YAML_COLON) {
|
|
1926
2241
|
return
|
|
1927
2242
|
}
|
|
@@ -1934,8 +2249,8 @@ class YamlParser {
|
|
|
1934
2249
|
)
|
|
1935
2250
|
}
|
|
1936
2251
|
|
|
1937
|
-
/**
|
|
1938
|
-
scanProps(flow: boolean): i32 {
|
|
2252
|
+
/** Reads the anchor and tag before a node; answers their slot, or `-1` for none. */
|
|
2253
|
+
private scanProps(flow: boolean): i32 {
|
|
1939
2254
|
const first: i32 = this.at(this.pos)
|
|
1940
2255
|
if (first !== YAML_AMP && first !== YAML_BANG && !yamlIsBlank(first)) {
|
|
1941
2256
|
return -1
|
|
@@ -1993,8 +2308,8 @@ class YamlParser {
|
|
|
1993
2308
|
return slot
|
|
1994
2309
|
}
|
|
1995
2310
|
|
|
1996
|
-
/**
|
|
1997
|
-
skipPropsAhead(from: i32): i32 {
|
|
2311
|
+
/** The first byte after the anchors and tags at `from`, and the blanks after them. */
|
|
2312
|
+
private skipPropsAhead(from: i32): i32 {
|
|
1998
2313
|
let i: i32 = from
|
|
1999
2314
|
while (true) {
|
|
2000
2315
|
const c: i32 = this.at(i)
|
|
@@ -2008,8 +2323,8 @@ class YamlParser {
|
|
|
2008
2323
|
}
|
|
2009
2324
|
}
|
|
2010
2325
|
|
|
2011
|
-
/**
|
|
2012
|
-
findAnchor(from: i32, to: i32): i32 {
|
|
2326
|
+
/** The entry of the anchor named `[from, to)` among those defined so far, or `-1`. */
|
|
2327
|
+
private findAnchor(from: i32, to: i32): i32 {
|
|
2013
2328
|
let i: i32 = this.anchorTop - 1
|
|
2014
2329
|
while (i >= 0) {
|
|
2015
2330
|
if (yamlSameBytes(this.text, yamlAt(this.anchorStarts, i), yamlAt(this.anchorEnds, i), from, to)) {
|
|
@@ -2020,8 +2335,8 @@ class YamlParser {
|
|
|
2020
2335
|
return -1
|
|
2021
2336
|
}
|
|
2022
2337
|
|
|
2023
|
-
/**
|
|
2024
|
-
defineAnchor(from: i32, to: i32, node: i32, slot: i32): void {
|
|
2338
|
+
/** Defines the anchor `[from, to)` as naming `node`, and ends it being pending. */
|
|
2339
|
+
private defineAnchor(from: i32, to: i32, node: i32, slot: i32): void {
|
|
2025
2340
|
yamlStackPush(this.anchorStarts, this.anchorTop, from)
|
|
2026
2341
|
yamlStackPush(this.anchorEnds, this.anchorTop, to)
|
|
2027
2342
|
yamlPut(this.stream.propEntries, slot, this.anchorTop)
|
|
@@ -2043,8 +2358,8 @@ class YamlParser {
|
|
|
2043
2358
|
}
|
|
2044
2359
|
}
|
|
2045
2360
|
|
|
2046
|
-
/**
|
|
2047
|
-
attachProps(node: i32, slot: i32): i32 {
|
|
2361
|
+
/** Gives `node` the properties in `slot`, and answers `node`. */
|
|
2362
|
+
private attachProps(node: i32, slot: i32): i32 {
|
|
2048
2363
|
if (slot < 0 || node < 0) {
|
|
2049
2364
|
return node
|
|
2050
2365
|
}
|
|
@@ -2105,8 +2420,8 @@ class YamlParser {
|
|
|
2105
2420
|
|
|
2106
2421
|
// ---- Scalars -------------------------------------------------------------------
|
|
2107
2422
|
|
|
2108
|
-
/**
|
|
2109
|
-
reportBadEscape(at: i32): void {
|
|
2423
|
+
/** Reports the bad escape whose `\` is at `at`. */
|
|
2424
|
+
private reportBadEscape(at: i32): void {
|
|
2110
2425
|
const e: i32 = this.at(at + 1)
|
|
2111
2426
|
let digits: i32 = 0
|
|
2112
2427
|
if (e === 120) {
|
|
@@ -2146,8 +2461,8 @@ class YamlParser {
|
|
|
2146
2461
|
this.error(YAML_ERR_BAD_ESCAPE, `"\\${escaped}" is not a valid escape sequence`, at, at + 1 + width)
|
|
2147
2462
|
}
|
|
2148
2463
|
|
|
2149
|
-
/**
|
|
2150
|
-
checkQuotedIndent(lineStart: i32, parentIndent: i32): boolean {
|
|
2464
|
+
/** Reports a quoted scalar's continuation line at `lineStart` that is not indented past its parent. */
|
|
2465
|
+
private checkQuotedIndent(lineStart: i32, parentIndent: i32): boolean {
|
|
2151
2466
|
let i: i32 = lineStart
|
|
2152
2467
|
while (this.at(i) === YAML_SPACE) {
|
|
2153
2468
|
i += 1
|
|
@@ -2166,8 +2481,8 @@ class YamlParser {
|
|
|
2166
2481
|
return true
|
|
2167
2482
|
}
|
|
2168
2483
|
|
|
2169
|
-
/**
|
|
2170
|
-
scanQuoted(quote: i32, parentIndent: i32): i32 {
|
|
2484
|
+
/** Reads a single- or double-quoted scalar at the cursor. */
|
|
2485
|
+
private scanQuoted(quote: i32, parentIndent: i32): i32 {
|
|
2171
2486
|
const start: i32 = this.pos
|
|
2172
2487
|
const single: boolean = quote === YAML_SQUOTE
|
|
2173
2488
|
let i: i32 = start + 1
|
|
@@ -2241,8 +2556,8 @@ class YamlParser {
|
|
|
2241
2556
|
return node
|
|
2242
2557
|
}
|
|
2243
2558
|
|
|
2244
|
-
/**
|
|
2245
|
-
scanAlias(): i32 {
|
|
2559
|
+
/** Reads an alias at the cursor and resolves it against the anchors defined so far. */
|
|
2560
|
+
private scanAlias(): i32 {
|
|
2246
2561
|
const start: i32 = this.pos
|
|
2247
2562
|
let i: i32 = start + 1
|
|
2248
2563
|
while (i < this.len) {
|
|
@@ -2284,13 +2599,13 @@ class YamlParser {
|
|
|
2284
2599
|
return node
|
|
2285
2600
|
}
|
|
2286
2601
|
|
|
2287
|
-
/**
|
|
2288
|
-
emptyScalar(at: i32): i32 {
|
|
2602
|
+
/** An empty plain scalar, a null, at `at`. */
|
|
2603
|
+
private emptyScalar(at: i32): i32 {
|
|
2289
2604
|
return this.stream.newNode(YAML_SCALAR, YAML_PLAIN, at, at)
|
|
2290
2605
|
}
|
|
2291
2606
|
|
|
2292
|
-
/**
|
|
2293
|
-
plainStartClass(code: i32): i32 {
|
|
2607
|
+
/** Whether `code` may not start a plain scalar: `1` always, `2` for `-?:` before a blank. */
|
|
2608
|
+
private plainStartClass(code: i32): i32 {
|
|
2294
2609
|
if (code === YAML_DASH || code === YAML_QUESTION || code === YAML_COLON) {
|
|
2295
2610
|
return 2
|
|
2296
2611
|
}
|
|
@@ -2313,14 +2628,14 @@ class YamlParser {
|
|
|
2313
2628
|
return 0
|
|
2314
2629
|
}
|
|
2315
2630
|
|
|
2316
|
-
/**
|
|
2317
|
-
flowIndicatorBoundary(after: i32): boolean {
|
|
2631
|
+
/** Whether `after` ends a flow indicator: the end, a blank, a break, `,`, `]` or `}`. */
|
|
2632
|
+
private flowIndicatorBoundary(after: i32): boolean {
|
|
2318
2633
|
const c: i32 = this.at(after)
|
|
2319
2634
|
return yamlIsWs(c) || c === YAML_COMMA || c === YAML_RBRACKET || c === YAML_RBRACE
|
|
2320
2635
|
}
|
|
2321
2636
|
|
|
2322
|
-
/**
|
|
2323
|
-
reportBadPlainStart(pos: i32, flow: boolean): void {
|
|
2637
|
+
/** Reports the indicator at `pos` that cannot start a plain scalar. */
|
|
2638
|
+
private reportBadPlainStart(pos: i32, flow: boolean): void {
|
|
2324
2639
|
if (this.lastErrStart <= pos && pos < this.lastErrEnd) {
|
|
2325
2640
|
return
|
|
2326
2641
|
}
|
|
@@ -2370,8 +2685,8 @@ class YamlParser {
|
|
|
2370
2685
|
)
|
|
2371
2686
|
}
|
|
2372
2687
|
|
|
2373
|
-
/**
|
|
2374
|
-
plainColonAt(from: i32, end: i32): i32 {
|
|
2688
|
+
/** The first `:` in `[from, end)` that a blank or the end follows, or `-1`. */
|
|
2689
|
+
private plainColonAt(from: i32, end: i32): i32 {
|
|
2375
2690
|
let i: i32 = from
|
|
2376
2691
|
while (i < end) {
|
|
2377
2692
|
if (this.at(i) === YAML_COLON && (i + 1 >= end || yamlIsBlank(this.at(i + 1)))) {
|
|
@@ -2382,8 +2697,8 @@ class YamlParser {
|
|
|
2382
2697
|
return -1
|
|
2383
2698
|
}
|
|
2384
2699
|
|
|
2385
|
-
/**
|
|
2386
|
-
reportPlainColon(at: i32): void {
|
|
2700
|
+
/** Reports the `: ` at `at` inside a plain scalar. */
|
|
2701
|
+
private reportPlainColon(at: i32): void {
|
|
2387
2702
|
this.error(
|
|
2388
2703
|
YAML_ERR_BAD_SCALAR_CONTENT,
|
|
2389
2704
|
'A plain scalar cannot contain ": " — quote the value, or indent it as a nested mapping',
|
|
@@ -2392,8 +2707,8 @@ class YamlParser {
|
|
|
2392
2707
|
)
|
|
2393
2708
|
}
|
|
2394
2709
|
|
|
2395
|
-
/**
|
|
2396
|
-
endsAtComment(from: i32): boolean {
|
|
2710
|
+
/** Whether only blanks and a comment follow `from` on its line. */
|
|
2711
|
+
private endsAtComment(from: i32): boolean {
|
|
2397
2712
|
let i: i32 = from
|
|
2398
2713
|
while (yamlIsBlank(this.at(i))) {
|
|
2399
2714
|
i += 1
|
|
@@ -2401,8 +2716,8 @@ class YamlParser {
|
|
|
2401
2716
|
return this.at(i) === YAML_HASH
|
|
2402
2717
|
}
|
|
2403
2718
|
|
|
2404
|
-
/**
|
|
2405
|
-
scanPlainScalar(parentIndent: i32): i32 {
|
|
2719
|
+
/** Reads a block-context plain scalar at the cursor, with its continuation lines. */
|
|
2720
|
+
private scanPlainScalar(parentIndent: i32): i32 {
|
|
2406
2721
|
const start: i32 = this.pos
|
|
2407
2722
|
let valueEnd: i32 = this.plainLineEnd(start)
|
|
2408
2723
|
let colonReported: boolean = false
|
|
@@ -2458,8 +2773,8 @@ class YamlParser {
|
|
|
2458
2773
|
return node
|
|
2459
2774
|
}
|
|
2460
2775
|
|
|
2461
|
-
/**
|
|
2462
|
-
checkBlockHeaderEnd(): void {
|
|
2776
|
+
/** Reports anything but a comment after a block scalar's header. */
|
|
2777
|
+
private checkBlockHeaderEnd(): void {
|
|
2463
2778
|
let i: i32 = this.pos
|
|
2464
2779
|
while (yamlIsBlank(this.at(i))) {
|
|
2465
2780
|
i += 1
|
|
@@ -2478,8 +2793,8 @@ class YamlParser {
|
|
|
2478
2793
|
)
|
|
2479
2794
|
}
|
|
2480
2795
|
|
|
2481
|
-
/**
|
|
2482
|
-
scanBlockScalar(parentIndent: i32): i32 {
|
|
2796
|
+
/** Reads a `|` or `>` block scalar at the cursor. */
|
|
2797
|
+
private scanBlockScalar(parentIndent: i32): i32 {
|
|
2483
2798
|
const start: i32 = this.pos
|
|
2484
2799
|
const folded: boolean = this.at(start) === YAML_GT
|
|
2485
2800
|
this.pos += 1
|
|
@@ -2565,8 +2880,8 @@ class YamlParser {
|
|
|
2565
2880
|
|
|
2566
2881
|
// ---- Directives and key colons -------------------------------------------------
|
|
2567
2882
|
|
|
2568
|
-
/**
|
|
2569
|
-
readDirective(at: i32): void {
|
|
2883
|
+
/** Reads the `%` directive at `at` into the document's handles and version. */
|
|
2884
|
+
private readDirective(at: i32): void {
|
|
2570
2885
|
const nameEnd: i32 = this.tokenEnd(at + 1)
|
|
2571
2886
|
const isTag: boolean = yamlIsWord(this.text, at + 1, nameEnd, "TAG")
|
|
2572
2887
|
if (isTag || yamlIsWord(this.text, at + 1, nameEnd, "YAML")) {
|
|
@@ -2614,8 +2929,8 @@ class YamlParser {
|
|
|
2614
2929
|
)
|
|
2615
2930
|
}
|
|
2616
2931
|
|
|
2617
|
-
/**
|
|
2618
|
-
readYamlVersion(at: i32, from: i32, to: i32): void {
|
|
2932
|
+
/** Checks the version `[from, to)` of the `%YAML` directive at `at`. */
|
|
2933
|
+
private readYamlVersion(at: i32, from: i32, to: i32): void {
|
|
2619
2934
|
if (this.yamlDirective) {
|
|
2620
2935
|
this.error(YAML_ERR_DUPLICATE_DIRECTIVE, "A document may carry only one %YAML directive", at, to)
|
|
2621
2936
|
}
|
|
@@ -2660,8 +2975,8 @@ class YamlParser {
|
|
|
2660
2975
|
}
|
|
2661
2976
|
}
|
|
2662
2977
|
|
|
2663
|
-
/**
|
|
2664
|
-
quotedKeyEnd(from: i32, stopAtBreak: boolean): i32 {
|
|
2978
|
+
/** The end of the quoted scalar opening at `from`, past its closing quote, or `-1` at a break. */
|
|
2979
|
+
private quotedKeyEnd(from: i32, stopAtBreak: boolean): i32 {
|
|
2665
2980
|
const quote: i32 = this.at(from)
|
|
2666
2981
|
let i: i32 = from + 1
|
|
2667
2982
|
while (i < this.len) {
|
|
@@ -2682,8 +2997,8 @@ class YamlParser {
|
|
|
2682
2997
|
return i + 1
|
|
2683
2998
|
}
|
|
2684
2999
|
|
|
2685
|
-
/**
|
|
2686
|
-
flowKeyEnd(from: i32): i32 {
|
|
3000
|
+
/** The end of the flow collection opening at `from`, when it closes on its line; else `-1`. */
|
|
3001
|
+
private flowKeyEnd(from: i32): i32 {
|
|
2687
3002
|
let depth: i32 = 0
|
|
2688
3003
|
let i: i32 = from
|
|
2689
3004
|
while (i < this.len) {
|
|
@@ -2711,8 +3026,8 @@ class YamlParser {
|
|
|
2711
3026
|
return -1
|
|
2712
3027
|
}
|
|
2713
3028
|
|
|
2714
|
-
/**
|
|
2715
|
-
findKeyColon(from: i32): i32 {
|
|
3029
|
+
/** The `:` that makes the line from `from` an implicit key, or `-1`. */
|
|
3030
|
+
private findKeyColon(from: i32): i32 {
|
|
2716
3031
|
let i: i32 = from
|
|
2717
3032
|
const first: i32 = this.at(from)
|
|
2718
3033
|
if (first === YAML_LBRACKET || first === YAML_LBRACE) {
|
|
@@ -2739,8 +3054,8 @@ class YamlParser {
|
|
|
2739
3054
|
return -1
|
|
2740
3055
|
}
|
|
2741
3056
|
|
|
2742
|
-
/**
|
|
2743
|
-
lineRestIsBlank(from: i32): boolean {
|
|
3057
|
+
/** Whether the rest of the line from `from` is blank or a comment. */
|
|
3058
|
+
private lineRestIsBlank(from: i32): boolean {
|
|
2744
3059
|
let i: i32 = from
|
|
2745
3060
|
while (yamlIsBlank(this.at(i))) {
|
|
2746
3061
|
i += 1
|
|
@@ -2749,8 +3064,8 @@ class YamlParser {
|
|
|
2749
3064
|
return c < 0 || yamlIsBreak(c) || c === YAML_HASH
|
|
2750
3065
|
}
|
|
2751
3066
|
|
|
2752
|
-
/**
|
|
2753
|
-
trimEnd(from: i32, to: i32): i32 {
|
|
3067
|
+
/** `to` moved back over the blanks that end `[from, to)`. */
|
|
3068
|
+
private trimEnd(from: i32, to: i32): i32 {
|
|
2754
3069
|
let e: i32 = to
|
|
2755
3070
|
while (e > from && yamlIsBlank(this.at(e - 1))) {
|
|
2756
3071
|
e -= 1
|
|
@@ -2758,21 +3073,21 @@ class YamlParser {
|
|
|
2758
3073
|
return e
|
|
2759
3074
|
}
|
|
2760
3075
|
|
|
2761
|
-
/**
|
|
2762
|
-
isExplicitKey(at: i32): boolean {
|
|
3076
|
+
/** Whether `at` holds a `?` explicit-key indicator. */
|
|
3077
|
+
private isExplicitKey(at: i32): boolean {
|
|
2763
3078
|
return this.at(at) === YAML_QUESTION && yamlIsWs(this.at(at + 1))
|
|
2764
3079
|
}
|
|
2765
3080
|
|
|
2766
3081
|
// ---- Flow collections ----------------------------------------------------------
|
|
2767
3082
|
|
|
2768
|
-
/**
|
|
2769
|
-
enterFlow(blockIndent: i32): void {
|
|
3083
|
+
/** Enters a flow collection nested in a block node indented `blockIndent`. */
|
|
3084
|
+
private enterFlow(blockIndent: i32): void {
|
|
2770
3085
|
this.flowIndent = blockIndent
|
|
2771
3086
|
this.flowIndentReported = false
|
|
2772
3087
|
}
|
|
2773
3088
|
|
|
2774
|
-
/**
|
|
2775
|
-
checkFlowIndent(lineStart: i32): void {
|
|
3089
|
+
/** Checks that the flow line starting at `lineStart` is indented deeper than its block parent. */
|
|
3090
|
+
private checkFlowIndent(lineStart: i32): void {
|
|
2776
3091
|
let i: i32 = lineStart
|
|
2777
3092
|
while (this.at(i) === YAML_SPACE) {
|
|
2778
3093
|
i += 1
|
|
@@ -2807,8 +3122,8 @@ class YamlParser {
|
|
|
2807
3122
|
)
|
|
2808
3123
|
}
|
|
2809
3124
|
|
|
2810
|
-
/**
|
|
2811
|
-
skipFlowWs(): void {
|
|
3125
|
+
/** Skips blanks, breaks and comments inside a flow collection. */
|
|
3126
|
+
private skipFlowWs(): void {
|
|
2812
3127
|
let p: i32 = this.pos
|
|
2813
3128
|
while (p < this.len) {
|
|
2814
3129
|
const c: i32 = this.at(p)
|
|
@@ -2846,14 +3161,14 @@ class YamlParser {
|
|
|
2846
3161
|
this.pos = p
|
|
2847
3162
|
}
|
|
2848
3163
|
|
|
2849
|
-
/**
|
|
2850
|
-
flowColonEnds(after: i32): boolean {
|
|
3164
|
+
/** Whether a `:` before `after` ends a flow plain scalar. */
|
|
3165
|
+
private flowColonEnds(after: i32): boolean {
|
|
2851
3166
|
const c: i32 = this.at(after)
|
|
2852
3167
|
return c === YAML_LBRACKET || c === YAML_LBRACE || this.flowIndicatorBoundary(after)
|
|
2853
3168
|
}
|
|
2854
3169
|
|
|
2855
|
-
/**
|
|
2856
|
-
flowPlainLineEnd(from: i32, lineStart: i32): i32 {
|
|
3170
|
+
/** Where a flow plain scalar's line from `from` stops. */
|
|
3171
|
+
private flowPlainLineEnd(from: i32, lineStart: i32): i32 {
|
|
2857
3172
|
let i: i32 = from
|
|
2858
3173
|
while (i < this.len) {
|
|
2859
3174
|
const hit: i32 = toI32(indexOfAny(this.text, YAML_PLAIN_FLOW_STOPS, i))
|
|
@@ -2877,8 +3192,8 @@ class YamlParser {
|
|
|
2877
3192
|
return this.len
|
|
2878
3193
|
}
|
|
2879
3194
|
|
|
2880
|
-
/**
|
|
2881
|
-
scanFlowPlain(): i32 {
|
|
3195
|
+
/** Reads a flow-context plain scalar at the cursor, with its continuation lines. */
|
|
3196
|
+
private scanFlowPlain(): i32 {
|
|
2882
3197
|
const start: i32 = this.pos
|
|
2883
3198
|
const i: i32 = this.flowPlainLineEnd(start, start)
|
|
2884
3199
|
let valueEnd: i32 = this.trimEnd(start, i)
|
|
@@ -2924,8 +3239,8 @@ class YamlParser {
|
|
|
2924
3239
|
return this.plainNode(start, valueEnd)
|
|
2925
3240
|
}
|
|
2926
3241
|
|
|
2927
|
-
/**
|
|
2928
|
-
plainNode(start: i32, end: i32): i32 {
|
|
3242
|
+
/** A plain scalar node over `[start, end)`. */
|
|
3243
|
+
private plainNode(start: i32, end: i32): i32 {
|
|
2929
3244
|
const stream: YamlStream = this.stream
|
|
2930
3245
|
const node: i32 = stream.newNode(YAML_SCALAR, YAML_PLAIN, start, end)
|
|
2931
3246
|
yamlPut(stream.firsts, node, start)
|
|
@@ -2933,8 +3248,8 @@ class YamlParser {
|
|
|
2933
3248
|
return node
|
|
2934
3249
|
}
|
|
2935
3250
|
|
|
2936
|
-
/**
|
|
2937
|
-
depthLimitNode(): i32 {
|
|
3251
|
+
/** Reports nesting past `maxDepth`, gives up on the rest of the text, and stands in an empty node. */
|
|
3252
|
+
private depthLimitNode(): i32 {
|
|
2938
3253
|
const at: i32 = this.pos
|
|
2939
3254
|
this.error(YAML_ERR_DEPTH_LIMIT, `Exceeded maximum nesting depth of ${this.maxDepth}`, at, at)
|
|
2940
3255
|
this.pos = this.len
|
|
@@ -2942,8 +3257,8 @@ class YamlParser {
|
|
|
2942
3257
|
return this.emptyScalar(at)
|
|
2943
3258
|
}
|
|
2944
3259
|
|
|
2945
|
-
/**
|
|
2946
|
-
parseFlowNode(): i32 {
|
|
3260
|
+
/** Reads one flow node with its properties. */
|
|
3261
|
+
private parseFlowNode(): i32 {
|
|
2947
3262
|
this.skipFlowWs()
|
|
2948
3263
|
const props: i32 = this.scanProps(true)
|
|
2949
3264
|
this.skipFlowWs()
|
|
@@ -2966,8 +3281,8 @@ class YamlParser {
|
|
|
2966
3281
|
return this.attachProps(node, props)
|
|
2967
3282
|
}
|
|
2968
3283
|
|
|
2969
|
-
/**
|
|
2970
|
-
skipFlowExplicitKey(): boolean {
|
|
3284
|
+
/** Steps over a `?` explicit-key indicator in flow; whether there was one. */
|
|
3285
|
+
private skipFlowExplicitKey(): boolean {
|
|
2971
3286
|
if (!this.isExplicitKey(this.pos)) {
|
|
2972
3287
|
return false
|
|
2973
3288
|
}
|
|
@@ -2976,8 +3291,8 @@ class YamlParser {
|
|
|
2976
3291
|
return true
|
|
2977
3292
|
}
|
|
2978
3293
|
|
|
2979
|
-
/**
|
|
2980
|
-
checkImplicitKeyLine(afterKey: i32): void {
|
|
3294
|
+
/** Reports an implicit key whose `:` is not on the key's line. */
|
|
3295
|
+
private checkImplicitKeyLine(afterKey: i32): void {
|
|
2981
3296
|
if (this.crossesLine(afterKey, this.pos)) {
|
|
2982
3297
|
this.error(
|
|
2983
3298
|
YAML_ERR_BAD_IMPLICIT_KEY,
|
|
@@ -2988,8 +3303,8 @@ class YamlParser {
|
|
|
2988
3303
|
}
|
|
2989
3304
|
}
|
|
2990
3305
|
|
|
2991
|
-
/**
|
|
2992
|
-
reportLongImplicitKey(keyStart: i32, colon: i32): void {
|
|
3306
|
+
/** Reports an implicit key longer than YAML allows. */
|
|
3307
|
+
private reportLongImplicitKey(keyStart: i32, colon: i32): void {
|
|
2993
3308
|
this.error(
|
|
2994
3309
|
YAML_ERR_BAD_IMPLICIT_KEY,
|
|
2995
3310
|
`An implicit key may not run more than ${YAML_MAX_KEY_LENGTH} characters before its ":"`,
|
|
@@ -2998,8 +3313,8 @@ class YamlParser {
|
|
|
2998
3313
|
)
|
|
2999
3314
|
}
|
|
3000
3315
|
|
|
3001
|
-
/**
|
|
3002
|
-
checkKeyGap(colon: i32): void {
|
|
3316
|
+
/** Reports content between a key node and its `:`. */
|
|
3317
|
+
private checkKeyGap(colon: i32): void {
|
|
3003
3318
|
let from: i32 = this.pos
|
|
3004
3319
|
while (yamlIsBlank(this.at(from))) {
|
|
3005
3320
|
from += 1
|
|
@@ -3016,8 +3331,8 @@ class YamlParser {
|
|
|
3016
3331
|
)
|
|
3017
3332
|
}
|
|
3018
3333
|
|
|
3019
|
-
/**
|
|
3020
|
-
reportPropsBeforeExplicitKey(at: i32): void {
|
|
3334
|
+
/** Reports node properties written before a `?` on its line. */
|
|
3335
|
+
private reportPropsBeforeExplicitKey(at: i32): void {
|
|
3021
3336
|
this.error(
|
|
3022
3337
|
YAML_ERR_BAD_PROPERTY,
|
|
3023
3338
|
'Node properties cannot come before a "?" explicit key indicator on its line; write them after the "?", or on a line of their own above',
|
|
@@ -3026,8 +3341,8 @@ class YamlParser {
|
|
|
3026
3341
|
)
|
|
3027
3342
|
}
|
|
3028
3343
|
|
|
3029
|
-
/**
|
|
3030
|
-
skipEmptyFlowEntry(): boolean {
|
|
3344
|
+
/** Steps over a `,` with no entry before it, reporting it; whether there was one. */
|
|
3345
|
+
private skipEmptyFlowEntry(): boolean {
|
|
3031
3346
|
if (this.at(this.pos) !== YAML_COMMA) {
|
|
3032
3347
|
return false
|
|
3033
3348
|
}
|
|
@@ -3036,8 +3351,8 @@ class YamlParser {
|
|
|
3036
3351
|
return true
|
|
3037
3352
|
}
|
|
3038
3353
|
|
|
3039
|
-
/**
|
|
3040
|
-
parseFlowValue(close: i32): i32 {
|
|
3354
|
+
/** Reads the flow value after a `:` in flow, or `-1` when the entry ends first. */
|
|
3355
|
+
private parseFlowValue(close: i32): i32 {
|
|
3041
3356
|
this.pos += 1
|
|
3042
3357
|
this.skipFlowWs()
|
|
3043
3358
|
const c: i32 = this.at(this.pos)
|
|
@@ -3047,8 +3362,8 @@ class YamlParser {
|
|
|
3047
3362
|
return this.parseFlowNode()
|
|
3048
3363
|
}
|
|
3049
3364
|
|
|
3050
|
-
/**
|
|
3051
|
-
flowSeparator(close: i32, start: i32): boolean {
|
|
3365
|
+
/** Reads the separator after a flow entry; whether the collection goes on. */
|
|
3366
|
+
private flowSeparator(close: i32, start: i32): boolean {
|
|
3052
3367
|
const c: i32 = this.at(this.pos)
|
|
3053
3368
|
if (c === YAML_COMMA) {
|
|
3054
3369
|
this.pos += 1
|
|
@@ -3062,8 +3377,8 @@ class YamlParser {
|
|
|
3062
3377
|
return false
|
|
3063
3378
|
}
|
|
3064
3379
|
|
|
3065
|
-
/**
|
|
3066
|
-
reportUnterminatedFlow(close: i32, start: i32): void {
|
|
3380
|
+
/** Reports a flow collection opened at `start` that never closes. */
|
|
3381
|
+
private reportUnterminatedFlow(close: i32, start: i32): void {
|
|
3067
3382
|
if (this.depthHit) {
|
|
3068
3383
|
return
|
|
3069
3384
|
}
|
|
@@ -3077,8 +3392,8 @@ class YamlParser {
|
|
|
3077
3392
|
)
|
|
3078
3393
|
}
|
|
3079
3394
|
|
|
3080
|
-
/**
|
|
3081
|
-
parseFlowSeq(): i32 {
|
|
3395
|
+
/** Reads the flow sequence opening at the cursor. */
|
|
3396
|
+
private parseFlowSeq(): i32 {
|
|
3082
3397
|
if (this.depth >= this.maxDepth) {
|
|
3083
3398
|
return this.depthLimitNode()
|
|
3084
3399
|
}
|
|
@@ -3088,8 +3403,8 @@ class YamlParser {
|
|
|
3088
3403
|
return node
|
|
3089
3404
|
}
|
|
3090
3405
|
|
|
3091
|
-
/**
|
|
3092
|
-
parseFlowSeqBody(): i32 {
|
|
3406
|
+
/** The body of `parseFlowSeq`, inside its depth guard. */
|
|
3407
|
+
private parseFlowSeqBody(): i32 {
|
|
3093
3408
|
const start: i32 = this.pos
|
|
3094
3409
|
const base: i32 = this.scratchTop
|
|
3095
3410
|
this.pos += 1
|
|
@@ -3131,8 +3446,8 @@ class YamlParser {
|
|
|
3131
3446
|
return node
|
|
3132
3447
|
}
|
|
3133
3448
|
|
|
3134
|
-
/**
|
|
3135
|
-
singlePairMap(pair: i32): i32 {
|
|
3449
|
+
/** The flow map of the one pair a `k: v` entry of a flow sequence makes. */
|
|
3450
|
+
private singlePairMap(pair: i32): i32 {
|
|
3136
3451
|
const stream: YamlStream = this.stream
|
|
3137
3452
|
const node: i32 = stream.newNode(YAML_MAP, YAML_FLOW, stream.start(pair), stream.end(pair))
|
|
3138
3453
|
yamlPut(stream.firsts, node, stream.pushKid(pair))
|
|
@@ -3140,8 +3455,8 @@ class YamlParser {
|
|
|
3140
3455
|
return node
|
|
3141
3456
|
}
|
|
3142
3457
|
|
|
3143
|
-
/**
|
|
3144
|
-
parseFlowMap(): i32 {
|
|
3458
|
+
/** Reads the flow mapping opening at the cursor. */
|
|
3459
|
+
private parseFlowMap(): i32 {
|
|
3145
3460
|
if (this.depth >= this.maxDepth) {
|
|
3146
3461
|
return this.depthLimitNode()
|
|
3147
3462
|
}
|
|
@@ -3151,8 +3466,8 @@ class YamlParser {
|
|
|
3151
3466
|
return node
|
|
3152
3467
|
}
|
|
3153
3468
|
|
|
3154
|
-
/**
|
|
3155
|
-
parseFlowMapBody(): i32 {
|
|
3469
|
+
/** The body of `parseFlowMap`, inside its depth guard. */
|
|
3470
|
+
private parseFlowMapBody(): i32 {
|
|
3156
3471
|
const start: i32 = this.pos
|
|
3157
3472
|
const base: i32 = this.scratchTop
|
|
3158
3473
|
let keySet: i32 = -1
|
|
@@ -3193,8 +3508,8 @@ class YamlParser {
|
|
|
3193
3508
|
|
|
3194
3509
|
// ---- Collections and pairs ------------------------------------------------------
|
|
3195
3510
|
|
|
3196
|
-
/**
|
|
3197
|
-
finishCollection(node: i32, base: i32): void {
|
|
3511
|
+
/** Moves the scratch slots from `base` up into `node`'s children. */
|
|
3512
|
+
private finishCollection(node: i32, base: i32): void {
|
|
3198
3513
|
const stream: YamlStream = this.stream
|
|
3199
3514
|
let first: i32 = stream.kidTop
|
|
3200
3515
|
let i: i32 = base
|
|
@@ -3210,8 +3525,8 @@ class YamlParser {
|
|
|
3210
3525
|
this.scratchTop = base
|
|
3211
3526
|
}
|
|
3212
3527
|
|
|
3213
|
-
/**
|
|
3214
|
-
makePair(key: i32, value: i32): i32 {
|
|
3528
|
+
/** A pair node joining `key` to `value`, which is `-1` when the key has none. */
|
|
3529
|
+
private makePair(key: i32, value: i32): i32 {
|
|
3215
3530
|
const stream: YamlStream = this.stream
|
|
3216
3531
|
const end: i32 = value >= 0 ? stream.end(value) : stream.end(key)
|
|
3217
3532
|
const pair: i32 = stream.newNode(YAML_PAIR, YAML_PLAIN, stream.start(key), end)
|
|
@@ -3224,12 +3539,12 @@ class YamlParser {
|
|
|
3224
3539
|
}
|
|
3225
3540
|
|
|
3226
3541
|
/**
|
|
3227
|
-
*
|
|
3542
|
+
* Reports the value of merge key `key` unless it is a map, an alias
|
|
3228
3543
|
* to one or a sequence of those; an empty value is reported on the key, a
|
|
3229
3544
|
* sequence on each item that is not, and an alias to a sequence on the alias.
|
|
3230
3545
|
* An alias with no target is already reported.
|
|
3231
3546
|
*/
|
|
3232
|
-
checkMerge(key: i32, value: i32): void {
|
|
3547
|
+
private checkMerge(key: i32, value: i32): void {
|
|
3233
3548
|
const stream: YamlStream = this.stream
|
|
3234
3549
|
if (value < 0) {
|
|
3235
3550
|
this.badMerge(stream.start(key), stream.end(key))
|
|
@@ -3256,8 +3571,8 @@ class YamlParser {
|
|
|
3256
3571
|
}
|
|
3257
3572
|
}
|
|
3258
3573
|
|
|
3259
|
-
/**
|
|
3260
|
-
mergesMap(n: i32): boolean {
|
|
3574
|
+
/** Whether `n` is a map, an alias to one or an alias with no target, which merges nothing and is reported as such. */
|
|
3575
|
+
private mergesMap(n: i32): boolean {
|
|
3261
3576
|
const stream: YamlStream = this.stream
|
|
3262
3577
|
if (stream.kind(n) === YAML_ALIAS) {
|
|
3263
3578
|
const target: i32 = stream.target(n)
|
|
@@ -3266,8 +3581,8 @@ class YamlParser {
|
|
|
3266
3581
|
return stream.kind(n) === YAML_MAP
|
|
3267
3582
|
}
|
|
3268
3583
|
|
|
3269
|
-
/**
|
|
3270
|
-
badMerge(start: i32, end: i32): void {
|
|
3584
|
+
/** Reports a merge value that names no map over `start` to `end`. */
|
|
3585
|
+
private badMerge(start: i32, end: i32): void {
|
|
3271
3586
|
this.error(
|
|
3272
3587
|
YAML_ERR_BAD_MERGE,
|
|
3273
3588
|
"Merge key value must be a map, an alias to a map or a sequence of those",
|
|
@@ -3276,17 +3591,17 @@ class YamlParser {
|
|
|
3276
3591
|
)
|
|
3277
3592
|
}
|
|
3278
3593
|
|
|
3279
|
-
/**
|
|
3280
|
-
isMergeKey(key: i32): boolean {
|
|
3594
|
+
/** Whether `key` is a `<<` merge key, which the duplicate check skips when merging is on. */
|
|
3595
|
+
private isMergeKey(key: i32): boolean {
|
|
3281
3596
|
return yamlIsMergeKey(this.stream, key)
|
|
3282
3597
|
}
|
|
3283
3598
|
|
|
3284
3599
|
/**
|
|
3285
|
-
*
|
|
3600
|
+
* Whether two keys share a style, a tag and their source bytes,
|
|
3286
3601
|
* which makes them equal without decoding. The tag counts because a key's
|
|
3287
3602
|
* range leaves out its properties: `~` is a null, `!!str ~` the string `"~"`.
|
|
3288
3603
|
*/
|
|
3289
|
-
sameKeyBytes(a: i32, b: i32): boolean {
|
|
3604
|
+
private sameKeyBytes(a: i32, b: i32): boolean {
|
|
3290
3605
|
const stream: YamlStream = this.stream
|
|
3291
3606
|
if (
|
|
3292
3607
|
stream.kind(a) !== YAML_SCALAR ||
|
|
@@ -3300,12 +3615,12 @@ class YamlParser {
|
|
|
3300
3615
|
}
|
|
3301
3616
|
|
|
3302
3617
|
/**
|
|
3303
|
-
*
|
|
3618
|
+
* Reports `key` when an earlier pair of the map whose pairs start
|
|
3304
3619
|
* at scratch slot `base` has an equal key. Up to YAML_PAIRWISE_KEYS pairs the
|
|
3305
3620
|
* keys are compared pairwise, by bytes first; past that the map takes a hash
|
|
3306
3621
|
* set from the pool, whose index it returns (`set` is the one it holds, or `-1`).
|
|
3307
3622
|
*/
|
|
3308
|
-
trackKey(base: i32, key: i32, set: i32): i32 {
|
|
3623
|
+
private trackKey(base: i32, key: i32, set: i32): i32 {
|
|
3309
3624
|
if (!this.uniqueKeys || this.isMergeKey(key)) {
|
|
3310
3625
|
return set
|
|
3311
3626
|
}
|
|
@@ -3354,16 +3669,16 @@ class YamlParser {
|
|
|
3354
3669
|
return held
|
|
3355
3670
|
}
|
|
3356
3671
|
|
|
3357
|
-
/**
|
|
3358
|
-
releaseKeySet(set: i32): void {
|
|
3672
|
+
/** Hands the key set a finished map held back to the pool. */
|
|
3673
|
+
private releaseKeySet(set: i32): void {
|
|
3359
3674
|
if (set >= 0) {
|
|
3360
3675
|
this.keySets[set].clear()
|
|
3361
3676
|
this.keySetTop = set
|
|
3362
3677
|
}
|
|
3363
3678
|
}
|
|
3364
3679
|
|
|
3365
|
-
/**
|
|
3366
|
-
reportDuplicateKey(key: i32): void {
|
|
3680
|
+
/** Reports `key` as a repeat of an earlier key in its map. */
|
|
3681
|
+
private reportDuplicateKey(key: i32): void {
|
|
3367
3682
|
const stream: YamlStream = this.stream
|
|
3368
3683
|
this.error(
|
|
3369
3684
|
YAML_ERR_DUPLICATE_KEY,
|
|
@@ -3375,8 +3690,8 @@ class YamlParser {
|
|
|
3375
3690
|
|
|
3376
3691
|
// ---- Documents --------------------------------------------------------------------
|
|
3377
3692
|
|
|
3378
|
-
/**
|
|
3379
|
-
docMarkerInlineNode(marker: i32): i32 {
|
|
3693
|
+
/** The start of a node written on the `---` line at `marker`, or `-1` when the line ends first. */
|
|
3694
|
+
private docMarkerInlineNode(marker: i32): i32 {
|
|
3380
3695
|
let i: i32 = marker + 3
|
|
3381
3696
|
while (yamlIsBlank(this.at(i))) {
|
|
3382
3697
|
i += 1
|
|
@@ -3393,14 +3708,14 @@ class YamlParser {
|
|
|
3393
3708
|
return i
|
|
3394
3709
|
}
|
|
3395
3710
|
|
|
3396
|
-
/**
|
|
3397
|
-
opensBlockMapping(from: i32): boolean {
|
|
3711
|
+
/** Whether the content at `from` opens a block mapping: a `?` key, or an implicit key's `:`. */
|
|
3712
|
+
private opensBlockMapping(from: i32): boolean {
|
|
3398
3713
|
const p: i32 = this.skipPropsAhead(from)
|
|
3399
3714
|
return this.isExplicitKey(p) || this.findKeyColon(p) >= 0
|
|
3400
3715
|
}
|
|
3401
3716
|
|
|
3402
|
-
/**
|
|
3403
|
-
checkDocEndTail(marker: i32): void {
|
|
3717
|
+
/** Reports content after the `...` marker at `marker` on its line. */
|
|
3718
|
+
private checkDocEndTail(marker: i32): void {
|
|
3404
3719
|
if (this.lineRestIsBlank(marker + 3)) {
|
|
3405
3720
|
return
|
|
3406
3721
|
}
|
|
@@ -3416,8 +3731,8 @@ class YamlParser {
|
|
|
3416
3731
|
)
|
|
3417
3732
|
}
|
|
3418
3733
|
|
|
3419
|
-
/**
|
|
3420
|
-
onlyEmptyDocumentsFollow(from: i32): boolean {
|
|
3734
|
+
/** Whether every line from `from` is blank, a comment, or a bare document marker. */
|
|
3735
|
+
private onlyEmptyDocumentsFollow(from: i32): boolean {
|
|
3421
3736
|
let i: i32 = from
|
|
3422
3737
|
while (i < this.len) {
|
|
3423
3738
|
if (!this.lineRestIsBlank(i)) {
|
|
@@ -3430,8 +3745,8 @@ class YamlParser {
|
|
|
3430
3745
|
return true
|
|
3431
3746
|
}
|
|
3432
3747
|
|
|
3433
|
-
/**
|
|
3434
|
-
parseDocMarkerNode(contentPos: i32): i32 {
|
|
3748
|
+
/** Reads the document that starts at the `---` line's content at `contentPos`. */
|
|
3749
|
+
private parseDocMarkerNode(contentPos: i32): i32 {
|
|
3435
3750
|
const seq: boolean = this.isSeqEntryDash(contentPos)
|
|
3436
3751
|
if (seq || this.opensBlockMapping(contentPos)) {
|
|
3437
3752
|
this.error(
|
|
@@ -3447,8 +3762,8 @@ class YamlParser {
|
|
|
3447
3762
|
return this.parseNode(toI32(0), YAML_NONE, true)
|
|
3448
3763
|
}
|
|
3449
3764
|
|
|
3450
|
-
/**
|
|
3451
|
-
parseBareRoot(contentPos: i32, indent: i32): i32 {
|
|
3765
|
+
/** Reads a document's root from the line `peekLine` found, whose content is at `contentPos`. */
|
|
3766
|
+
private parseBareRoot(contentPos: i32, indent: i32): i32 {
|
|
3452
3767
|
if (indent !== 0) {
|
|
3453
3768
|
this.checkRootTabIndent(contentPos)
|
|
3454
3769
|
}
|
|
@@ -3456,8 +3771,8 @@ class YamlParser {
|
|
|
3456
3771
|
return this.parseNode(indent, YAML_NONE, true)
|
|
3457
3772
|
}
|
|
3458
3773
|
|
|
3459
|
-
/**
|
|
3460
|
-
checkRootTabIndent(contentPos: i32): void {
|
|
3774
|
+
/** Reports a tab in the indentation of a root collection's first line, which starts at the cursor. */
|
|
3775
|
+
private checkRootTabIndent(contentPos: i32): void {
|
|
3461
3776
|
const lineStart: i32 = this.pos
|
|
3462
3777
|
let tab: i32 = lineStart
|
|
3463
3778
|
while (tab < contentPos && this.at(tab) !== YAML_TAB) {
|
|
@@ -3472,13 +3787,13 @@ class YamlParser {
|
|
|
3472
3787
|
}
|
|
3473
3788
|
}
|
|
3474
3789
|
|
|
3475
|
-
/**
|
|
3476
|
-
atMarkerLine(): boolean {
|
|
3790
|
+
/** Whether the line `peekLine` found is a `---` or `...` marker. */
|
|
3791
|
+
private atMarkerLine(): boolean {
|
|
3477
3792
|
return !this.lineEof && this.lineIndent === 0 && this.isDocMarker(this.lineContent)
|
|
3478
3793
|
}
|
|
3479
3794
|
|
|
3480
|
-
/**
|
|
3481
|
-
checkTaggedNode(node: i32, slot: i32): void {
|
|
3795
|
+
/** Warns when the core-schema tag of the properties in `slot` does not fit `node`. */
|
|
3796
|
+
private checkTaggedNode(node: i32, slot: i32): void {
|
|
3482
3797
|
const stream: YamlStream = this.stream
|
|
3483
3798
|
const tag: string = stream.tag(node)
|
|
3484
3799
|
let want: i32 = 0
|
|
@@ -3522,10 +3837,10 @@ class YamlParser {
|
|
|
3522
3837
|
}
|
|
3523
3838
|
|
|
3524
3839
|
/**
|
|
3525
|
-
*
|
|
3840
|
+
* Checks what follows the first document's node, and answers the
|
|
3526
3841
|
* end of its `...` footer when one closes it, or `-1`.
|
|
3527
3842
|
*/
|
|
3528
|
-
checkDocumentEnd(): i32 {
|
|
3843
|
+
private checkDocumentEnd(): i32 {
|
|
3529
3844
|
if (this.pos >= this.len) {
|
|
3530
3845
|
return -1
|
|
3531
3846
|
}
|
|
@@ -3547,11 +3862,11 @@ class YamlParser {
|
|
|
3547
3862
|
}
|
|
3548
3863
|
|
|
3549
3864
|
/**
|
|
3550
|
-
*
|
|
3865
|
+
* Warns that the documents after the marker at `marker` were not
|
|
3551
3866
|
* read, unless none of them holds anything. Answers the end of a `...`
|
|
3552
3867
|
* marker, which is the first document's footer, or `-1`.
|
|
3553
3868
|
*/
|
|
3554
|
-
warnIfMoreDocuments(marker: i32): i32 {
|
|
3869
|
+
private warnIfMoreDocuments(marker: i32): i32 {
|
|
3555
3870
|
this.recordLineComment(marker + 3)
|
|
3556
3871
|
const footer: boolean = this.at(marker) === YAML_DOT
|
|
3557
3872
|
let hidden: boolean = false
|
|
@@ -3578,11 +3893,11 @@ class YamlParser {
|
|
|
3578
3893
|
}
|
|
3579
3894
|
|
|
3580
3895
|
/**
|
|
3581
|
-
*
|
|
3896
|
+
* Reads the directives and markers before a document's body, and
|
|
3582
3897
|
* answers which of `YAML_SAW_*` it met. `closed` says the document before
|
|
3583
3898
|
* ended with `...` (or there is none), so a directive may follow.
|
|
3584
3899
|
*/
|
|
3585
|
-
skipStreamHead(closed: boolean): i32 {
|
|
3900
|
+
private skipStreamHead(closed: boolean): i32 {
|
|
3586
3901
|
let seen: i32 = 0
|
|
3587
3902
|
let sawDirective: boolean = false
|
|
3588
3903
|
while (true) {
|
|
@@ -3632,8 +3947,8 @@ class YamlParser {
|
|
|
3632
3947
|
return seen
|
|
3633
3948
|
}
|
|
3634
3949
|
|
|
3635
|
-
/**
|
|
3636
|
-
skipBom(): void {
|
|
3950
|
+
/** Steps past a UTF-8 byte order mark. */
|
|
3951
|
+
private skipBom(): void {
|
|
3637
3952
|
if (
|
|
3638
3953
|
yamlByte(this.text, 0) === 0xef &&
|
|
3639
3954
|
yamlByte(this.text, 1) === 0xbb &&
|
|
@@ -3643,7 +3958,10 @@ class YamlParser {
|
|
|
3643
3958
|
}
|
|
3644
3959
|
}
|
|
3645
3960
|
|
|
3646
|
-
/**
|
|
3961
|
+
/**
|
|
3962
|
+
* Reads the first document only.
|
|
3963
|
+
* @internal Called by `parseYamlWith`.
|
|
3964
|
+
*/
|
|
3647
3965
|
parseFirst(): void {
|
|
3648
3966
|
this.skipBom()
|
|
3649
3967
|
const markers: i32 = this.skipStreamHead(true)
|
|
@@ -3660,7 +3978,10 @@ class YamlParser {
|
|
|
3660
3978
|
this.pushDocument(root, footerEnd)
|
|
3661
3979
|
}
|
|
3662
3980
|
|
|
3663
|
-
/**
|
|
3981
|
+
/**
|
|
3982
|
+
* Reads every document of the stream.
|
|
3983
|
+
* @internal Called by `parseYamlWith`.
|
|
3984
|
+
*/
|
|
3664
3985
|
parseAll(): void {
|
|
3665
3986
|
this.skipBom()
|
|
3666
3987
|
let closed: boolean = true
|
|
@@ -3730,8 +4051,8 @@ class YamlParser {
|
|
|
3730
4051
|
}
|
|
3731
4052
|
}
|
|
3732
4053
|
|
|
3733
|
-
/**
|
|
3734
|
-
pushDocument(root: i32, footerEnd: i32): void {
|
|
4054
|
+
/** Records a document whose root is `root` (or `-1`), closed by a `...` ending at `footerEnd` (or `-1`). */
|
|
4055
|
+
private pushDocument(root: i32, footerEnd: i32): void {
|
|
3735
4056
|
const stream: YamlStream = this.stream
|
|
3736
4057
|
let start: i32 = root >= 0 ? stream.start(root) : this.pos
|
|
3737
4058
|
if (this.markerAt >= 0) {
|
|
@@ -3758,10 +4079,10 @@ class YamlParser {
|
|
|
3758
4079
|
// ---- Block collections ----------------------------------------------------------
|
|
3759
4080
|
|
|
3760
4081
|
/**
|
|
3761
|
-
*
|
|
4082
|
+
* The value of properties written alone at the end of their line,
|
|
3762
4083
|
* whose slot is `props`: the node on the lines below, or an empty scalar.
|
|
3763
4084
|
*/
|
|
3764
|
-
parsePropsOnlyValue(props: i32, parentIndent: i32, seqAtParentIndent: boolean): i32 {
|
|
4085
|
+
private parsePropsOnlyValue(props: i32, parentIndent: i32, seqAtParentIndent: boolean): i32 {
|
|
3765
4086
|
const propsEnd: i32 = this.pos
|
|
3766
4087
|
this.finishLine()
|
|
3767
4088
|
this.peekLine(parentIndent + 1)
|
|
@@ -3781,8 +4102,8 @@ class YamlParser {
|
|
|
3781
4102
|
return this.attachProps(this.emptyScalar(propsEnd), props)
|
|
3782
4103
|
}
|
|
3783
4104
|
|
|
3784
|
-
/**
|
|
3785
|
-
parseInlineValue(parentIndent: i32): i32 {
|
|
4105
|
+
/** The value written on a key's line after its `:`, or `-1` when there is none. */
|
|
4106
|
+
private parseInlineValue(parentIndent: i32): i32 {
|
|
3786
4107
|
const props: i32 = this.scanProps(false)
|
|
3787
4108
|
this.skipInlineSpaces()
|
|
3788
4109
|
if (this.atLineEnd()) {
|
|
@@ -3811,8 +4132,8 @@ class YamlParser {
|
|
|
3811
4132
|
return this.attachProps(node, props)
|
|
3812
4133
|
}
|
|
3813
4134
|
|
|
3814
|
-
/**
|
|
3815
|
-
columnOf(at: i32): i32 {
|
|
4135
|
+
/** The column of `at`: its distance from the start of its line. */
|
|
4136
|
+
private columnOf(at: i32): i32 {
|
|
3816
4137
|
let i: i32 = at
|
|
3817
4138
|
while (i > 0 && !yamlIsBreak(this.at(i - 1))) {
|
|
3818
4139
|
i -= 1
|
|
@@ -3821,10 +4142,10 @@ class YamlParser {
|
|
|
3821
4142
|
}
|
|
3822
4143
|
|
|
3823
4144
|
/**
|
|
3824
|
-
*
|
|
4145
|
+
* A block collection written on an indicator's line (`- - a`,
|
|
3825
4146
|
* `- k: v`, `? - a`), or `-1` when the cursor holds no such collection.
|
|
3826
4147
|
*/
|
|
3827
|
-
parseCompactCollection(): i32 {
|
|
4148
|
+
private parseCompactCollection(): i32 {
|
|
3828
4149
|
const at: i32 = this.pos
|
|
3829
4150
|
const seq: boolean = this.isSeqEntryDash(at)
|
|
3830
4151
|
const keyAt: i32 = seq ? at : this.skipPropsAhead(at)
|
|
@@ -3856,11 +4177,11 @@ class YamlParser {
|
|
|
3856
4177
|
}
|
|
3857
4178
|
|
|
3858
4179
|
/**
|
|
3859
|
-
*
|
|
4180
|
+
* The value after an indicator of a block collection at `indent`:
|
|
3860
4181
|
* on the same line, or on the lines below. `compact` lets a collection
|
|
3861
4182
|
* start on the indicator's line. `-1` when there is none.
|
|
3862
4183
|
*/
|
|
3863
|
-
parseValueOrChild(indent: i32, compact: boolean): i32 {
|
|
4184
|
+
private parseValueOrChild(indent: i32, compact: boolean): i32 {
|
|
3864
4185
|
if (compact) {
|
|
3865
4186
|
this.skipIndicatorSeparation()
|
|
3866
4187
|
} else {
|
|
@@ -3891,12 +4212,12 @@ class YamlParser {
|
|
|
3891
4212
|
}
|
|
3892
4213
|
|
|
3893
4214
|
/**
|
|
3894
|
-
*
|
|
4215
|
+
* Reads a block mapping at `indent`. Its first entry is already
|
|
3895
4216
|
* found: an implicit key whose `:` is at `firstColon`, with the properties in
|
|
3896
4217
|
* `firstProps`; or the node `firstKey`, read up to its `:`; or, with both
|
|
3897
4218
|
* `-1`, an explicit `?` key at the cursor.
|
|
3898
4219
|
*/
|
|
3899
|
-
parseBlockMap(indent: i32, firstColon: i32, firstKey: i32, firstProps: i32): i32 {
|
|
4220
|
+
private parseBlockMap(indent: i32, firstColon: i32, firstKey: i32, firstProps: i32): i32 {
|
|
3900
4221
|
if (this.depth >= this.maxDepth) {
|
|
3901
4222
|
return this.depthLimitNode()
|
|
3902
4223
|
}
|
|
@@ -3906,8 +4227,8 @@ class YamlParser {
|
|
|
3906
4227
|
return node
|
|
3907
4228
|
}
|
|
3908
4229
|
|
|
3909
|
-
/**
|
|
3910
|
-
parseBlockMapBody(indent: i32, firstColon: i32, firstKey: i32, firstProps: i32): i32 {
|
|
4230
|
+
/** The body of `parseBlockMap`, inside its depth guard. */
|
|
4231
|
+
private parseBlockMapBody(indent: i32, firstColon: i32, firstKey: i32, firstProps: i32): i32 {
|
|
3911
4232
|
const stream: YamlStream = this.stream
|
|
3912
4233
|
const base: i32 = this.scratchTop
|
|
3913
4234
|
let keySet: i32 = -1
|
|
@@ -3995,8 +4316,8 @@ class YamlParser {
|
|
|
3995
4316
|
return node
|
|
3996
4317
|
}
|
|
3997
4318
|
|
|
3998
|
-
/**
|
|
3999
|
-
parseImplicitKey(indent: i32, from: i32, colon: i32): i32 {
|
|
4319
|
+
/** Reads the implicit key at `from` of a block mapping at `indent`, whose `:` is at `colon`. */
|
|
4320
|
+
private parseImplicitKey(indent: i32, from: i32, colon: i32): i32 {
|
|
4000
4321
|
if (colon - from > YAML_MAX_KEY_LENGTH) {
|
|
4001
4322
|
this.reportLongImplicitKey(from, colon)
|
|
4002
4323
|
}
|
|
@@ -4031,8 +4352,8 @@ class YamlParser {
|
|
|
4031
4352
|
return key
|
|
4032
4353
|
}
|
|
4033
4354
|
|
|
4034
|
-
/**
|
|
4035
|
-
parseBlockSeq(indent: i32): i32 {
|
|
4355
|
+
/** Reads a block sequence at `indent`, whose first `-` is at the cursor. */
|
|
4356
|
+
private parseBlockSeq(indent: i32): i32 {
|
|
4036
4357
|
if (this.depth >= this.maxDepth) {
|
|
4037
4358
|
return this.depthLimitNode()
|
|
4038
4359
|
}
|
|
@@ -4042,8 +4363,8 @@ class YamlParser {
|
|
|
4042
4363
|
return node
|
|
4043
4364
|
}
|
|
4044
4365
|
|
|
4045
|
-
/**
|
|
4046
|
-
parseBlockSeqBody(indent: i32): i32 {
|
|
4366
|
+
/** The body of `parseBlockSeq`, inside its depth guard. */
|
|
4367
|
+
private parseBlockSeqBody(indent: i32): i32 {
|
|
4047
4368
|
const stream: YamlStream = this.stream
|
|
4048
4369
|
const base: i32 = this.scratchTop
|
|
4049
4370
|
let start: i32 = -1
|
|
@@ -4098,11 +4419,11 @@ class YamlParser {
|
|
|
4098
4419
|
}
|
|
4099
4420
|
|
|
4100
4421
|
/**
|
|
4101
|
-
*
|
|
4422
|
+
* Reads the block node at the cursor, at `indent`, whose parent
|
|
4102
4423
|
* is at `parentIndent`. `seqAtParentIndent` lets a sequence at the parent's
|
|
4103
4424
|
* own indent be the value of lone properties.
|
|
4104
4425
|
*/
|
|
4105
|
-
parseNode(indent: i32, parentIndent: i32, seqAtParentIndent: boolean): i32 {
|
|
4426
|
+
private parseNode(indent: i32, parentIndent: i32, seqAtParentIndent: boolean): i32 {
|
|
4106
4427
|
if (this.isSeqEntryDash(this.pos)) {
|
|
4107
4428
|
return this.parseBlockSeq(indent)
|
|
4108
4429
|
}
|
|
@@ -4197,10 +4518,10 @@ const yamlKeyHash = (text: string): i32 => {
|
|
|
4197
4518
|
* slots, so a set handed back to the pool clears only those.
|
|
4198
4519
|
*/
|
|
4199
4520
|
class YamlKeySet {
|
|
4200
|
-
texts: string[]
|
|
4201
|
-
used: boolean[]
|
|
4202
|
-
filled: i32[]
|
|
4203
|
-
mask: i32 = 0
|
|
4521
|
+
private texts: string[]
|
|
4522
|
+
private used: boolean[]
|
|
4523
|
+
private filled: i32[]
|
|
4524
|
+
private mask: i32 = 0
|
|
4204
4525
|
|
|
4205
4526
|
constructor() {
|
|
4206
4527
|
this.texts = []
|
|
@@ -4209,7 +4530,10 @@ class YamlKeySet {
|
|
|
4209
4530
|
this.resize(YAML_KEY_SET_SLOTS)
|
|
4210
4531
|
}
|
|
4211
4532
|
|
|
4212
|
-
/**
|
|
4533
|
+
/**
|
|
4534
|
+
* Adds `text`; false when it was already there.
|
|
4535
|
+
* @internal Called by `YamlParser`.
|
|
4536
|
+
*/
|
|
4213
4537
|
add(text: string): boolean {
|
|
4214
4538
|
if ((toI32(this.filled.length) + 1) * 2 > this.mask + 1) {
|
|
4215
4539
|
this.grow()
|
|
@@ -4229,7 +4553,10 @@ class YamlKeySet {
|
|
|
4229
4553
|
return true
|
|
4230
4554
|
}
|
|
4231
4555
|
|
|
4232
|
-
/**
|
|
4556
|
+
/**
|
|
4557
|
+
* Empties the set, keeping its table.
|
|
4558
|
+
* @internal Called by `YamlParser`.
|
|
4559
|
+
*/
|
|
4233
4560
|
clear(): void {
|
|
4234
4561
|
let i: i32 = 0
|
|
4235
4562
|
while (i < toI32(this.filled.length)) {
|
|
@@ -4243,8 +4570,8 @@ class YamlKeySet {
|
|
|
4243
4570
|
this.filled = []
|
|
4244
4571
|
}
|
|
4245
4572
|
|
|
4246
|
-
/**
|
|
4247
|
-
grow(): void {
|
|
4573
|
+
/** Doubles the table and puts every key back. */
|
|
4574
|
+
private grow(): void {
|
|
4248
4575
|
const texts: string[] = []
|
|
4249
4576
|
let i: i32 = 0
|
|
4250
4577
|
while (i < toI32(this.filled.length)) {
|
|
@@ -4260,8 +4587,8 @@ class YamlKeySet {
|
|
|
4260
4587
|
}
|
|
4261
4588
|
}
|
|
4262
4589
|
|
|
4263
|
-
/**
|
|
4264
|
-
resize(slots: i32): void {
|
|
4590
|
+
/** An empty table of `slots` slots. */
|
|
4591
|
+
private resize(slots: i32): void {
|
|
4265
4592
|
this.texts = []
|
|
4266
4593
|
this.used = []
|
|
4267
4594
|
this.filled = []
|
|
@@ -4305,10 +4632,11 @@ const YAML_ALIAS_HOPS: i32 = 100
|
|
|
4305
4632
|
|
|
4306
4633
|
/** Writes a collection key as one line of flow text, within `YAML_KEY_TEXT_BUDGET` bytes. */
|
|
4307
4634
|
class YamlFlowWriter {
|
|
4308
|
-
stream: YamlStream
|
|
4635
|
+
private stream: YamlStream
|
|
4636
|
+
/** @internal Used by `yamlKeyText`. */
|
|
4309
4637
|
out: string
|
|
4310
|
-
left: i32 = 0
|
|
4311
|
-
cut: boolean = false
|
|
4638
|
+
private left: i32 = 0
|
|
4639
|
+
private cut: boolean = false
|
|
4312
4640
|
|
|
4313
4641
|
constructor(stream: YamlStream) {
|
|
4314
4642
|
this.stream = stream
|
|
@@ -4316,8 +4644,8 @@ class YamlFlowWriter {
|
|
|
4316
4644
|
this.left = YAML_KEY_TEXT_BUDGET
|
|
4317
4645
|
}
|
|
4318
4646
|
|
|
4319
|
-
/**
|
|
4320
|
-
append(s: string): void {
|
|
4647
|
+
/** Appends `s`, or as much of it as the budget allows and then `…`. */
|
|
4648
|
+
private append(s: string): void {
|
|
4321
4649
|
if (this.cut) {
|
|
4322
4650
|
return
|
|
4323
4651
|
}
|
|
@@ -4336,7 +4664,10 @@ class YamlFlowWriter {
|
|
|
4336
4664
|
this.left -= length
|
|
4337
4665
|
}
|
|
4338
4666
|
|
|
4339
|
-
/**
|
|
4667
|
+
/**
|
|
4668
|
+
* Appends node `n` (`-1` for a missing value), nested `depth` deep.
|
|
4669
|
+
* @internal Called by `yamlKeyText`.
|
|
4670
|
+
*/
|
|
4340
4671
|
write(n: i32, depth: i32): void {
|
|
4341
4672
|
const stream: YamlStream = this.stream
|
|
4342
4673
|
if (depth > YAML_KEY_TEXT_DEPTH) {
|
|
@@ -4401,27 +4732,45 @@ const yamlKeyText = (stream: YamlStream, node: i32): string => {
|
|
|
4401
4732
|
return writer.out
|
|
4402
4733
|
}
|
|
4403
4734
|
|
|
4404
|
-
/**
|
|
4735
|
+
/**
|
|
4736
|
+
* The text a map key is matched by in a path and named by in a diagnostic.
|
|
4737
|
+
*
|
|
4738
|
+
* @param stream The parsed stream.
|
|
4739
|
+
* @param node The key node.
|
|
4740
|
+
* @returns A scalar's decoded text (its source text for a number or a boolean, `""` for a null), an
|
|
4741
|
+
* alias's target's text (`*name` when it names no anchor), or a collection written as one line of
|
|
4742
|
+
* flow text, `{ a: 1 }` or `[ a, b ]`, cut to `…` past 4096 bytes at a character's start or
|
|
4743
|
+
* past nesting depth 64.
|
|
4744
|
+
*/
|
|
4405
4745
|
export const keyText = (stream: YamlStream, node: i32): string => yamlKeyText(stream, node)
|
|
4406
4746
|
|
|
4407
4747
|
// ---- Paths ----------------------------------------------------------------------
|
|
4408
4748
|
|
|
4409
4749
|
/** Walks a path of map keys and sequence indexes down from a node. */
|
|
4410
4750
|
class YamlPathWalker {
|
|
4411
|
-
stream: YamlStream
|
|
4412
|
-
/**
|
|
4751
|
+
private stream: YamlStream
|
|
4752
|
+
/**
|
|
4753
|
+
* The deepest node reached.
|
|
4754
|
+
* @internal Used by `pathNode`.
|
|
4755
|
+
*/
|
|
4413
4756
|
node: i32 = -1
|
|
4414
|
-
/**
|
|
4757
|
+
/**
|
|
4758
|
+
* The last pair stepped through, or `-1`.
|
|
4759
|
+
* @internal Used by `pathPair`.
|
|
4760
|
+
*/
|
|
4415
4761
|
pair: i32 = -1
|
|
4416
|
-
/**
|
|
4762
|
+
/**
|
|
4763
|
+
* How many steps matched.
|
|
4764
|
+
* @internal Used by `pathMatch`.
|
|
4765
|
+
*/
|
|
4417
4766
|
matched: i32 = 0
|
|
4418
4767
|
|
|
4419
4768
|
constructor(stream: YamlStream) {
|
|
4420
4769
|
this.stream = stream
|
|
4421
4770
|
}
|
|
4422
4771
|
|
|
4423
|
-
/**
|
|
4424
|
-
follow(n: i32): i32 {
|
|
4772
|
+
/** Node `n` with its aliases followed, up to `YAML_ALIAS_HOPS` of them; `-1` past that. */
|
|
4773
|
+
private follow(n: i32): i32 {
|
|
4425
4774
|
const stream: YamlStream = this.stream
|
|
4426
4775
|
let at: i32 = n
|
|
4427
4776
|
let hops: i32 = 0
|
|
@@ -4436,11 +4785,11 @@ class YamlPathWalker {
|
|
|
4436
4785
|
}
|
|
4437
4786
|
|
|
4438
4787
|
/**
|
|
4439
|
-
*
|
|
4788
|
+
* Whether map key `key` is matched by `step`. A one-line plain key
|
|
4440
4789
|
* that is not a null is its own source text, so it is compared in place;
|
|
4441
4790
|
* every other key goes through `yamlKeyText`.
|
|
4442
4791
|
*/
|
|
4443
|
-
keyIs(key: i32, step: string): boolean {
|
|
4792
|
+
private keyIs(key: i32, step: string): boolean {
|
|
4444
4793
|
const stream: YamlStream = this.stream
|
|
4445
4794
|
const start: i32 = stream.start(key)
|
|
4446
4795
|
const end: i32 = stream.end(key)
|
|
@@ -4456,8 +4805,8 @@ class YamlPathWalker {
|
|
|
4456
4805
|
return yamlKeyText(stream, key) === step
|
|
4457
4806
|
}
|
|
4458
4807
|
|
|
4459
|
-
/**
|
|
4460
|
-
indexOf(step: string): i32 {
|
|
4808
|
+
/** The index `step` writes, or `-1` when it is not 1 to 9 decimal digits without a leading zero. */
|
|
4809
|
+
private indexOf(step: string): i32 {
|
|
4461
4810
|
const length: i32 = toI32(step.length)
|
|
4462
4811
|
if (length === 0 || length > 9 || (length > 1 && toI32(step.charCodeAt(0)) === 48)) {
|
|
4463
4812
|
return -1
|
|
@@ -4475,8 +4824,8 @@ class YamlPathWalker {
|
|
|
4475
4824
|
return index
|
|
4476
4825
|
}
|
|
4477
4826
|
|
|
4478
|
-
/**
|
|
4479
|
-
ownPair(map: i32, step: string): i32 {
|
|
4827
|
+
/** The last pair of map `map` whose key `step` matches, as when a duplicate is let through; `-1` for none. */
|
|
4828
|
+
private ownPair(map: i32, step: string): i32 {
|
|
4480
4829
|
const stream: YamlStream = this.stream
|
|
4481
4830
|
let i: i32 = stream.count(map) - 1
|
|
4482
4831
|
while (i >= 0) {
|
|
@@ -4490,7 +4839,7 @@ class YamlPathWalker {
|
|
|
4490
4839
|
}
|
|
4491
4840
|
|
|
4492
4841
|
/**
|
|
4493
|
-
*
|
|
4842
|
+
* The pair `step` matches in the maps the merge keys of map `map`
|
|
4494
4843
|
* name, in the order they are written, each searched as `ownPair` and then
|
|
4495
4844
|
* through its own merge keys, so the first map listed wins. A merge key's
|
|
4496
4845
|
* value is a map, an alias to one or a sequence of those; anything else
|
|
@@ -4500,7 +4849,7 @@ class YamlPathWalker {
|
|
|
4500
4849
|
* once its node ends, so both guards are defensive: they bound the work, not
|
|
4501
4850
|
* a loop.
|
|
4502
4851
|
*/
|
|
4503
|
-
mergedPair(map: i32, step: string, depth: i32): i32 {
|
|
4852
|
+
private mergedPair(map: i32, step: string, depth: i32): i32 {
|
|
4504
4853
|
const stream: YamlStream = this.stream
|
|
4505
4854
|
const count: i32 = stream.count(map)
|
|
4506
4855
|
let i: i32 = 0
|
|
@@ -4530,8 +4879,8 @@ class YamlPathWalker {
|
|
|
4530
4879
|
return -1
|
|
4531
4880
|
}
|
|
4532
4881
|
|
|
4533
|
-
/**
|
|
4534
|
-
mergedFrom(from: i32, step: string, depth: i32): i32 {
|
|
4882
|
+
/** `mergedPair`'s search of one merged node `from`, which merges nothing unless it is a map not yet searched. */
|
|
4883
|
+
private mergedFrom(from: i32, step: string, depth: i32): i32 {
|
|
4535
4884
|
const stream: YamlStream = this.stream
|
|
4536
4885
|
if (from < 0 || stream.kind(from) !== YAML_MAP) {
|
|
4537
4886
|
return -1
|
|
@@ -4544,11 +4893,11 @@ class YamlPathWalker {
|
|
|
4544
4893
|
}
|
|
4545
4894
|
|
|
4546
4895
|
/**
|
|
4547
|
-
*
|
|
4896
|
+
* Starts a step's merge search: a new `mergeStep` stamp, with
|
|
4548
4897
|
* `mergeStamps` grown to every node. The stamps are cleared only when the
|
|
4549
4898
|
* count wraps, so a step costs what it searches, not the document's size.
|
|
4550
4899
|
*/
|
|
4551
|
-
startMerge(): void {
|
|
4900
|
+
private startMerge(): void {
|
|
4552
4901
|
const stream: YamlStream = this.stream
|
|
4553
4902
|
const stamps: i32[] = stream.mergeStamps
|
|
4554
4903
|
while (toI32(stamps.length) < stream.top) {
|
|
@@ -4565,8 +4914,8 @@ class YamlPathWalker {
|
|
|
4565
4914
|
stream.mergeStep += 1
|
|
4566
4915
|
}
|
|
4567
4916
|
|
|
4568
|
-
/**
|
|
4569
|
-
markSeen(map: i32): boolean {
|
|
4917
|
+
/** Marks map `map` searched by this step; `false` when it already was. */
|
|
4918
|
+
private markSeen(map: i32): boolean {
|
|
4570
4919
|
const stream: YamlStream = this.stream
|
|
4571
4920
|
const stamps: i32[] = stream.mergeStamps
|
|
4572
4921
|
if (map < 0 || map >= toI32(stamps.length) || stamps[map] === stream.mergeStep) {
|
|
@@ -4576,7 +4925,10 @@ class YamlPathWalker {
|
|
|
4576
4925
|
return true
|
|
4577
4926
|
}
|
|
4578
4927
|
|
|
4579
|
-
/**
|
|
4928
|
+
/**
|
|
4929
|
+
* Walks `path` down from `root`, as far as it matches.
|
|
4930
|
+
* @internal Called by `pathNode`, `pathPair` and `pathMatch`.
|
|
4931
|
+
*/
|
|
4580
4932
|
walk(root: i32, path: string[]): void {
|
|
4581
4933
|
const stream: YamlStream = this.stream
|
|
4582
4934
|
this.node = root
|
|
@@ -4622,14 +4974,19 @@ class YamlPathWalker {
|
|
|
4622
4974
|
}
|
|
4623
4975
|
|
|
4624
4976
|
/**
|
|
4625
|
-
* The node
|
|
4626
|
-
*
|
|
4627
|
-
*
|
|
4628
|
-
*
|
|
4629
|
-
*
|
|
4630
|
-
*
|
|
4631
|
-
*
|
|
4632
|
-
*
|
|
4977
|
+
* The node a path names. Each step is a map key (matched by `keyText`; of
|
|
4978
|
+
* duplicate keys, the last) or a sequence index (`"0"`, no leading zero),
|
|
4979
|
+
* through aliases. While the stream merges (`YamlOptions.merge`), a key a map
|
|
4980
|
+
* does not hold is looked for in the maps its `<<` keys name, in order: the
|
|
4981
|
+
* map's own keys win, then the first merged map that has it, and the pair found
|
|
4982
|
+
* is the one inside that map.
|
|
4983
|
+
*
|
|
4984
|
+
* @param stream The parsed stream.
|
|
4985
|
+
* @param root The node the path starts at, such as a `documentRoot`.
|
|
4986
|
+
* @param path The steps, outermost first.
|
|
4987
|
+
* @returns The node the last matching step reached, as written (an alias is not followed): `root` itself
|
|
4988
|
+
* for an empty path, and `-1` when a step lands on an empty value (`a:`). A chain of more than
|
|
4989
|
+
* `YAML_ALIAS_HOPS` (100) aliases stops the walk at its first alias, which is returned, not `-1`.
|
|
4633
4990
|
*/
|
|
4634
4991
|
export const pathNode = (stream: YamlStream, root: i32, path: string[]): i32 => {
|
|
4635
4992
|
const walker: YamlPathWalker = new YamlPathWalker(stream)
|
|
@@ -4637,7 +4994,14 @@ export const pathNode = (stream: YamlStream, root: i32, path: string[]): i32 =>
|
|
|
4637
4994
|
return walker.node
|
|
4638
4995
|
}
|
|
4639
4996
|
|
|
4640
|
-
/**
|
|
4997
|
+
/**
|
|
4998
|
+
* The last map pair a path steps through (see `pathNode`).
|
|
4999
|
+
*
|
|
5000
|
+
* @param stream The parsed stream.
|
|
5001
|
+
* @param root The node the path starts at.
|
|
5002
|
+
* @param path The steps, outermost first.
|
|
5003
|
+
* @returns The pair, or `-1` for none.
|
|
5004
|
+
*/
|
|
4641
5005
|
export const pathPair = (stream: YamlStream, root: i32, path: string[]): i32 => {
|
|
4642
5006
|
const walker: YamlPathWalker = new YamlPathWalker(stream)
|
|
4643
5007
|
walker.walk(root, path)
|
|
@@ -4645,8 +5009,12 @@ export const pathPair = (stream: YamlStream, root: i32, path: string[]): i32 =>
|
|
|
4645
5009
|
}
|
|
4646
5010
|
|
|
4647
5011
|
/**
|
|
4648
|
-
* How many steps of
|
|
4649
|
-
*
|
|
5012
|
+
* How many steps of a path match (see `pathNode`).
|
|
5013
|
+
*
|
|
5014
|
+
* @param stream The parsed stream.
|
|
5015
|
+
* @param root The node the path starts at.
|
|
5016
|
+
* @param path The steps, outermost first.
|
|
5017
|
+
* @returns The matching steps, an empty value's included: `path.length` when every step matches.
|
|
4650
5018
|
*/
|
|
4651
5019
|
export const pathMatch = (stream: YamlStream, root: i32, path: string[]): i32 => {
|
|
4652
5020
|
const walker: YamlPathWalker = new YamlPathWalker(stream)
|
|
@@ -4656,7 +5024,14 @@ export const pathMatch = (stream: YamlStream, root: i32, path: string[]): i32 =>
|
|
|
4656
5024
|
|
|
4657
5025
|
// ---- Parsing --------------------------------------------------------------------
|
|
4658
5026
|
|
|
4659
|
-
/**
|
|
5027
|
+
/**
|
|
5028
|
+
* Parses a YAML stream with options. Panics when `maxDepth` is outside 1 to
|
|
5029
|
+
* 1000.
|
|
5030
|
+
*
|
|
5031
|
+
* @param text The YAML source.
|
|
5032
|
+
* @param options What to keep and check, and how deep collections may nest.
|
|
5033
|
+
* @returns The documents, nodes and diagnostics the parse found.
|
|
5034
|
+
*/
|
|
4660
5035
|
export const parseYamlWith = (text: string, options: YamlOptions): YamlStream => {
|
|
4661
5036
|
if (options.maxDepth < 1 || options.maxDepth > YAML_MAX_DEPTH) {
|
|
4662
5037
|
panic("nish/yaml: maxDepth must be between 1 and 1000")
|
|
@@ -4671,5 +5046,10 @@ export const parseYamlWith = (text: string, options: YamlOptions): YamlStream =>
|
|
|
4671
5046
|
return parser.stream
|
|
4672
5047
|
}
|
|
4673
5048
|
|
|
4674
|
-
/**
|
|
5049
|
+
/**
|
|
5050
|
+
* Parses a YAML stream with the default options.
|
|
5051
|
+
*
|
|
5052
|
+
* @param text The YAML source.
|
|
5053
|
+
* @returns The documents, nodes and diagnostics the parse found.
|
|
5054
|
+
*/
|
|
4675
5055
|
export const parseYaml = (text: string): YamlStream => parseYamlWith(text, new YamlOptions())
|