spexcode 0.6.8 → 0.7.0-next.1

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.
Files changed (72) hide show
  1. package/node_modules/@spexcode/session-application/package.json +5 -5
  2. package/node_modules/@spexcode/session-events/package.json +2 -2
  3. package/node_modules/@spexcode/session-protocol/package.json +1 -1
  4. package/node_modules/@spexcode/session-runtime/package.json +2 -2
  5. package/node_modules/@spexcode/session-selflaunch/dist/locality.d.ts +12 -1
  6. package/node_modules/@spexcode/session-selflaunch/dist/locality.js +62 -10
  7. package/node_modules/@spexcode/session-selflaunch/package.json +3 -3
  8. package/node_modules/@spexcode/session-topology/package.json +2 -2
  9. package/node_modules/@spexcode/spec-cli/bin/spex.mjs +127 -10
  10. package/node_modules/@spexcode/spec-cli/dist/cli.js +19 -0
  11. package/node_modules/@spexcode/spec-cli/dist/file-write.js +14 -2
  12. package/node_modules/@spexcode/spec-cli/dist/guide.js +9 -11
  13. package/node_modules/@spexcode/spec-cli/dist/harness.d.ts +11 -5
  14. package/node_modules/@spexcode/spec-cli/dist/harness.js +185 -28
  15. package/node_modules/@spexcode/spec-cli/dist/host.js +5 -1
  16. package/node_modules/@spexcode/spec-cli/dist/index.js +21 -65
  17. package/node_modules/@spexcode/spec-cli/dist/machine-peer.d.ts +2 -1
  18. package/node_modules/@spexcode/spec-cli/dist/machine-peer.js +45 -14
  19. package/node_modules/@spexcode/spec-cli/dist/opencode.js +10 -2
  20. package/node_modules/@spexcode/spec-cli/dist/pi-harness.js +18 -5
  21. package/node_modules/@spexcode/spec-cli/dist/pi-headless.d.ts +2 -0
  22. package/node_modules/@spexcode/spec-cli/dist/pi-headless.js +27 -0
  23. package/node_modules/@spexcode/spec-cli/dist/session-transcript.d.ts +57 -0
  24. package/node_modules/@spexcode/spec-cli/dist/session-transcript.js +137 -0
  25. package/node_modules/@spexcode/spec-cli/dist/sessions.d.ts +4 -0
  26. package/node_modules/@spexcode/spec-cli/dist/sessions.js +104 -36
  27. package/node_modules/@spexcode/spec-cli/dist/shim-runtime.js +14 -0
  28. package/node_modules/@spexcode/spec-cli/dist/supervise.js +1 -1
  29. package/node_modules/@spexcode/spec-cli/package.json +8 -6
  30. package/node_modules/@spexcode/spec-core/dist/layout.d.ts +0 -1
  31. package/node_modules/@spexcode/spec-core/package.json +1 -1
  32. package/node_modules/@spexcode/spec-core/templates/spexcode.json +36 -13
  33. package/node_modules/@spexcode/spec-eval/package.json +2 -2
  34. package/node_modules/@spexcode/spec-forge/package.json +2 -2
  35. package/node_modules/@spexcode/transcript/dist/frames.d.ts +46 -0
  36. package/node_modules/@spexcode/transcript/dist/frames.js +87 -0
  37. package/node_modules/@spexcode/transcript/dist/index.d.ts +5 -0
  38. package/node_modules/@spexcode/transcript/dist/index.js +5 -0
  39. package/node_modules/@spexcode/transcript/dist/live.d.ts +16 -0
  40. package/node_modules/@spexcode/transcript/dist/live.js +65 -0
  41. package/node_modules/@spexcode/transcript/dist/parsers.d.ts +50 -0
  42. package/node_modules/@spexcode/transcript/dist/parsers.js +395 -0
  43. package/node_modules/@spexcode/transcript/dist/readers.d.ts +16 -0
  44. package/node_modules/@spexcode/transcript/dist/readers.js +375 -0
  45. package/node_modules/@spexcode/{spec-cli/dist/transcript-reader.d.ts → transcript/dist/turns.d.ts} +11 -5
  46. package/node_modules/@spexcode/transcript/dist/turns.js +11 -0
  47. package/node_modules/@spexcode/transcript/package.json +30 -0
  48. package/node_modules/smol-toml/LICENSE +24 -0
  49. package/node_modules/smol-toml/README.md +418 -0
  50. package/node_modules/smol-toml/dist/date.d.ts +41 -0
  51. package/node_modules/smol-toml/dist/date.js +127 -0
  52. package/node_modules/smol-toml/dist/error.d.ts +38 -0
  53. package/node_modules/smol-toml/dist/error.js +63 -0
  54. package/node_modules/smol-toml/dist/extract.js +69 -0
  55. package/node_modules/smol-toml/dist/index.cjs +734 -0
  56. package/node_modules/smol-toml/dist/index.d.ts +43 -0
  57. package/node_modules/smol-toml/dist/index.js +33 -0
  58. package/node_modules/smol-toml/dist/parse.d.ts +36 -0
  59. package/node_modules/smol-toml/dist/parse.js +149 -0
  60. package/node_modules/smol-toml/dist/primitive.js +238 -0
  61. package/node_modules/smol-toml/dist/stringify.d.ts +31 -0
  62. package/node_modules/smol-toml/dist/stringify.js +181 -0
  63. package/node_modules/smol-toml/dist/struct.js +179 -0
  64. package/node_modules/smol-toml/dist/util.d.ts +38 -0
  65. package/node_modules/smol-toml/dist/util.js +89 -0
  66. package/node_modules/smol-toml/package.json +68 -0
  67. package/package.json +3 -3
  68. package/node_modules/@spexcode/spec-cli/dist/execution-trace.d.ts +0 -27
  69. package/node_modules/@spexcode/spec-cli/dist/execution-trace.js +0 -475
  70. package/node_modules/@spexcode/spec-cli/dist/session-execution.d.ts +0 -10
  71. package/node_modules/@spexcode/spec-cli/dist/session-execution.js +0 -70
  72. package/node_modules/@spexcode/spec-cli/dist/transcript-reader.js +0 -251
