@amritk/nish-aarch64-linux 0.35.0 → 0.37.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 +73 -59
- package/bin/nish +0 -0
- package/docs/AI.md +50 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +4849 -430
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +252 -15
- package/std/README.md +107 -82
- package/std/base64.ts +34 -5
- package/std/bytes.ts +279 -59
- 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 +128 -52
- package/std/crypto/base64url.ts +29 -5
- package/std/crypto/bcrypt-batch.ts +101 -34
- package/std/crypto/bcrypt.ts +93 -27
- package/std/crypto/chacha20poly1305.ts +69 -14
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +66 -16
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +242 -37
- package/std/crypto/jwt.ts +204 -72
- package/std/crypto/p256.ts +222 -72
- package/std/crypto/p384.ts +51 -23
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +99 -30
- package/std/crypto/rsa.ts +56 -22
- 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 +163 -24
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +133 -66
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +31 -11
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +76 -26
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +126 -51
- package/std/json-typed.ts +757 -96
- package/std/json-value.ts +438 -157
- package/std/json.ts +170 -38
- 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 +1267 -290
- package/std/net/handler.ts +296 -80
- package/std/net/hpack.ts +290 -77
- package/std/net/http-compress.ts +152 -36
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +129 -44
- package/std/net/http1-codec.ts +279 -114
- package/std/net/http1-server.ts +409 -139
- package/std/net/http2-frame.ts +289 -51
- package/std/net/http2-tls.ts +152 -49
- package/std/net/http2.ts +314 -160
- package/std/net/http3-frame.ts +165 -27
- package/std/net/http3-server.ts +282 -131
- package/std/net/http3.ts +377 -173
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +898 -260
- package/std/net/prefork.ts +202 -65
- package/std/net/qpack.ts +120 -32
- package/std/net/quic-conn-ack.ts +60 -12
- package/std/net/quic-conn-cid.ts +135 -27
- package/std/net/quic-conn-params.ts +109 -22
- package/std/net/quic-datagram.ts +50 -3
- package/std/net/quic-frame.ts +333 -23
- package/std/net/quic-listener.ts +161 -75
- package/std/net/quic-packet.ts +373 -73
- package/std/net/quic-recovery.ts +287 -65
- package/std/net/quic-stream.ts +436 -146
- package/std/net/quic.ts +693 -323
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +167 -51
- package/std/net/tls/codec.ts +494 -68
- package/std/net/tls/record-client.ts +140 -73
- package/std/net/tls/record-server.ts +233 -105
- package/std/net/tls/record.ts +142 -36
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +161 -40
- package/std/net/tls/verify.ts +57 -10
- package/std/net/tls-tcp.ts +308 -95
- package/std/net/tls.ts +276 -102
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +109 -22
- package/std/net/websocket.ts +140 -26
- package/std/net/webtransport.ts +243 -106
- package/std/pair.ts +10 -2
- package/std/random.ts +42 -15
- package/std/regex.ts +422 -257
- 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 +229 -56
- package/std/sync/shm.ts +203 -23
- package/std/term-io.ts +154 -78
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +77 -35
- package/std/term-rate.ts +199 -118
- package/std/term.ts +400 -175
- package/std/testing.ts +130 -32
- package/std/text.ts +84 -17
- package/std/threads.ts +248 -56
- package/std/yaml-json.ts +111 -97
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +45 -30
- package/std/yaml.ts +764 -384
package/std/yaml-json.ts
CHANGED
|
@@ -43,21 +43,23 @@
|
|
|
43
43
|
* the alias's range, where it is used.
|
|
44
44
|
*
|
|
45
45
|
* **An alias bomb is refused before anything is built.** The values the
|
|
46
|
-
* document expands to are counted first, from the nodes, with each node's
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
46
|
+
* document expands to are counted first, from the nodes, with each node's count
|
|
47
|
+
* kept, so the count costs one step per node however far the aliases multiply
|
|
48
|
+
* it. Past the document's `maxValues` the load is `YAML_JSON_ERR_EXPANSION`, at
|
|
49
|
+
* the first alias whose copy is the largest (the first whose copy alone is past
|
|
50
|
+
* the limit, in a bomb), or `JSON_VALUE_ERR_VALUES` when the document has no
|
|
51
|
+
* alias.
|
|
52
|
+
*
|
|
53
|
+
* A merged map counts all its keys, also those the merging map overrides, so a
|
|
54
|
+
* document within a few values of the limit can be refused for merges that
|
|
55
|
+
* would have fit. The loader's merging is linear too: a map is merged into a
|
|
56
|
+
* given map at most once, however many paths through the merge keys reach it,
|
|
57
|
+
* and the pairs every merge visits and the items of every merge sequence it
|
|
58
|
+
* walks are charged to a budget of `maxValues` plus the stream's node count,
|
|
59
|
+
* past which the load is `YAML_JSON_ERR_EXPANSION` at the merge key.
|
|
60
|
+
*
|
|
61
|
+
* `parseYaml`'s own merge check is not bounded this way: it walks a shared
|
|
62
|
+
* merge sequence once for each merge key that names it.
|
|
61
63
|
*
|
|
62
64
|
* **A merge key's value** is a mapping, an alias to one, or a sequence of
|
|
63
65
|
* those; anything else is refused at the value, by the parser as
|
|
@@ -159,7 +161,12 @@ const YAML_JSON_DOT: i32 = 46
|
|
|
159
161
|
const YAML_JSON_ZERO: i32 = 48
|
|
160
162
|
const YAML_JSON_LT: i32 = 60
|
|
161
163
|
|
|
162
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* A load failure's name, for a message.
|
|
166
|
+
*
|
|
167
|
+
* @param code A `YAML_JSON_ERR_*` code, as `failed` holds it.
|
|
168
|
+
* @returns The code's name without the `YAML_JSON_ERR_` prefix, such as `"DEPTH"`; `""` for any other code.
|
|
169
|
+
*/
|
|
163
170
|
export const yamlJsonErrorName = (code: i32): string => {
|
|
164
171
|
const names: string[] = ["DOCUMENT", "YAML", "NOT_FINITE", "EXPANSION", "DEPTH", "NUMBER", "MERGE"]
|
|
165
172
|
const i: i32 = YAML_JSON_ERR_DOCUMENT - code
|
|
@@ -167,54 +174,56 @@ export const yamlJsonErrorName = (code: i32): string => {
|
|
|
167
174
|
}
|
|
168
175
|
|
|
169
176
|
/**
|
|
170
|
-
* Loads documents of a `YamlStream` into a `JsonDocument`. Keeps its scratch
|
|
171
|
-
* from one load to the next
|
|
172
|
-
*
|
|
177
|
+
* Loads documents of a `YamlStream` into a `JsonDocument`. Keeps its scratch,
|
|
178
|
+
* in private fields, from one load to the next; use `load` and the result
|
|
179
|
+
* fields.
|
|
173
180
|
*/
|
|
174
181
|
export class YamlJsonLoader {
|
|
175
182
|
/** How deeply collections may nest, counting copies; `JSON_WRITER_MAX_DEPTH` so the result can be written. */
|
|
176
183
|
maxDepth: i32 = 0
|
|
177
184
|
/** The last `load`'s code: `0`, a `YAML_JSON_ERR_*` code or a `JSON_VALUE_ERR_*` code. */
|
|
178
185
|
failed: i32 = 0
|
|
179
|
-
/** The byte
|
|
186
|
+
/** The first byte the failure is about; `-1` after a load that succeeds. */
|
|
180
187
|
errorStart: i32 = -1
|
|
188
|
+
/** One past the last byte the failure is about; `-1` after a load that succeeds. */
|
|
181
189
|
errorEnd: i32 = -1
|
|
182
190
|
|
|
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
|
|
191
|
+
/** The stream and document of the load in progress. */
|
|
192
|
+
private stream: YamlStream
|
|
193
|
+
private doc: JsonDocument
|
|
194
|
+
/** Per node, the values it expands to (`0` not counted yet, `-1` being counted). */
|
|
195
|
+
private sizes: i32[]
|
|
196
|
+
/** The nodes the last count set a size on, the first `countedTop` of them: all a count clears. */
|
|
197
|
+
private counted: i32[]
|
|
198
|
+
private countedTop: i32 = 0
|
|
199
|
+
/** The count's own stack of nodes. */
|
|
200
|
+
private pending: i32[]
|
|
201
|
+
/** The most values the document may hold; a size saturates one past it. */
|
|
202
|
+
private cap: i32 = 0
|
|
203
|
+
/** The alias with the largest copy, and its size. */
|
|
204
|
+
private bigAlias: i32 = -1
|
|
205
|
+
private bigSize: i32 = 0
|
|
206
|
+
/** The outermost alias being copied (`-1` for none), and the text the document may store. */
|
|
207
|
+
private copying: i32 = -1
|
|
208
|
+
private byteCap: i32 = 0
|
|
209
|
+
/** Where the next map member goes in the `entry` arrays. */
|
|
210
|
+
private entryTop: i32 = 0
|
|
203
211
|
/**
|
|
204
|
-
*
|
|
212
|
+
* The members of the maps being built, one map's after another's:
|
|
205
213
|
* each one's key text and pair, and the value node it holds (`-1` for none).
|
|
206
214
|
*/
|
|
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
|
-
|
|
215
|
+
private entryKeys: string[]
|
|
216
|
+
private entryPairs: i32[]
|
|
217
|
+
private entryValues: i32[]
|
|
218
|
+
/** A large map's key texts, to their entry. */
|
|
219
|
+
private seen: Map<string, i32>
|
|
220
|
+
/** Per node, the stamp of the last map it was merged into; and that map's stamp. */
|
|
221
|
+
private mergeMarks: i32[]
|
|
222
|
+
private mergeStamp: i32 = 0
|
|
223
|
+
/** The merged pairs the load may still visit. */
|
|
224
|
+
private mergeBudget: i32 = 0
|
|
225
|
+
|
|
226
|
+
/** A loader that holds collections to `JSON_WRITER_MAX_DEPTH`, so whatever it loads can be written back out. */
|
|
218
227
|
constructor() {
|
|
219
228
|
this.maxDepth = JSON_WRITER_MAX_DEPTH
|
|
220
229
|
this.stream = parseYaml("")
|
|
@@ -230,9 +239,14 @@ export class YamlJsonLoader {
|
|
|
230
239
|
}
|
|
231
240
|
|
|
232
241
|
/**
|
|
233
|
-
* Clears `doc` and loads document `d` of `stream` into it.
|
|
234
|
-
*
|
|
235
|
-
*
|
|
242
|
+
* Clears `doc` and loads document `d` of `stream` into it. Nothing is kept
|
|
243
|
+
* from a load that fails.
|
|
244
|
+
*
|
|
245
|
+
* @param stream The parsed stream, with the options it was parsed under; its `merge` decides whether `<<` keys merge.
|
|
246
|
+
* @param d The document's 0-based index in `stream`.
|
|
247
|
+
* @param doc Where the values go; cleared first, and cleared again when the load fails.
|
|
248
|
+
* @returns The root value, or a negative code that is also in `failed`, with the range in
|
|
249
|
+
* `errorStart` and `errorEnd`.
|
|
236
250
|
*/
|
|
237
251
|
load(stream: YamlStream, d: i32, doc: JsonDocument): JsonValue {
|
|
238
252
|
this.stream = stream
|
|
@@ -269,8 +283,8 @@ export class YamlJsonLoader {
|
|
|
269
283
|
return this.build(root, origin)
|
|
270
284
|
}
|
|
271
285
|
|
|
272
|
-
/**
|
|
273
|
-
fail(code: i32, start: i32, end: i32): i32 {
|
|
286
|
+
/** Records a failed load, clearing the document, and answers `code`. */
|
|
287
|
+
private fail(code: i32, start: i32, end: i32): i32 {
|
|
274
288
|
this.failed = code
|
|
275
289
|
this.errorStart = start
|
|
276
290
|
this.errorEnd = end
|
|
@@ -279,8 +293,8 @@ export class YamlJsonLoader {
|
|
|
279
293
|
return code
|
|
280
294
|
}
|
|
281
295
|
|
|
282
|
-
/**
|
|
283
|
-
ranged(v: JsonValue, start: i32, end: i32): JsonValue {
|
|
296
|
+
/** `v`, given the range `[start, end)`, or the failure the document answers. */
|
|
297
|
+
private ranged(v: JsonValue, start: i32, end: i32): JsonValue {
|
|
284
298
|
if (v < 0) {
|
|
285
299
|
return this.fail(v, start, end)
|
|
286
300
|
}
|
|
@@ -288,21 +302,21 @@ export class YamlJsonLoader {
|
|
|
288
302
|
return code < 0 ? this.fail(code, start, end) : v
|
|
289
303
|
}
|
|
290
304
|
|
|
291
|
-
/**
|
|
292
|
-
nullAt(at: i32): JsonValue {
|
|
305
|
+
/** A null with the empty range at `at`. */
|
|
306
|
+
private nullAt(at: i32): JsonValue {
|
|
293
307
|
return this.ranged(this.doc.newNull(), at, at)
|
|
294
308
|
}
|
|
295
309
|
|
|
296
310
|
// ---- Counting ------------------------------------------------------------------
|
|
297
311
|
|
|
298
312
|
/**
|
|
299
|
-
*
|
|
313
|
+
* How many values node `root` expands to, saturating at `cap + 1`.
|
|
300
314
|
* Each node is counted once and its count kept, on a stack of its own
|
|
301
315
|
* rather than by recursion, because a chain of aliases can be as long as
|
|
302
316
|
* the text. Sets `bigAlias`. Clears only the sizes the last count set, so a
|
|
303
317
|
* stream of many documents is not cleared whole for each.
|
|
304
318
|
*/
|
|
305
|
-
count(root: i32, cap: i32): i32 {
|
|
319
|
+
private count(root: i32, cap: i32): i32 {
|
|
306
320
|
const stream: YamlStream = this.stream
|
|
307
321
|
const nodes: i32 = toI32(stream.kinds.length)
|
|
308
322
|
const sizes: i32[] = this.sizes
|
|
@@ -349,8 +363,8 @@ export class YamlJsonLoader {
|
|
|
349
363
|
return sizes[root]
|
|
350
364
|
}
|
|
351
365
|
|
|
352
|
-
/**
|
|
353
|
-
pushNode(top: i32, n: i32): i32 {
|
|
366
|
+
/** Pushes node `n` onto the count's stack unless it is counted; answers the new top. */
|
|
367
|
+
private pushNode(top: i32, n: i32): i32 {
|
|
354
368
|
if (n < 0 || this.sizes[n] !== 0) {
|
|
355
369
|
return top
|
|
356
370
|
}
|
|
@@ -362,8 +376,8 @@ export class YamlJsonLoader {
|
|
|
362
376
|
return top + 1
|
|
363
377
|
}
|
|
364
378
|
|
|
365
|
-
/**
|
|
366
|
-
pushParts(top: i32, n: i32): i32 {
|
|
379
|
+
/** Pushes the nodes node `n`'s count is the sum of. */
|
|
380
|
+
private pushParts(top: i32, n: i32): i32 {
|
|
367
381
|
const stream: YamlStream = this.stream
|
|
368
382
|
const kind: i32 = stream.kind(n)
|
|
369
383
|
let t: i32 = top
|
|
@@ -383,10 +397,10 @@ export class YamlJsonLoader {
|
|
|
383
397
|
}
|
|
384
398
|
|
|
385
399
|
/**
|
|
386
|
-
*
|
|
400
|
+
* Node `n`'s count from its parts' counts, all of them kept by
|
|
387
401
|
* now; a part still being counted is a cycle, which counts as too many.
|
|
388
402
|
*/
|
|
389
|
-
sizeOf(n: i32): i32 {
|
|
403
|
+
private sizeOf(n: i32): i32 {
|
|
390
404
|
const stream: YamlStream = this.stream
|
|
391
405
|
const kind: i32 = stream.kind(n)
|
|
392
406
|
if (kind === YAML_ALIAS) {
|
|
@@ -422,8 +436,8 @@ export class YamlJsonLoader {
|
|
|
422
436
|
return total
|
|
423
437
|
}
|
|
424
438
|
|
|
425
|
-
/**
|
|
426
|
-
partSize(n: i32): i32 {
|
|
439
|
+
/** A counted part's size: `1` for a missing node, too many for one still being counted. */
|
|
440
|
+
private partSize(n: i32): i32 {
|
|
427
441
|
if (n < 0) {
|
|
428
442
|
return 1
|
|
429
443
|
}
|
|
@@ -431,16 +445,16 @@ export class YamlJsonLoader {
|
|
|
431
445
|
return size < 0 ? this.cap + 1 : size
|
|
432
446
|
}
|
|
433
447
|
|
|
434
|
-
/**
|
|
435
|
-
plus(a: i32, b: i32): i32 {
|
|
448
|
+
/** `a + b`, saturating at `cap + 1`; both are at most that, so the sum fits. */
|
|
449
|
+
private plus(a: i32, b: i32): i32 {
|
|
436
450
|
const sum: i32 = a + b
|
|
437
451
|
return sum > this.cap ? this.cap + 1 : sum
|
|
438
452
|
}
|
|
439
453
|
|
|
440
454
|
// ---- Building ------------------------------------------------------------------
|
|
441
455
|
|
|
442
|
-
/**
|
|
443
|
-
build(n: i32, depth: i32): JsonValue {
|
|
456
|
+
/** Builds node `n`, nested `depth` collections deep, with `n`'s range on the value it answers. */
|
|
457
|
+
private build(n: i32, depth: i32): JsonValue {
|
|
444
458
|
const stream: YamlStream = this.stream
|
|
445
459
|
const at: i32 = stream.resolved(n)
|
|
446
460
|
const kind: i32 = stream.kind(at)
|
|
@@ -470,8 +484,8 @@ export class YamlJsonLoader {
|
|
|
470
484
|
return this.ranged(v, stream.start(n), stream.end(n))
|
|
471
485
|
}
|
|
472
486
|
|
|
473
|
-
/**
|
|
474
|
-
tooMuchText(n: i32): i32 {
|
|
487
|
+
/** The failure for text past `byteCap`, stored for node `n`. */
|
|
488
|
+
private tooMuchText(n: i32): i32 {
|
|
475
489
|
const stream: YamlStream = this.stream
|
|
476
490
|
const a: i32 = this.copying
|
|
477
491
|
if (a >= 0) {
|
|
@@ -480,8 +494,8 @@ export class YamlJsonLoader {
|
|
|
480
494
|
return this.fail(JSON_TOK_ERR_TOTAL_LIMIT, stream.start(n), stream.end(n))
|
|
481
495
|
}
|
|
482
496
|
|
|
483
|
-
/**
|
|
484
|
-
buildScalar(at: i32): JsonValue {
|
|
497
|
+
/** A scalar's value, by its core-schema type. */
|
|
498
|
+
private buildScalar(at: i32): JsonValue {
|
|
485
499
|
const stream: YamlStream = this.stream
|
|
486
500
|
const doc: JsonDocument = this.doc
|
|
487
501
|
const type: i32 = stream.type(at)
|
|
@@ -504,8 +518,8 @@ export class YamlJsonLoader {
|
|
|
504
518
|
return doc.newString(stream.text(at))
|
|
505
519
|
}
|
|
506
520
|
|
|
507
|
-
/**
|
|
508
|
-
buildSeq(at: i32, depth: i32): JsonValue {
|
|
521
|
+
/** A sequence's array, each entry built in turn. */
|
|
522
|
+
private buildSeq(at: i32, depth: i32): JsonValue {
|
|
509
523
|
const stream: YamlStream = this.stream
|
|
510
524
|
const doc: JsonDocument = this.doc
|
|
511
525
|
const a: JsonValue = doc.newArray()
|
|
@@ -527,10 +541,10 @@ export class YamlJsonLoader {
|
|
|
527
541
|
}
|
|
528
542
|
|
|
529
543
|
/**
|
|
530
|
-
*
|
|
544
|
+
* A map's object. Its members are gathered first, own keys then
|
|
531
545
|
* merged ones, with repeats settled; then each value is built and added.
|
|
532
546
|
*/
|
|
533
|
-
buildMap(at: i32, depth: i32): JsonValue {
|
|
547
|
+
private buildMap(at: i32, depth: i32): JsonValue {
|
|
534
548
|
const stream: YamlStream = this.stream
|
|
535
549
|
const doc: JsonDocument = this.doc
|
|
536
550
|
const base: i32 = this.entryTop
|
|
@@ -582,11 +596,11 @@ export class YamlJsonLoader {
|
|
|
582
596
|
}
|
|
583
597
|
|
|
584
598
|
/**
|
|
585
|
-
*
|
|
599
|
+
* Adds the merge keys' maps of map `at` to the entries from
|
|
586
600
|
* `base`, each key only if it is not there yet: every map a merge key
|
|
587
601
|
* names, in order, its own keys first and then its merge keys', `hops` deep.
|
|
588
602
|
*/
|
|
589
|
-
mergeInto(base: i32, at: i32, hops: i32): i32 {
|
|
603
|
+
private mergeInto(base: i32, at: i32, hops: i32): i32 {
|
|
590
604
|
const stream: YamlStream = this.stream
|
|
591
605
|
for (let i: i32 = 0; i < stream.count(at); i += 1) {
|
|
592
606
|
const pair: i32 = stream.child(at, i)
|
|
@@ -627,11 +641,11 @@ export class YamlJsonLoader {
|
|
|
627
641
|
}
|
|
628
642
|
|
|
629
643
|
/**
|
|
630
|
-
*
|
|
644
|
+
* Merges map `m`'s own keys, then its merge keys' maps, for the
|
|
631
645
|
* merge key `pair`; nothing if `m` is merged into this map already, since
|
|
632
646
|
* a second merge would find every key taken.
|
|
633
647
|
*/
|
|
634
|
-
mergeMap(base: i32, pair: i32, m: i32, hops: i32): i32 {
|
|
648
|
+
private mergeMap(base: i32, pair: i32, m: i32, hops: i32): i32 {
|
|
635
649
|
const stream: YamlStream = this.stream
|
|
636
650
|
if (!this.markMerged(m)) {
|
|
637
651
|
return 0
|
|
@@ -649,8 +663,8 @@ export class YamlJsonLoader {
|
|
|
649
663
|
return this.mergeInto(base, m, hops)
|
|
650
664
|
}
|
|
651
665
|
|
|
652
|
-
/**
|
|
653
|
-
newMergeStamp(): void {
|
|
666
|
+
/** Starts a map's merges, so no node is marked as merged into it yet. */
|
|
667
|
+
private newMergeStamp(): void {
|
|
654
668
|
const nodes: i32 = toI32(this.stream.kinds.length)
|
|
655
669
|
const marks: i32[] = this.mergeMarks
|
|
656
670
|
while (toI32(marks.length) < nodes) {
|
|
@@ -666,8 +680,8 @@ export class YamlJsonLoader {
|
|
|
666
680
|
}
|
|
667
681
|
}
|
|
668
682
|
|
|
669
|
-
/**
|
|
670
|
-
markMerged(n: i32): boolean {
|
|
683
|
+
/** Marks node `n` as merged into the current map; `false` if it already was. */
|
|
684
|
+
private markMerged(n: i32): boolean {
|
|
671
685
|
const marks: i32[] = this.mergeMarks
|
|
672
686
|
if (n < 0 || n >= toI32(marks.length) || marks[n] === this.mergeStamp) {
|
|
673
687
|
return false
|
|
@@ -677,11 +691,11 @@ export class YamlJsonLoader {
|
|
|
677
691
|
}
|
|
678
692
|
|
|
679
693
|
/**
|
|
680
|
-
*
|
|
694
|
+
* Adds pair `pair` to the entries of the map from `base`. A key
|
|
681
695
|
* already there is skipped for a merged pair; for an own pair it follows
|
|
682
696
|
* the document's `duplicates`, keeping the first key and its place.
|
|
683
697
|
*/
|
|
684
|
-
addEntry(base: i32, pair: i32, own: boolean): i32 {
|
|
698
|
+
private addEntry(base: i32, pair: i32, own: boolean): i32 {
|
|
685
699
|
const stream: YamlStream = this.stream
|
|
686
700
|
const keyNode: i32 = stream.key(pair)
|
|
687
701
|
const key: string = keyNode < 0 ? "" : keyText(stream, keyNode)
|
|
@@ -715,10 +729,10 @@ export class YamlJsonLoader {
|
|
|
715
729
|
}
|
|
716
730
|
|
|
717
731
|
/**
|
|
718
|
-
*
|
|
732
|
+
* The entry from `base` whose key is `key`, or `-1`. The first
|
|
719
733
|
* `YAML_JSON_SCAN_KEYS` are compared one by one; the rest are in `seen`.
|
|
720
734
|
*/
|
|
721
|
-
findEntry(base: i32, key: string): i32 {
|
|
735
|
+
private findEntry(base: i32, key: string): i32 {
|
|
722
736
|
const top: i32 = this.entryTop
|
|
723
737
|
const scanned: i32 = top - base < YAML_JSON_SCAN_KEYS ? top : base + YAML_JSON_SCAN_KEYS
|
|
724
738
|
for (let e: i32 = base; e < scanned; e += 1) {
|
|
@@ -734,11 +748,11 @@ export class YamlJsonLoader {
|
|
|
734
748
|
}
|
|
735
749
|
|
|
736
750
|
/**
|
|
737
|
-
*
|
|
751
|
+
* Whether `key` is a merge key, as the stream reads one: a plain
|
|
738
752
|
* `<<`, untagged or `!!merge`. Keep in step with `yamlIsMergeKey` in
|
|
739
753
|
* `std/yaml.ts`, which is not exported.
|
|
740
754
|
*/
|
|
741
|
-
isMergeKey(key: i32): boolean {
|
|
755
|
+
private isMergeKey(key: i32): boolean {
|
|
742
756
|
const stream: YamlStream = this.stream
|
|
743
757
|
if (!stream.merge || key < 0 || stream.kind(key) !== YAML_SCALAR || stream.style(key) !== YAML_PLAIN) {
|
|
744
758
|
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
|