@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-json.ts
CHANGED
|
@@ -159,7 +159,12 @@ const YAML_JSON_DOT: i32 = 46
|
|
|
159
159
|
const YAML_JSON_ZERO: i32 = 48
|
|
160
160
|
const YAML_JSON_LT: i32 = 60
|
|
161
161
|
|
|
162
|
-
/**
|
|
162
|
+
/**
|
|
163
|
+
* A load failure's name, for a message.
|
|
164
|
+
*
|
|
165
|
+
* @param code A `YAML_JSON_ERR_*` code, as `failed` holds it.
|
|
166
|
+
* @returns The code's name without the `YAML_JSON_ERR_` prefix, such as `"DEPTH"`; `""` for any other code.
|
|
167
|
+
*/
|
|
163
168
|
export const yamlJsonErrorName = (code: i32): string => {
|
|
164
169
|
const names: string[] = ["DOCUMENT", "YAML", "NOT_FINITE", "EXPANSION", "DEPTH", "NUMBER", "MERGE"]
|
|
165
170
|
const i: i32 = YAML_JSON_ERR_DOCUMENT - code
|
|
@@ -167,54 +172,56 @@ export const yamlJsonErrorName = (code: i32): string => {
|
|
|
167
172
|
}
|
|
168
173
|
|
|
169
174
|
/**
|
|
170
|
-
* Loads documents of a `YamlStream` into a `JsonDocument`. Keeps its scratch
|
|
171
|
-
* from one load to the next
|
|
172
|
-
*
|
|
175
|
+
* Loads documents of a `YamlStream` into a `JsonDocument`. Keeps its scratch,
|
|
176
|
+
* in private fields, from one load to the next; use `load` and the result
|
|
177
|
+
* fields.
|
|
173
178
|
*/
|
|
174
179
|
export class YamlJsonLoader {
|
|
175
180
|
/** How deeply collections may nest, counting copies; `JSON_WRITER_MAX_DEPTH` so the result can be written. */
|
|
176
181
|
maxDepth: i32 = 0
|
|
177
182
|
/** The last `load`'s code: `0`, a `YAML_JSON_ERR_*` code or a `JSON_VALUE_ERR_*` code. */
|
|
178
183
|
failed: i32 = 0
|
|
179
|
-
/** The byte
|
|
184
|
+
/** The first byte the failure is about; `-1` after a load that succeeds. */
|
|
180
185
|
errorStart: i32 = -1
|
|
186
|
+
/** One past the last byte the failure is about; `-1` after a load that succeeds. */
|
|
181
187
|
errorEnd: i32 = -1
|
|
182
188
|
|
|
183
|
-
/**
|
|
184
|
-
stream: YamlStream
|
|
185
|
-
doc: JsonDocument
|
|
186
|
-
/**
|
|
187
|
-
sizes: i32[]
|
|
188
|
-
/**
|
|
189
|
-
counted: i32[]
|
|
190
|
-
countedTop: i32 = 0
|
|
191
|
-
/**
|
|
192
|
-
pending: i32[]
|
|
193
|
-
/**
|
|
194
|
-
cap: i32 = 0
|
|
195
|
-
/**
|
|
196
|
-
bigAlias: i32 = -1
|
|
197
|
-
bigSize: i32 = 0
|
|
198
|
-
/**
|
|
199
|
-
copying: i32 = -1
|
|
200
|
-
byteCap: i32 = 0
|
|
201
|
-
/**
|
|
202
|
-
entryTop: i32 = 0
|
|
189
|
+
/** The stream and document of the load in progress. */
|
|
190
|
+
private stream: YamlStream
|
|
191
|
+
private doc: JsonDocument
|
|
192
|
+
/** Per node, the values it expands to (`0` not counted yet, `-1` being counted). */
|
|
193
|
+
private sizes: i32[]
|
|
194
|
+
/** The nodes the last count set a size on, the first `countedTop` of them: all a count clears. */
|
|
195
|
+
private counted: i32[]
|
|
196
|
+
private countedTop: i32 = 0
|
|
197
|
+
/** The count's own stack of nodes. */
|
|
198
|
+
private pending: i32[]
|
|
199
|
+
/** The most values the document may hold; a size saturates one past it. */
|
|
200
|
+
private cap: i32 = 0
|
|
201
|
+
/** The alias with the largest copy, and its size. */
|
|
202
|
+
private bigAlias: i32 = -1
|
|
203
|
+
private bigSize: i32 = 0
|
|
204
|
+
/** The outermost alias being copied (`-1` for none), and the text the document may store. */
|
|
205
|
+
private copying: i32 = -1
|
|
206
|
+
private byteCap: i32 = 0
|
|
207
|
+
/** Where the next map member goes in the `entry` arrays. */
|
|
208
|
+
private entryTop: i32 = 0
|
|
203
209
|
/**
|
|
204
|
-
*
|
|
210
|
+
* The members of the maps being built, one map's after another's:
|
|
205
211
|
* each one's key text and pair, and the value node it holds (`-1` for none).
|
|
206
212
|
*/
|
|
207
|
-
entryKeys: string[]
|
|
208
|
-
entryPairs: i32[]
|
|
209
|
-
entryValues: i32[]
|
|
210
|
-
/**
|
|
211
|
-
seen: Map<string, i32>
|
|
212
|
-
/**
|
|
213
|
-
mergeMarks: i32[]
|
|
214
|
-
mergeStamp: i32 = 0
|
|
215
|
-
/**
|
|
216
|
-
mergeBudget: i32 = 0
|
|
217
|
-
|
|
213
|
+
private entryKeys: string[]
|
|
214
|
+
private entryPairs: i32[]
|
|
215
|
+
private entryValues: i32[]
|
|
216
|
+
/** A large map's key texts, to their entry. */
|
|
217
|
+
private seen: Map<string, i32>
|
|
218
|
+
/** Per node, the stamp of the last map it was merged into; and that map's stamp. */
|
|
219
|
+
private mergeMarks: i32[]
|
|
220
|
+
private mergeStamp: i32 = 0
|
|
221
|
+
/** The merged pairs the load may still visit. */
|
|
222
|
+
private mergeBudget: i32 = 0
|
|
223
|
+
|
|
224
|
+
/** A loader that holds collections to `JSON_WRITER_MAX_DEPTH`, so whatever it loads can be written back out. */
|
|
218
225
|
constructor() {
|
|
219
226
|
this.maxDepth = JSON_WRITER_MAX_DEPTH
|
|
220
227
|
this.stream = parseYaml("")
|
|
@@ -230,9 +237,14 @@ export class YamlJsonLoader {
|
|
|
230
237
|
}
|
|
231
238
|
|
|
232
239
|
/**
|
|
233
|
-
* Clears `doc` and loads document `d` of `stream` into it.
|
|
234
|
-
*
|
|
235
|
-
*
|
|
240
|
+
* Clears `doc` and loads document `d` of `stream` into it. Nothing is kept
|
|
241
|
+
* from a load that fails.
|
|
242
|
+
*
|
|
243
|
+
* @param stream The parsed stream, with the options it was parsed under; its `merge` decides whether `<<` keys merge.
|
|
244
|
+
* @param d The document's 0-based index in `stream`.
|
|
245
|
+
* @param doc Where the values go; cleared first, and cleared again when the load fails.
|
|
246
|
+
* @returns The root value, or a negative code that is also in `failed`, with the range in
|
|
247
|
+
* `errorStart` and `errorEnd`.
|
|
236
248
|
*/
|
|
237
249
|
load(stream: YamlStream, d: i32, doc: JsonDocument): JsonValue {
|
|
238
250
|
this.stream = stream
|
|
@@ -269,8 +281,8 @@ export class YamlJsonLoader {
|
|
|
269
281
|
return this.build(root, origin)
|
|
270
282
|
}
|
|
271
283
|
|
|
272
|
-
/**
|
|
273
|
-
fail(code: i32, start: i32, end: i32): i32 {
|
|
284
|
+
/** Records a failed load, clearing the document, and answers `code`. */
|
|
285
|
+
private fail(code: i32, start: i32, end: i32): i32 {
|
|
274
286
|
this.failed = code
|
|
275
287
|
this.errorStart = start
|
|
276
288
|
this.errorEnd = end
|
|
@@ -279,8 +291,8 @@ export class YamlJsonLoader {
|
|
|
279
291
|
return code
|
|
280
292
|
}
|
|
281
293
|
|
|
282
|
-
/**
|
|
283
|
-
ranged(v: JsonValue, start: i32, end: i32): JsonValue {
|
|
294
|
+
/** `v`, given the range `[start, end)`, or the failure the document answers. */
|
|
295
|
+
private ranged(v: JsonValue, start: i32, end: i32): JsonValue {
|
|
284
296
|
if (v < 0) {
|
|
285
297
|
return this.fail(v, start, end)
|
|
286
298
|
}
|
|
@@ -288,21 +300,21 @@ export class YamlJsonLoader {
|
|
|
288
300
|
return code < 0 ? this.fail(code, start, end) : v
|
|
289
301
|
}
|
|
290
302
|
|
|
291
|
-
/**
|
|
292
|
-
nullAt(at: i32): JsonValue {
|
|
303
|
+
/** A null with the empty range at `at`. */
|
|
304
|
+
private nullAt(at: i32): JsonValue {
|
|
293
305
|
return this.ranged(this.doc.newNull(), at, at)
|
|
294
306
|
}
|
|
295
307
|
|
|
296
308
|
// ---- Counting ------------------------------------------------------------------
|
|
297
309
|
|
|
298
310
|
/**
|
|
299
|
-
*
|
|
311
|
+
* How many values node `root` expands to, saturating at `cap + 1`.
|
|
300
312
|
* Each node is counted once and its count kept, on a stack of its own
|
|
301
313
|
* rather than by recursion, because a chain of aliases can be as long as
|
|
302
314
|
* the text. Sets `bigAlias`. Clears only the sizes the last count set, so a
|
|
303
315
|
* stream of many documents is not cleared whole for each.
|
|
304
316
|
*/
|
|
305
|
-
count(root: i32, cap: i32): i32 {
|
|
317
|
+
private count(root: i32, cap: i32): i32 {
|
|
306
318
|
const stream: YamlStream = this.stream
|
|
307
319
|
const nodes: i32 = toI32(stream.kinds.length)
|
|
308
320
|
const sizes: i32[] = this.sizes
|
|
@@ -349,8 +361,8 @@ export class YamlJsonLoader {
|
|
|
349
361
|
return sizes[root]
|
|
350
362
|
}
|
|
351
363
|
|
|
352
|
-
/**
|
|
353
|
-
pushNode(top: i32, n: i32): i32 {
|
|
364
|
+
/** Pushes node `n` onto the count's stack unless it is counted; answers the new top. */
|
|
365
|
+
private pushNode(top: i32, n: i32): i32 {
|
|
354
366
|
if (n < 0 || this.sizes[n] !== 0) {
|
|
355
367
|
return top
|
|
356
368
|
}
|
|
@@ -362,8 +374,8 @@ export class YamlJsonLoader {
|
|
|
362
374
|
return top + 1
|
|
363
375
|
}
|
|
364
376
|
|
|
365
|
-
/**
|
|
366
|
-
pushParts(top: i32, n: i32): i32 {
|
|
377
|
+
/** Pushes the nodes node `n`'s count is the sum of. */
|
|
378
|
+
private pushParts(top: i32, n: i32): i32 {
|
|
367
379
|
const stream: YamlStream = this.stream
|
|
368
380
|
const kind: i32 = stream.kind(n)
|
|
369
381
|
let t: i32 = top
|
|
@@ -383,10 +395,10 @@ export class YamlJsonLoader {
|
|
|
383
395
|
}
|
|
384
396
|
|
|
385
397
|
/**
|
|
386
|
-
*
|
|
398
|
+
* Node `n`'s count from its parts' counts, all of them kept by
|
|
387
399
|
* now; a part still being counted is a cycle, which counts as too many.
|
|
388
400
|
*/
|
|
389
|
-
sizeOf(n: i32): i32 {
|
|
401
|
+
private sizeOf(n: i32): i32 {
|
|
390
402
|
const stream: YamlStream = this.stream
|
|
391
403
|
const kind: i32 = stream.kind(n)
|
|
392
404
|
if (kind === YAML_ALIAS) {
|
|
@@ -422,8 +434,8 @@ export class YamlJsonLoader {
|
|
|
422
434
|
return total
|
|
423
435
|
}
|
|
424
436
|
|
|
425
|
-
/**
|
|
426
|
-
partSize(n: i32): i32 {
|
|
437
|
+
/** A counted part's size: `1` for a missing node, too many for one still being counted. */
|
|
438
|
+
private partSize(n: i32): i32 {
|
|
427
439
|
if (n < 0) {
|
|
428
440
|
return 1
|
|
429
441
|
}
|
|
@@ -431,16 +443,16 @@ export class YamlJsonLoader {
|
|
|
431
443
|
return size < 0 ? this.cap + 1 : size
|
|
432
444
|
}
|
|
433
445
|
|
|
434
|
-
/**
|
|
435
|
-
plus(a: i32, b: i32): i32 {
|
|
446
|
+
/** `a + b`, saturating at `cap + 1`; both are at most that, so the sum fits. */
|
|
447
|
+
private plus(a: i32, b: i32): i32 {
|
|
436
448
|
const sum: i32 = a + b
|
|
437
449
|
return sum > this.cap ? this.cap + 1 : sum
|
|
438
450
|
}
|
|
439
451
|
|
|
440
452
|
// ---- Building ------------------------------------------------------------------
|
|
441
453
|
|
|
442
|
-
/**
|
|
443
|
-
build(n: i32, depth: i32): JsonValue {
|
|
454
|
+
/** Builds node `n`, nested `depth` collections deep, with `n`'s range on the value it answers. */
|
|
455
|
+
private build(n: i32, depth: i32): JsonValue {
|
|
444
456
|
const stream: YamlStream = this.stream
|
|
445
457
|
const at: i32 = stream.resolved(n)
|
|
446
458
|
const kind: i32 = stream.kind(at)
|
|
@@ -470,8 +482,8 @@ export class YamlJsonLoader {
|
|
|
470
482
|
return this.ranged(v, stream.start(n), stream.end(n))
|
|
471
483
|
}
|
|
472
484
|
|
|
473
|
-
/**
|
|
474
|
-
tooMuchText(n: i32): i32 {
|
|
485
|
+
/** The failure for text past `byteCap`, stored for node `n`. */
|
|
486
|
+
private tooMuchText(n: i32): i32 {
|
|
475
487
|
const stream: YamlStream = this.stream
|
|
476
488
|
const a: i32 = this.copying
|
|
477
489
|
if (a >= 0) {
|
|
@@ -480,8 +492,8 @@ export class YamlJsonLoader {
|
|
|
480
492
|
return this.fail(JSON_TOK_ERR_TOTAL_LIMIT, stream.start(n), stream.end(n))
|
|
481
493
|
}
|
|
482
494
|
|
|
483
|
-
/**
|
|
484
|
-
buildScalar(at: i32): JsonValue {
|
|
495
|
+
/** A scalar's value, by its core-schema type. */
|
|
496
|
+
private buildScalar(at: i32): JsonValue {
|
|
485
497
|
const stream: YamlStream = this.stream
|
|
486
498
|
const doc: JsonDocument = this.doc
|
|
487
499
|
const type: i32 = stream.type(at)
|
|
@@ -504,8 +516,8 @@ export class YamlJsonLoader {
|
|
|
504
516
|
return doc.newString(stream.text(at))
|
|
505
517
|
}
|
|
506
518
|
|
|
507
|
-
/**
|
|
508
|
-
buildSeq(at: i32, depth: i32): JsonValue {
|
|
519
|
+
/** A sequence's array, each entry built in turn. */
|
|
520
|
+
private buildSeq(at: i32, depth: i32): JsonValue {
|
|
509
521
|
const stream: YamlStream = this.stream
|
|
510
522
|
const doc: JsonDocument = this.doc
|
|
511
523
|
const a: JsonValue = doc.newArray()
|
|
@@ -527,10 +539,10 @@ export class YamlJsonLoader {
|
|
|
527
539
|
}
|
|
528
540
|
|
|
529
541
|
/**
|
|
530
|
-
*
|
|
542
|
+
* A map's object. Its members are gathered first, own keys then
|
|
531
543
|
* merged ones, with repeats settled; then each value is built and added.
|
|
532
544
|
*/
|
|
533
|
-
buildMap(at: i32, depth: i32): JsonValue {
|
|
545
|
+
private buildMap(at: i32, depth: i32): JsonValue {
|
|
534
546
|
const stream: YamlStream = this.stream
|
|
535
547
|
const doc: JsonDocument = this.doc
|
|
536
548
|
const base: i32 = this.entryTop
|
|
@@ -582,11 +594,11 @@ export class YamlJsonLoader {
|
|
|
582
594
|
}
|
|
583
595
|
|
|
584
596
|
/**
|
|
585
|
-
*
|
|
597
|
+
* Adds the merge keys' maps of map `at` to the entries from
|
|
586
598
|
* `base`, each key only if it is not there yet: every map a merge key
|
|
587
599
|
* names, in order, its own keys first and then its merge keys', `hops` deep.
|
|
588
600
|
*/
|
|
589
|
-
mergeInto(base: i32, at: i32, hops: i32): i32 {
|
|
601
|
+
private mergeInto(base: i32, at: i32, hops: i32): i32 {
|
|
590
602
|
const stream: YamlStream = this.stream
|
|
591
603
|
for (let i: i32 = 0; i < stream.count(at); i += 1) {
|
|
592
604
|
const pair: i32 = stream.child(at, i)
|
|
@@ -627,11 +639,11 @@ export class YamlJsonLoader {
|
|
|
627
639
|
}
|
|
628
640
|
|
|
629
641
|
/**
|
|
630
|
-
*
|
|
642
|
+
* Merges map `m`'s own keys, then its merge keys' maps, for the
|
|
631
643
|
* merge key `pair`; nothing if `m` is merged into this map already, since
|
|
632
644
|
* a second merge would find every key taken.
|
|
633
645
|
*/
|
|
634
|
-
mergeMap(base: i32, pair: i32, m: i32, hops: i32): i32 {
|
|
646
|
+
private mergeMap(base: i32, pair: i32, m: i32, hops: i32): i32 {
|
|
635
647
|
const stream: YamlStream = this.stream
|
|
636
648
|
if (!this.markMerged(m)) {
|
|
637
649
|
return 0
|
|
@@ -649,8 +661,8 @@ export class YamlJsonLoader {
|
|
|
649
661
|
return this.mergeInto(base, m, hops)
|
|
650
662
|
}
|
|
651
663
|
|
|
652
|
-
/**
|
|
653
|
-
newMergeStamp(): void {
|
|
664
|
+
/** Starts a map's merges, so no node is marked as merged into it yet. */
|
|
665
|
+
private newMergeStamp(): void {
|
|
654
666
|
const nodes: i32 = toI32(this.stream.kinds.length)
|
|
655
667
|
const marks: i32[] = this.mergeMarks
|
|
656
668
|
while (toI32(marks.length) < nodes) {
|
|
@@ -666,8 +678,8 @@ export class YamlJsonLoader {
|
|
|
666
678
|
}
|
|
667
679
|
}
|
|
668
680
|
|
|
669
|
-
/**
|
|
670
|
-
markMerged(n: i32): boolean {
|
|
681
|
+
/** Marks node `n` as merged into the current map; `false` if it already was. */
|
|
682
|
+
private markMerged(n: i32): boolean {
|
|
671
683
|
const marks: i32[] = this.mergeMarks
|
|
672
684
|
if (n < 0 || n >= toI32(marks.length) || marks[n] === this.mergeStamp) {
|
|
673
685
|
return false
|
|
@@ -677,11 +689,11 @@ export class YamlJsonLoader {
|
|
|
677
689
|
}
|
|
678
690
|
|
|
679
691
|
/**
|
|
680
|
-
*
|
|
692
|
+
* Adds pair `pair` to the entries of the map from `base`. A key
|
|
681
693
|
* already there is skipped for a merged pair; for an own pair it follows
|
|
682
694
|
* the document's `duplicates`, keeping the first key and its place.
|
|
683
695
|
*/
|
|
684
|
-
addEntry(base: i32, pair: i32, own: boolean): i32 {
|
|
696
|
+
private addEntry(base: i32, pair: i32, own: boolean): i32 {
|
|
685
697
|
const stream: YamlStream = this.stream
|
|
686
698
|
const keyNode: i32 = stream.key(pair)
|
|
687
699
|
const key: string = keyNode < 0 ? "" : keyText(stream, keyNode)
|
|
@@ -715,10 +727,10 @@ export class YamlJsonLoader {
|
|
|
715
727
|
}
|
|
716
728
|
|
|
717
729
|
/**
|
|
718
|
-
*
|
|
730
|
+
* The entry from `base` whose key is `key`, or `-1`. The first
|
|
719
731
|
* `YAML_JSON_SCAN_KEYS` are compared one by one; the rest are in `seen`.
|
|
720
732
|
*/
|
|
721
|
-
findEntry(base: i32, key: string): i32 {
|
|
733
|
+
private findEntry(base: i32, key: string): i32 {
|
|
722
734
|
const top: i32 = this.entryTop
|
|
723
735
|
const scanned: i32 = top - base < YAML_JSON_SCAN_KEYS ? top : base + YAML_JSON_SCAN_KEYS
|
|
724
736
|
for (let e: i32 = base; e < scanned; e += 1) {
|
|
@@ -734,11 +746,11 @@ export class YamlJsonLoader {
|
|
|
734
746
|
}
|
|
735
747
|
|
|
736
748
|
/**
|
|
737
|
-
*
|
|
749
|
+
* Whether `key` is a merge key, as the stream reads one: a plain
|
|
738
750
|
* `<<`, untagged or `!!merge`. Keep in step with `yamlIsMergeKey` in
|
|
739
751
|
* `std/yaml.ts`, which is not exported.
|
|
740
752
|
*/
|
|
741
|
-
isMergeKey(key: i32): boolean {
|
|
753
|
+
private isMergeKey(key: i32): boolean {
|
|
742
754
|
const stream: YamlStream = this.stream
|
|
743
755
|
if (!stream.merge || key < 0 || stream.kind(key) !== YAML_SCALAR || stream.style(key) !== YAML_PLAIN) {
|
|
744
756
|
return false
|
package/std/yaml-lines.ts
CHANGED
|
@@ -22,8 +22,9 @@
|
|
|
22
22
|
* start rather than panicking. `column` counts characters: every byte that is
|
|
23
23
|
* not a UTF-8 continuation byte, so `é` is one column natively. `byteColumn`
|
|
24
24
|
* counts bytes, which is what an editor that indexes lines by byte wants.
|
|
25
|
-
* Under Node a string is UTF-16 and
|
|
26
|
-
*
|
|
25
|
+
* Under Node a string is UTF-16 and `column` still skips every unit from
|
|
26
|
+
* `0x80` to `0xBF`, so `©` or `µ` does not count: the column is exact for
|
|
27
|
+
* ASCII everywhere and for any text only natively.
|
|
27
28
|
*/
|
|
28
29
|
|
|
29
30
|
const YAML_LINES_LF: i32 = 10
|
|
@@ -33,15 +34,19 @@ const YAML_LINES_LEAD: i32 = 192
|
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Where each line of one text starts, for turning byte offsets into lines and
|
|
36
|
-
* columns.
|
|
37
|
-
* in Nish is; use the others, and do not change the fields.
|
|
37
|
+
* columns. Do not change `text`: the line starts were worked out from it.
|
|
38
38
|
*/
|
|
39
39
|
export class YamlLineIndex {
|
|
40
40
|
/** The text the index was built from. */
|
|
41
41
|
text: string
|
|
42
|
-
/**
|
|
43
|
-
starts: i32[]
|
|
42
|
+
/** `starts[n]` is the byte at which line `n + 1` begins; line 1 begins at 0. */
|
|
43
|
+
private starts: i32[]
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Records where each line of `text` starts, in one scan.
|
|
47
|
+
*
|
|
48
|
+
* @param text The text the offsets index, such as the source `parseYaml` read.
|
|
49
|
+
*/
|
|
45
50
|
constructor(text: string) {
|
|
46
51
|
this.text = text
|
|
47
52
|
this.starts = [0]
|
|
@@ -65,12 +70,21 @@ export class YamlLineIndex {
|
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* How many lines the text has.
|
|
75
|
+
*
|
|
76
|
+
* @returns One more than its line breaks, so `""` has one and a text ending in a break has an empty last line.
|
|
77
|
+
*/
|
|
69
78
|
lineCount(): i32 {
|
|
70
79
|
return toI32(this.starts.length)
|
|
71
80
|
}
|
|
72
81
|
|
|
73
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Where a line begins.
|
|
84
|
+
*
|
|
85
|
+
* @param line The 1-based line; one outside the text clamps to the first or last line.
|
|
86
|
+
* @returns The byte offset of the line's first byte.
|
|
87
|
+
*/
|
|
74
88
|
lineStart(line: i32): i32 {
|
|
75
89
|
const count: i32 = toI32(this.starts.length)
|
|
76
90
|
let index: i32 = line - 1
|
|
@@ -83,12 +97,24 @@ export class YamlLineIndex {
|
|
|
83
97
|
return index < count ? this.starts[index] : 0
|
|
84
98
|
}
|
|
85
99
|
|
|
86
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Which line an offset is on.
|
|
102
|
+
*
|
|
103
|
+
* @param offset A byte offset into the text; clamped to `[0, text.length]`.
|
|
104
|
+
* @returns The 1-based line; a break belongs to the line it ends.
|
|
105
|
+
*/
|
|
87
106
|
line(offset: i32): i32 {
|
|
88
107
|
return this.lineIndexOf(this.clamp(offset)) + 1
|
|
89
108
|
}
|
|
90
109
|
|
|
91
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Where an offset is on its line, in characters.
|
|
112
|
+
*
|
|
113
|
+
* @param offset A byte offset into the text; clamped to `[0, text.length]`.
|
|
114
|
+
* @returns The 1-based column: one more than the characters between the line's start and
|
|
115
|
+
* `offset`, a UTF-8 continuation byte not counting (under Node, a UTF-16 unit from `0x80` to `0xBF`
|
|
116
|
+
* not counting either, so `©` is not a column).
|
|
117
|
+
*/
|
|
92
118
|
column(offset: i32): i32 {
|
|
93
119
|
const at: i32 = this.clamp(offset)
|
|
94
120
|
const index: i32 = this.lineIndexOf(at)
|
|
@@ -107,14 +133,20 @@ export class YamlLineIndex {
|
|
|
107
133
|
return column
|
|
108
134
|
}
|
|
109
135
|
|
|
110
|
-
/**
|
|
136
|
+
/**
|
|
137
|
+
* Where an offset is on its line, in bytes.
|
|
138
|
+
*
|
|
139
|
+
* @param offset A byte offset into the text; clamped to `[0, text.length]`.
|
|
140
|
+
* @returns The 1-based column: one more than the bytes between the line's start and `offset`
|
|
141
|
+
* (under Node, UTF-16 units).
|
|
142
|
+
*/
|
|
111
143
|
byteColumn(offset: i32): i32 {
|
|
112
144
|
const at: i32 = this.clamp(offset)
|
|
113
145
|
return at - this.lineStart(this.lineIndexOf(at) + 1) + 1
|
|
114
146
|
}
|
|
115
147
|
|
|
116
|
-
/**
|
|
117
|
-
clamp(offset: i32): i32 {
|
|
148
|
+
/** `offset` clamped to `[0, text.length]`. */
|
|
149
|
+
private clamp(offset: i32): i32 {
|
|
118
150
|
const length: i32 = toI32(this.text.length)
|
|
119
151
|
if (offset < 0) {
|
|
120
152
|
return 0
|
|
@@ -122,8 +154,8 @@ export class YamlLineIndex {
|
|
|
122
154
|
return offset > length ? length : offset
|
|
123
155
|
}
|
|
124
156
|
|
|
125
|
-
/**
|
|
126
|
-
lineIndexOf(at: i32): i32 {
|
|
157
|
+
/** The 0-based line holding byte `at`, by binary search over `starts`. */
|
|
158
|
+
private lineIndexOf(at: i32): i32 {
|
|
127
159
|
const starts: i32[] = this.starts
|
|
128
160
|
let low: i32 = 0
|
|
129
161
|
let high: i32 = toI32(starts.length) - 1
|
package/std/yaml-write.ts
CHANGED
|
@@ -224,9 +224,13 @@ const yamlWriteLength = (text: string, quoted: boolean): i32 => {
|
|
|
224
224
|
|
|
225
225
|
/** Writes one JSON value as block YAML, byte by byte, into `out`. */
|
|
226
226
|
class YamlWriter {
|
|
227
|
-
doc: JsonDocument
|
|
227
|
+
private doc: JsonDocument
|
|
228
|
+
/** @internal Used by `stringifyYaml`. */
|
|
228
229
|
out: u8[]
|
|
229
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* Whether a collection nested past `JSON_WRITER_MAX_DEPTH`.
|
|
232
|
+
* @internal Used by `stringifyYaml`.
|
|
233
|
+
*/
|
|
230
234
|
tooDeep: boolean = false
|
|
231
235
|
|
|
232
236
|
constructor(doc: JsonDocument) {
|
|
@@ -234,38 +238,38 @@ class YamlWriter {
|
|
|
234
238
|
this.out = []
|
|
235
239
|
}
|
|
236
240
|
|
|
237
|
-
byte(c: i32): void {
|
|
241
|
+
private byte(c: i32): void {
|
|
238
242
|
this.out.push(toU8(c))
|
|
239
243
|
}
|
|
240
244
|
|
|
241
245
|
/** Writes the bytes of `text` from `from` up to `to`. */
|
|
242
|
-
bytes(text: string, from: i32, to: i32): void {
|
|
246
|
+
private bytes(text: string, from: i32, to: i32): void {
|
|
243
247
|
for (let i: i32 = from; i < to; i += 1) {
|
|
244
248
|
this.byte(yamlWriteByte(text, i))
|
|
245
249
|
}
|
|
246
250
|
}
|
|
247
251
|
|
|
248
|
-
text(text: string): void {
|
|
252
|
+
private text(text: string): void {
|
|
249
253
|
const from: i32 = 0
|
|
250
254
|
this.bytes(text, from, toI32(text.length))
|
|
251
255
|
}
|
|
252
256
|
|
|
253
257
|
/** Writes `count` spaces. */
|
|
254
|
-
spaces(count: i32): void {
|
|
258
|
+
private spaces(count: i32): void {
|
|
255
259
|
for (let i: i32 = 0; i < count; i += 1) {
|
|
256
260
|
this.byte(YAML_WRITE_SPACE)
|
|
257
261
|
}
|
|
258
262
|
}
|
|
259
263
|
|
|
260
264
|
/** Writes `\xXX` for byte `c`. */
|
|
261
|
-
hex(c: i32): void {
|
|
265
|
+
private hex(c: i32): void {
|
|
262
266
|
this.text("\\x")
|
|
263
267
|
this.byte(yamlWriteByte(YAML_WRITE_HEX, c >> 4))
|
|
264
268
|
this.byte(yamlWriteByte(YAML_WRITE_HEX, c & 15))
|
|
265
269
|
}
|
|
266
270
|
|
|
267
271
|
/** Writes the escape for the `length` bytes at `i`, a character yamlWriteEscapedLength names. */
|
|
268
|
-
escape(text: string, i: i32, length: i32): void {
|
|
272
|
+
private escape(text: string, i: i32, length: i32): void {
|
|
269
273
|
const c: i32 = yamlWriteByte(text, i)
|
|
270
274
|
const second: i32 = yamlWriteByte(text, i + 1)
|
|
271
275
|
const third: i32 = yamlWriteByte(text, i + 2)
|
|
@@ -289,7 +293,7 @@ class YamlWriter {
|
|
|
289
293
|
}
|
|
290
294
|
|
|
291
295
|
/** Writes `text` as a double-quoted scalar on one line. */
|
|
292
|
-
quoted(text: string): void {
|
|
296
|
+
private quoted(text: string): void {
|
|
293
297
|
const n: i32 = toI32(text.length)
|
|
294
298
|
this.byte(YAML_WRITE_QUOTE)
|
|
295
299
|
let i: i32 = 0
|
|
@@ -312,7 +316,7 @@ class YamlWriter {
|
|
|
312
316
|
}
|
|
313
317
|
|
|
314
318
|
/** Writes `text` as a scalar: plain when that reads back as the same string, double-quoted otherwise. */
|
|
315
|
-
string(text: string, quoted: boolean): void {
|
|
319
|
+
private string(text: string, quoted: boolean): void {
|
|
316
320
|
if (quoted) {
|
|
317
321
|
this.quoted(text)
|
|
318
322
|
} else {
|
|
@@ -321,13 +325,13 @@ class YamlWriter {
|
|
|
321
325
|
}
|
|
322
326
|
|
|
323
327
|
/** Whether `v` is a collection with members, which takes lines of its own. */
|
|
324
|
-
isBlock(v: JsonValue): boolean {
|
|
328
|
+
private isBlock(v: JsonValue): boolean {
|
|
325
329
|
const kind: i32 = this.doc.kind(v)
|
|
326
330
|
return (kind === JSON_VALUE_ARRAY || kind === JSON_VALUE_OBJECT) && this.doc.length(v) > 0
|
|
327
331
|
}
|
|
328
332
|
|
|
329
333
|
/** Writes `v` on one line: a scalar, `{}` or `[]`. */
|
|
330
|
-
inline(v: JsonValue): void {
|
|
334
|
+
private inline(v: JsonValue): void {
|
|
331
335
|
const doc: JsonDocument = this.doc
|
|
332
336
|
const kind: i32 = doc.kind(v)
|
|
333
337
|
if (kind === JSON_VALUE_NULL) {
|
|
@@ -349,6 +353,7 @@ class YamlWriter {
|
|
|
349
353
|
/**
|
|
350
354
|
* Writes `v` starting at column `indent`, where the line has already reached
|
|
351
355
|
* it, and ends its last line; `depth` is how many collections hold it.
|
|
356
|
+
* @internal Called by `stringifyYaml`.
|
|
352
357
|
*/
|
|
353
358
|
node(v: JsonValue, indent: i32, depth: i32): void {
|
|
354
359
|
const doc: JsonDocument = this.doc
|
|
@@ -397,10 +402,13 @@ class YamlWriter {
|
|
|
397
402
|
}
|
|
398
403
|
|
|
399
404
|
/**
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
* that
|
|
405
|
+
* A value as block YAML text that `parseYaml` reads back as the same tree. See
|
|
406
|
+
* the module comment for the rule that quotes a string.
|
|
407
|
+
*
|
|
408
|
+
* @param doc The document that holds `v`.
|
|
409
|
+
* @param v The value to write, usually the document's root.
|
|
410
|
+
* @returns The text, ending in a line break; `""` when `v` names no value or nests deeper than
|
|
411
|
+
* `JSON_WRITER_MAX_DEPTH` collections.
|
|
404
412
|
*/
|
|
405
413
|
export const stringifyYaml = (doc: JsonDocument, v: JsonValue): string => {
|
|
406
414
|
if (doc.kind(v) === JSON_VALUE_NONE) {
|