@thomasfosterau/effect-parse 0.1.0 → 0.3.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 +291 -231
- package/dist/Ascii.d.ts +32 -53
- package/dist/Ascii.d.ts.map +1 -1
- package/dist/Ascii.js +576 -571
- package/dist/Ascii.js.map +1 -1
- package/dist/Binary.d.ts +6 -29
- package/dist/Binary.d.ts.map +1 -1
- package/dist/Binary.js +129 -116
- package/dist/Binary.js.map +1 -1
- package/dist/Bits.d.ts +4 -2
- package/dist/Bits.d.ts.map +1 -1
- package/dist/Bits.js +121 -123
- package/dist/Bits.js.map +1 -1
- package/dist/Compiler.d.ts +39 -0
- package/dist/Compiler.d.ts.map +1 -0
- package/dist/Compiler.js +48 -0
- package/dist/Compiler.js.map +1 -0
- package/dist/Encoding.d.ts +29 -46
- package/dist/Encoding.d.ts.map +1 -1
- package/dist/Encoding.js +76 -75
- package/dist/Encoding.js.map +1 -1
- package/dist/Expression.d.ts +15 -49
- package/dist/Expression.d.ts.map +1 -1
- package/dist/Expression.js +151 -132
- package/dist/Expression.js.map +1 -1
- package/dist/Input.d.ts +251 -177
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +409 -299
- package/dist/Input.js.map +1 -1
- package/dist/Nom.d.ts +45 -85
- package/dist/Nom.d.ts.map +1 -1
- package/dist/Nom.js +423 -453
- package/dist/Nom.js.map +1 -1
- package/dist/ParseError.d.ts +54 -49
- package/dist/ParseError.d.ts.map +1 -1
- package/dist/ParseError.js +232 -275
- package/dist/ParseError.js.map +1 -1
- package/dist/Parser.d.ts +345 -313
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +2034 -1802
- package/dist/Parser.js.map +1 -1
- package/dist/ParserSchema.d.ts +206 -7
- package/dist/ParserSchema.d.ts.map +1 -1
- package/dist/ParserSchema.js +678 -49
- package/dist/ParserSchema.js.map +1 -1
- package/dist/ParserStream.d.ts +26 -20
- package/dist/ParserStream.d.ts.map +1 -1
- package/dist/ParserStream.js +267 -255
- package/dist/ParserStream.js.map +1 -1
- package/dist/Syntax.d.ts +401 -0
- package/dist/Syntax.d.ts.map +1 -0
- package/dist/Syntax.js +717 -0
- package/dist/Syntax.js.map +1 -0
- package/dist/Text.d.ts +98 -134
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +534 -496
- package/dist/Text.js.map +1 -1
- package/dist/Token.d.ts +60 -42
- package/dist/Token.d.ts.map +1 -1
- package/dist/Token.js +331 -265
- package/dist/Token.js.map +1 -1
- package/dist/index.d.ts +16 -17
- package/dist/index.js +16 -17
- package/dist/internal/compiler/closure.d.ts +14 -16
- package/dist/internal/compiler/closure.d.ts.map +1 -1
- package/dist/internal/compiler/closure.js +1458 -1637
- package/dist/internal/compiler/closure.js.map +1 -1
- package/dist/internal/compiler/entries.d.ts +11 -11
- package/dist/internal/compiler/entries.d.ts.map +1 -1
- package/dist/internal/compiler/entries.js +36 -26
- package/dist/internal/compiler/entries.js.map +1 -1
- package/dist/internal/compiler/first.d.ts +19 -19
- package/dist/internal/compiler/first.d.ts.map +1 -1
- package/dist/internal/compiler/first.js +251 -227
- package/dist/internal/compiler/first.js.map +1 -1
- package/dist/internal/compiler/jit.d.ts +6 -17
- package/dist/internal/compiler/jit.d.ts.map +1 -1
- package/dist/internal/compiler/jit.js +860 -988
- package/dist/internal/compiler/jit.js.map +1 -1
- package/dist/internal/compiler/registry.d.ts +20 -21
- package/dist/internal/compiler/registry.d.ts.map +1 -1
- package/dist/internal/compiler/registry.js +21 -41
- package/dist/internal/compiler/registry.js.map +1 -1
- package/dist/internal/compiler/sets.d.ts +9 -13
- package/dist/internal/compiler/sets.d.ts.map +1 -1
- package/dist/internal/compiler/sets.js +76 -73
- package/dist/internal/compiler/sets.js.map +1 -1
- package/dist/internal/entries.d.ts +3 -3
- package/dist/internal/entries.d.ts.map +1 -1
- package/dist/internal/entries.js +38 -30
- package/dist/internal/entries.js.map +1 -1
- package/dist/internal/node.d.ts +177 -173
- package/dist/internal/node.d.ts.map +1 -1
- package/dist/internal/node.js +77 -66
- package/dist/internal/node.js.map +1 -1
- package/dist/internal/numbers.d.ts +7 -8
- package/dist/internal/numbers.d.ts.map +1 -1
- package/dist/internal/numbers.js +246 -276
- package/dist/internal/numbers.js.map +1 -1
- package/dist/internal/resume.d.ts +6 -24
- package/dist/internal/resume.d.ts.map +1 -1
- package/dist/internal/resume.js +30 -29
- package/dist/internal/resume.js.map +1 -1
- package/dist/internal/run.d.ts +15 -0
- package/dist/internal/run.d.ts.map +1 -0
- package/dist/internal/run.js +36 -0
- package/dist/internal/run.js.map +1 -0
- package/dist/internal/stack.d.ts +16 -0
- package/dist/internal/stack.d.ts.map +1 -0
- package/dist/internal/stack.js +36 -0
- package/dist/internal/stack.js.map +1 -0
- package/dist/internal/syntax.d.ts +147 -0
- package/dist/internal/syntax.d.ts.map +1 -0
- package/dist/internal/syntax.js +309 -0
- package/dist/internal/syntax.js.map +1 -0
- package/dist/internal/text.d.ts +10 -2
- package/dist/internal/text.d.ts.map +1 -1
- package/dist/internal/text.js +295 -345
- package/dist/internal/text.js.map +1 -1
- package/dist/internal/ties.d.ts +30 -0
- package/dist/internal/ties.d.ts.map +1 -0
- package/dist/internal/ties.js +67 -0
- package/dist/internal/ties.js.map +1 -0
- package/dist/internal/tokens.d.ts +25 -30
- package/dist/internal/tokens.d.ts.map +1 -1
- package/dist/internal/tokens.js +369 -363
- package/dist/internal/tokens.js.map +1 -1
- package/package.json +42 -28
- package/src/Ascii.ts +278 -187
- package/src/Binary.ts +150 -44
- package/src/Bits.ts +6 -3
- package/src/Compiler.ts +98 -0
- package/src/Expression.ts +24 -16
- package/src/Input.ts +210 -35
- package/src/Nom.ts +4 -3
- package/src/ParseError.ts +49 -52
- package/src/Parser.ts +1199 -799
- package/src/ParserSchema.ts +982 -23
- package/src/ParserStream.ts +104 -80
- package/src/Syntax.ts +900 -0
- package/src/Text.ts +272 -187
- package/src/Token.ts +180 -87
- package/src/index.ts +2 -0
- package/src/internal/compiler/closure.ts +121 -88
- package/src/internal/compiler/entries.ts +21 -8
- package/src/internal/compiler/first.ts +17 -15
- package/src/internal/compiler/jit.ts +360 -157
- package/src/internal/compiler/registry.ts +12 -33
- package/src/internal/compiler/sets.ts +17 -11
- package/src/internal/entries.ts +4 -2
- package/src/internal/node.ts +51 -37
- package/src/internal/numbers.ts +22 -20
- package/src/internal/resume.ts +8 -4
- package/src/internal/run.ts +41 -0
- package/src/internal/stack.ts +41 -0
- package/src/internal/syntax.ts +426 -0
- package/src/internal/text.ts +32 -25
- package/src/internal/ties.ts +83 -0
- package/src/internal/tokens.ts +96 -51
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,85 +1,88 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Predicate from "effect/Predicate";
|
|
2
|
+
import { PredicateRanges, compile, compileAny } from "../tokens.js";
|
|
3
|
+
import { firstCodePoint } from "../text.js";
|
|
4
|
+
import * as Arr from "effect/Array";
|
|
5
|
+
import * as Order from "effect/Order";
|
|
6
|
+
//#region src/internal/compiler/sets.ts
|
|
7
|
+
/**
|
|
8
|
+
* Token sets for compiled parsers: membership tables for small units, the
|
|
9
|
+
* exact test for the rest, and the code point ranges when they are known.
|
|
10
|
+
*/
|
|
2
11
|
/** Size of the membership table: every byte, and the Latin-1 code points. */
|
|
3
|
-
|
|
4
|
-
const isRange = (u) =>
|
|
5
|
-
const toCode = (u) =>
|
|
12
|
+
const TableSize = 256;
|
|
13
|
+
const isRange = (u) => Predicate.isObjectOrArray(u) && u._tag === "TokenRange";
|
|
14
|
+
const toCode = (u) => Predicate.isNumber(u) ? u : firstCodePoint(u);
|
|
6
15
|
/** The code point ranges of a token set, or `undefined` if it has an unknown predicate. */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (b < a)
|
|
48
|
-
continue;
|
|
49
|
-
const last = merged[merged.length - 1];
|
|
50
|
-
if (last !== undefined && a <= last[1] + 1)
|
|
51
|
-
last[1] = Math.max(last[1], b);
|
|
52
|
-
else
|
|
53
|
-
merged.push([a, b]);
|
|
54
|
-
}
|
|
55
|
-
return merged;
|
|
16
|
+
const rangesOf = (set) => {
|
|
17
|
+
const out = [];
|
|
18
|
+
const add = (u) => {
|
|
19
|
+
if (Predicate.isString(u)) {
|
|
20
|
+
for (const c of u) {
|
|
21
|
+
const cp = firstCodePoint(c);
|
|
22
|
+
out.push([cp, cp]);
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (Predicate.isNumber(u)) {
|
|
27
|
+
out.push([u, u]);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (u instanceof Uint8Array) {
|
|
31
|
+
for (const b of u) out.push([b, b]);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (isRange(u)) {
|
|
35
|
+
out.push([toCode(u.from), toCode(u.to)]);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (Predicate.isFunction(u)) {
|
|
39
|
+
const r = u[PredicateRanges];
|
|
40
|
+
if (r === void 0) return false;
|
|
41
|
+
for (const [a, b] of r) out.push([a, b]);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(u)) return u.every(add);
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
47
|
+
if (!add(set)) return void 0;
|
|
48
|
+
const merged = [];
|
|
49
|
+
for (const [a, b] of Arr.sort(out, Order.mapInput(Order.Number, (range) => range[0]))) {
|
|
50
|
+
if (b < a) continue;
|
|
51
|
+
const last = merged[merged.length - 1];
|
|
52
|
+
if (last !== void 0 && a <= last[1] + 1) last[1] = Math.max(last[1], b);
|
|
53
|
+
else merged.push([a, b]);
|
|
54
|
+
}
|
|
55
|
+
return merged;
|
|
56
56
|
};
|
|
57
57
|
const makeSet = (test, set) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
const table = /* @__PURE__ */ new Uint8Array(256);
|
|
59
|
+
for (let c = 0; c < 256; c++) table[c] = test(c) ? 1 : 0;
|
|
60
|
+
return {
|
|
61
|
+
test,
|
|
62
|
+
table,
|
|
63
|
+
ranges: rangesOf(set)
|
|
64
|
+
};
|
|
64
65
|
};
|
|
65
66
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
* The set as a `Token` parser sees it: string predicates receive strings on
|
|
68
|
+
* string input, everything receives numbers on byte input.
|
|
69
|
+
*/
|
|
70
|
+
const tokenSet = (set, kind) => {
|
|
71
|
+
const m = compileAny(set);
|
|
72
|
+
return makeSet(kind === 0 ? m.forString.code : m.forCode.code, set);
|
|
72
73
|
};
|
|
73
74
|
/** The set as a `Text` parser sees it: code points, for any encoding. */
|
|
74
|
-
|
|
75
|
+
const textSet = (set) => makeSet(compile(set, "string").code, set);
|
|
75
76
|
/** Whether some accepted code point is at least `limit` (true when unknown). */
|
|
76
|
-
|
|
77
|
+
const reachesAbove = (s, limit) => s.ranges === void 0 || s.ranges.some(([, b]) => b >= limit);
|
|
77
78
|
/** The input kind a `Text` encoding reads: 0 for strings, 1 for bytes. */
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return k;
|
|
79
|
+
const kindOfEncoding = (enc) => {
|
|
80
|
+
let k = kinds.get(enc);
|
|
81
|
+
if (k === void 0) kinds.set(enc, k = Predicate.isString(enc.encode("")) ? 0 : 1);
|
|
82
|
+
return k;
|
|
83
83
|
};
|
|
84
|
-
const kinds = new WeakMap();
|
|
84
|
+
const kinds = /*#__PURE__*/ new WeakMap();
|
|
85
|
+
//#endregion
|
|
86
|
+
export { TableSize, kindOfEncoding, reachesAbove, textSet, tokenSet };
|
|
87
|
+
|
|
85
88
|
//# sourceMappingURL=sets.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sets.js","
|
|
1
|
+
{"version":3,"file":"sets.js","names":[],"sources":["../../../src/internal/compiler/sets.ts"],"sourcesContent":["/**\n * Token sets for compiled parsers: membership tables for small units, the\n * exact test for the rest, and the code point ranges when they are known.\n */\nimport * as Arr from \"effect/Array\"\nimport * as Order from \"effect/Order\"\nimport * as Predicate from \"effect/Predicate\"\nimport type { Encoding } from \"../../Encoding.js\"\nimport { firstCodePoint } from \"../text.js\"\nimport { compile, compileAny, PredicateRanges } from \"../tokens.js\"\n\n/** Size of the membership table: every byte, and the Latin-1 code points. */\nexport const TableSize = 256\n\nexport interface CharSet {\n /** Tests a code point (or byte, for `Token` on bytes). */\n readonly test: (code: number) => boolean\n /** `table[c] === 1` iff `test(c)`, for `c < TableSize`. */\n readonly table: Uint8Array\n /** Sorted inclusive ranges of accepted code points, when known. */\n readonly ranges: ReadonlyArray<readonly [number, number]> | undefined\n}\n\nconst isRange = (u: unknown): u is { readonly from: string | number; readonly to: string | number } =>\n Predicate.isObjectOrArray(u) && (u as any)._tag === \"TokenRange\"\n\nconst toCode = (u: string | number): number => (Predicate.isNumber(u) ? u : firstCodePoint(u))\n\n/** The code point ranges of a token set, or `undefined` if it has an unknown predicate. */\nconst rangesOf = (set: unknown): Array<[number, number]> | undefined => {\n const out: Array<[number, number]> = []\n const add = (u: unknown): boolean => {\n if (Predicate.isString(u)) {\n for (const c of u) {\n const cp = firstCodePoint(c)\n out.push([cp, cp])\n }\n return true\n }\n if (Predicate.isNumber(u)) {\n out.push([u, u])\n return true\n }\n if (u instanceof Uint8Array) {\n for (const b of u) out.push([b, b])\n return true\n }\n if (isRange(u)) {\n out.push([toCode(u.from), toCode(u.to)])\n return true\n }\n if (Predicate.isFunction(u)) {\n const r = (u as any)[PredicateRanges] as ReadonlyArray<readonly [number, number]> | undefined\n if (r === undefined) return false\n for (const [a, b] of r) out.push([a, b])\n return true\n }\n if (Array.isArray(u)) return u.every(add)\n return false\n }\n if (!add(set)) return undefined\n const merged: Array<[number, number]> = []\n for (const [a, b] of Arr.sort(\n out,\n Order.mapInput(Order.Number, (range: readonly [number, number]) => range[0])\n )) {\n if (b < a) continue\n const last = merged[merged.length - 1]\n if (last !== undefined && a <= last[1] + 1) last[1] = Math.max(last[1], b)\n else merged.push([a, b])\n }\n return merged\n}\n\nconst makeSet = (test: (code: number) => boolean, set: unknown): CharSet => {\n // The table calls the test once per small code: token-set predicates are\n // assumed to be pure (see the design notes).\n const table = new Uint8Array(TableSize)\n for (let c = 0; c < TableSize; c++) table[c] = test(c) ? 1 : 0\n return { test, table, ranges: rangesOf(set) }\n}\n\n/**\n * The set as a `Token` parser sees it: string predicates receive strings on\n * string input, everything receives numbers on byte input.\n */\nexport const tokenSet = (set: unknown, kind: 0 | 1): CharSet => {\n const m = compileAny(set)\n return makeSet(kind === 0 ? m.forString.code : m.forCode.code, set)\n}\n\n/** The set as a `Text` parser sees it: code points, for any encoding. */\nexport const textSet = (set: unknown): CharSet => makeSet(compile(set, \"string\").code, set)\n\n/** Whether some accepted code point is at least `limit` (true when unknown). */\nexport const reachesAbove = (s: CharSet, limit: number): boolean =>\n s.ranges === undefined || s.ranges.some(([, b]) => b >= limit)\n\n/** The input kind a `Text` encoding reads: 0 for strings, 1 for bytes. */\nexport const kindOfEncoding = (enc: Encoding<any>): 0 | 1 => {\n let k = kinds.get(enc)\n if (k === undefined) kinds.set(enc, (k = Predicate.isString(enc.encode(\"\")) ? 0 : 1))\n return k\n}\n\nconst kinds = /*#__PURE__*/ new WeakMap<Encoding<any>, 0 | 1>()\n"],"mappings":";;;;;;;;;;;AAYA,MAAa,YAAY;AAWzB,MAAM,WAAW,MACf,UAAU,gBAAgB,CAAC,KAAM,EAAU,SAAS;AAEtD,MAAM,UAAU,MAAgC,UAAU,SAAS,CAAC,IAAI,IAAI,eAAe,CAAC;;AAG5F,MAAM,YAAY,QAAsD;CACtE,MAAM,MAA+B,CAAC;CACtC,MAAM,OAAO,MAAwB;EACnC,IAAI,UAAU,SAAS,CAAC,GAAG;GACzB,KAAK,MAAM,KAAK,GAAG;IACjB,MAAM,KAAK,eAAe,CAAC;IAC3B,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;GACnB;GACA,OAAO;EACT;EACA,IAAI,UAAU,SAAS,CAAC,GAAG;GACzB,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;GACf,OAAO;EACT;EACA,IAAI,aAAa,YAAY;GAC3B,KAAK,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;GAClC,OAAO;EACT;EACA,IAAI,QAAQ,CAAC,GAAG;GACd,IAAI,KAAK,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,EAAE,EAAE,CAAC,CAAC;GACvC,OAAO;EACT;EACA,IAAI,UAAU,WAAW,CAAC,GAAG;GAC3B,MAAM,IAAK,EAAU;GACrB,IAAI,MAAM,KAAA,GAAW,OAAO;GAC5B,KAAK,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;GACvC,OAAO;EACT;EACA,IAAI,MAAM,QAAQ,CAAC,GAAG,OAAO,EAAE,MAAM,GAAG;EACxC,OAAO;CACT;CACA,IAAI,CAAC,IAAI,GAAG,GAAG,OAAO,KAAA;CACtB,MAAM,SAAkC,CAAC;CACzC,KAAK,MAAM,CAAC,GAAG,MAAM,IAAI,KACvB,KACA,MAAM,SAAS,MAAM,SAAS,UAAqC,MAAM,EAAE,CAC7E,GAAG;EACD,IAAI,IAAI,GAAG;EACX,MAAM,OAAO,OAAO,OAAO,SAAS;EACpC,IAAI,SAAS,KAAA,KAAa,KAAK,KAAK,KAAK,GAAG,KAAK,KAAK,KAAK,IAAI,KAAK,IAAI,CAAC;OACpE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;CACzB;CACA,OAAO;AACT;AAEA,MAAM,WAAW,MAAiC,QAA0B;CAG1E,MAAM,wBAAQ,IAAI,WAAA,GAAoB;CACtC,KAAK,IAAI,IAAI,GAAG,IAAA,KAAe,KAAK,MAAM,KAAK,KAAK,CAAC,IAAI,IAAI;CAC7D,OAAO;EAAE;EAAM;EAAO,QAAQ,SAAS,GAAG;CAAE;AAC9C;;;;;AAMA,MAAa,YAAY,KAAc,SAAyB;CAC9D,MAAM,IAAI,WAAW,GAAG;CACxB,OAAO,QAAQ,SAAS,IAAI,EAAE,UAAU,OAAO,EAAE,QAAQ,MAAM,GAAG;AACpE;;AAGA,MAAa,WAAW,QAA0B,QAAQ,QAAQ,KAAK,QAAQ,CAAC,CAAC,MAAM,GAAG;;AAG1F,MAAa,gBAAgB,GAAY,UACvC,EAAE,WAAW,KAAA,KAAa,EAAE,OAAO,MAAM,GAAG,OAAO,KAAK,KAAK;;AAG/D,MAAa,kBAAkB,QAA8B;CAC3D,IAAI,IAAI,MAAM,IAAI,GAAG;CACrB,IAAI,MAAM,KAAA,GAAW,MAAM,IAAI,KAAM,IAAI,UAAU,SAAS,IAAI,OAAO,EAAE,CAAC,IAAI,IAAI,CAAE;CACpF,OAAO;AACT;AAEA,MAAM,sBAAsB,IAAI,QAA8B"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
//#region src/internal/entries.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Building objects as `Object.fromEntries` does, without its array of
|
|
3
4
|
* `[key, value]` pairs: the compilers use these when a parser maps a
|
|
4
5
|
* repetition of pairs with `Object.fromEntries` (see `Parser.fromEntries`).
|
|
5
6
|
*/
|
|
6
7
|
/** The built-in `Object.fromEntries`, which compiled parsers recognize. */
|
|
7
|
-
export declare const fromEntries: <K extends PropertyKey, V>(entries: Iterable<readonly [K, V]>) => {
|
|
8
|
-
[P in K]: V;
|
|
9
|
-
};
|
|
8
|
+
export declare const fromEntries: <K extends PropertyKey, V>(entries: Iterable<readonly [K, V]>) => { [P in K]: V; };
|
|
10
9
|
/**
|
|
11
10
|
* Whether `o[key] = value` on a new plain object creates the same property
|
|
12
11
|
* as `Object.fromEntries` (a writable, enumerable, configurable data
|
|
@@ -24,4 +23,5 @@ export declare const isPlainKey: (key: unknown) => key is string;
|
|
|
24
23
|
export declare const addEntry: (o: object, deferred: Array<unknown> | undefined, key: unknown, value: unknown) => Array<unknown> | undefined;
|
|
25
24
|
/** Adds the deferred entries of {@link addEntry} to `o`, in order. */
|
|
26
25
|
export declare const flushEntries: (o: object, deferred: ReadonlyArray<unknown>) => void;
|
|
26
|
+
//#endregion
|
|
27
27
|
//# sourceMappingURL=entries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entries.d.ts","
|
|
1
|
+
{"version":3,"file":"entries.d.ts","names":[],"sources":["../../src/internal/entries.ts"],"mappings":";;;;;;;qBASa,cAAc,UAAU,aAAa,GAAG,SAAS,mBAAmB,GAAG,WAAW,KAAK,IAAI;;;;;;;qBAY3F,aAAc,iBAAe;;;;;;;;qBAa7B,WACX,WACA,UAAU,4BACV,cACA,mBACC;;qBAWU,eAAgB,WAAW,UAAU"}
|
package/dist/internal/entries.js
CHANGED
|
@@ -1,42 +1,50 @@
|
|
|
1
|
+
import * as Predicate from "effect/Predicate";
|
|
2
|
+
//#region src/internal/entries.ts
|
|
1
3
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
* Building objects as `Object.fromEntries` does, without its array of
|
|
5
|
+
* `[key, value]` pairs: the compilers use these when a parser maps a
|
|
6
|
+
* repetition of pairs with `Object.fromEntries` (see `Parser.fromEntries`).
|
|
7
|
+
*/
|
|
6
8
|
/** The built-in `Object.fromEntries`, which compiled parsers recognize. */
|
|
7
|
-
|
|
9
|
+
const fromEntries = Object.fromEntries;
|
|
8
10
|
const objectPrototype = Object.prototype;
|
|
9
11
|
const hasOwn = objectPrototype.hasOwnProperty;
|
|
10
12
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
* Whether `o[key] = value` on a new plain object creates the same property
|
|
14
|
+
* as `Object.fromEntries` (a writable, enumerable, configurable data
|
|
15
|
+
* property): `key` is a string that `Object.prototype` has no property for,
|
|
16
|
+
* so there is no setter (`__proto__`) or read-only property to run into.
|
|
17
|
+
*/
|
|
18
|
+
const isPlainKey = (key) => Predicate.isString(key) && !hasOwn.call(objectPrototype, key);
|
|
17
19
|
const define = (o, key, value) => {
|
|
18
|
-
|
|
20
|
+
Object.defineProperty(o, key, {
|
|
21
|
+
value,
|
|
22
|
+
writable: true,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true
|
|
25
|
+
});
|
|
19
26
|
};
|
|
20
27
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return deferred;
|
|
28
|
+
* Adds an entry whose key is not plain to `o`, given the entries already
|
|
29
|
+
* deferred. Keys that are objects may run code when converted to property
|
|
30
|
+
* keys, which `Object.fromEntries` only does once every entry is parsed:
|
|
31
|
+
* from the first such key on, entries are deferred to {@link flushEntries}.
|
|
32
|
+
* Returns the deferred entries, if any.
|
|
33
|
+
*/
|
|
34
|
+
const addEntry = (o, deferred, key, value) => {
|
|
35
|
+
if (deferred === void 0 && !Predicate.isObjectOrArray(key) && !Predicate.isFunction(key)) {
|
|
36
|
+
define(o, key, value);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (deferred === void 0) deferred = [];
|
|
40
|
+
deferred.push(key, value);
|
|
41
|
+
return deferred;
|
|
36
42
|
};
|
|
37
43
|
/** Adds the deferred entries of {@link addEntry} to `o`, in order. */
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
define(o, deferred[i], deferred[i + 1]);
|
|
44
|
+
const flushEntries = (o, deferred) => {
|
|
45
|
+
for (let i = 0; i < deferred.length; i += 2) define(o, deferred[i], deferred[i + 1]);
|
|
41
46
|
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { addEntry, flushEntries, fromEntries, isPlainKey };
|
|
49
|
+
|
|
42
50
|
//# sourceMappingURL=entries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entries.js","
|
|
1
|
+
{"version":3,"file":"entries.js","names":[],"sources":["../../src/internal/entries.ts"],"sourcesContent":["/**\n * Building objects as `Object.fromEntries` does, without its array of\n * `[key, value]` pairs: the compilers use these when a parser maps a\n * repetition of pairs with `Object.fromEntries` (see `Parser.fromEntries`).\n */\n\nimport * as Predicate from \"effect/Predicate\"\n\n/** The built-in `Object.fromEntries`, which compiled parsers recognize. */\nexport const fromEntries: <K extends PropertyKey, V>(entries: Iterable<readonly [K, V]>) => { [P in K]: V } =\n Object.fromEntries as any\n\nconst objectPrototype = Object.prototype\nconst hasOwn = objectPrototype.hasOwnProperty\n\n/**\n * Whether `o[key] = value` on a new plain object creates the same property\n * as `Object.fromEntries` (a writable, enumerable, configurable data\n * property): `key` is a string that `Object.prototype` has no property for,\n * so there is no setter (`__proto__`) or read-only property to run into.\n */\nexport const isPlainKey = (key: unknown): key is string => Predicate.isString(key) && !hasOwn.call(objectPrototype, key)\n\nconst define = (o: object, key: unknown, value: unknown): void => {\n Object.defineProperty(o, key as PropertyKey, { value, writable: true, enumerable: true, configurable: true })\n}\n\n/**\n * Adds an entry whose key is not plain to `o`, given the entries already\n * deferred. Keys that are objects may run code when converted to property\n * keys, which `Object.fromEntries` only does once every entry is parsed:\n * from the first such key on, entries are deferred to {@link flushEntries}.\n * Returns the deferred entries, if any.\n */\nexport const addEntry = (\n o: object,\n deferred: Array<unknown> | undefined,\n key: unknown,\n value: unknown\n): Array<unknown> | undefined => {\n if (deferred === undefined && !Predicate.isObjectOrArray(key) && !Predicate.isFunction(key)) {\n define(o, key, value)\n return undefined\n }\n if (deferred === undefined) deferred = []\n deferred.push(key, value)\n return deferred\n}\n\n/** Adds the deferred entries of {@link addEntry} to `o`, in order. */\nexport const flushEntries = (o: object, deferred: ReadonlyArray<unknown>): void => {\n for (let i = 0; i < deferred.length; i += 2) define(o, deferred[i], deferred[i + 1])\n}\n"],"mappings":";;;;;;;;AASA,MAAa,cACX,OAAO;AAET,MAAM,kBAAkB,OAAO;AAC/B,MAAM,SAAS,gBAAgB;;;;;;;AAQ/B,MAAa,cAAc,QAAgC,UAAU,SAAS,GAAG,KAAK,CAAC,OAAO,KAAK,iBAAiB,GAAG;AAEvH,MAAM,UAAU,GAAW,KAAc,UAAyB;CAChE,OAAO,eAAe,GAAG,KAAoB;EAAE;EAAO,UAAU;EAAM,YAAY;EAAM,cAAc;CAAK,CAAC;AAC9G;;;;;;;;AASA,MAAa,YACX,GACA,UACA,KACA,UAC+B;CAC/B,IAAI,aAAa,KAAA,KAAa,CAAC,UAAU,gBAAgB,GAAG,KAAK,CAAC,UAAU,WAAW,GAAG,GAAG;EAC3F,OAAO,GAAG,KAAK,KAAK;EACpB;CACF;CACA,IAAI,aAAa,KAAA,GAAW,WAAW,CAAC;CACxC,SAAS,KAAK,KAAK,KAAK;CACxB,OAAO;AACT;;AAGA,MAAa,gBAAgB,GAAW,aAA2C;CACjF,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK,GAAG,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,EAAE;AACrF"}
|