kimi-plugin-cc 2.4.5 → 2.5.2
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +22 -0
- package/README.md +103 -29
- package/dist/commands/setup.js +78 -51
- package/dist/dsh/companion.js +177 -0
- package/dist/dsh/index.js +169 -0
- package/dist/hooks/install-paths.js +2 -2
- package/dist/hooks/managed-block.js +86 -20
- package/dist/version.js +1 -1
- package/docs/migration.md +4 -2
- package/docs/models.md +5 -1
- package/docs/registry-releases.md +84 -20
- package/docs/safety.md +25 -10
- package/docs/upstream-2.4.1-certification.md +6 -0
- package/package.json +75 -8
- package/plugins/kimi-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/kimi-codex/dist/commands/setup.js +78 -51
- package/plugins/kimi-codex/dist/dsh/companion.js +177 -0
- package/plugins/kimi-codex/dist/dsh/index.js +169 -0
- package/plugins/kimi-codex/dist/hooks/install-paths.js +2 -2
- package/plugins/kimi-codex/dist/hooks/managed-block.js +86 -20
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-dsh/LICENSE +201 -0
- package/plugins/kimi-dsh/README.md +83 -0
- package/plugins/kimi-dsh/cordis.patch.yml +45 -0
- package/plugins/kimi-dsh/dist/background-spawn.js +216 -0
- package/plugins/kimi-dsh/dist/cli-cancellation.js +43 -0
- package/plugins/kimi-dsh/dist/cli-client.js +876 -0
- package/plugins/kimi-dsh/dist/commands/ask.js +336 -0
- package/plugins/kimi-dsh/dist/commands/cancel.js +216 -0
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +201 -0
- package/plugins/kimi-dsh/dist/commands/models.js +140 -0
- package/plugins/kimi-dsh/dist/commands/not-implemented.js +4 -0
- package/plugins/kimi-dsh/dist/commands/pursue.js +307 -0
- package/plugins/kimi-dsh/dist/commands/recover-swarm.js +135 -0
- package/plugins/kimi-dsh/dist/commands/registry.js +74 -0
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +160 -0
- package/plugins/kimi-dsh/dist/commands/replay.js +124 -0
- package/plugins/kimi-dsh/dist/commands/rescue.js +347 -0
- package/plugins/kimi-dsh/dist/commands/result.js +66 -0
- package/plugins/kimi-dsh/dist/commands/review-gate.js +390 -0
- package/plugins/kimi-dsh/dist/commands/review.js +220 -0
- package/plugins/kimi-dsh/dist/commands/setup.js +1074 -0
- package/plugins/kimi-dsh/dist/commands/status.js +27 -0
- package/plugins/kimi-dsh/dist/commands/swarm.js +754 -0
- package/plugins/kimi-dsh/dist/commands/worker.js +25 -0
- package/plugins/kimi-dsh/dist/companion.js +97 -0
- package/plugins/kimi-dsh/dist/config.js +22 -0
- package/plugins/kimi-dsh/dist/dsh/companion.js +177 -0
- package/plugins/kimi-dsh/dist/dsh/index.js +169 -0
- package/plugins/kimi-dsh/dist/errors.js +40 -0
- package/plugins/kimi-dsh/dist/git.js +224 -0
- package/plugins/kimi-dsh/dist/help.js +43 -0
- package/plugins/kimi-dsh/dist/hook-escape.js +71 -0
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +101 -0
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +211 -0
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +653 -0
- package/plugins/kimi-dsh/dist/hooks/install-paths.js +428 -0
- package/plugins/kimi-dsh/dist/hooks/install.js +210 -0
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +685 -0
- package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +19 -0
- package/plugins/kimi-dsh/dist/job-id.js +12 -0
- package/plugins/kimi-dsh/dist/job-store.js +659 -0
- package/plugins/kimi-dsh/dist/jobs.js +217 -0
- package/plugins/kimi-dsh/dist/kimi-command.js +70 -0
- package/plugins/kimi-dsh/dist/kimi-engine.js +632 -0
- package/plugins/kimi-dsh/dist/kimi-errors.js +260 -0
- package/plugins/kimi-dsh/dist/kimi-home.js +9 -0
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +52 -0
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +216 -0
- package/plugins/kimi-dsh/dist/logging.js +22 -0
- package/plugins/kimi-dsh/dist/mcp/binding.js +58 -0
- package/plugins/kimi-dsh/dist/mcp/job-control.js +345 -0
- package/plugins/kimi-dsh/dist/mcp/launcher.js +257 -0
- package/plugins/kimi-dsh/dist/mcp/operations.js +301 -0
- package/plugins/kimi-dsh/dist/mcp/protocol.js +275 -0
- package/plugins/kimi-dsh/dist/mcp/server.js +8 -0
- package/plugins/kimi-dsh/dist/mcp/stdio.js +78 -0
- package/plugins/kimi-dsh/dist/mcp/supervised-child.js +15 -0
- package/plugins/kimi-dsh/dist/mcp/tool-result.js +7 -0
- package/plugins/kimi-dsh/dist/mcp/workspace.js +34 -0
- package/plugins/kimi-dsh/dist/model-command.js +32 -0
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +417 -0
- package/plugins/kimi-dsh/dist/package.json +1 -0
- package/plugins/kimi-dsh/dist/parsing.js +620 -0
- package/plugins/kimi-dsh/dist/paths.js +27 -0
- package/plugins/kimi-dsh/dist/plugin-data.js +98 -0
- package/plugins/kimi-dsh/dist/process-tree.js +479 -0
- package/plugins/kimi-dsh/dist/prompt-size.js +18 -0
- package/plugins/kimi-dsh/dist/render.js +177 -0
- package/plugins/kimi-dsh/dist/rescue-approval.js +865 -0
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +43 -0
- package/plugins/kimi-dsh/dist/session-recovery.js +200 -0
- package/plugins/kimi-dsh/dist/session-title.js +293 -0
- package/plugins/kimi-dsh/dist/stream-json.js +346 -0
- package/plugins/kimi-dsh/dist/swarm-activation.js +834 -0
- package/plugins/kimi-dsh/dist/swarm-recovery.js +134 -0
- package/plugins/kimi-dsh/dist/types.js +1 -0
- package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +24 -0
- package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +1 -0
- package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +229 -0
- package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +24 -0
- package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +156 -0
- package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +67 -0
- package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +293 -0
- package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +164 -0
- package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +151 -0
- package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +156 -0
- package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +57 -0
- package/plugins/kimi-dsh/dist/version.js +7 -0
- package/plugins/kimi-dsh/package.json +78 -0
- package/plugins/kimi-dsh/scripts/companion.sh +37 -0
- package/plugins/kimi-dsh/scripts/review-gate-hook.sh +32 -0
|
@@ -0,0 +1,293 @@
|
|
|
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 { parseString } from './primitive.js';
|
|
29
|
+
import { parseArray, parseInlineTable } from './struct.js';
|
|
30
|
+
import { TomlError } from './error.js';
|
|
31
|
+
import { TomlDate } from './date.js';
|
|
32
|
+
function isDigit(char, base = 10) {
|
|
33
|
+
return base === 16
|
|
34
|
+
? (char > 0x2f && char < 0x3a) || (char > 0x40 && char < 0x47) || (char > 0x60 && char < 0x67)
|
|
35
|
+
: (char > 0x2f && char < 0x30 + base);
|
|
36
|
+
}
|
|
37
|
+
function isEndOfValue(char, delim) {
|
|
38
|
+
// Whitespace -- we're permissive on `\r` for performance; it'll be dealt with later anyway
|
|
39
|
+
return char === 0x20 || char === 0x9 /* \t */ || char === 0xa /* \n */ || char === 0xd /* \r */ ||
|
|
40
|
+
// Structure end or next value delimiter
|
|
41
|
+
(delim && (char === delim || char === 0x2c /* , */)) ||
|
|
42
|
+
// Comment
|
|
43
|
+
char === 0x23; /* # */
|
|
44
|
+
}
|
|
45
|
+
/** @internal */
|
|
46
|
+
export function extractValue(ctx, end) {
|
|
47
|
+
let errPtr = ctx.p;
|
|
48
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
49
|
+
// Structs
|
|
50
|
+
if (c === 0x5b /* [ */ || c === 0x7b /* { */) {
|
|
51
|
+
ctx.d-- || TomlError.x('document contains excessively nested structures. aborting.', ctx);
|
|
52
|
+
let value = c === 0x5b /* [ */
|
|
53
|
+
? parseArray(ctx)
|
|
54
|
+
: parseInlineTable(ctx);
|
|
55
|
+
ctx.d++;
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
// Strings
|
|
59
|
+
if (c === 0x22 /* " */ || c === 0x27 /* ' */) {
|
|
60
|
+
return parseString(ctx);
|
|
61
|
+
}
|
|
62
|
+
// Booleans
|
|
63
|
+
// We can fast-path because the first character is enough to know the only possible value
|
|
64
|
+
if (c === 0x74 /* t */) { // Only possible valid value is `true`
|
|
65
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 0x72 || ctx.s.charCodeAt(++ctx.p) !== 0x75 || ctx.s.charCodeAt(++ctx.p) !== 0x65)
|
|
66
|
+
TomlError.x('invalid value', ctx, errPtr);
|
|
67
|
+
return ctx.p++, true;
|
|
68
|
+
}
|
|
69
|
+
if (c === 0x66 /* f */) { // Only possible valid value is `false`
|
|
70
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 0x61 || ctx.s.charCodeAt(++ctx.p) !== 0x6c || ctx.s.charCodeAt(++ctx.p) !== 0x73 || ctx.s.charCodeAt(++ctx.p) !== 0x65)
|
|
71
|
+
TomlError.x('invalid value', ctx, errPtr);
|
|
72
|
+
return ctx.p++, false;
|
|
73
|
+
}
|
|
74
|
+
if (c === 0x2b /* + */ || c === 0x2d /* - */) {
|
|
75
|
+
return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 0x2c - c, end);
|
|
76
|
+
}
|
|
77
|
+
// Rough heuristic, but `parseDate` falls back to number parsing if it's a false positive.
|
|
78
|
+
// e.g.: `a = 1\n-------------- = 1` would match this heuristic, but gracefully fallback to numbers.
|
|
79
|
+
if (ctx.s.charCodeAt(ctx.p + 4) === 0x2d /* - */ && ctx.s.charCodeAt(ctx.p + 7) === 0x2d /* - */) {
|
|
80
|
+
return parseDate(ctx, c, end);
|
|
81
|
+
}
|
|
82
|
+
// Same logic as above; `parseTime` falls back to number parsing if it's a false positive.
|
|
83
|
+
if (ctx.s.charCodeAt(ctx.p + 2) === 0x3a /* : */) {
|
|
84
|
+
return parseTime(ctx, c, end);
|
|
85
|
+
}
|
|
86
|
+
return parseNumber(ctx, ctx.p, c, 0, end);
|
|
87
|
+
}
|
|
88
|
+
// State:
|
|
89
|
+
// 0: init
|
|
90
|
+
// 1: integer
|
|
91
|
+
// 2: fractional dot
|
|
92
|
+
// 3: fractional
|
|
93
|
+
// 4: exponent letter
|
|
94
|
+
// 5: exponent
|
|
95
|
+
// 6: exponent sign
|
|
96
|
+
// 7: exponent with sign
|
|
97
|
+
// >9: underscore; see below
|
|
98
|
+
// -> 12: was integer
|
|
99
|
+
// -> 14: was fractional
|
|
100
|
+
// -> 16: was exponent
|
|
101
|
+
// states 2-5, 14, 16 are ONLY permitted iif base === 10
|
|
102
|
+
function parseNumber(ctx, startPtr, startChr, sign, endChr) {
|
|
103
|
+
let c = startChr;
|
|
104
|
+
let state = 0;
|
|
105
|
+
let hasUnderscores = false;
|
|
106
|
+
// (+/-)inf
|
|
107
|
+
if (c === 0x69 /* i */) {
|
|
108
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 0x6e || ctx.s.charCodeAt(++ctx.p) !== 0x66)
|
|
109
|
+
TomlError.x('invalid value', ctx, startPtr);
|
|
110
|
+
return ctx.p++, (sign || 1) / 0;
|
|
111
|
+
}
|
|
112
|
+
// (+/-)nan
|
|
113
|
+
if (c === 0x6e /* n */) {
|
|
114
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 0x61 || ctx.s.charCodeAt(++ctx.p) !== 0x6e)
|
|
115
|
+
TomlError.x('invalid value', ctx, startPtr);
|
|
116
|
+
return ctx.p++, NaN;
|
|
117
|
+
}
|
|
118
|
+
// Leading zero
|
|
119
|
+
// Only allowed cases: `0<EOV>`, `0.(...)`, `0e(...)`, `0x(...)`, `0b(...)`, `0o(...)`
|
|
120
|
+
// FWIW, `0e(...)` is a stupid case, but it's not banned per-se so we have to parse it
|
|
121
|
+
if (c === 0x30 /* 0 */) {
|
|
122
|
+
if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr))
|
|
123
|
+
return ctx.bi === true ? 0n : 0; // note: conveniently deals with `-0`
|
|
124
|
+
if (!sign) {
|
|
125
|
+
if (c === 0x78 /* x */)
|
|
126
|
+
return parseIntegerBaseN(ctx, startPtr, 16, endChr);
|
|
127
|
+
else if (c === 0x62 /* b */)
|
|
128
|
+
return parseIntegerBaseN(ctx, startPtr, 2, endChr);
|
|
129
|
+
else if (c === 0x6f /* o */)
|
|
130
|
+
return parseIntegerBaseN(ctx, startPtr, 8, endChr);
|
|
131
|
+
}
|
|
132
|
+
if (c === 0x2e /* . */)
|
|
133
|
+
state = 2;
|
|
134
|
+
else if (c === 0x65 /* e */ || c === 0x45 /* E */)
|
|
135
|
+
state = 4;
|
|
136
|
+
else
|
|
137
|
+
TomlError.x('illegal leading zero', ctx, startPtr);
|
|
138
|
+
}
|
|
139
|
+
// If the 1st char is not a digit by now, then it's not a valid TOML value at all
|
|
140
|
+
else if (!isDigit(c))
|
|
141
|
+
TomlError.x('invalid value', ctx, startPtr);
|
|
142
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
143
|
+
if (!state)
|
|
144
|
+
state = 1; // Detects single-digit numbers we can use a fast parse path for
|
|
145
|
+
// The way the states are numbered is not random: underscores are always permitted in odd-numbered states and
|
|
146
|
+
// never permitted in even-numbered ones.
|
|
147
|
+
if (c === 0x5f /* _ */) {
|
|
148
|
+
if (!(state & 1))
|
|
149
|
+
TomlError.x('illegal underscore', ctx);
|
|
150
|
+
state += 11; // 11 is a marker that makes the state even and greater than 9; see the numbering + rationale above
|
|
151
|
+
hasUnderscores = true;
|
|
152
|
+
}
|
|
153
|
+
// Transition to fractional part.
|
|
154
|
+
else if (state === 1 && c === 0x2e /* . */)
|
|
155
|
+
state = 2;
|
|
156
|
+
// Transition to exponent part.
|
|
157
|
+
else if ((state === 1 || state === 3) && (c === 0x65 /* e */ || c === 0x45 /* E */))
|
|
158
|
+
state = 4;
|
|
159
|
+
// + and - are permitted in state 4 only (handled before entering the function for state 0)
|
|
160
|
+
else if (state === 4 && (c === 0x2b /* + */ || c === 0x2d /* - */)) {
|
|
161
|
+
state = 6;
|
|
162
|
+
}
|
|
163
|
+
// All special cases have been handled; only digits are allowed here
|
|
164
|
+
else if (!isDigit(c))
|
|
165
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
166
|
+
// Clear state flags
|
|
167
|
+
else if (state > 9)
|
|
168
|
+
state -= 11;
|
|
169
|
+
else if (!(state & 1))
|
|
170
|
+
state++;
|
|
171
|
+
}
|
|
172
|
+
// Single-char number; we can fast-path these very easily.
|
|
173
|
+
if (!state) {
|
|
174
|
+
let val = (startChr - 0x30 /* 0 */) * (sign || 1);
|
|
175
|
+
return ctx.bi === true ? BigInt(val) : val;
|
|
176
|
+
}
|
|
177
|
+
// Even-numbered states absolutely require a digit next; not even end of value is permitted
|
|
178
|
+
if (!(state & 1))
|
|
179
|
+
TomlError.x('unfinished numeric value', ctx, startPtr);
|
|
180
|
+
let str = ctx.s.slice(startPtr, ctx.p);
|
|
181
|
+
if (hasUnderscores)
|
|
182
|
+
str = str.replaceAll('_', ''); // perf: replaceAll 1.25x faster than replace with a regex
|
|
183
|
+
return state > 1
|
|
184
|
+
? parseFloat(str)
|
|
185
|
+
: parseInteger(ctx, str, 10, startPtr);
|
|
186
|
+
}
|
|
187
|
+
function parseIntegerBaseN(ctx, startPtr, base, endChr) {
|
|
188
|
+
let c, underscore = 1;
|
|
189
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
190
|
+
if (c === 0x5f /* _ */) {
|
|
191
|
+
if (underscore & 1)
|
|
192
|
+
TomlError.x('illegal underscore', ctx);
|
|
193
|
+
underscore = 3;
|
|
194
|
+
}
|
|
195
|
+
// We only need to check if the number is a valid digit, nothing else is permitted
|
|
196
|
+
else if (!isDigit(c, base))
|
|
197
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
198
|
+
// Clear underscore flag
|
|
199
|
+
else if (underscore & 1)
|
|
200
|
+
underscore--;
|
|
201
|
+
}
|
|
202
|
+
// Trailing underscore is not allowed
|
|
203
|
+
if (underscore & 1)
|
|
204
|
+
TomlError.x('unfinished numeric value', ctx);
|
|
205
|
+
let str = ctx.s.slice(startPtr + 2, ctx.p);
|
|
206
|
+
if (underscore)
|
|
207
|
+
str = str.replaceAll('_', ''); // perf: replaceAll 1.25x faster than replace with a regex
|
|
208
|
+
return parseInteger(ctx, str, base, startPtr);
|
|
209
|
+
}
|
|
210
|
+
function parseInteger(ctx, str, base, startPtr) {
|
|
211
|
+
if (ctx.bi !== true)
|
|
212
|
+
int: {
|
|
213
|
+
let val = parseInt(str, base);
|
|
214
|
+
if (!Number.isSafeInteger(val)) {
|
|
215
|
+
if (ctx.bi)
|
|
216
|
+
break int;
|
|
217
|
+
TomlError.x('integer value cannot be represented losslessly', ctx, startPtr);
|
|
218
|
+
}
|
|
219
|
+
return val;
|
|
220
|
+
}
|
|
221
|
+
return base === 10 ? BigInt(str) : BigInt((base === 2 ? '0b' : base === 8 ? '0o' : '0x') + str);
|
|
222
|
+
}
|
|
223
|
+
function parseDate(ctx, c, endChr) {
|
|
224
|
+
let startPtr = ctx.p++, unsafeSeparator;
|
|
225
|
+
if (!isDigit(c) ||
|
|
226
|
+
!isDigit(ctx.s.charCodeAt(ctx.p++)) ||
|
|
227
|
+
!isDigit(ctx.s.charCodeAt(ctx.p++)) ||
|
|
228
|
+
!isDigit(ctx.s.charCodeAt(ctx.p++))) {
|
|
229
|
+
return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
|
|
230
|
+
}
|
|
231
|
+
ctx.p += 5;
|
|
232
|
+
if (!isDigit(ctx.s.charCodeAt(ctx.p++)))
|
|
233
|
+
TomlError.x('invalid date-time: date part is malformed', ctx, startPtr);
|
|
234
|
+
if (ctx.p >= ctx.s.length || (((c = ctx.s.charCodeAt(ctx.p)) !== 0x20 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 0x54 /* T */ && c !== 0x74 /* t */)) {
|
|
235
|
+
let t = ctx.s.slice(startPtr, ctx.p);
|
|
236
|
+
return readDate(ctx, t, 3, false, startPtr);
|
|
237
|
+
}
|
|
238
|
+
if (ctx.s.charCodeAt(ctx.p += 3) !== 0x3a /* : */)
|
|
239
|
+
TomlError.x('invalid date-time: time part is malformed', ctx, startPtr);
|
|
240
|
+
if (ctx.s.charCodeAt(ctx.p += 3) === 0x3a /* : */)
|
|
241
|
+
ctx.p += 3;
|
|
242
|
+
if (ctx.s.charCodeAt(ctx.p) === 0x2e /* . */)
|
|
243
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
244
|
+
;
|
|
245
|
+
if (c = ctx.s.charCodeAt(ctx.p)) {
|
|
246
|
+
if (c === 0x5a /* Z */ || c === 0x7a /* z */) {
|
|
247
|
+
let t = ctx.s.slice(startPtr, ++ctx.p);
|
|
248
|
+
return readDate(ctx, t, 1, unsafeSeparator, startPtr, '[+00:00]');
|
|
249
|
+
}
|
|
250
|
+
if (c === 0x2b /* + */ || c === 0x2d /* - */) {
|
|
251
|
+
// Temporal's ZonedDateTime is weird asf when it comes to dealing with traditional offsets...
|
|
252
|
+
// It's 1.2x faster to allocate a new string to pass to ZDT than use Instant.toZonedDateTimeISO
|
|
253
|
+
let t = ctx.s.slice(startPtr, ctx.p += 6);
|
|
254
|
+
return readDate(ctx, t, 1, unsafeSeparator, startPtr, !ctx.ld && ('[' + ctx.s.slice(ctx.p - 6, ctx.p) + ']'));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
let t = ctx.s.slice(startPtr, ctx.p);
|
|
258
|
+
return readDate(ctx, t, 2, unsafeSeparator, startPtr);
|
|
259
|
+
}
|
|
260
|
+
function parseTime(ctx, c, endChr) {
|
|
261
|
+
let start = ctx.p;
|
|
262
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) {
|
|
263
|
+
return parseNumber(ctx, --ctx.p, c, 0, endChr);
|
|
264
|
+
}
|
|
265
|
+
if (ctx.s.charCodeAt(ctx.p += 4) === 0x3a /* : */)
|
|
266
|
+
ctx.p += 3;
|
|
267
|
+
if (ctx.s.charCodeAt(ctx.p) === 0x2e /* . */)
|
|
268
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
269
|
+
;
|
|
270
|
+
let t = ctx.s.slice(start, ctx.p);
|
|
271
|
+
return readDate(ctx, t, 4, false, start);
|
|
272
|
+
}
|
|
273
|
+
function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
274
|
+
if (ctx.ld) {
|
|
275
|
+
let date = new TomlDate(str, type, unsafeDelim);
|
|
276
|
+
if (!date.isValid())
|
|
277
|
+
TomlError.x('invalid date', ctx, errPtr);
|
|
278
|
+
return date;
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
if (temporalSuffix)
|
|
282
|
+
str += temporalSuffix;
|
|
283
|
+
switch (type) {
|
|
284
|
+
case 1: return Temporal.ZonedDateTime.from(str);
|
|
285
|
+
case 2: return Temporal.PlainDateTime.from(str);
|
|
286
|
+
case 3: return Temporal.PlainDate.from(str);
|
|
287
|
+
case 4: return Temporal.PlainTime.from(str);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
catch (e) {
|
|
291
|
+
TomlError.x(e instanceof Error ? e.message : '' + e, ctx, errPtr);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
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(ctx, 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] = Object.create(null));
|
|
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
|
+
let unsafe = k === '__proto__';
|
|
57
|
+
if (ctx.uk && (unsafe || k === 'constructor'))
|
|
58
|
+
return false;
|
|
59
|
+
if (unsafe) {
|
|
60
|
+
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
61
|
+
Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
|
|
62
|
+
}
|
|
63
|
+
m[k] = {
|
|
64
|
+
t: i < key.length - 1 && type === 2 /* Type.ARRAY */
|
|
65
|
+
? 3 /* Type.ARRAY_DOTTED */ : type,
|
|
66
|
+
d: false,
|
|
67
|
+
i: 0,
|
|
68
|
+
c: Object.create(null),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
state = m[k];
|
|
73
|
+
if (state.t !== type && !(type === 1 /* Type.EXPLICIT */ && state.t === 3 /* Type.ARRAY_DOTTED */)) {
|
|
74
|
+
// Bad key type!
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
if (type === 2 /* Type.ARRAY */) {
|
|
78
|
+
if (!state.d) {
|
|
79
|
+
state.d = true;
|
|
80
|
+
t[k] = [];
|
|
81
|
+
}
|
|
82
|
+
t[k].push(t = Object.create(null));
|
|
83
|
+
state.c[state.i++] = (state = { t: 1 /* Type.EXPLICIT */, d: false, i: 0, c: Object.create(null) });
|
|
84
|
+
}
|
|
85
|
+
if (state.d) {
|
|
86
|
+
// Redefining a table!
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
state.d = true;
|
|
90
|
+
if (type === 1 /* Type.EXPLICIT */) {
|
|
91
|
+
t = hasOwn ? t[k] : (t[k] = Object.create(null));
|
|
92
|
+
}
|
|
93
|
+
else if (type === 0 /* Type.DOTTED */ && hasOwn) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return [k, t, state.c];
|
|
97
|
+
}
|
|
98
|
+
function validateTablePeek(ctx, peek, ptr) {
|
|
99
|
+
if (peek === null || ctx.uk === 2)
|
|
100
|
+
TomlError.x(peek === null
|
|
101
|
+
? 'trying to redefine an already defined table or value'
|
|
102
|
+
: 'document contains an unsafe property', ctx, ptr);
|
|
103
|
+
}
|
|
104
|
+
export function parse(toml, options = {}) {
|
|
105
|
+
let ctx = {
|
|
106
|
+
s: toml,
|
|
107
|
+
p: 0,
|
|
108
|
+
d: options.maxDepth ?? 1000,
|
|
109
|
+
bi: options.integersAsBigInt ?? false,
|
|
110
|
+
ld: options.useLegacyDate ?? true,
|
|
111
|
+
uk: options.unsafeKeyBehaviour === 'throw' ? 2 : options.unsafeKeyBehaviour === 'drop' ? 1 : 0,
|
|
112
|
+
};
|
|
113
|
+
let res = Object.create(null);
|
|
114
|
+
let meta = Object.create(null);
|
|
115
|
+
let tmp;
|
|
116
|
+
let skipping = false;
|
|
117
|
+
let tbl = res;
|
|
118
|
+
let m = meta;
|
|
119
|
+
// BOM is allowed, skip.
|
|
120
|
+
// JS is UTF-16, so we have to check for the UTF-16 BOM instead of the UTF-8 BOM sequence!
|
|
121
|
+
if (toml.charCodeAt(0) === 0xfeff)
|
|
122
|
+
ctx.p++;
|
|
123
|
+
skipVoid(ctx);
|
|
124
|
+
while (ctx.p < toml.length) {
|
|
125
|
+
if (toml.charCodeAt(ctx.p) === 0x5b /* [ */) {
|
|
126
|
+
let isTableArray = toml.charCodeAt(++ctx.p) === 0x5b; /* [ */
|
|
127
|
+
tmp = ctx.p += +isTableArray;
|
|
128
|
+
skipping = false;
|
|
129
|
+
let k = parseKey(ctx, 0x5d /* ] */);
|
|
130
|
+
if (isTableArray) {
|
|
131
|
+
if (toml.charCodeAt(ctx.p) !== 0x5d /* ] */) {
|
|
132
|
+
TomlError.x('expected end of table array declaration', ctx);
|
|
133
|
+
}
|
|
134
|
+
ctx.p++;
|
|
135
|
+
}
|
|
136
|
+
let p = peekTable(ctx, k, res, meta, isTableArray ? 2 /* Type.ARRAY */ : 1 /* Type.EXPLICIT */);
|
|
137
|
+
if (!p) {
|
|
138
|
+
validateTablePeek(ctx, p, tmp);
|
|
139
|
+
skipping = true;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
m = p[2];
|
|
143
|
+
tbl = p[1];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
tmp = ctx.p;
|
|
148
|
+
let k = parseKey(ctx);
|
|
149
|
+
let p = peekTable(ctx, k, tbl, m, 0 /* Type.DOTTED */);
|
|
150
|
+
if (!p && !skipping)
|
|
151
|
+
validateTablePeek(ctx, p, tmp);
|
|
152
|
+
skipVoid(ctx, true, true);
|
|
153
|
+
let v = extractValue(ctx, void 0);
|
|
154
|
+
if (p && !skipping)
|
|
155
|
+
p[1][p[0]] = v;
|
|
156
|
+
}
|
|
157
|
+
skipVoid(ctx, true);
|
|
158
|
+
if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 0xa /* \n */ && (tmp !== 0xd /* \r */ || toml.charCodeAt(ctx.p + 1) !== 0xa /* \n */)) {
|
|
159
|
+
TomlError.x('each key-value declaration must be followed by an end-of-line', ctx);
|
|
160
|
+
}
|
|
161
|
+
skipVoid(ctx);
|
|
162
|
+
}
|
|
163
|
+
return res;
|
|
164
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
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 { TomlError } from './error.js';
|
|
29
|
+
/** @internal */
|
|
30
|
+
export function parseString(ctx) {
|
|
31
|
+
let startPtr = ctx.p;
|
|
32
|
+
let c = ctx.s.charCodeAt(ctx.p++);
|
|
33
|
+
let first = c;
|
|
34
|
+
let isLiteral = c === 0x27; /* ' */
|
|
35
|
+
let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
|
|
36
|
+
if (isMultiline) {
|
|
37
|
+
// Trim initial newline
|
|
38
|
+
if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 0xa /* \n */)
|
|
39
|
+
ctx.p++;
|
|
40
|
+
else if (c === 0xd /* \r */ && ctx.s.charCodeAt(ctx.p + 1) === 0xa /* \n */)
|
|
41
|
+
ctx.p += 2;
|
|
42
|
+
}
|
|
43
|
+
// For the record: it is not worth it to use a fast-path for literal strings using `indexOf`.
|
|
44
|
+
// Doing a char-by-char iteration ends up dispatching less instructions, for the same wall-clock runtime.
|
|
45
|
+
let parsed = '';
|
|
46
|
+
let sliceStart = ctx.p;
|
|
47
|
+
// states:
|
|
48
|
+
// 0 - decoding
|
|
49
|
+
// 1 - decoding escape
|
|
50
|
+
// 2 - whitespace escape (no newline encountered yet, must fail on non-whitespace)
|
|
51
|
+
// 3 - whitespace escape (newline encountered, allowed to transition back to normal decode)
|
|
52
|
+
let state = 0;
|
|
53
|
+
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
54
|
+
c = ctx.s.charCodeAt(ctx.p);
|
|
55
|
+
// Deal with newlines first, since that simplifies control character checking and handling across all states
|
|
56
|
+
if (isMultiline && (c === 0xa /* \n */ || (c === 0xd /* \r */ && ctx.s.charCodeAt(ctx.p + 1) === 0xa /* \n */))) {
|
|
57
|
+
state = state && 3;
|
|
58
|
+
}
|
|
59
|
+
// Control characters are banned in TOML, so we throw an error if we encounter them
|
|
60
|
+
else if ((c < 0x20 && c !== 0x9 /* \t */) || c === 0x7f) {
|
|
61
|
+
TomlError.x('control characters are not allowed in strings', ctx);
|
|
62
|
+
}
|
|
63
|
+
// The string might terminate while we're parsing through a newline escape.
|
|
64
|
+
// It must have encountered a newline; otherwise, it'll simply fail in another branch.
|
|
65
|
+
else if ((!state || state === 3) && c === first && (!isMultiline || (ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first))) {
|
|
66
|
+
if (isMultiline) {
|
|
67
|
+
// If the string ends with 4-5 quotes, then the first 1-2 are part of the string
|
|
68
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
69
|
+
ctx.p++;
|
|
70
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
71
|
+
ctx.p++;
|
|
72
|
+
}
|
|
73
|
+
// If we're in a newline escape still, then there's nothing to add.
|
|
74
|
+
if (!state) {
|
|
75
|
+
// Avoid a useless concat operation if the string can be used as-is.
|
|
76
|
+
let s = ctx.s.slice(sliceStart, ctx.p);
|
|
77
|
+
parsed = parsed ? parsed + s : s;
|
|
78
|
+
}
|
|
79
|
+
ctx.p += isMultiline ? 3 : 1;
|
|
80
|
+
return parsed;
|
|
81
|
+
}
|
|
82
|
+
// Baseline state; keep moving forward unless an escape sequence starts
|
|
83
|
+
else if (!state) {
|
|
84
|
+
if (!isLiteral && c === 0x5c /* \ */) {
|
|
85
|
+
parsed += ctx.s.slice(sliceStart, (sliceStart = ctx.p));
|
|
86
|
+
state = 1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (state === 1) {
|
|
90
|
+
if (c === 0x78 /* x */ || c === 0x75 /* u */ || c === 0x55 /* U */) { // Unicode escape
|
|
91
|
+
let errPtr = ctx.p++ - 1;
|
|
92
|
+
let value = 0;
|
|
93
|
+
let len = c === 0x78 /* x */ ? 2 : c === 0x75 /* u */ ? 4 : 8;
|
|
94
|
+
for (let j = 0; j < len; j++, ctx.p++) {
|
|
95
|
+
let hex = ctx.s.charCodeAt(ctx.p);
|
|
96
|
+
let digit =
|
|
97
|
+
/* 0-9 */ hex >= 0x30 && hex <= 0x39 ? hex - 0x30 :
|
|
98
|
+
/* A-F */ hex >= 0x41 && hex <= 0x46 ? hex - 0x41 + 10 :
|
|
99
|
+
/* a-f */ hex >= 0x61 && hex <= 0x66 ? hex - 0x61 + 10 : -1;
|
|
100
|
+
if (digit < 0)
|
|
101
|
+
TomlError.x('invalid non-hex character in unicode escape', ctx);
|
|
102
|
+
value = (value << 4) | digit;
|
|
103
|
+
}
|
|
104
|
+
// Because JS does bitwise on signed 32bit integers, all 0xfzzzzzzz values are actually seen as negative
|
|
105
|
+
if (value < 0 || value > 0x10ffff || (value >= 0xd800 && value <= 0xdfff)) {
|
|
106
|
+
TomlError.x('invalid unicode escape', ctx, errPtr);
|
|
107
|
+
}
|
|
108
|
+
parsed += String.fromCodePoint(value);
|
|
109
|
+
sliceStart = ctx.p--;
|
|
110
|
+
state = 0;
|
|
111
|
+
}
|
|
112
|
+
// Newline escape sequence. We only need to care about spaces and tabs; newlines are dealt with earlier
|
|
113
|
+
else if (isMultiline && (c === 0x20 || c === 0x9 /* \t */)) {
|
|
114
|
+
state = 2;
|
|
115
|
+
}
|
|
116
|
+
// Basic escape sequence
|
|
117
|
+
else {
|
|
118
|
+
if (c === 0x62 /* b */)
|
|
119
|
+
parsed += '\b';
|
|
120
|
+
else if (c === 0x74 /* t */)
|
|
121
|
+
parsed += '\t';
|
|
122
|
+
else if (c === 0x6e /* n */)
|
|
123
|
+
parsed += '\n';
|
|
124
|
+
else if (c === 0x66 /* f */)
|
|
125
|
+
parsed += '\f';
|
|
126
|
+
else if (c === 0x72 /* r */)
|
|
127
|
+
parsed += '\r';
|
|
128
|
+
else if (c === 0x65 /* e */)
|
|
129
|
+
parsed += '\x1b';
|
|
130
|
+
else if (c === 0x22 /* " */)
|
|
131
|
+
parsed += '"';
|
|
132
|
+
else if (c === 0x5c /* \ */)
|
|
133
|
+
parsed += '\\';
|
|
134
|
+
else
|
|
135
|
+
TomlError.x('unrecognised escape sequence', ctx);
|
|
136
|
+
sliceStart = ctx.p + 1;
|
|
137
|
+
state = 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Newline escape continuation: keep moving forward until the first non-whitespace char
|
|
141
|
+
else if (c !== 0x20 && c !== 0x9 /* \t */) {
|
|
142
|
+
if (state === 2)
|
|
143
|
+
TomlError.x('invalid escape: only line-ending whitespace may be escaped', ctx, sliceStart);
|
|
144
|
+
// State cannot be zero, or we'd have branched earlier already.
|
|
145
|
+
// If it's a backslash, immediately transition to the escape state so it can be processed.
|
|
146
|
+
state = !isLiteral && c === 0x5c /* \ */ ? 1 : 0;
|
|
147
|
+
sliceStart = ctx.p;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
TomlError.x('unfinished string', ctx, startPtr);
|
|
151
|
+
}
|