@effected/toml 0.14.0 → 0.16.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/Toml.js +35 -30
- package/TomlDateTime.js +1 -2
- package/TomlDiagnostic.js +1 -2
- package/TomlDocument.js +85 -45
- package/TomlEdit.js +1 -2
- package/TomlFormat.js +77 -24
- package/TomlNode.js +1 -2
- package/TomlVisitor.js +9 -21
- package/index.d.ts +113 -21
- package/internal/diagnostics.js +1 -2
- package/internal/limits.js +1 -2
- package/internal/parser.js +1 -2
- package/internal/scanner.js +1 -2
- package/internal/semantic.js +1 -2
- package/internal/stringifyValue.js +1 -2
- package/package.json +1 -1
package/Toml.js
CHANGED
|
@@ -6,7 +6,7 @@ import { stringifyValue } from "./internal/stringifyValue.js";
|
|
|
6
6
|
import { TomlDiagnostic } from "./TomlDiagnostic.js";
|
|
7
7
|
import { Effect, Result, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// src/Toml.ts
|
|
10
10
|
/**
|
|
11
11
|
* Options controlling stringify behavior. The only knob is `newline` —
|
|
12
12
|
* omitted, it resolves to `"\n"`.
|
|
@@ -58,41 +58,47 @@ var TomlStringifyError = class extends Schema.TaggedError()("TomlStringifyError"
|
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
61
|
+
* Materialize an engine throw into the typed {@link TomlParseError}:
|
|
62
|
+
* `RawTomlError` becomes a positioned diagnostic and a `GuardExceeded` depth
|
|
63
|
+
* trip becomes a `NestingDepthExceeded` diagnostic (never an unhandled
|
|
64
|
+
* defect). Anything else is a genuine defect and rethrows — synchronously to a
|
|
65
|
+
* `Result` caller, and as a `Die` through the `Effect` forms, which evaluate
|
|
66
|
+
* it inside the effect.
|
|
67
|
+
*
|
|
68
|
+
* The one mapping shared by every parse path — `Toml.parse`/`parseResult`,
|
|
69
|
+
* `TomlDocument.parseResult`/`toValueResult` and `TomlVisitor.visit` — so a
|
|
70
|
+
* given input fails identically through each of them.
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
67
73
|
*/
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
length: 0
|
|
78
|
-
})] }));
|
|
79
|
-
throw defect;
|
|
80
|
-
}
|
|
74
|
+
const toTomlParseError = (text, defect) => {
|
|
75
|
+
if (isRawTomlError(defect)) return new TomlParseError({ diagnostics: [TomlDiagnostic.fromRaw(text, defect.diagnostic)] });
|
|
76
|
+
if (isGuardExceeded(defect)) return new TomlParseError({ diagnostics: [TomlDiagnostic.fromRaw(text, {
|
|
77
|
+
code: "NestingDepthExceeded",
|
|
78
|
+
message: defect.message,
|
|
79
|
+
offset: defect.offset,
|
|
80
|
+
length: 0
|
|
81
|
+
})] });
|
|
82
|
+
throw defect;
|
|
81
83
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
/** Run the parser and semantic pass, materializing failures via {@link toTomlParseError}. */
|
|
85
|
+
const parseToResult = (text) => Result.try({
|
|
86
|
+
try: () => buildValue(parseExpressions(text)),
|
|
87
|
+
catch: (defect) => toTomlParseError(text, defect)
|
|
88
|
+
});
|
|
89
|
+
const stringifyToResult = (value, options) => Result.try({
|
|
90
|
+
try: () => stringifyValue(value, options?.newline ?? "\n"),
|
|
91
|
+
catch: (defect) => {
|
|
92
|
+
if (isRawTomlError(defect)) return new TomlStringifyError({ diagnostic: TomlDiagnostic.fromRaw("", defect.diagnostic) });
|
|
93
|
+
if (isGuardExceeded(defect)) return new TomlStringifyError({ diagnostic: TomlDiagnostic.fromRaw("", {
|
|
88
94
|
code: "NestingDepthExceeded",
|
|
89
95
|
message: defect.message,
|
|
90
96
|
offset: 0,
|
|
91
97
|
length: 0
|
|
92
|
-
}) })
|
|
98
|
+
}) });
|
|
93
99
|
throw defect;
|
|
94
100
|
}
|
|
95
|
-
};
|
|
101
|
+
});
|
|
96
102
|
/**
|
|
97
103
|
* Static entry points for TOML parsing, stringification and the schema
|
|
98
104
|
* factories. Not instantiable.
|
|
@@ -303,5 +309,4 @@ var Toml = class Toml {
|
|
|
303
309
|
}
|
|
304
310
|
};
|
|
305
311
|
|
|
306
|
-
|
|
307
|
-
export { Toml, TomlParseError, TomlStringifyError, TomlStringifyOptions };
|
|
312
|
+
export { Toml, TomlParseError, TomlStringifyError, TomlStringifyOptions, toTomlParseError };
|
package/TomlDateTime.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/TomlDateTime.ts
|
|
4
4
|
/** Zero-pad `value` to `width` digits (never truncates a wider value). */
|
|
5
5
|
function pad(value, width) {
|
|
6
6
|
return String(value).padStart(width, "0");
|
|
@@ -143,5 +143,4 @@ var TomlOffsetDateTime = class extends Schema.Class("TomlOffsetDateTime")(Schema
|
|
|
143
143
|
}
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
-
//#endregion
|
|
147
146
|
export { TomlLocalDate, TomlLocalDateTime, TomlLocalTime, TomlOffsetDateTime };
|
package/TomlDiagnostic.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TOML_LEX_ERROR_CODES, TOML_PARSE_ERROR_CODES, TOML_SEMANTIC_ERROR_CODES, TOML_STRINGIFY_ERROR_CODES } from "./internal/diagnostics.js";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/TomlDiagnostic.ts
|
|
5
5
|
/**
|
|
6
6
|
* Error codes emitted by the lexer stage.
|
|
7
7
|
*
|
|
@@ -106,5 +106,4 @@ function lineChar(text, offset) {
|
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
//#endregion
|
|
110
109
|
export { TomlDiagnostic, TomlErrorCode, TomlLexErrorCode, TomlParseErrorCode, TomlSemanticErrorCode, TomlStringifyErrorCode };
|
package/TomlDocument.js
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
1
|
import { isRawTomlError } from "./internal/diagnostics.js";
|
|
2
|
-
import { isGuardExceeded } from "./internal/limits.js";
|
|
3
2
|
import { TomlExpression } from "./TomlNode.js";
|
|
4
3
|
import { parseExpressions } from "./internal/parser.js";
|
|
5
4
|
import { analyze, buildValue } from "./internal/semantic.js";
|
|
6
5
|
import { TomlDiagnostic } from "./TomlDiagnostic.js";
|
|
7
|
-
import { TomlParseError } from "./Toml.js";
|
|
8
|
-
import { Effect, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
6
|
+
import { TomlParseError, toTomlParseError } from "./Toml.js";
|
|
7
|
+
import { Effect, Result, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Materialize an engine throw into the typed error: `RawTomlError` becomes a
|
|
13
|
-
* positioned diagnostic and a `GuardExceeded` depth trip becomes a
|
|
14
|
-
* `NestingDepthExceeded` diagnostic. Anything else is a genuine defect and
|
|
15
|
-
* rethrows.
|
|
16
|
-
*/
|
|
17
|
-
const materializeError = (text, defect) => {
|
|
18
|
-
if (isRawTomlError(defect)) return new TomlParseError({ diagnostics: [TomlDiagnostic.fromRaw(text, defect.diagnostic)] });
|
|
19
|
-
if (isGuardExceeded(defect)) return new TomlParseError({ diagnostics: [TomlDiagnostic.fromRaw(text, {
|
|
20
|
-
code: "NestingDepthExceeded",
|
|
21
|
-
message: defect.message,
|
|
22
|
-
offset: defect.offset,
|
|
23
|
-
length: 0
|
|
24
|
-
})] });
|
|
25
|
-
throw defect;
|
|
26
|
-
};
|
|
9
|
+
// src/TomlDocument.ts
|
|
27
10
|
/**
|
|
28
11
|
* A parsed TOML document that never loses a byte: the `source` text, the
|
|
29
12
|
* linear {@link (TomlExpression:type)} CST whose spans tile the source
|
|
@@ -61,36 +44,64 @@ var TomlDocument = class TomlDocument extends Schema.Class("TomlDocument")({
|
|
|
61
44
|
expressions: Schema.Array(TomlExpression),
|
|
62
45
|
diagnostics: Schema.Array(TomlDiagnostic)
|
|
63
46
|
}) {
|
|
47
|
+
/**
|
|
48
|
+
* Synchronous {@link TomlDocument.parse}, returning a `Result` instead of
|
|
49
|
+
* an `Effect` — the primitive `parse` is defined in terms of, so a
|
|
50
|
+
* synchronous host can call it without an Effect runtime. Fails with
|
|
51
|
+
* {@link TomlParseError} only on lex/parse errors — including a
|
|
52
|
+
* nesting-depth bomb, which surfaces as a `NestingDepthExceeded`
|
|
53
|
+
* diagnostic, never a throw. Semantic violations do not fail: they land in
|
|
54
|
+
* `diagnostics` as data (first violation wins, so there is at most one
|
|
55
|
+
* today; the array shape is the contract).
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { TomlDocument } from "@effected/toml";
|
|
60
|
+
* import { Result } from "effect";
|
|
61
|
+
*
|
|
62
|
+
* const result = TomlDocument.parseResult('name = "Alice"\n');
|
|
63
|
+
* if (Result.isSuccess(result)) {
|
|
64
|
+
* console.log(result.success.stringify()); // => 'name = "Alice"\n'
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @param text - The TOML source to parse.
|
|
69
|
+
* @returns A `Result` succeeding with the {@link TomlDocument}, or failing
|
|
70
|
+
* with {@link TomlParseError}.
|
|
71
|
+
*/
|
|
72
|
+
static parseResult(text) {
|
|
73
|
+
return Result.map(Result.try({
|
|
74
|
+
try: () => parseExpressions(text),
|
|
75
|
+
catch: (defect) => toTomlParseError(text, defect)
|
|
76
|
+
}), (expressions) => {
|
|
77
|
+
const diagnostics = [];
|
|
78
|
+
try {
|
|
79
|
+
analyze(expressions);
|
|
80
|
+
} catch (defect) {
|
|
81
|
+
if (!isRawTomlError(defect)) throw defect;
|
|
82
|
+
diagnostics.push(TomlDiagnostic.fromRaw(text, defect.diagnostic));
|
|
83
|
+
}
|
|
84
|
+
return TomlDocument.make({
|
|
85
|
+
source: text,
|
|
86
|
+
expressions,
|
|
87
|
+
diagnostics
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
64
91
|
/**
|
|
65
92
|
* Parse TOML text into a lossless document. Fails with
|
|
66
93
|
* {@link TomlParseError} only on lex/parse errors — including a
|
|
67
94
|
* nesting-depth bomb, which surfaces as a `NestingDepthExceeded`
|
|
68
95
|
* diagnostic, never an unhandled defect. Semantic violations do not fail:
|
|
69
|
-
* they land in `diagnostics` as data
|
|
70
|
-
*
|
|
96
|
+
* they land in `diagnostics` as data. Defined in terms of
|
|
97
|
+
* {@link TomlDocument.parseResult} — synchronous callers can use that
|
|
98
|
+
* variant directly.
|
|
71
99
|
*
|
|
72
100
|
* @param text - The TOML source to parse.
|
|
73
101
|
* @returns An `Effect` that succeeds with the {@link TomlDocument}, or fails
|
|
74
102
|
* with {@link TomlParseError}.
|
|
75
103
|
*/
|
|
76
|
-
static parse = Effect.fn("TomlDocument.parse")(
|
|
77
|
-
const expressions = yield* Effect.try({
|
|
78
|
-
try: () => parseExpressions(text),
|
|
79
|
-
catch: (defect) => materializeError(text, defect)
|
|
80
|
-
});
|
|
81
|
-
const diagnostics = [];
|
|
82
|
-
try {
|
|
83
|
-
analyze(expressions);
|
|
84
|
-
} catch (defect) {
|
|
85
|
-
if (!isRawTomlError(defect)) throw defect;
|
|
86
|
-
diagnostics.push(TomlDiagnostic.fromRaw(text, defect.diagnostic));
|
|
87
|
-
}
|
|
88
|
-
return TomlDocument.make({
|
|
89
|
-
source: text,
|
|
90
|
-
expressions,
|
|
91
|
-
diagnostics
|
|
92
|
-
});
|
|
93
|
-
});
|
|
104
|
+
static parse = Effect.fn("TomlDocument.parse")((text) => Effect.fromResult(TomlDocument.parseResult(text)));
|
|
94
105
|
/**
|
|
95
106
|
* A `Schema<TomlDocument, string>` decoding TOML text into a full document
|
|
96
107
|
* (source, expressions, diagnostics) and encoding a document back to its
|
|
@@ -111,13 +122,43 @@ var TomlDocument = class TomlDocument extends Schema.Class("TomlDocument")({
|
|
|
111
122
|
* {@link TomlParseError} carrying the stored `diagnostics` when the parse
|
|
112
123
|
* recorded semantic violations; otherwise builds the value from the
|
|
113
124
|
* expression list (already validated, so the defensive materialization
|
|
114
|
-
* wrapper is belt-and-suspenders).
|
|
125
|
+
* wrapper is belt-and-suspenders). Defined in terms of
|
|
126
|
+
* {@link TomlDocument.toValueResult} — synchronous callers can use that
|
|
127
|
+
* variant directly.
|
|
128
|
+
*
|
|
129
|
+
* @returns An `Effect` that succeeds with the plain value, or fails with
|
|
130
|
+
* {@link TomlParseError}.
|
|
115
131
|
*/
|
|
116
132
|
toValue() {
|
|
117
|
-
|
|
118
|
-
|
|
133
|
+
return Effect.suspend(() => Effect.fromResult(this.toValueResult()));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Synchronous {@link TomlDocument.toValue}, returning a `Result` — the
|
|
137
|
+
* second half of a synchronous document round-trip that starts at
|
|
138
|
+
* {@link TomlDocument.parseResult}. Fails with {@link TomlParseError}
|
|
139
|
+
* carrying the stored `diagnostics` when the parse recorded semantic
|
|
140
|
+
* violations.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* import { TomlDocument } from "@effected/toml";
|
|
145
|
+
* import { Result } from "effect";
|
|
146
|
+
*
|
|
147
|
+
* const parsed = TomlDocument.parseResult("a = 1\na = 2\n");
|
|
148
|
+
* if (Result.isSuccess(parsed)) {
|
|
149
|
+
* const value = parsed.success.toValueResult();
|
|
150
|
+
* console.log(Result.isFailure(value)); // => true — DuplicateKey
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @returns A `Result` succeeding with the plain value, or failing with
|
|
155
|
+
* {@link TomlParseError}.
|
|
156
|
+
*/
|
|
157
|
+
toValueResult() {
|
|
158
|
+
if (this.diagnostics.length > 0) return Result.fail(new TomlParseError({ diagnostics: this.diagnostics }));
|
|
159
|
+
return Result.try({
|
|
119
160
|
try: () => buildValue(this.expressions),
|
|
120
|
-
catch: (defect) =>
|
|
161
|
+
catch: (defect) => toTomlParseError(this.source, defect)
|
|
121
162
|
});
|
|
122
163
|
}
|
|
123
164
|
/**
|
|
@@ -133,5 +174,4 @@ var TomlDocument = class TomlDocument extends Schema.Class("TomlDocument")({
|
|
|
133
174
|
}
|
|
134
175
|
};
|
|
135
176
|
|
|
136
|
-
//#endregion
|
|
137
177
|
export { TomlDocument };
|
package/TomlEdit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/TomlEdit.ts
|
|
4
4
|
/**
|
|
5
5
|
* A range within a TOML document, expressed as a zero-based character
|
|
6
6
|
* `offset` and a `length` in UTF-16 code units. Pass to `TomlFormat.format`
|
|
@@ -52,5 +52,4 @@ var TomlEdit = class extends Schema.Class("TomlEdit")({
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
//#endregion
|
|
56
55
|
export { TomlEdit, TomlRange };
|
package/TomlFormat.js
CHANGED
|
@@ -7,9 +7,9 @@ import { renderInlineValue, renderKey } from "./internal/stringifyValue.js";
|
|
|
7
7
|
import { TomlDiagnostic } from "./TomlDiagnostic.js";
|
|
8
8
|
import { TomlDocument } from "./TomlDocument.js";
|
|
9
9
|
import { TomlEdit } from "./TomlEdit.js";
|
|
10
|
-
import { Effect, Schema } from "effect";
|
|
10
|
+
import { Effect, Result, Schema } from "effect";
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
// src/TomlFormat.ts
|
|
13
13
|
/**
|
|
14
14
|
* Options controlling formatting and modification behavior. The only knob is
|
|
15
15
|
* `newline`: for `format` it normalizes every newline outside multi-line
|
|
@@ -579,7 +579,9 @@ var TomlFormat = class TomlFormat {
|
|
|
579
579
|
}
|
|
580
580
|
/**
|
|
581
581
|
* Compute the edits that replace, delete, or insert a value at `path`,
|
|
582
|
-
*
|
|
582
|
+
* synchronously — the primitive {@link TomlFormat.modify} is defined in
|
|
583
|
+
* terms of, so a synchronous host can call it without an Effect runtime.
|
|
584
|
+
* Paths resolve through the document's semantic view. Every segment but the
|
|
583
585
|
* last must resolve — intermediate tables are never auto-created. A
|
|
584
586
|
* `value` of `undefined` deletes: a key-value's whole line, an inline
|
|
585
587
|
* entry, or an array item, splicing separators. A new key inserts per the
|
|
@@ -596,22 +598,24 @@ var TomlFormat = class TomlFormat {
|
|
|
596
598
|
* target instead.
|
|
597
599
|
* @param options - Optional {@link TomlFormattingOptions}; `newline` overrides
|
|
598
600
|
* the newline used for inserted lines.
|
|
599
|
-
* @returns
|
|
600
|
-
* `TomlEdit.applyAll`), or
|
|
601
|
+
* @returns A `Result` succeeding with the edits to apply (via
|
|
602
|
+
* `TomlEdit.applyAll`), or failing with {@link TomlParseError} when the
|
|
601
603
|
* source does not parse, or {@link TomlModificationError} when `path`
|
|
602
604
|
* cannot be resolved or the insertion target is not allowed.
|
|
603
605
|
*/
|
|
604
|
-
static
|
|
605
|
-
const failWith = (code, message, offset = 0, length = 0) => new TomlModificationError({ diagnostic: TomlDiagnostic.fromRaw(text, {
|
|
606
|
+
static modifyResult(text, path, value, options) {
|
|
607
|
+
const failWith = (code, message, offset = 0, length = 0) => Result.fail(new TomlModificationError({ diagnostic: TomlDiagnostic.fromRaw(text, {
|
|
606
608
|
code,
|
|
607
609
|
message,
|
|
608
610
|
offset,
|
|
609
611
|
length
|
|
610
|
-
}) });
|
|
611
|
-
if (path.length === 0) return
|
|
612
|
-
if (path.length > 256) return
|
|
613
|
-
const
|
|
614
|
-
if (
|
|
612
|
+
}) }));
|
|
613
|
+
if (path.length === 0) return failWith("DottedKeyConflict", "an empty path does not address a value");
|
|
614
|
+
if (path.length > 256) return failWith("NestingDepthExceeded", `path depth ${path.length} exceeds the ${256} cap`);
|
|
615
|
+
const parsed = TomlDocument.parseResult(text);
|
|
616
|
+
if (Result.isFailure(parsed)) return Result.fail(parsed.failure);
|
|
617
|
+
const doc = parsed.success;
|
|
618
|
+
if (doc.diagnostics.length > 0) return Result.fail(new TomlModificationError({ diagnostic: doc.diagnostics[0] }));
|
|
615
619
|
const { root, sections } = buildSemanticIndex(doc.expressions);
|
|
616
620
|
const ctx = {
|
|
617
621
|
source: text,
|
|
@@ -627,20 +631,73 @@ var TomlFormat = class TomlFormat {
|
|
|
627
631
|
for (let i = 0; i < path.length - 1; i++) cursor = step(cursor, path[i]);
|
|
628
632
|
raw = terminal(cursor, path[path.length - 1], value, ctx);
|
|
629
633
|
} catch (defect) {
|
|
630
|
-
if (defect instanceof ModifyFailure) return
|
|
631
|
-
if (isRawTomlError(defect)) return
|
|
632
|
-
if (isGuardExceeded(defect)) return
|
|
634
|
+
if (defect instanceof ModifyFailure) return failWith(defect.code, defect.message, defect.offset, defect.len);
|
|
635
|
+
if (isRawTomlError(defect)) return Result.fail(new TomlModificationError({ diagnostic: TomlDiagnostic.fromRaw(text, defect.diagnostic) }));
|
|
636
|
+
if (isGuardExceeded(defect)) return failWith("NestingDepthExceeded", defect.message, defect.offset);
|
|
633
637
|
throw defect;
|
|
634
638
|
}
|
|
635
|
-
return raw.map((edit) => TomlEdit.make({
|
|
639
|
+
return Result.succeed(raw.map((edit) => TomlEdit.make({
|
|
636
640
|
offset: edit.offset,
|
|
637
641
|
length: edit.length,
|
|
638
642
|
content: edit.newText
|
|
639
|
-
}));
|
|
640
|
-
}
|
|
643
|
+
})));
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Compute the edits that replace, delete, or insert a value at `path`.
|
|
647
|
+
* Defined in terms of {@link TomlFormat.modifyResult}, which carries the
|
|
648
|
+
* full contract — semantic path resolution, deletion splicing and the
|
|
649
|
+
* pinned insertion placement rules — behind a `TomlFormat.modify` span;
|
|
650
|
+
* synchronous callers can use that variant directly.
|
|
651
|
+
*
|
|
652
|
+
* @param text - The TOML source to modify.
|
|
653
|
+
* @param path - The location to set, replace or delete.
|
|
654
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
655
|
+
* target instead.
|
|
656
|
+
* @param options - Optional {@link TomlFormattingOptions}; `newline` overrides
|
|
657
|
+
* the newline used for inserted lines.
|
|
658
|
+
* @returns An `Effect` that succeeds with the edits to apply (via
|
|
659
|
+
* `TomlEdit.applyAll`), or fails with {@link TomlParseError} when the
|
|
660
|
+
* source does not parse, or {@link TomlModificationError} when `path`
|
|
661
|
+
* cannot be resolved or the insertion target is not allowed.
|
|
662
|
+
*
|
|
663
|
+
* @remarks
|
|
664
|
+
* The source is parsed through `TomlDocument.parseResult`, so this span no
|
|
665
|
+
* longer opens a nested `TomlDocument.parse` child span.
|
|
666
|
+
*/
|
|
667
|
+
static modify = Effect.fn("TomlFormat.modify")((text, path, value, options) => Effect.fromResult(TomlFormat.modifyResult(text, path, value, options)));
|
|
668
|
+
/**
|
|
669
|
+
* Synchronous {@link TomlFormat.modifyToString}: modify `text` and apply the
|
|
670
|
+
* resulting edits in one step (`TomlEdit.applyAll ∘ modifyResult`),
|
|
671
|
+
* returning a `Result`. Inherits the {@link TomlFormat.modifyResult} error
|
|
672
|
+
* channel.
|
|
673
|
+
*
|
|
674
|
+
* @example
|
|
675
|
+
* ```ts
|
|
676
|
+
* import { TomlFormat } from "@effected/toml";
|
|
677
|
+
* import { Result } from "effect";
|
|
678
|
+
*
|
|
679
|
+
* const result = TomlFormat.modifyToStringResult("port = 3000 # dev\n", ["port"], 8080);
|
|
680
|
+
* if (Result.isSuccess(result)) {
|
|
681
|
+
* console.log(result.success); // => "port = 8080 # dev\n"
|
|
682
|
+
* }
|
|
683
|
+
* ```
|
|
684
|
+
*
|
|
685
|
+
* @param text - The TOML source to modify.
|
|
686
|
+
* @param path - The location to set, replace or delete.
|
|
687
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
688
|
+
* target instead.
|
|
689
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
690
|
+
* @returns A `Result` succeeding with the modified text, or failing with
|
|
691
|
+
* {@link TomlParseError} or {@link TomlModificationError}.
|
|
692
|
+
*/
|
|
693
|
+
static modifyToStringResult(text, path, value, options) {
|
|
694
|
+
return Result.map(TomlFormat.modifyResult(text, path, value, options), (edits) => TomlEdit.applyAll(text, edits));
|
|
695
|
+
}
|
|
641
696
|
/**
|
|
642
697
|
* Modify `text` and apply the resulting edits in one step
|
|
643
|
-
* (`TomlEdit.applyAll ∘ modify`).
|
|
698
|
+
* (`TomlEdit.applyAll ∘ modify`). Defined in terms of
|
|
699
|
+
* {@link TomlFormat.modifyToStringResult}; it opens its own span and no
|
|
700
|
+
* longer a nested `TomlFormat.modify` child span.
|
|
644
701
|
*
|
|
645
702
|
* @param text - The TOML source to modify.
|
|
646
703
|
* @param path - The location to set, replace or delete.
|
|
@@ -651,11 +708,7 @@ var TomlFormat = class TomlFormat {
|
|
|
651
708
|
* {@link TomlParseError} or {@link TomlModificationError}, as
|
|
652
709
|
* {@link TomlFormat.modify} does.
|
|
653
710
|
*/
|
|
654
|
-
static modifyToString = Effect.fn("TomlFormat.modifyToString")(
|
|
655
|
-
const edits = yield* TomlFormat.modify(text, path, value, options);
|
|
656
|
-
return TomlEdit.applyAll(text, edits);
|
|
657
|
-
});
|
|
711
|
+
static modifyToString = Effect.fn("TomlFormat.modifyToString")((text, path, value, options) => Effect.fromResult(TomlFormat.modifyToStringResult(text, path, value, options)));
|
|
658
712
|
};
|
|
659
713
|
|
|
660
|
-
//#endregion
|
|
661
714
|
export { TomlFormat, TomlFormattingOptions, TomlModificationError };
|
package/TomlNode.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TomlLocalDate, TomlLocalDateTime, TomlLocalTime, TomlOffsetDateTime } from "./TomlDateTime.js";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/TomlNode.ts
|
|
5
5
|
/**
|
|
6
6
|
* The three simple-key spellings: `bare`, `basic` (`"..."`) and `literal`
|
|
7
7
|
* (`'...'`).
|
|
@@ -209,5 +209,4 @@ const TomlExpression = Schema.Union([
|
|
|
209
209
|
TomlTrivia
|
|
210
210
|
]);
|
|
211
211
|
|
|
212
|
-
//#endregion
|
|
213
212
|
export { TomlArray, TomlArrayTableHeader, TomlBoolean, TomlDateTimeLiteral, TomlExpression, TomlFloat, TomlInlineEntry, TomlInlineTable, TomlInteger, TomlKey, TomlKeyKind, TomlKeyValue, TomlString, TomlStringStyle, TomlTableHeader, TomlTrivia, TomlValueNode };
|
package/TomlVisitor.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { isRawTomlError } from "./internal/diagnostics.js";
|
|
2
|
-
import { isGuardExceeded } from "./internal/limits.js";
|
|
3
1
|
import { TomlKeyValue, TomlTrivia } from "./TomlNode.js";
|
|
4
2
|
import { scanComment, scanNewline, scanWhitespace } from "./internal/scanner.js";
|
|
5
3
|
import { parseExpressions } from "./internal/parser.js";
|
|
6
4
|
import { analyze } from "./internal/semantic.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { Data, Effect, Stream } from "effect";
|
|
5
|
+
import { toTomlParseError } from "./Toml.js";
|
|
6
|
+
import { Data, Effect, Result, Stream } from "effect";
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
// src/TomlVisitor.ts
|
|
12
9
|
/**
|
|
13
10
|
* Constructors and matchers for the `TomlVisitorEvent` union (e.g.
|
|
14
11
|
* `TomlVisitorEvent.KeyValue({ path, node })`, `TomlVisitorEvent.$is("Comment")`).
|
|
@@ -108,22 +105,14 @@ const collectEvents = (text) => {
|
|
|
108
105
|
};
|
|
109
106
|
/**
|
|
110
107
|
* Run `collectEvents`, materializing the engine's raw carriers into
|
|
111
|
-
* {@link TomlParseError}
|
|
112
|
-
* semantic-pass error (e.g.
|
|
108
|
+
* {@link TomlParseError} through the same `toTomlParseError` mapping
|
|
109
|
+
* `Toml.parse` uses — a lex/parse error and a semantic-pass error (e.g.
|
|
110
|
+
* `DuplicateKey`) both fail the same way.
|
|
113
111
|
*/
|
|
114
|
-
const collectEventsOrFail = (text) => Effect.try({
|
|
112
|
+
const collectEventsOrFail = (text) => Effect.suspend(() => Effect.fromResult(Result.try({
|
|
115
113
|
try: () => collectEvents(text),
|
|
116
|
-
catch: (defect) =>
|
|
117
|
-
|
|
118
|
-
if (isGuardExceeded(defect)) return new TomlParseError({ diagnostics: [TomlDiagnostic.fromRaw(text, {
|
|
119
|
-
code: "NestingDepthExceeded",
|
|
120
|
-
message: defect.message,
|
|
121
|
-
offset: defect.offset,
|
|
122
|
-
length: 0
|
|
123
|
-
})] });
|
|
124
|
-
throw defect;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
114
|
+
catch: (defect) => toTomlParseError(text, defect)
|
|
115
|
+
})));
|
|
127
116
|
/**
|
|
128
117
|
* Walks TOML text as a `Stream` of table, array-table, key-value and comment
|
|
129
118
|
* events in document order, without building a value. Not instantiable.
|
|
@@ -162,5 +151,4 @@ var TomlVisitor = class {
|
|
|
162
151
|
}
|
|
163
152
|
};
|
|
164
153
|
|
|
165
|
-
//#endregion
|
|
166
154
|
export { TomlVisitor, TomlVisitorEvent };
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Data, Effect, Result, Schema, Stream } from "effect";
|
|
2
|
-
//#region src/TomlDiagnostic.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Error codes emitted by the lexer stage.
|
|
5
4
|
*
|
|
@@ -99,8 +98,6 @@ export declare class TomlDiagnostic extends TomlDiagnostic_base {
|
|
|
99
98
|
readonly length: number;
|
|
100
99
|
}): TomlDiagnostic;
|
|
101
100
|
}
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/Toml.d.ts
|
|
104
101
|
declare const TomlStringifyOptions_base: Schema.Class<TomlStringifyOptions, Schema.Struct<{
|
|
105
102
|
readonly newline: Schema.optionalKey<Schema.Literals<readonly ["\n", "\r\n"]>>;
|
|
106
103
|
}>, {}>;
|
|
@@ -360,8 +357,6 @@ export declare class Toml {
|
|
|
360
357
|
*/
|
|
361
358
|
static bind<T, E, RD = never, RE = never>(target: Schema.Codec<T, E, RD, RE>): TomlBoundCodec<T, RD, RE>;
|
|
362
359
|
}
|
|
363
|
-
//#endregion
|
|
364
|
-
//#region src/TomlDateTime.d.ts
|
|
365
360
|
declare const TomlLocalDate_base: Schema.Class<TomlLocalDate, Schema.Struct<{
|
|
366
361
|
year: Schema.Int;
|
|
367
362
|
month: Schema.Int;
|
|
@@ -429,8 +424,6 @@ declare const TomlOffsetDateTime_base: Schema.Class<TomlOffsetDateTime, Schema.S
|
|
|
429
424
|
export declare class TomlOffsetDateTime extends TomlOffsetDateTime_base {
|
|
430
425
|
toString(): string;
|
|
431
426
|
}
|
|
432
|
-
//#endregion
|
|
433
|
-
//#region src/TomlNode.d.ts
|
|
434
427
|
/**
|
|
435
428
|
* The three simple-key spellings: `bare`, `basic` (`"..."`) and `literal`
|
|
436
429
|
* (`'...'`).
|
|
@@ -647,8 +640,6 @@ export declare const TomlExpression: Schema.Union<readonly [typeof TomlKeyValue,
|
|
|
647
640
|
* @public
|
|
648
641
|
*/
|
|
649
642
|
export type TomlExpression = typeof TomlExpression.Type;
|
|
650
|
-
//#endregion
|
|
651
|
-
//#region src/TomlDocument.d.ts
|
|
652
643
|
declare const TomlDocument_base: Schema.Class<TomlDocument, Schema.Struct<{
|
|
653
644
|
readonly source: Schema.String;
|
|
654
645
|
readonly expressions: Schema.$Array<Schema.Union<readonly [typeof TomlKeyValue, typeof TomlTableHeader, typeof TomlArrayTableHeader, typeof TomlTrivia]>>;
|
|
@@ -687,13 +678,40 @@ declare const TomlDocument_base: Schema.Class<TomlDocument, Schema.Struct<{
|
|
|
687
678
|
* @public
|
|
688
679
|
*/
|
|
689
680
|
export declare class TomlDocument extends TomlDocument_base {
|
|
681
|
+
/**
|
|
682
|
+
* Synchronous {@link TomlDocument.parse}, returning a `Result` instead of
|
|
683
|
+
* an `Effect` — the primitive `parse` is defined in terms of, so a
|
|
684
|
+
* synchronous host can call it without an Effect runtime. Fails with
|
|
685
|
+
* {@link TomlParseError} only on lex/parse errors — including a
|
|
686
|
+
* nesting-depth bomb, which surfaces as a `NestingDepthExceeded`
|
|
687
|
+
* diagnostic, never a throw. Semantic violations do not fail: they land in
|
|
688
|
+
* `diagnostics` as data (first violation wins, so there is at most one
|
|
689
|
+
* today; the array shape is the contract).
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* ```ts
|
|
693
|
+
* import { TomlDocument } from "@effected/toml";
|
|
694
|
+
* import { Result } from "effect";
|
|
695
|
+
*
|
|
696
|
+
* const result = TomlDocument.parseResult('name = "Alice"\n');
|
|
697
|
+
* if (Result.isSuccess(result)) {
|
|
698
|
+
* console.log(result.success.stringify()); // => 'name = "Alice"\n'
|
|
699
|
+
* }
|
|
700
|
+
* ```
|
|
701
|
+
*
|
|
702
|
+
* @param text - The TOML source to parse.
|
|
703
|
+
* @returns A `Result` succeeding with the {@link TomlDocument}, or failing
|
|
704
|
+
* with {@link TomlParseError}.
|
|
705
|
+
*/
|
|
706
|
+
static parseResult(text: string): Result.Result<TomlDocument, TomlParseError>;
|
|
690
707
|
/**
|
|
691
708
|
* Parse TOML text into a lossless document. Fails with
|
|
692
709
|
* {@link TomlParseError} only on lex/parse errors — including a
|
|
693
710
|
* nesting-depth bomb, which surfaces as a `NestingDepthExceeded`
|
|
694
711
|
* diagnostic, never an unhandled defect. Semantic violations do not fail:
|
|
695
|
-
* they land in `diagnostics` as data
|
|
696
|
-
*
|
|
712
|
+
* they land in `diagnostics` as data. Defined in terms of
|
|
713
|
+
* {@link TomlDocument.parseResult} — synchronous callers can use that
|
|
714
|
+
* variant directly.
|
|
697
715
|
*
|
|
698
716
|
* @param text - The TOML source to parse.
|
|
699
717
|
* @returns An `Effect` that succeeds with the {@link TomlDocument}, or fails
|
|
@@ -715,9 +733,37 @@ export declare class TomlDocument extends TomlDocument_base {
|
|
|
715
733
|
* {@link TomlParseError} carrying the stored `diagnostics` when the parse
|
|
716
734
|
* recorded semantic violations; otherwise builds the value from the
|
|
717
735
|
* expression list (already validated, so the defensive materialization
|
|
718
|
-
* wrapper is belt-and-suspenders).
|
|
736
|
+
* wrapper is belt-and-suspenders). Defined in terms of
|
|
737
|
+
* {@link TomlDocument.toValueResult} — synchronous callers can use that
|
|
738
|
+
* variant directly.
|
|
739
|
+
*
|
|
740
|
+
* @returns An `Effect` that succeeds with the plain value, or fails with
|
|
741
|
+
* {@link TomlParseError}.
|
|
719
742
|
*/
|
|
720
743
|
toValue(): Effect.Effect<unknown, TomlParseError>;
|
|
744
|
+
/**
|
|
745
|
+
* Synchronous {@link TomlDocument.toValue}, returning a `Result` — the
|
|
746
|
+
* second half of a synchronous document round-trip that starts at
|
|
747
|
+
* {@link TomlDocument.parseResult}. Fails with {@link TomlParseError}
|
|
748
|
+
* carrying the stored `diagnostics` when the parse recorded semantic
|
|
749
|
+
* violations.
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* ```ts
|
|
753
|
+
* import { TomlDocument } from "@effected/toml";
|
|
754
|
+
* import { Result } from "effect";
|
|
755
|
+
*
|
|
756
|
+
* const parsed = TomlDocument.parseResult("a = 1\na = 2\n");
|
|
757
|
+
* if (Result.isSuccess(parsed)) {
|
|
758
|
+
* const value = parsed.success.toValueResult();
|
|
759
|
+
* console.log(Result.isFailure(value)); // => true — DuplicateKey
|
|
760
|
+
* }
|
|
761
|
+
* ```
|
|
762
|
+
*
|
|
763
|
+
* @returns A `Result` succeeding with the plain value, or failing with
|
|
764
|
+
* {@link TomlParseError}.
|
|
765
|
+
*/
|
|
766
|
+
toValueResult(): Result.Result<unknown, TomlParseError>;
|
|
721
767
|
/**
|
|
722
768
|
* Reconstruct the document text by concatenating each expression's source
|
|
723
769
|
* span in order. The expression spans tile the source exactly, so the
|
|
@@ -726,8 +772,6 @@ export declare class TomlDocument extends TomlDocument_base {
|
|
|
726
772
|
*/
|
|
727
773
|
stringify(): string;
|
|
728
774
|
}
|
|
729
|
-
//#endregion
|
|
730
|
-
//#region src/TomlEdit.d.ts
|
|
731
775
|
/**
|
|
732
776
|
* A single path segment: a `string` for table keys or a `number` for array
|
|
733
777
|
* and array-of-tables indices.
|
|
@@ -784,8 +828,6 @@ export declare class TomlEdit extends TomlEdit_base {
|
|
|
784
828
|
*/
|
|
785
829
|
static applyAll(text: string, edits: ReadonlyArray<TomlEdit>): string;
|
|
786
830
|
}
|
|
787
|
-
//#endregion
|
|
788
|
-
//#region src/TomlFormat.d.ts
|
|
789
831
|
/**
|
|
790
832
|
* A range accepted at the `format`/`formatToString` call sites: either a
|
|
791
833
|
* {@link TomlRange} instance or a plain `{ offset, length }` literal (the two
|
|
@@ -887,7 +929,9 @@ export declare class TomlFormat {
|
|
|
887
929
|
static formatToString(text: string, range?: TomlRangeLike, options?: TomlFormattingOptions): string;
|
|
888
930
|
/**
|
|
889
931
|
* Compute the edits that replace, delete, or insert a value at `path`,
|
|
890
|
-
*
|
|
932
|
+
* synchronously — the primitive {@link TomlFormat.modify} is defined in
|
|
933
|
+
* terms of, so a synchronous host can call it without an Effect runtime.
|
|
934
|
+
* Paths resolve through the document's semantic view. Every segment but the
|
|
891
935
|
* last must resolve — intermediate tables are never auto-created. A
|
|
892
936
|
* `value` of `undefined` deletes: a key-value's whole line, an inline
|
|
893
937
|
* entry, or an array item, splicing separators. A new key inserts per the
|
|
@@ -904,15 +948,66 @@ export declare class TomlFormat {
|
|
|
904
948
|
* target instead.
|
|
905
949
|
* @param options - Optional {@link TomlFormattingOptions}; `newline` overrides
|
|
906
950
|
* the newline used for inserted lines.
|
|
951
|
+
* @returns A `Result` succeeding with the edits to apply (via
|
|
952
|
+
* `TomlEdit.applyAll`), or failing with {@link TomlParseError} when the
|
|
953
|
+
* source does not parse, or {@link TomlModificationError} when `path`
|
|
954
|
+
* cannot be resolved or the insertion target is not allowed.
|
|
955
|
+
*/
|
|
956
|
+
static modifyResult(text: string, path: TomlPath, value: unknown, options?: TomlFormattingOptions): Result.Result<ReadonlyArray<TomlEdit>, TomlParseError | TomlModificationError>;
|
|
957
|
+
/**
|
|
958
|
+
* Compute the edits that replace, delete, or insert a value at `path`.
|
|
959
|
+
* Defined in terms of {@link TomlFormat.modifyResult}, which carries the
|
|
960
|
+
* full contract — semantic path resolution, deletion splicing and the
|
|
961
|
+
* pinned insertion placement rules — behind a `TomlFormat.modify` span;
|
|
962
|
+
* synchronous callers can use that variant directly.
|
|
963
|
+
*
|
|
964
|
+
* @param text - The TOML source to modify.
|
|
965
|
+
* @param path - The location to set, replace or delete.
|
|
966
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
967
|
+
* target instead.
|
|
968
|
+
* @param options - Optional {@link TomlFormattingOptions}; `newline` overrides
|
|
969
|
+
* the newline used for inserted lines.
|
|
907
970
|
* @returns An `Effect` that succeeds with the edits to apply (via
|
|
908
971
|
* `TomlEdit.applyAll`), or fails with {@link TomlParseError} when the
|
|
909
972
|
* source does not parse, or {@link TomlModificationError} when `path`
|
|
910
973
|
* cannot be resolved or the insertion target is not allowed.
|
|
974
|
+
*
|
|
975
|
+
* @remarks
|
|
976
|
+
* The source is parsed through `TomlDocument.parseResult`, so this span no
|
|
977
|
+
* longer opens a nested `TomlDocument.parse` child span.
|
|
911
978
|
*/
|
|
912
979
|
static readonly modify: (text: string, path: TomlPath, value: unknown, options?: TomlFormattingOptions | undefined) => Effect.Effect<readonly TomlEdit[], TomlModificationError | TomlParseError, never>;
|
|
980
|
+
/**
|
|
981
|
+
* Synchronous {@link TomlFormat.modifyToString}: modify `text` and apply the
|
|
982
|
+
* resulting edits in one step (`TomlEdit.applyAll ∘ modifyResult`),
|
|
983
|
+
* returning a `Result`. Inherits the {@link TomlFormat.modifyResult} error
|
|
984
|
+
* channel.
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```ts
|
|
988
|
+
* import { TomlFormat } from "@effected/toml";
|
|
989
|
+
* import { Result } from "effect";
|
|
990
|
+
*
|
|
991
|
+
* const result = TomlFormat.modifyToStringResult("port = 3000 # dev\n", ["port"], 8080);
|
|
992
|
+
* if (Result.isSuccess(result)) {
|
|
993
|
+
* console.log(result.success); // => "port = 8080 # dev\n"
|
|
994
|
+
* }
|
|
995
|
+
* ```
|
|
996
|
+
*
|
|
997
|
+
* @param text - The TOML source to modify.
|
|
998
|
+
* @param path - The location to set, replace or delete.
|
|
999
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
1000
|
+
* target instead.
|
|
1001
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
1002
|
+
* @returns A `Result` succeeding with the modified text, or failing with
|
|
1003
|
+
* {@link TomlParseError} or {@link TomlModificationError}.
|
|
1004
|
+
*/
|
|
1005
|
+
static modifyToStringResult(text: string, path: TomlPath, value: unknown, options?: TomlFormattingOptions): Result.Result<string, TomlParseError | TomlModificationError>;
|
|
913
1006
|
/**
|
|
914
1007
|
* Modify `text` and apply the resulting edits in one step
|
|
915
|
-
* (`TomlEdit.applyAll ∘ modify`).
|
|
1008
|
+
* (`TomlEdit.applyAll ∘ modify`). Defined in terms of
|
|
1009
|
+
* {@link TomlFormat.modifyToStringResult}; it opens its own span and no
|
|
1010
|
+
* longer a nested `TomlFormat.modify` child span.
|
|
916
1011
|
*
|
|
917
1012
|
* @param text - The TOML source to modify.
|
|
918
1013
|
* @param path - The location to set, replace or delete.
|
|
@@ -925,8 +1020,6 @@ export declare class TomlFormat {
|
|
|
925
1020
|
*/
|
|
926
1021
|
static readonly modifyToString: (text: string, path: TomlPath, value: unknown, options?: TomlFormattingOptions | undefined) => Effect.Effect<string, TomlModificationError | TomlParseError, never>;
|
|
927
1022
|
}
|
|
928
|
-
//#endregion
|
|
929
|
-
//#region src/TomlVisitor.d.ts
|
|
930
1023
|
/**
|
|
931
1024
|
* The discriminated union of TOML visitor events, in document order.
|
|
932
1025
|
* `TableStart` fires once for the root with `path: []` before any other
|
|
@@ -1116,6 +1209,5 @@ export declare class TomlVisitor {
|
|
|
1116
1209
|
*/
|
|
1117
1210
|
static visit(text: string): Stream.Stream<TomlVisitorEvent, TomlParseError>;
|
|
1118
1211
|
}
|
|
1119
|
-
//#endregion
|
|
1120
1212
|
export type { TomlBoundCodec, TomlPath, TomlRangeLike, TomlSegment };
|
|
1121
1213
|
//# sourceMappingURL=index.d.ts.map
|
package/internal/diagnostics.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal/diagnostics.ts
|
|
2
2
|
const TOML_LEX_ERROR_CODES = [
|
|
3
3
|
"InvalidUtf8",
|
|
4
4
|
"UnterminatedString",
|
|
@@ -47,5 +47,4 @@ var RawTomlError = class extends Error {
|
|
|
47
47
|
};
|
|
48
48
|
const isRawTomlError = (u) => u instanceof RawTomlError;
|
|
49
49
|
|
|
50
|
-
//#endregion
|
|
51
50
|
export { RawTomlError, TOML_LEX_ERROR_CODES, TOML_PARSE_ERROR_CODES, TOML_SEMANTIC_ERROR_CODES, TOML_STRINGIFY_ERROR_CODES, isRawTomlError };
|
package/internal/limits.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/internal/limits.ts
|
|
2
2
|
/**
|
|
3
3
|
* Raw guard-trip signal. The engine throws it; ONLY the public modules catch
|
|
4
4
|
* it and materialize the typed error. It must never escape a public entry
|
|
@@ -20,5 +20,4 @@ var GuardExceeded = class extends Error {
|
|
|
20
20
|
};
|
|
21
21
|
const isGuardExceeded = (u) => u instanceof GuardExceeded;
|
|
22
22
|
|
|
23
|
-
//#endregion
|
|
24
23
|
export { GuardExceeded, isGuardExceeded };
|
package/internal/parser.js
CHANGED
|
@@ -4,7 +4,7 @@ import { TomlLocalDate, TomlLocalDateTime, TomlLocalTime, TomlOffsetDateTime } f
|
|
|
4
4
|
import { TomlArray, TomlArrayTableHeader, TomlBoolean, TomlDateTimeLiteral, TomlFloat, TomlInlineEntry, TomlInlineTable, TomlInteger, TomlKey, TomlKeyValue, TomlString, TomlTableHeader, TomlTrivia } from "../TomlNode.js";
|
|
5
5
|
import { assertValidUnicode, classifyValueToken, scanBareKey, scanBasicString, scanComment, scanLiteralString, scanMultilineBasicString, scanMultilineLiteralString, scanNewline, scanValueToken, scanWhitespace, skipBom } from "./scanner.js";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/internal/parser.ts
|
|
8
8
|
const LF = 10;
|
|
9
9
|
const CR = 13;
|
|
10
10
|
const QUOTE = 34;
|
|
@@ -400,5 +400,4 @@ const parseExpressions = (source) => {
|
|
|
400
400
|
return expressions;
|
|
401
401
|
};
|
|
402
402
|
|
|
403
|
-
//#endregion
|
|
404
403
|
export { parseExpressions };
|
package/internal/scanner.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RawTomlError } from "./diagnostics.js";
|
|
2
2
|
import { TomlLocalDate, TomlLocalDateTime, TomlLocalTime, TomlOffsetDateTime } from "../TomlDateTime.js";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/internal/scanner.ts
|
|
5
5
|
const NUL = 0;
|
|
6
6
|
const TAB = 9;
|
|
7
7
|
const LF = 10;
|
|
@@ -503,5 +503,4 @@ const classifyValueToken = (token, offset) => {
|
|
|
503
503
|
return raise("InvalidValue", `${token} is not a valid TOML value`, offset, length);
|
|
504
504
|
};
|
|
505
505
|
|
|
506
|
-
//#endregion
|
|
507
506
|
export { assertValidUnicode, classifyValueToken, isBareKeyChar, scanBareKey, scanBasicString, scanComment, scanLiteralString, scanMultilineBasicString, scanMultilineLiteralString, scanNewline, scanValueToken, scanWhitespace, skipBom };
|
package/internal/semantic.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RawTomlError } from "./diagnostics.js";
|
|
2
2
|
import { TomlArray, TomlArrayTableHeader, TomlInlineTable, TomlTableHeader, TomlTrivia } from "../TomlNode.js";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/internal/semantic.ts
|
|
5
5
|
const makeNode = (kind, sectionId = 0) => ({
|
|
6
6
|
kind,
|
|
7
7
|
table: /* @__PURE__ */ new Map(),
|
|
@@ -249,5 +249,4 @@ const buildValue = (expressions) => {
|
|
|
249
249
|
return result;
|
|
250
250
|
};
|
|
251
251
|
|
|
252
|
-
//#endregion
|
|
253
252
|
export { analyze, buildValue };
|
|
@@ -2,7 +2,7 @@ import { RawTomlError } from "./diagnostics.js";
|
|
|
2
2
|
import { GuardExceeded } from "./limits.js";
|
|
3
3
|
import { TomlLocalDate, TomlLocalDateTime, TomlLocalTime, TomlOffsetDateTime } from "../TomlDateTime.js";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/internal/stringifyValue.ts
|
|
6
6
|
const INT64_MIN = -(2n ** 63n);
|
|
7
7
|
const INT64_MAX = 2n ** 63n - 1n;
|
|
8
8
|
const INT64_FLOAT_BOUND = 2 ** 63;
|
|
@@ -187,5 +187,4 @@ const stringifyValue = (value, newline) => {
|
|
|
187
187
|
return lines.length === 0 ? "" : `${lines.join(newline)}${newline}`;
|
|
188
188
|
};
|
|
189
189
|
|
|
190
|
-
//#endregion
|
|
191
190
|
export { renderInlineValue, renderKey, stringifyValue };
|
package/package.json
CHANGED