@effected/toml 0.10.0 → 0.11.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/README.md +4 -4
- package/Toml.js +3 -0
- package/TomlDiagnostic.js +5 -1
- package/TomlDocument.js +4 -0
- package/TomlEdit.js +7 -3
- package/TomlFormat.js +50 -2
- package/TomlVisitor.js +15 -1
- package/index.d.ts +87 -8
- package/internal/parser.js +1 -1
- package/internal/scanner.js +2 -2
- package/internal/semantic.js +6 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
Zero-dependency TOML 1.1.0 parsing, editing and formatting expressed as Effect schemas and pure functions. Parse TOML into plain values or a byte-exact linear CST, compute comment-preserving edits, format, modify by path, walk a document as a `Stream`, and decode straight into a validated domain schema.
|
|
9
9
|
|
|
10
|
-
> **Pre
|
|
11
|
-
>
|
|
12
|
-
> `1.0.0`
|
|
13
|
-
>
|
|
10
|
+
> **Pre-`1.0.0`.** This package is part of the `@effected/*` kit, built on stable
|
|
11
|
+
> Effect v4 (`effect` `^4.0.0`) and still in `0.x` development. Stable Effect
|
|
12
|
+
> makes a kit `1.0.0` possible, not automatic. To keep your `effect` and
|
|
13
|
+
> `@effect/*` versions on the line the kit is built and tested against, install
|
|
14
14
|
> [`@effected/pnpm-plugin-effect`](https://www.npmjs.com/package/@effected/pnpm-plugin-effect).
|
|
15
15
|
>
|
|
16
16
|
> **Stability: unstable.** This package's API surface is not yet considered
|
package/Toml.js
CHANGED
|
@@ -244,6 +244,9 @@ var Toml = class Toml {
|
|
|
244
244
|
*
|
|
245
245
|
* Schema-producing: bind the result to a `const` on hot paths (see
|
|
246
246
|
* {@link Toml.fromString}).
|
|
247
|
+
*
|
|
248
|
+
* @param target - The domain schema decoded values must satisfy.
|
|
249
|
+
* @returns A `Schema.Codec<T, string>` decoding TOML text straight into `T`.
|
|
247
250
|
*/
|
|
248
251
|
static schema(target) {
|
|
249
252
|
return Toml.TomlFromString.pipe(Schema.decodeTo(target));
|
package/TomlDiagnostic.js
CHANGED
|
@@ -61,8 +61,12 @@ var TomlDiagnostic = class TomlDiagnostic extends Schema.Class("TomlDiagnostic")
|
|
|
61
61
|
}) {
|
|
62
62
|
/**
|
|
63
63
|
* Materialize an engine record, deriving `line`/`character` (0-based)
|
|
64
|
-
* from `offset` against the source
|
|
64
|
+
* from `offset` against the source text. Advanced — the parse/stringify
|
|
65
65
|
* entry points call this for you.
|
|
66
|
+
*
|
|
67
|
+
* @param source - The source text the record's `offset` indexes into.
|
|
68
|
+
* @param raw - The engine record: `code`, `message`, `offset` and `length`.
|
|
69
|
+
* @returns The diagnostic with `line` and `character` filled in.
|
|
66
70
|
*/
|
|
67
71
|
static fromRaw(source, raw) {
|
|
68
72
|
const { line, character } = lineChar(source, raw.offset);
|
package/TomlDocument.js
CHANGED
|
@@ -68,6 +68,10 @@ var TomlDocument = class TomlDocument extends Schema.Class("TomlDocument")({
|
|
|
68
68
|
* diagnostic, never an unhandled defect. Semantic violations do not fail:
|
|
69
69
|
* they land in `diagnostics` as data (first violation wins, so there is at
|
|
70
70
|
* most one today; the array shape is the contract).
|
|
71
|
+
*
|
|
72
|
+
* @param text - The TOML source to parse.
|
|
73
|
+
* @returns An `Effect` that succeeds with the {@link TomlDocument}, or fails
|
|
74
|
+
* with {@link TomlParseError}.
|
|
71
75
|
*/
|
|
72
76
|
static parse = Effect.fn("TomlDocument.parse")(function* (text) {
|
|
73
77
|
const expressions = yield* Effect.try({
|
package/TomlEdit.js
CHANGED
|
@@ -17,9 +17,9 @@ var TomlRange = class extends Schema.Class("TomlRange")({
|
|
|
17
17
|
* `content`. Set `length` to `0` to insert, `content` to `""` to delete.
|
|
18
18
|
*
|
|
19
19
|
* @remarks
|
|
20
|
-
* Structurally identical to
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Structurally identical to the edit shapes of `@effected/jsonc`,
|
|
21
|
+
* `@effected/yaml` and `@effected/markdown` (same field names, types and
|
|
22
|
+
* semantics), so consumer code can be written once over "a document codec's
|
|
23
23
|
* Edit/Range/Path".
|
|
24
24
|
*
|
|
25
25
|
* @public
|
|
@@ -34,6 +34,10 @@ var TomlEdit = class extends Schema.Class("TomlEdit")({
|
|
|
34
34
|
* reverse-offset order so earlier offsets stay valid; the input `edits`
|
|
35
35
|
* array is not mutated. Overlapping edits are a programmer error and throw
|
|
36
36
|
* as a defect — `TomlFormat` never produces them.
|
|
37
|
+
*
|
|
38
|
+
* @param text - The source text to edit.
|
|
39
|
+
* @param edits - The edits to apply, in any order.
|
|
40
|
+
* @returns The edited text.
|
|
37
41
|
*/
|
|
38
42
|
static applyAll(text, edits) {
|
|
39
43
|
const sorted = [...edits].sort((a, b) => b.offset - a.offset);
|
package/TomlFormat.js
CHANGED
|
@@ -508,7 +508,22 @@ const terminal = (cur, segment, value, ctx) => {
|
|
|
508
508
|
return failResolve("DottedKeyConflict", "cannot address a key beneath a scalar value", node.offset, node.length);
|
|
509
509
|
};
|
|
510
510
|
/**
|
|
511
|
-
*
|
|
511
|
+
* Formats TOML text and modifies values at a path as byte-minimal edits that
|
|
512
|
+
* leave comments and layout elsewhere untouched. Not instantiable.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```ts
|
|
516
|
+
* import { TomlFormat } from "@effected/toml";
|
|
517
|
+
* import { Effect } from "effect";
|
|
518
|
+
*
|
|
519
|
+
* const formatted = TomlFormat.formatToString(' title="x" #note\n[server]\nport=1');
|
|
520
|
+
* // => 'title = "x" # note\n[server]\nport = 1\n'
|
|
521
|
+
*
|
|
522
|
+
* const program = Effect.gen(function* () {
|
|
523
|
+
* return yield* TomlFormat.modifyToString("[server]\nport = 1 # dev\n", ["server", "port"], 2);
|
|
524
|
+
* // => "[server]\nport = 2 # dev\n"
|
|
525
|
+
* });
|
|
526
|
+
* ```
|
|
512
527
|
*
|
|
513
528
|
* @remarks
|
|
514
529
|
* `format`/`formatToString` are pure and total: malformed input yields no
|
|
@@ -532,7 +547,14 @@ var TomlFormat = class TomlFormat {
|
|
|
532
547
|
* strings. Nothing else: no reordering, no blank-line collapsing, no value
|
|
533
548
|
* rewriting. `range` restricts edits to the expressions intersecting it.
|
|
534
549
|
* Non-mutating — apply with `TomlEdit.applyAll` (or use
|
|
535
|
-
* {@link TomlFormat.formatToString}).
|
|
550
|
+
* {@link TomlFormat.formatToString}). Pure and total.
|
|
551
|
+
*
|
|
552
|
+
* @param text - The TOML source to format.
|
|
553
|
+
* @param range - Optional sub-range; only edits whose expression intersects
|
|
554
|
+
* it are returned.
|
|
555
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
556
|
+
* @returns The edits that bring `text` (or `range`) to canonical shape;
|
|
557
|
+
* apply them with `TomlEdit.applyAll`.
|
|
536
558
|
*/
|
|
537
559
|
static format(text, range, options) {
|
|
538
560
|
const tagged = computeFormatEdits(text, options);
|
|
@@ -545,6 +567,12 @@ var TomlFormat = class TomlFormat {
|
|
|
545
567
|
/**
|
|
546
568
|
* Format `text` and apply the resulting edits in one step
|
|
547
569
|
* (`TomlEdit.applyAll ∘ format`). Pure and total.
|
|
570
|
+
*
|
|
571
|
+
* @param text - The TOML source to format.
|
|
572
|
+
* @param range - Optional sub-range; only edits whose expression intersects
|
|
573
|
+
* it are applied.
|
|
574
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
575
|
+
* @returns The formatted text.
|
|
548
576
|
*/
|
|
549
577
|
static formatToString(text, range, options) {
|
|
550
578
|
return TomlEdit.applyAll(text, TomlFormat.format(text, range, options));
|
|
@@ -561,6 +589,17 @@ var TomlFormat = class TomlFormat {
|
|
|
561
589
|
* section; inline and implicitly created tables refuse. Inserted lines
|
|
562
590
|
* inherit the document's dominant newline unless `options.newline`
|
|
563
591
|
* overrides it. Every modified document reparses cleanly.
|
|
592
|
+
*
|
|
593
|
+
* @param text - The TOML source to modify.
|
|
594
|
+
* @param path - The location to set, replace or delete.
|
|
595
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
596
|
+
* target instead.
|
|
597
|
+
* @param options - Optional {@link TomlFormattingOptions}; `newline` overrides
|
|
598
|
+
* the newline used for inserted lines.
|
|
599
|
+
* @returns An `Effect` that succeeds with the edits to apply (via
|
|
600
|
+
* `TomlEdit.applyAll`), or fails with {@link TomlParseError} when the
|
|
601
|
+
* source does not parse, or {@link TomlModificationError} when `path`
|
|
602
|
+
* cannot be resolved or the insertion target is not allowed.
|
|
564
603
|
*/
|
|
565
604
|
static modify = Effect.fn("TomlFormat.modify")(function* (text, path, value, options) {
|
|
566
605
|
const failWith = (code, message, offset = 0, length = 0) => new TomlModificationError({ diagnostic: TomlDiagnostic.fromRaw(text, {
|
|
@@ -602,6 +641,15 @@ var TomlFormat = class TomlFormat {
|
|
|
602
641
|
/**
|
|
603
642
|
* Modify `text` and apply the resulting edits in one step
|
|
604
643
|
* (`TomlEdit.applyAll ∘ modify`).
|
|
644
|
+
*
|
|
645
|
+
* @param text - The TOML source to modify.
|
|
646
|
+
* @param path - The location to set, replace or delete.
|
|
647
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
648
|
+
* target instead.
|
|
649
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
650
|
+
* @returns An `Effect` that succeeds with the modified text, or fails with
|
|
651
|
+
* {@link TomlParseError} or {@link TomlModificationError}, as
|
|
652
|
+
* {@link TomlFormat.modify} does.
|
|
605
653
|
*/
|
|
606
654
|
static modifyToString = Effect.fn("TomlFormat.modifyToString")(function* (text, path, value, options) {
|
|
607
655
|
const edits = yield* TomlFormat.modify(text, path, value, options);
|
package/TomlVisitor.js
CHANGED
|
@@ -125,7 +125,21 @@ const collectEventsOrFail = (text) => Effect.try({
|
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
127
|
/**
|
|
128
|
-
*
|
|
128
|
+
* Walks TOML text as a `Stream` of table, array-table, key-value and comment
|
|
129
|
+
* events in document order, without building a value. Not instantiable.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { TomlVisitor, TomlVisitorEvent } from "@effected/toml";
|
|
134
|
+
* import { Effect, Stream } from "effect";
|
|
135
|
+
*
|
|
136
|
+
* const keys = TomlVisitor.visit("[server]\nport = 1\n").pipe(
|
|
137
|
+
* Stream.filter(TomlVisitorEvent.$is("KeyValue")),
|
|
138
|
+
* Stream.map((event) => event.path.join(".")),
|
|
139
|
+
* Stream.runCollect,
|
|
140
|
+
* );
|
|
141
|
+
* // Effect.runSync(keys) // => ["server.port"]
|
|
142
|
+
* ```
|
|
129
143
|
*
|
|
130
144
|
* @public
|
|
131
145
|
*/
|
package/index.d.ts
CHANGED
|
@@ -85,8 +85,12 @@ declare const TomlDiagnostic_base: Schema.Class<TomlDiagnostic, Schema.Struct<{
|
|
|
85
85
|
export declare class TomlDiagnostic extends TomlDiagnostic_base {
|
|
86
86
|
/**
|
|
87
87
|
* Materialize an engine record, deriving `line`/`character` (0-based)
|
|
88
|
-
* from `offset` against the source
|
|
88
|
+
* from `offset` against the source text. Advanced — the parse/stringify
|
|
89
89
|
* entry points call this for you.
|
|
90
|
+
*
|
|
91
|
+
* @param source - The source text the record's `offset` indexes into.
|
|
92
|
+
* @param raw - The engine record: `code`, `message`, `offset` and `length`.
|
|
93
|
+
* @returns The diagnostic with `line` and `character` filled in.
|
|
90
94
|
*/
|
|
91
95
|
static fromRaw(source: string, raw: {
|
|
92
96
|
readonly code: TomlErrorCode;
|
|
@@ -307,6 +311,9 @@ export declare class Toml {
|
|
|
307
311
|
*
|
|
308
312
|
* Schema-producing: bind the result to a `const` on hot paths (see
|
|
309
313
|
* {@link Toml.fromString}).
|
|
314
|
+
*
|
|
315
|
+
* @param target - The domain schema decoded values must satisfy.
|
|
316
|
+
* @returns A `Schema.Codec<T, string>` decoding TOML text straight into `T`.
|
|
310
317
|
*/
|
|
311
318
|
static schema<T, E, RD = never, RE = never>(target: Schema.Codec<T, E, RD, RE>): Schema.Codec<T, string, RD, RE>;
|
|
312
319
|
/**
|
|
@@ -680,6 +687,10 @@ export declare class TomlDocument extends TomlDocument_base {
|
|
|
680
687
|
* diagnostic, never an unhandled defect. Semantic violations do not fail:
|
|
681
688
|
* they land in `diagnostics` as data (first violation wins, so there is at
|
|
682
689
|
* most one today; the array shape is the contract).
|
|
690
|
+
*
|
|
691
|
+
* @param text - The TOML source to parse.
|
|
692
|
+
* @returns An `Effect` that succeeds with the {@link TomlDocument}, or fails
|
|
693
|
+
* with {@link TomlParseError}.
|
|
683
694
|
*/
|
|
684
695
|
static readonly parse: (text: string) => Effect.Effect<TomlDocument, TomlParseError, never>;
|
|
685
696
|
/**
|
|
@@ -746,9 +757,9 @@ declare const TomlEdit_base: Schema.Class<TomlEdit, Schema.Struct<{
|
|
|
746
757
|
* `content`. Set `length` to `0` to insert, `content` to `""` to delete.
|
|
747
758
|
*
|
|
748
759
|
* @remarks
|
|
749
|
-
* Structurally identical to
|
|
750
|
-
*
|
|
751
|
-
*
|
|
760
|
+
* Structurally identical to the edit shapes of `@effected/jsonc`,
|
|
761
|
+
* `@effected/yaml` and `@effected/markdown` (same field names, types and
|
|
762
|
+
* semantics), so consumer code can be written once over "a document codec's
|
|
752
763
|
* Edit/Range/Path".
|
|
753
764
|
*
|
|
754
765
|
* @public
|
|
@@ -759,6 +770,10 @@ export declare class TomlEdit extends TomlEdit_base {
|
|
|
759
770
|
* reverse-offset order so earlier offsets stay valid; the input `edits`
|
|
760
771
|
* array is not mutated. Overlapping edits are a programmer error and throw
|
|
761
772
|
* as a defect — `TomlFormat` never produces them.
|
|
773
|
+
*
|
|
774
|
+
* @param text - The source text to edit.
|
|
775
|
+
* @param edits - The edits to apply, in any order.
|
|
776
|
+
* @returns The edited text.
|
|
762
777
|
*/
|
|
763
778
|
static applyAll(text: string, edits: ReadonlyArray<TomlEdit>): string;
|
|
764
779
|
}
|
|
@@ -803,7 +818,22 @@ export declare class TomlModificationError extends TomlModificationError_base {
|
|
|
803
818
|
get message(): string;
|
|
804
819
|
}
|
|
805
820
|
/**
|
|
806
|
-
*
|
|
821
|
+
* Formats TOML text and modifies values at a path as byte-minimal edits that
|
|
822
|
+
* leave comments and layout elsewhere untouched. Not instantiable.
|
|
823
|
+
*
|
|
824
|
+
* @example
|
|
825
|
+
* ```ts
|
|
826
|
+
* import { TomlFormat } from "@effected/toml";
|
|
827
|
+
* import { Effect } from "effect";
|
|
828
|
+
*
|
|
829
|
+
* const formatted = TomlFormat.formatToString(' title="x" #note\n[server]\nport=1');
|
|
830
|
+
* // => 'title = "x" # note\n[server]\nport = 1\n'
|
|
831
|
+
*
|
|
832
|
+
* const program = Effect.gen(function* () {
|
|
833
|
+
* return yield* TomlFormat.modifyToString("[server]\nport = 1 # dev\n", ["server", "port"], 2);
|
|
834
|
+
* // => "[server]\nport = 2 # dev\n"
|
|
835
|
+
* });
|
|
836
|
+
* ```
|
|
807
837
|
*
|
|
808
838
|
* @remarks
|
|
809
839
|
* `format`/`formatToString` are pure and total: malformed input yields no
|
|
@@ -827,12 +857,25 @@ export declare class TomlFormat {
|
|
|
827
857
|
* strings. Nothing else: no reordering, no blank-line collapsing, no value
|
|
828
858
|
* rewriting. `range` restricts edits to the expressions intersecting it.
|
|
829
859
|
* Non-mutating — apply with `TomlEdit.applyAll` (or use
|
|
830
|
-
* {@link TomlFormat.formatToString}).
|
|
860
|
+
* {@link TomlFormat.formatToString}). Pure and total.
|
|
861
|
+
*
|
|
862
|
+
* @param text - The TOML source to format.
|
|
863
|
+
* @param range - Optional sub-range; only edits whose expression intersects
|
|
864
|
+
* it are returned.
|
|
865
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
866
|
+
* @returns The edits that bring `text` (or `range`) to canonical shape;
|
|
867
|
+
* apply them with `TomlEdit.applyAll`.
|
|
831
868
|
*/
|
|
832
869
|
static format(text: string, range?: TomlRangeLike, options?: TomlFormattingOptions): ReadonlyArray<TomlEdit>;
|
|
833
870
|
/**
|
|
834
871
|
* Format `text` and apply the resulting edits in one step
|
|
835
872
|
* (`TomlEdit.applyAll ∘ format`). Pure and total.
|
|
873
|
+
*
|
|
874
|
+
* @param text - The TOML source to format.
|
|
875
|
+
* @param range - Optional sub-range; only edits whose expression intersects
|
|
876
|
+
* it are applied.
|
|
877
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
878
|
+
* @returns The formatted text.
|
|
836
879
|
*/
|
|
837
880
|
static formatToString(text: string, range?: TomlRangeLike, options?: TomlFormattingOptions): string;
|
|
838
881
|
/**
|
|
@@ -847,11 +890,31 @@ export declare class TomlFormat {
|
|
|
847
890
|
* section; inline and implicitly created tables refuse. Inserted lines
|
|
848
891
|
* inherit the document's dominant newline unless `options.newline`
|
|
849
892
|
* overrides it. Every modified document reparses cleanly.
|
|
893
|
+
*
|
|
894
|
+
* @param text - The TOML source to modify.
|
|
895
|
+
* @param path - The location to set, replace or delete.
|
|
896
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
897
|
+
* target instead.
|
|
898
|
+
* @param options - Optional {@link TomlFormattingOptions}; `newline` overrides
|
|
899
|
+
* the newline used for inserted lines.
|
|
900
|
+
* @returns An `Effect` that succeeds with the edits to apply (via
|
|
901
|
+
* `TomlEdit.applyAll`), or fails with {@link TomlParseError} when the
|
|
902
|
+
* source does not parse, or {@link TomlModificationError} when `path`
|
|
903
|
+
* cannot be resolved or the insertion target is not allowed.
|
|
850
904
|
*/
|
|
851
905
|
static readonly modify: (text: string, path: TomlPath, value: unknown, options?: TomlFormattingOptions | undefined) => Effect.Effect<readonly TomlEdit[], TomlModificationError | TomlParseError, never>;
|
|
852
906
|
/**
|
|
853
907
|
* Modify `text` and apply the resulting edits in one step
|
|
854
908
|
* (`TomlEdit.applyAll ∘ modify`).
|
|
909
|
+
*
|
|
910
|
+
* @param text - The TOML source to modify.
|
|
911
|
+
* @param path - The location to set, replace or delete.
|
|
912
|
+
* @param value - The plain JavaScript value to write; `undefined` deletes the
|
|
913
|
+
* target instead.
|
|
914
|
+
* @param options - Optional {@link TomlFormattingOptions}.
|
|
915
|
+
* @returns An `Effect` that succeeds with the modified text, or fails with
|
|
916
|
+
* {@link TomlParseError} or {@link TomlModificationError}, as
|
|
917
|
+
* {@link TomlFormat.modify} does.
|
|
855
918
|
*/
|
|
856
919
|
static readonly modifyToString: (text: string, path: TomlPath, value: unknown, options?: TomlFormattingOptions | undefined) => Effect.Effect<string, TomlModificationError | TomlParseError, never>;
|
|
857
920
|
}
|
|
@@ -863,7 +926,9 @@ export declare class TomlFormat {
|
|
|
863
926
|
* event, then again for every `[table]` header. `ArrayTableStart` fires for
|
|
864
927
|
* every `[[array]]` header with the 0-based element `index`. `KeyValue.path`
|
|
865
928
|
* includes the final key. `Comment` covers both standalone (trivia) and
|
|
866
|
-
* trailing comments
|
|
929
|
+
* trailing comments: `offset` is the source position of the comment's `#`
|
|
930
|
+
* marker, and `text` is the comment after the `#` with one leading space
|
|
931
|
+
* removed.
|
|
867
932
|
*
|
|
868
933
|
* @public
|
|
869
934
|
*/
|
|
@@ -1010,7 +1075,21 @@ export declare const TomlVisitorEvent: {
|
|
|
1010
1075
|
}, "_tag">;
|
|
1011
1076
|
};
|
|
1012
1077
|
/**
|
|
1013
|
-
*
|
|
1078
|
+
* Walks TOML text as a `Stream` of table, array-table, key-value and comment
|
|
1079
|
+
* events in document order, without building a value. Not instantiable.
|
|
1080
|
+
*
|
|
1081
|
+
* @example
|
|
1082
|
+
* ```ts
|
|
1083
|
+
* import { TomlVisitor, TomlVisitorEvent } from "@effected/toml";
|
|
1084
|
+
* import { Effect, Stream } from "effect";
|
|
1085
|
+
*
|
|
1086
|
+
* const keys = TomlVisitor.visit("[server]\nport = 1\n").pipe(
|
|
1087
|
+
* Stream.filter(TomlVisitorEvent.$is("KeyValue")),
|
|
1088
|
+
* Stream.map((event) => event.path.join(".")),
|
|
1089
|
+
* Stream.runCollect,
|
|
1090
|
+
* );
|
|
1091
|
+
* // Effect.runSync(keys) // => ["server.port"]
|
|
1092
|
+
* ```
|
|
1014
1093
|
*
|
|
1015
1094
|
* @public
|
|
1016
1095
|
*/
|
package/internal/parser.js
CHANGED
|
@@ -363,7 +363,7 @@ const parseHeaderExpression = (source, lineStart, bracketPos) => {
|
|
|
363
363
|
/**
|
|
364
364
|
* Parse a TOML document into its linear CST: the flat, source-tiling list of
|
|
365
365
|
* expressions. Throws RawTomlError on malformed input and GuardExceeded when
|
|
366
|
-
* value nesting exceeds MAX_NESTING_DEPTH; the facade
|
|
366
|
+
* value nesting exceeds MAX_NESTING_DEPTH; the facade materializes
|
|
367
367
|
* both into typed errors.
|
|
368
368
|
*/
|
|
369
369
|
const parseExpressions = (source) => {
|
package/internal/scanner.js
CHANGED
|
@@ -339,7 +339,7 @@ const LOCAL_DATE = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/;
|
|
|
339
339
|
const LOCAL_TIME = /^([0-9]{2}):([0-9]{2})(?::([0-9]{2})(?:\.([0-9]+))?)?$/;
|
|
340
340
|
/**
|
|
341
341
|
* Scan a non-string scalar value token. Stops at whitespace, newlines, `,`,
|
|
342
|
-
* `]`, `}` and `#` — with
|
|
342
|
+
* `]`, `}` and `#` — with one extension: a token that scanned as a full
|
|
343
343
|
* date followed by a single space and a digit continues through the time
|
|
344
344
|
* part, so `1979-05-27 07:32:00Z` is one token.
|
|
345
345
|
*/
|
|
@@ -412,7 +412,7 @@ const decodeOffsetMinutes = (text, offset, length) => {
|
|
|
412
412
|
return text.charCodeAt(0) === HYPHEN ? -total : total;
|
|
413
413
|
};
|
|
414
414
|
/**
|
|
415
|
-
* Classify a scanned value token
|
|
415
|
+
* Classify a scanned value token: booleans, the four datetime
|
|
416
416
|
* shapes (validated against the Gregorian calendar and clock ranges before
|
|
417
417
|
* construction), integers across four radixes with int64 range checking and
|
|
418
418
|
* number/bigint narrowing, and floats including the special spellings.
|
package/internal/semantic.js
CHANGED
|
@@ -17,7 +17,7 @@ const raise = (code, message, key) => {
|
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
|
-
* Header navigation (
|
|
20
|
+
* Header navigation (rules 1 and 2, shared prefix): walk every segment but
|
|
21
21
|
* the last, creating `table-implicit` for absent names, passing through
|
|
22
22
|
* tables (dotted included — the corpus deviation) and descending into the
|
|
23
23
|
* last element of an array of tables.
|
|
@@ -49,7 +49,7 @@ const navigateHeaderPrefix = (root, keyPath) => {
|
|
|
49
49
|
}
|
|
50
50
|
return current;
|
|
51
51
|
};
|
|
52
|
-
/**
|
|
52
|
+
/** Rule 1, final segment: create `table-explicit`, promote `table-implicit`, or error. */
|
|
53
53
|
const openTable = (root, keyPath) => {
|
|
54
54
|
const parent = navigateHeaderPrefix(root, keyPath);
|
|
55
55
|
const key = keyPath[keyPath.length - 1];
|
|
@@ -65,7 +65,7 @@ const openTable = (root, keyPath) => {
|
|
|
65
65
|
}
|
|
66
66
|
return raise("TableRedefined", `table "${key.value}" is already defined`, key);
|
|
67
67
|
};
|
|
68
|
-
/**
|
|
68
|
+
/** Rule 2, final segment: create the array and its first element, append to an existing one, or error. */
|
|
69
69
|
const openArrayTable = (root, keyPath) => {
|
|
70
70
|
const parent = navigateHeaderPrefix(root, keyPath);
|
|
71
71
|
const key = keyPath[keyPath.length - 1];
|
|
@@ -91,7 +91,7 @@ const openArrayTable = (root, keyPath) => {
|
|
|
91
91
|
return raise("ArrayOfTablesConflict", `"${key.value}" cannot be redefined as an array of tables`, key);
|
|
92
92
|
};
|
|
93
93
|
/**
|
|
94
|
-
*
|
|
94
|
+
* Rule 3: a (possibly dotted) key assignment scoped to `table` under
|
|
95
95
|
* `sectionId`. Intermediates must be absent (create `table-dotted`) or
|
|
96
96
|
* `table-dotted` from the same section; the final key must be absent.
|
|
97
97
|
*/
|
|
@@ -135,7 +135,7 @@ const checkArrayItem = (item, context) => {
|
|
|
135
135
|
if (item instanceof TomlArray) for (const inner of item.items) checkArrayItem(inner, context);
|
|
136
136
|
};
|
|
137
137
|
/**
|
|
138
|
-
*
|
|
138
|
+
* Rule 4: build an inline table's own scope (dotted keys follow rule 3
|
|
139
139
|
* inside it), then freeze it — the returned node's `inline` kind makes every
|
|
140
140
|
* later navigation through it an `InlineTableExtended` error.
|
|
141
141
|
*/
|
|
@@ -147,7 +147,7 @@ const inlineNode = (node, context) => {
|
|
|
147
147
|
return sem;
|
|
148
148
|
};
|
|
149
149
|
/**
|
|
150
|
-
* Walk the expressions through the
|
|
150
|
+
* Walk the expressions through the provenance state machine, firing the visitor after
|
|
151
151
|
* each expression validates; throws `RawTomlError` at the first violation.
|
|
152
152
|
*/
|
|
153
153
|
const analyze = (expressions, visitor) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/toml",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "TOML 1.1.0 parsing, editing and formatting as Effect schemas: typed diagnostics, a lossless CST and first-class date-time values.",
|
|
6
6
|
"keywords": [
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"./package.json": "./package.json"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"effect": "4.0.0
|
|
41
|
+
"effect": "^4.0.0"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=24.11.0"
|