@@ -0,0 +1,43 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ import { parse } from './parse.js';
29
+ import { stringify } from './stringify.js';
30
+ import { TomlDate } from './date.js';
31
+ import { TomlError } from './error.js';
32
+ export type { TomlValue, TomlTable, TomlValueWithoutBigInt, TomlTableWithoutBigInt } from './util.js';
33
+ declare const _default: {
34
+ parse: typeof parse;
35
+ stringify: typeof stringify;
36
+ TomlDate: typeof TomlDate;
37
+ TomlError: typeof TomlError;
38
+ };
39
+ export default _default;
40
+ export { parse, stringify, TomlDate, TomlError };
41
+ export type {
42
+ /** @deprecated use TomlValue instead */
43
+ TomlValue as TomlPrimitive, } from './util.js';
@@ -0,0 +1,33 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ import { parse } from './parse.js';
29
+ import { stringify } from './stringify.js';
30
+ import { TomlDate } from './date.js';
31
+ import { TomlError } from './error.js';
32
+ export default { parse, stringify, TomlDate, TomlError };
33
+ export { parse, stringify, TomlDate, TomlError };
@@ -0,0 +1,36 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ import { type IntegersAsBigInt, type TomlTable, type TomlTableWithoutBigInt } from './util.js';
29
+ export interface ParseOptions {
30
+ maxDepth?: number;
31
+ integersAsBigInt?: IntegersAsBigInt;
32
+ }
33
+ export declare function parse(toml: string, options?: ParseOptions & {
34
+ integersAsBigInt: Exclude<IntegersAsBigInt, undefined | false>;
35
+ }): TomlTable;
36
+ export declare function parse(toml: string, options?: ParseOptions): TomlTableWithoutBigInt;
@@ -0,0 +1,149 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ import { parseKey } from './struct.js';
29
+ import { extractValue } from './extract.js';
30
+ import { skipVoid } from './util.js';
31
+ import { TomlError } from './error.js';
32
+ function peekTable(key, table, meta, type) {
33
+ let t = table;
34
+ let m = meta;
35
+ let k;
36
+ let hasOwn = false;
37
+ let state;
38
+ for (let i = 0; i < key.length; i++) {
39
+ if (i) {
40
+ t = hasOwn ? t[k] : (t[k] = {});
41
+ m = (state = m[k]).c;
42
+ if (type === 0 /* Type.DOTTED */ && (state.t === 1 /* Type.EXPLICIT */ || state.t === 2 /* Type.ARRAY */)) {
43
+ return null;
44
+ }
45
+ if (state.t === 2 /* Type.ARRAY */) {
46
+ let l = t.length - 1;
47
+ t = t[l];
48
+ m = m[l].c;
49
+ }
50
+ }
51
+ k = key[i];
52
+ if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 /* Type.DOTTED */ && m[k]?.d) {
53
+ return null;
54
+ }
55
+ if (!hasOwn) {
56
+ if (k === '__proto__') {
57
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
58
+ Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
59
+ }
60
+ m[k] = {
61
+ t: i < key.length - 1 && type === 2 /* Type.ARRAY */
62
+ ? 3 /* Type.ARRAY_DOTTED */ : type,
63
+ d: false,
64
+ i: 0,
65
+ c: {},
66
+ };
67
+ }
68
+ }
69
+ state = m[k];
70
+ if (state.t !== type && !(type === 1 /* Type.EXPLICIT */ && state.t === 3 /* Type.ARRAY_DOTTED */)) {
71
+ // Bad key type!
72
+ return null;
73
+ }
74
+ if (type === 2 /* Type.ARRAY */) {
75
+ if (!state.d) {
76
+ state.d = true;
77
+ t[k] = [];
78
+ }
79
+ t[k].push(t = {});
80
+ state.c[state.i++] = (state = { t: 1 /* Type.EXPLICIT */, d: false, i: 0, c: {} });
81
+ }
82
+ if (state.d) {
83
+ // Redefining a table!
84
+ return null;
85
+ }
86
+ state.d = true;
87
+ if (type === 1 /* Type.EXPLICIT */) {
88
+ t = hasOwn ? t[k] : (t[k] = {});
89
+ }
90
+ else if (type === 0 /* Type.DOTTED */ && hasOwn) {
91
+ return null;
92
+ }
93
+ return [k, t, state.c];
94
+ }
95
+ export function parse(toml, { maxDepth = 1000, integersAsBigInt } = {}) {
96
+ let ctx = { s: toml, p: 0, d: maxDepth };
97
+ let res = {};
98
+ let meta = {};
99
+ let tmp;
100
+ let tbl = res;
101
+ let m = meta;
102
+ skipVoid(ctx);
103
+ while (ctx.p < toml.length) {
104
+ if (toml.charCodeAt(ctx.p) === 0x5b /* [ */) {
105
+ let isTableArray = toml.charCodeAt(++ctx.p) === 0x5b; /* [ */
106
+ tmp = ctx.p += +isTableArray;
107
+ let k = parseKey(ctx, ']');
108
+ if (isTableArray) {
109
+ if (toml.charCodeAt(ctx.p - 1) !== 0x5d /* ] */) {
110
+ throw new TomlError('expected end of table declaration', {
111
+ toml: toml,
112
+ ptr: ctx.p - 1,
113
+ });
114
+ }
115
+ ctx.p++;
116
+ }
117
+ let p = peekTable(k, res, meta, isTableArray ? 2 /* Type.ARRAY */ : 1 /* Type.EXPLICIT */);
118
+ if (!p) {
119
+ throw new TomlError('trying to redefine an already defined table or value', {
120
+ toml: toml,
121
+ ptr: tmp,
122
+ });
123
+ }
124
+ m = p[2];
125
+ tbl = p[1];
126
+ }
127
+ else {
128
+ tmp = ctx.p;
129
+ let k = parseKey(ctx);
130
+ let p = peekTable(k, tbl, m, 0 /* Type.DOTTED */);
131
+ if (!p) {
132
+ throw new TomlError('trying to redefine an already defined table or value', {
133
+ toml: toml,
134
+ ptr: tmp,
135
+ });
136
+ }
137
+ p[1][p[0]] = extractValue(ctx, void 0, integersAsBigInt);
138
+ }
139
+ skipVoid(ctx, true);
140
+ if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 0xa /* \n */ && tmp !== 0xd /* \r */) {
141
+ throw new TomlError('each key-value declaration must be followed by an end-of-line', {
142
+ toml: toml,
143
+ ptr: ctx.p,
144
+ });
145
+ }
146
+ skipVoid(ctx);
147
+ }
148
+ return res;
149
+ }
@@ -0,0 +1,238 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ import { TomlDate } from './date.js';
29
+ import { TomlError } from './error.js';
30
+ import { skipComment, skipUntil } from './util.js';
31
+ // let CTRL_REGEX = /[\x00-\x08\x0f-\x1f\x7f]/
32
+ let INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
33
+ let FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
34
+ let LEADING_ZERO = /^[+-]?0[0-9_]/;
35
+ /** @internal */
36
+ export function parseString(ctx) {
37
+ let start = ctx.p;
38
+ let c = ctx.s.charCodeAt(ctx.p++);
39
+ let first = c;
40
+ let isLiteral = c === 0x27; /* ' */
41
+ let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
42
+ if (isMultiline) {
43
+ // Trim initial newline
44
+ if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 0xa /* \n */)
45
+ ctx.p++;
46
+ else if (c === 0xd /* \r */ && ctx.s.charCodeAt(ctx.p + 1) === 0xa /* \n */)
47
+ ctx.p += 2;
48
+ }
49
+ /*
50
+ The fast path does not seem to bring significant performance gains, so it's commented out.
51
+ Kept for reference and/or future fafoing.
52
+
53
+ Without: spec 5.08 µs/iter 3.88 ipc (99.44% cache) 23.90 branch misses 28.61k cycles 111.01k instructions
54
+ 5MB 115.73 ms/iter 2.51 ipc (98.36% cache) 3.12M branch misses 619.30M cycles 1.56G instructions
55
+
56
+ With: spec 5.09 µs/iter 3.90 ipc (99.46% cache) 24.42 branch misses 28.57k cycles 111.49k instructions
57
+ 5MB 113.89 ms/iter 2.47 ipc (98.38% cache) 3.12M branch misses 611.94M cycles 1.51G instructions
58
+
59
+ if (c === "'") {
60
+ // Literal strings fast path - no transform needs to occur; just grab the str and that's it
61
+ let endPtr = str.indexOf(isMultiline ? "'''" : "'", ptr)
62
+ if (endPtr < 0) {
63
+ throw new TomlError("unfinished string literal", { toml: str, ptr })
64
+ }
65
+
66
+ if (isMultiline) {
67
+ // If the string ends with 4-5 quotes, then the first 1-2 are part of the string
68
+ if (str[endPtr + 3] === "'") endPtr++
69
+ if (str[endPtr + 3] === "'") endPtr++
70
+ }
71
+
72
+ let string = str.slice(ptr, endPtr)
73
+ if (CTRL_REGEX.test(string)) {
74
+ let match = string.match(CTRL_REGEX)!
75
+ throw new TomlError('control characters are not allowed in strings', { toml: str, ptr: ptr + (match.index ?? 0) })
76
+ }
77
+ return [string, endPtr + (isMultiline ? 3 : 1)]
78
+ }
79
+ */
80
+ let parsed = '';
81
+ let sliceStart = ctx.p;
82
+ // states:
83
+ // 0 - decoding
84
+ // 1 - decoding escape
85
+ // 2 - whitespace escape (no newline encountered yet, must fail on non-whitespace)
86
+ // 3 - whitespace escape (newline encountered, allowed to transition back to normal decode)
87
+ let state = 0;
88
+ for (; ctx.p < ctx.s.length; ctx.p++) {
89
+ c = ctx.s.charCodeAt(ctx.p);
90
+ // Deal with newlines first, since that simplifies control character checking and handling across all states
91
+ if (isMultiline && (c === 0xa /* \n */ || (c === 0xd /* \r */ && ctx.s.charCodeAt(ctx.p + 1) === 0xa /* \n */))) {
92
+ state = state && 3;
93
+ }
94
+ // Control characters are banned in TOML, so we throw an error if we encounter them
95
+ else if ((c < 0x20 && c !== 0x9 /* \t */) || c === 0x7f) {
96
+ throw new TomlError('control characters are not allowed in strings', {
97
+ toml: ctx.s,
98
+ ptr: ctx.p,
99
+ });
100
+ }
101
+ // The string might terminate while we're parsing through a newline escape.
102
+ // It must have encountered a newline; otherwise, it'll simply fail in another branch.
103
+ else if ((!state || state === 3) && c === first && (!isMultiline || (ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first))) {
104
+ if (isMultiline) {
105
+ // If the string ends with 4-5 quotes, then the first 1-2 are part of the string
106
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
107
+ ctx.p++;
108
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
109
+ ctx.p++;
110
+ }
111
+ // If we're in a newline escape still, then there's nothing to add.
112
+ if (!state)
113
+ parsed += ctx.s.slice(sliceStart, ctx.p);
114
+ ctx.p += isMultiline ? 3 : 1;
115
+ return parsed;
116
+ }
117
+ else if (!state) {
118
+ if (!isLiteral && c === 0x5c /* \ */) {
119
+ parsed += ctx.s.slice(sliceStart, (sliceStart = ctx.p));
120
+ state = 1;
121
+ }
122
+ }
123
+ else if (state === 1) {
124
+ if (c === 0x78 /* x */ || c === 0x75 /* u */ || c === 0x55 /* U */) { // Unicode escape
125
+ let value = 0;
126
+ let len = c === 0x78 /* x */ ? 2 : c === 0x75 /* u */ ? 4 : 8;
127
+ for (let j = 0; j < len; j++, ctx.p++) {
128
+ let hex = ctx.s.charCodeAt(ctx.p + 1);
129
+ let digit =
130
+ /* 0-9 */ hex >= 0x30 && hex <= 0x39 ? hex - 0x30 :
131
+ /* A-F */ hex >= 0x41 && hex <= 0x46 ? hex - 0x41 + 10 :
132
+ /* a-f */ hex >= 0x61 && hex <= 0x66 ? hex - 0x61 + 10 : -1;
133
+ if (digit < 0)
134
+ throw new TomlError('invalid non-hex character in unicode escape', { toml: ctx.s, ptr: ctx.p + 1 });
135
+ value = (value << 4) | digit;
136
+ }
137
+ // Because JS does bitwise on signed 32bit integers, all 0xfzzzzzzz values are actually seen as negative
138
+ if (value < 0 || value > 0x10ffff || (value >= 0xd800 && value <= 0xdfff)) {
139
+ throw new TomlError('invalid unicode escape', { toml: ctx.s, ptr: ctx.p });
140
+ }
141
+ parsed += String.fromCodePoint(value);
142
+ sliceStart = ctx.p + 1;
143
+ state = 0;
144
+ }
145
+ else if (c === 0x20 || c === 0x9 /* \t */) { // If it was a newline, it'd have been handled earlier
146
+ state = 2;
147
+ }
148
+ else {
149
+ if (c === 0x62 /* b */)
150
+ parsed += '\b';
151
+ else if (c === 0x74 /* t */)
152
+ parsed += '\t';
153
+ else if (c === 0x6e /* n */)
154
+ parsed += '\n';
155
+ else if (c === 0x66 /* f */)
156
+ parsed += '\f';
157
+ else if (c === 0x72 /* r */)
158
+ parsed += '\r';
159
+ else if (c === 0x65 /* e */)
160
+ parsed += '\x1b';
161
+ else if (c === 0x22 /* " */)
162
+ parsed += '"';
163
+ else if (c === 0x5c /* \ */)
164
+ parsed += '\\';
165
+ else
166
+ throw new TomlError('unrecognized escape sequence', { toml: ctx.s, ptr: ctx.p });
167
+ sliceStart = ctx.p + 1;
168
+ state = 0;
169
+ }
170
+ }
171
+ else if (c !== 0x20 && c !== 0x9 /* \t */) {
172
+ if (state === 2) {
173
+ throw new TomlError('invalid escape: only line-ending whitespace may be escaped', {
174
+ toml: ctx.s,
175
+ ptr: sliceStart,
176
+ });
177
+ }
178
+ // State cannot be zero, or we'd have branched earlier already.
179
+ // If it's a backslash, immediately transition to the escape state so it can be processed.
180
+ state = !isLiteral && c === 0x5c /* \ */ ? 1 : 0;
181
+ sliceStart = ctx.p;
182
+ }
183
+ }
184
+ throw new TomlError('unfinished string', { toml: ctx.s, ptr: start });
185
+ }
186
+ function sliceAndTrimEndOf(ctx, start, end) {
187
+ let value = ctx.s.slice(start, end);
188
+ let commentIdx = value.indexOf('#');
189
+ if (commentIdx > 0) {
190
+ // The call to skipComment allows to "validate" the comment
191
+ // (absence of control characters)
192
+ skipComment({ s: value, p: commentIdx, d: 0 });
193
+ value = value.slice(0, commentIdx);
194
+ }
195
+ return value.trimEnd();
196
+ }
197
+ /** @internal */
198
+ export function parseValue(ctx, integersAsBigInt, end) {
199
+ let ptr = ctx.p;
200
+ let err = { toml: ctx.s, ptr };
201
+ skipUntil(ctx, 0x2c /* , */, end);
202
+ let value = sliceAndTrimEndOf(ctx, ptr, ctx.p);
203
+ if (!value)
204
+ throw new TomlError('incomplete declaration: value expected', err);
205
+ if (value === '-inf')
206
+ return -Infinity;
207
+ if (value === 'inf' || value === '+inf')
208
+ return Infinity;
209
+ if (value === 'nan' || value === '+nan' || value === '-nan')
210
+ return NaN;
211
+ // Avoid FP representation of -0
212
+ if (value === '-0')
213
+ return integersAsBigInt ? 0n : 0;
214
+ // Numbers
215
+ let isInt = INT_REGEX.test(value);
216
+ if (isInt || FLOAT_REGEX.test(value)) {
217
+ if (LEADING_ZERO.test(value)) {
218
+ throw new TomlError('leading zeroes are not allowed', err);
219
+ }
220
+ value = value.replace(/_/g, '');
221
+ let numeric = +value;
222
+ if (isNaN(numeric)) {
223
+ throw new TomlError('invalid number', err);
224
+ }
225
+ if (isInt) {
226
+ if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) {
227
+ throw new TomlError('integer value cannot be represented losslessly', err);
228
+ }
229
+ if (isInt || integersAsBigInt === true)
230
+ numeric = BigInt(value);
231
+ }
232
+ return numeric;
233
+ }
234
+ const date = new TomlDate(value);
235
+ if (!date.isValid())
236
+ throw new TomlError('invalid value', err);
237
+ return date;
238
+ }
@@ -0,0 +1,31 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ export declare function stringify(obj: any, { maxDepth, numbersAsFloat }?: {
29
+ maxDepth?: number;
30
+ numbersAsFloat?: boolean;
31
+ }): string;