@thomasfosterau/effect-parse 0.0.0-stage → 0.0.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.
Files changed (133) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +550 -2
  3. package/dist/Ascii.d.ts +392 -0
  4. package/dist/Ascii.d.ts.map +1 -0
  5. package/dist/Ascii.js +610 -0
  6. package/dist/Ascii.js.map +1 -0
  7. package/dist/Binary.d.ts +153 -0
  8. package/dist/Binary.d.ts.map +1 -0
  9. package/dist/Binary.js +171 -0
  10. package/dist/Binary.js.map +1 -0
  11. package/dist/Bits.d.ts +60 -0
  12. package/dist/Bits.d.ts.map +1 -0
  13. package/dist/Bits.js +144 -0
  14. package/dist/Bits.js.map +1 -0
  15. package/dist/Encoding.d.ts +116 -0
  16. package/dist/Encoding.d.ts.map +1 -0
  17. package/dist/Encoding.js +85 -0
  18. package/dist/Encoding.js.map +1 -0
  19. package/dist/Expression.d.ts +124 -0
  20. package/dist/Expression.d.ts.map +1 -0
  21. package/dist/Expression.js +139 -0
  22. package/dist/Expression.js.map +1 -0
  23. package/dist/Input.d.ts +301 -0
  24. package/dist/Input.d.ts.map +1 -0
  25. package/dist/Input.js +312 -0
  26. package/dist/Input.js.map +1 -0
  27. package/dist/Nom.d.ts +518 -0
  28. package/dist/Nom.d.ts.map +1 -0
  29. package/dist/Nom.js +519 -0
  30. package/dist/Nom.js.map +1 -0
  31. package/dist/ParseError.d.ts +120 -0
  32. package/dist/ParseError.d.ts.map +1 -0
  33. package/dist/ParseError.js +301 -0
  34. package/dist/ParseError.js.map +1 -0
  35. package/dist/Parser.d.ts +1312 -0
  36. package/dist/Parser.d.ts.map +1 -0
  37. package/dist/Parser.js +1936 -0
  38. package/dist/Parser.js.map +1 -0
  39. package/dist/ParserSchema.d.ts +31 -0
  40. package/dist/ParserSchema.d.ts.map +1 -0
  41. package/dist/ParserSchema.js +56 -0
  42. package/dist/ParserSchema.js.map +1 -0
  43. package/dist/ParserStream.d.ts +127 -0
  44. package/dist/ParserStream.d.ts.map +1 -0
  45. package/dist/ParserStream.js +270 -0
  46. package/dist/ParserStream.js.map +1 -0
  47. package/dist/Text.d.ts +330 -0
  48. package/dist/Text.d.ts.map +1 -0
  49. package/dist/Text.js +529 -0
  50. package/dist/Text.js.map +1 -0
  51. package/dist/Token.d.ts +225 -0
  52. package/dist/Token.d.ts.map +1 -0
  53. package/dist/Token.js +294 -0
  54. package/dist/Token.js.map +1 -0
  55. package/dist/index.d.ts +17 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +17 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/internal/compiler/closure.d.ts +25 -0
  60. package/dist/internal/compiler/closure.d.ts.map +1 -0
  61. package/dist/internal/compiler/closure.js +1668 -0
  62. package/dist/internal/compiler/closure.js.map +1 -0
  63. package/dist/internal/compiler/entries.d.ts +19 -0
  64. package/dist/internal/compiler/entries.d.ts.map +1 -0
  65. package/dist/internal/compiler/entries.js +32 -0
  66. package/dist/internal/compiler/entries.js.map +1 -0
  67. package/dist/internal/compiler/first.d.ts +33 -0
  68. package/dist/internal/compiler/first.d.ts.map +1 -0
  69. package/dist/internal/compiler/first.js +235 -0
  70. package/dist/internal/compiler/first.js.map +1 -0
  71. package/dist/internal/compiler/jit.d.ts +20 -0
  72. package/dist/internal/compiler/jit.d.ts.map +1 -0
  73. package/dist/internal/compiler/jit.js +1030 -0
  74. package/dist/internal/compiler/jit.js.map +1 -0
  75. package/dist/internal/compiler/registry.d.ts +34 -0
  76. package/dist/internal/compiler/registry.d.ts.map +1 -0
  77. package/dist/internal/compiler/registry.js +46 -0
  78. package/dist/internal/compiler/registry.js.map +1 -0
  79. package/dist/internal/compiler/sets.d.ts +29 -0
  80. package/dist/internal/compiler/sets.d.ts.map +1 -0
  81. package/dist/internal/compiler/sets.js +85 -0
  82. package/dist/internal/compiler/sets.js.map +1 -0
  83. package/dist/internal/entries.d.ts +27 -0
  84. package/dist/internal/entries.d.ts.map +1 -0
  85. package/dist/internal/entries.js +42 -0
  86. package/dist/internal/entries.js.map +1 -0
  87. package/dist/internal/node.d.ts +251 -0
  88. package/dist/internal/node.d.ts.map +1 -0
  89. package/dist/internal/node.js +73 -0
  90. package/dist/internal/node.js.map +1 -0
  91. package/dist/internal/numbers.d.ts +41 -0
  92. package/dist/internal/numbers.d.ts.map +1 -0
  93. package/dist/internal/numbers.js +302 -0
  94. package/dist/internal/numbers.js.map +1 -0
  95. package/dist/internal/resume.d.ts +39 -0
  96. package/dist/internal/resume.d.ts.map +1 -0
  97. package/dist/internal/resume.js +37 -0
  98. package/dist/internal/resume.js.map +1 -0
  99. package/dist/internal/text.d.ts +72 -0
  100. package/dist/internal/text.d.ts.map +1 -0
  101. package/dist/internal/text.js +391 -0
  102. package/dist/internal/text.js.map +1 -0
  103. package/dist/internal/tokens.d.ts +93 -0
  104. package/dist/internal/tokens.d.ts.map +1 -0
  105. package/dist/internal/tokens.js +400 -0
  106. package/dist/internal/tokens.js.map +1 -0
  107. package/package.json +115 -3
  108. package/src/Ascii.ts +741 -0
  109. package/src/Binary.ts +228 -0
  110. package/src/Bits.ts +192 -0
  111. package/src/Encoding.ts +128 -0
  112. package/src/Expression.ts +245 -0
  113. package/src/Input.ts +429 -0
  114. package/src/Nom.ts +642 -0
  115. package/src/ParseError.ts +378 -0
  116. package/src/Parser.ts +2763 -0
  117. package/src/ParserSchema.ts +87 -0
  118. package/src/ParserStream.ts +390 -0
  119. package/src/Text.ts +757 -0
  120. package/src/Token.ts +416 -0
  121. package/src/index.ts +16 -0
  122. package/src/internal/compiler/closure.ts +1583 -0
  123. package/src/internal/compiler/entries.ts +36 -0
  124. package/src/internal/compiler/first.ts +252 -0
  125. package/src/internal/compiler/jit.ts +1091 -0
  126. package/src/internal/compiler/registry.ts +79 -0
  127. package/src/internal/compiler/sets.ts +100 -0
  128. package/src/internal/entries.ts +51 -0
  129. package/src/internal/node.ts +207 -0
  130. package/src/internal/numbers.ts +291 -0
  131. package/src/internal/resume.ts +55 -0
  132. package/src/internal/text.ts +411 -0
  133. package/src/internal/tokens.ts +409 -0
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Descriptions of parsers, recorded next to their steps so that parsers can
3
+ * be compiled (see `docs/DESIGN.md`, "Compiled parsers").
4
+ *
5
+ * Nodes refer to their child parsers rather than to child nodes, so a
6
+ * child's own step is always at hand for fallback, and recursion through
7
+ * `Suspend` is just a reference.
8
+ */
9
+ import type { Encoding } from "../Encoding.js";
10
+ import type { ErrMode, Input, State } from "../Input.js";
11
+ /** The parts of a parser the compiler needs. */
12
+ export interface ParserLike {
13
+ readonly step: (state: State<any>) => unknown;
14
+ readonly name: string | undefined;
15
+ }
16
+ type P = ParserLike;
17
+ type Step = (state: State<any>) => unknown;
18
+ /** A repetition range, normalized: `max` may be `Infinity`. */
19
+ interface Bounds {
20
+ readonly min: number;
21
+ readonly max: number;
22
+ }
23
+ /**
24
+ * For token nodes: `undefined` for the `Token`/`Ascii` parsers (code points
25
+ * of strings with lenient surrogates, bytes, or array elements), or the
26
+ * encoding of a `Text` parser.
27
+ */
28
+ type Enc = Encoding<any> | undefined;
29
+ export type Node = {
30
+ readonly _tag: "Opaque";
31
+ readonly step: Step;
32
+ } | {
33
+ readonly _tag: "Succeed";
34
+ readonly value: unknown;
35
+ } | {
36
+ readonly _tag: "Sync";
37
+ readonly evaluate: () => unknown;
38
+ } | {
39
+ readonly _tag: "Fail";
40
+ readonly mode: ErrMode;
41
+ } | {
42
+ readonly _tag: "Eof";
43
+ } | {
44
+ readonly _tag: "Location";
45
+ } | {
46
+ readonly _tag: "Suspend";
47
+ readonly resolve: () => P;
48
+ } | {
49
+ readonly _tag: "Any";
50
+ readonly encoding: Enc;
51
+ } | {
52
+ readonly _tag: "Literal";
53
+ readonly literal: Input;
54
+ readonly caseless: boolean;
55
+ readonly encoding: Enc;
56
+ } | {
57
+ readonly _tag: "OneOf";
58
+ readonly set: unknown;
59
+ readonly negate: boolean;
60
+ readonly encoding: Enc;
61
+ } | {
62
+ readonly _tag: "Take";
63
+ readonly count: number;
64
+ readonly encoding: Enc;
65
+ } | ({
66
+ readonly _tag: "TakeWhile";
67
+ readonly set: unknown;
68
+ readonly negate: boolean;
69
+ readonly encoding: Enc;
70
+ } & Bounds) | ({
71
+ readonly _tag: "TakeUntil";
72
+ readonly literal: Input;
73
+ readonly encoding: Enc;
74
+ } & Bounds) | {
75
+ readonly _tag: "Rest";
76
+ readonly encoding: Enc;
77
+ } | {
78
+ readonly _tag: "RestLen";
79
+ } | {
80
+ readonly _tag: "TillLineEnding";
81
+ readonly encoding: Enc;
82
+ } | {
83
+ readonly _tag: "Identifier";
84
+ readonly encoding: Enc;
85
+ } | {
86
+ readonly _tag: "Bom";
87
+ readonly encoding: Enc;
88
+ } | {
89
+ readonly _tag: "Escaped";
90
+ readonly normal: P;
91
+ /** The control character, as a code point (or a byte / unit for `Ascii`). */
92
+ readonly control: number;
93
+ readonly escape: P;
94
+ /** `takeEscaped`: return the raw slice instead of the unescaped text. */
95
+ readonly raw: boolean;
96
+ readonly encoding: Enc;
97
+ } | {
98
+ readonly _tag: "Map";
99
+ readonly self: P;
100
+ readonly f: (a: any) => unknown;
101
+ } | {
102
+ readonly _tag: "As";
103
+ readonly self: P;
104
+ readonly value: unknown;
105
+ } | {
106
+ readonly _tag: "Tap";
107
+ readonly self: P;
108
+ readonly f: (a: any) => void;
109
+ } | {
110
+ readonly _tag: "TryMap";
111
+ readonly self: P;
112
+ readonly f: (a: any) => unknown;
113
+ } | {
114
+ readonly _tag: "FilterMap";
115
+ readonly self: P;
116
+ readonly f: (a: any) => unknown;
117
+ } | {
118
+ readonly _tag: "Filter";
119
+ readonly self: P;
120
+ readonly predicate: (a: any) => boolean;
121
+ } | {
122
+ readonly _tag: "FlatMap";
123
+ readonly self: P;
124
+ readonly f: (a: any) => P;
125
+ } | {
126
+ readonly _tag: "Taken";
127
+ readonly self: P;
128
+ readonly encoding: Enc;
129
+ } | {
130
+ readonly _tag: "WithTaken";
131
+ readonly self: P;
132
+ } | {
133
+ readonly _tag: "Span";
134
+ readonly self: P;
135
+ } | {
136
+ readonly _tag: "WithSpan";
137
+ readonly self: P;
138
+ } | {
139
+ readonly _tag: "Mode";
140
+ readonly self: P;
141
+ readonly from: ErrMode;
142
+ readonly to: ErrMode;
143
+ } | {
144
+ readonly _tag: "Context";
145
+ readonly self: P;
146
+ readonly label: string;
147
+ } | {
148
+ readonly _tag: "Expected";
149
+ readonly self: P;
150
+ readonly description: string;
151
+ } | {
152
+ readonly _tag: "MapError";
153
+ readonly self: P;
154
+ } | {
155
+ readonly _tag: "OrFail";
156
+ readonly self: P;
157
+ } | {
158
+ readonly _tag: "Opt";
159
+ readonly self: P;
160
+ } | {
161
+ readonly _tag: "OrElseSucceed";
162
+ readonly self: P;
163
+ readonly value: () => unknown;
164
+ } | {
165
+ readonly _tag: "Peek";
166
+ readonly self: P;
167
+ } | {
168
+ readonly _tag: "Not";
169
+ readonly self: P;
170
+ } | {
171
+ readonly _tag: "Seq";
172
+ readonly parsers: ReadonlyArray<P>;
173
+ /** Which outputs are kept: all (a tuple), one index, or a pair of indices. */
174
+ readonly output: "tuple" | number | readonly [number, number];
175
+ } | {
176
+ readonly _tag: "Struct";
177
+ readonly keys: ReadonlyArray<string>;
178
+ readonly parsers: ReadonlyArray<P>;
179
+ } | {
180
+ readonly _tag: "ZipWith";
181
+ readonly self: P;
182
+ readonly that: P;
183
+ readonly f: (a: any, b: any) => unknown;
184
+ } | {
185
+ readonly _tag: "Alt";
186
+ readonly parsers: ReadonlyArray<P>;
187
+ } | {
188
+ readonly _tag: "Dispatch";
189
+ readonly selector: P;
190
+ /** A record of cases, when `dispatch` was given one. */
191
+ readonly cases: Readonly<Record<PropertyKey, P>> | undefined;
192
+ readonly otherwise: P | undefined;
193
+ readonly choose: (key: any) => P | undefined;
194
+ } | ({
195
+ readonly _tag: "Repeat";
196
+ readonly self: P;
197
+ } & Bounds) | ({
198
+ readonly _tag: "Fold";
199
+ readonly self: P;
200
+ readonly init: () => unknown;
201
+ readonly f: (acc: any, a: any) => unknown;
202
+ readonly name: string;
203
+ } & Bounds) | ({
204
+ readonly _tag: "RepeatTill";
205
+ readonly self: P;
206
+ readonly end: P;
207
+ } & Bounds) | ({
208
+ readonly _tag: "Separated";
209
+ readonly self: P;
210
+ readonly separator: P;
211
+ } & Bounds) | {
212
+ readonly _tag: "SeparatedFold";
213
+ readonly self: P;
214
+ readonly separator: P;
215
+ readonly op: (l: any, s: any, r: any) => unknown;
216
+ readonly right: boolean;
217
+ } | {
218
+ readonly _tag: "Service";
219
+ } | {
220
+ readonly _tag: "Provide";
221
+ readonly self: P;
222
+ } | {
223
+ readonly _tag: "ResumeAfter";
224
+ readonly self: P;
225
+ readonly recover: P;
226
+ } | {
227
+ readonly _tag: "RetryAfter";
228
+ readonly self: P;
229
+ readonly recover: P;
230
+ } | {
231
+ readonly _tag: "Trace";
232
+ readonly self: P;
233
+ readonly name: string;
234
+ };
235
+ export type Tag = Node["_tag"];
236
+ export type NodeOf<T extends Tag> = Extract<Node, {
237
+ readonly _tag: T;
238
+ }>;
239
+ /** Where a parser's description is stored. */
240
+ export declare const NodeId: unique symbol;
241
+ /** The description of a parser: `Opaque` when it has none. */
242
+ export declare const nodeOf: (p: ParserLike) => Node;
243
+ /** Normalizes a range, as `repeat`, `takeWhile`, ... do. */
244
+ export declare const bounds: (range: number | {
245
+ readonly min?: number | undefined;
246
+ readonly max?: number | undefined;
247
+ } | undefined) => Bounds;
248
+ /** The child parsers of a node, in evaluation order. */
249
+ export declare const children: (node: Node) => ReadonlyArray<P>;
250
+ export {};
251
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/internal/node.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,OA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,OAAO,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAAA;AAEvE,8CAA8C;AAC9C,eAAO,MAAM,MAAM,EAAE,OAAO,MAA+C,CAAA;AAE3E,8DAA8D;AAC9D,eAAO,MAAM,MAAM,MAAO,UAAU,KAAG,IAA8D,CAAA;AAErG,4DAA4D;AAC5D,eAAO,MAAM,MAAM,UAAW,MAAM,GAAG;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,SAAS,KAAG,MAI7H,CAAA;AAED,wDAAwD;AACxD,eAAO,MAAM,QAAQ,SAAU,IAAI,KAAG,aAAa,CAAC,CAAC,CAwDpD,CAAA"}
@@ -0,0 +1,73 @@
1
+ /** Where a parser's description is stored. */
2
+ export const NodeId = Symbol.for("effect-parse/Parser/node");
3
+ /** The description of a parser: `Opaque` when it has none. */
4
+ export const nodeOf = (p) => p[NodeId] ?? { _tag: "Opaque", step: p.step };
5
+ /** Normalizes a range, as `repeat`, `takeWhile`, ... do. */
6
+ export const bounds = (range) => {
7
+ if (range === undefined)
8
+ return { min: 0, max: Infinity };
9
+ if (typeof range === "number")
10
+ return { min: range, max: range };
11
+ return { min: range.min ?? 0, max: range.max ?? Infinity };
12
+ };
13
+ /** The child parsers of a node, in evaluation order. */
14
+ export const children = (node) => {
15
+ switch (node._tag) {
16
+ case "Escaped":
17
+ return [node.normal, node.escape];
18
+ case "Map":
19
+ case "As":
20
+ case "Tap":
21
+ case "TryMap":
22
+ case "FilterMap":
23
+ case "Filter":
24
+ case "FlatMap":
25
+ case "Taken":
26
+ case "WithTaken":
27
+ case "Span":
28
+ case "WithSpan":
29
+ case "Mode":
30
+ case "Context":
31
+ case "Expected":
32
+ case "MapError":
33
+ case "OrFail":
34
+ case "Opt":
35
+ case "OrElseSucceed":
36
+ case "Peek":
37
+ case "Not":
38
+ case "Repeat":
39
+ case "Fold":
40
+ case "Provide":
41
+ case "Trace":
42
+ return [node.self];
43
+ case "ResumeAfter":
44
+ case "RetryAfter":
45
+ return [node.self, node.recover];
46
+ case "Seq":
47
+ case "Struct":
48
+ case "Alt":
49
+ return node.parsers;
50
+ case "ZipWith":
51
+ return [node.self, node.that];
52
+ case "Dispatch": {
53
+ const out = [node.selector];
54
+ if (node.cases !== undefined) {
55
+ for (const key of Reflect.ownKeys(node.cases))
56
+ out.push(node.cases[key]);
57
+ }
58
+ if (node.otherwise !== undefined)
59
+ out.push(node.otherwise);
60
+ return out;
61
+ }
62
+ case "RepeatTill":
63
+ return [node.self, node.end];
64
+ case "Separated":
65
+ case "SeparatedFold":
66
+ return [node.self, node.separator];
67
+ case "Suspend":
68
+ return [node.resolve()];
69
+ default:
70
+ return [];
71
+ }
72
+ };
73
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/internal/node.ts"],"names":[],"mappings":"AAwIA,8CAA8C;AAC9C,MAAM,CAAC,MAAM,MAAM,GAAkB,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;AAE3E,8DAA8D;AAC9D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAa,EAAQ,EAAE,CAAE,CAAS,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;AAErG,4DAA4D;AAC5D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAoG,EAAU,EAAE;IACrI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAA;IACzD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CA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E,IAAI,CAAC,IAAI,CAAC,CAAA;QAC/B,KAAK,UAAU,EAAE,CAAC;YAChB,MAAM,GAAG,GAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YACrC,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC7B,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;oBAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAU,CAAE,CAAC,CAAA;YAClF,CAAC;YACD,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS;gBAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAC1D,OAAO,GAAG,CAAA;QACZ,CAAC;QACD,KAAK,YAAY;YACf,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;QAC9B,KAAK,WAAW,CAAC;QACjB,KAAK,eAAe;YAClB,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;QACpC,KAAK,SAAS;YACZ,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;QACzB;YACE,OAAO,EAAE,CAAA;IACb,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Number conversions shared by the `Ascii` and `Text` parsers and the
3
+ * compilers.
4
+ */
5
+ import type { Input } from "../Input.js";
6
+ import { Fail } from "../Input.js";
7
+ /** The value of the text matched by `Ascii.float` and `Text.float`. */
8
+ export declare const toFloat: (s: Input) => number;
9
+ /**
10
+ * The parsers that `Ascii.float` and `Text.float` map with `toFloat`: the
11
+ * compilers replace them by {@link scanFloatString} and
12
+ * {@link scanFloatBytes} when the text is in decimal notation.
13
+ */
14
+ export declare const floatTexts: WeakSet<object>;
15
+ /** Adds a parser to {@link floatTexts}. */
16
+ export declare const floatText: <P extends object>(p: P) => P;
17
+ /**
18
+ * Where the latest scan ended, when it succeeded, and the furthest offset it
19
+ * read (when it succeeded or failed): streaming builds re-run the parser
20
+ * when that is near the end of a partial input.
21
+ */
22
+ export declare const floatScan: {
23
+ end: number;
24
+ read: number;
25
+ };
26
+ /**
27
+ * Matches and converts what `Ascii.float` matches at `i`, when it is in
28
+ * decimal notation: an optional sign, then digits or "." (the other forms,
29
+ * `nan` and `inf`, start with a letter). Returns the value, setting
30
+ * `floatScan.end`; `Fail` if the float parser fails there (always with
31
+ * `Backtrack`); or `undefined` if the text does not start like a decimal
32
+ * number, for the caller to run the parser.
33
+ *
34
+ * Numbers with up to 19 significant digits and a decimal exponent up to 22
35
+ * are converted by {@link decimal}, the rest by `Number`, so the value is
36
+ * always what `Number` gives for the text.
37
+ */
38
+ export declare const scanFloatString: (s: string, i: number, end: number) => number | Fail | undefined;
39
+ /** {@link scanFloatString} on bytes, or the units of an ASCII compatible encoding. */
40
+ export declare const scanFloatBytes: (b: Uint8Array, i: number, end: number) => number | Fail | undefined;
41
+ //# sourceMappingURL=numbers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/internal/numbers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAMlC,uEAAuE;AACvE,eAAO,MAAM,OAAO,MAAO,KAAK,KAAG,MAYlC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,iBAAwB,CAAA;AAE/C,2CAA2C;AAC3C,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,KAAK,CAAC,KAAG,CAGlD,CAAA;AAKD;;;;GAIG;AACH,eAAO,MAAM,SAAS;IAAK,GAAG;IAAK,IAAI;CAAK,CAAA;AAqE5C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,MAAO,MAAM,KAAK,MAAM,OAAO,MAAM,KAAG,MAAM,GAAG,IAAI,GAAG,SAgFnF,CAAA;AAED,sFAAsF;AACtF,eAAO,MAAM,cAAc,MAAO,UAAU,KAAK,MAAM,OAAO,MAAM,KAAG,MAAM,GAAG,IAAI,GAAG,SA2EtF,CAAA"}
@@ -0,0 +1,302 @@
1
+ import { Fail } from "../Input.js";
2
+ import { latin1 } from "./text.js";
3
+ const toText = (s) => typeof s === "string" ? s : s instanceof Uint8Array ? latin1.text(s, 0, s.length) : s.join("");
4
+ /** The value of the text matched by `Ascii.float` and `Text.float`. */
5
+ export const toFloat = (s) => {
6
+ if (typeof s === "string") {
7
+ // Plain decimal notation (as opposed to `inf` or `nan`) ends in a digit or "."
8
+ const last = s.charCodeAt(s.length - 1);
9
+ if ((last >= 48 && last <= 57) || last === 46)
10
+ return Number(s);
11
+ }
12
+ const t = toText(s).toLowerCase();
13
+ const negative = t.startsWith("-");
14
+ const body = t.startsWith("-") || t.startsWith("+") ? t.slice(1) : t;
15
+ if (body === "nan")
16
+ return NaN;
17
+ if (body.startsWith("inf"))
18
+ return negative ? -Infinity : Infinity;
19
+ return Number(t);
20
+ };
21
+ /**
22
+ * The parsers that `Ascii.float` and `Text.float` map with `toFloat`: the
23
+ * compilers replace them by {@link scanFloatString} and
24
+ * {@link scanFloatBytes} when the text is in decimal notation.
25
+ */
26
+ export const floatTexts = new WeakSet();
27
+ /** Adds a parser to {@link floatTexts}. */
28
+ export const floatText = (p) => {
29
+ floatTexts.add(p);
30
+ return p;
31
+ };
32
+ /** The powers of ten that doubles represent exactly. */
33
+ const exact = Array.from({ length: 23 }, (_, i) => Number(`1e${i}`));
34
+ /**
35
+ * Where the latest scan ended, when it succeeded, and the furthest offset it
36
+ * read (when it succeeded or failed): streaming builds re-run the parser
37
+ * when that is near the end of a partial input.
38
+ */
39
+ export const floatScan = { end: 0, read: 0 };
40
+ const isDigit = (c) => c >= 48 && c <= 57;
41
+ // Exact products of doubles (Dekker), without allocating: `a * b` is
42
+ // `productHi + productLo` exactly, barring overflow and underflow
43
+ const Split = 134217729; // 2^27 + 1
44
+ let productHi = 0;
45
+ let productLo = 0;
46
+ const twoProduct = (a, b) => {
47
+ const p = a * b;
48
+ let t = Split * a;
49
+ const ah = t - (t - a);
50
+ const al = a - ah;
51
+ t = Split * b;
52
+ const bh = t - (t - b);
53
+ const bl = b - bh;
54
+ productHi = p;
55
+ productLo = ((ah * bh - p) + ah * bl + al * bh) + al * bl;
56
+ };
57
+ /** 2^-96: a bound on the relative error of {@link decimal}'s 19-digit path. */
58
+ const Error19 = 1 / 2 ** 96;
59
+ /**
60
+ * The double nearest to `±(high * 10^low digits + low) * 10^e10`, where
61
+ * `high` holds the first 15 significant digits, and `low` the next `lowDigits`
62
+ * (at most 4). Returns `undefined` when this can't tell it apart from the
63
+ * neighbouring doubles, for the caller to use `Number`.
64
+ *
65
+ * Up to 15 digits, the digits and a power of ten up to 10^22 are exact
66
+ * doubles, so one multiplication or division rounds correctly (Clinger's
67
+ * fast path). Up to 19 digits, the digits are an exact sum of two doubles,
68
+ * and multiplying or dividing that by an exact power of ten gives the value
69
+ * to within a relative 2^-96 (double-double arithmetic). It is then rounded
70
+ * once, and kept only if the bounds of that error round to the same double:
71
+ * this is never the case for an exact tie, so ties go to `Number` too.
72
+ */
73
+ const decimal = (negative, high, low, lowDigits, e10) => {
74
+ let v;
75
+ if (lowDigits === 0) {
76
+ if (e10 > 22 || e10 < -22)
77
+ return undefined;
78
+ v = e10 === 0 ? high : e10 > 0 ? high * exact[e10] : high / exact[-e10];
79
+ }
80
+ else {
81
+ if (e10 > 22 || e10 < -22)
82
+ return undefined;
83
+ // The digits: high * 10^lowDigits + low = wh + wl, exactly
84
+ twoProduct(high, exact[lowDigits]);
85
+ const wh = productHi + low;
86
+ const wl = productLo + (low - (wh - productHi));
87
+ let xh;
88
+ let xl;
89
+ if (e10 >= 0) {
90
+ const p = exact[e10];
91
+ twoProduct(wh, p);
92
+ xh = productHi;
93
+ xl = productLo + wl * p;
94
+ }
95
+ else {
96
+ const p = exact[-e10];
97
+ xh = wh / p;
98
+ twoProduct(xh, p);
99
+ xl = ((wh - productHi) - productLo + wl) / p;
100
+ }
101
+ v = xh + xl;
102
+ const error = (xh < 0 ? -xh : xh) * Error19;
103
+ if (xh + (xl + error) !== v || xh + (xl - error) !== v)
104
+ return undefined;
105
+ }
106
+ return negative ? -v : v;
107
+ };
108
+ /**
109
+ * Matches and converts what `Ascii.float` matches at `i`, when it is in
110
+ * decimal notation: an optional sign, then digits or "." (the other forms,
111
+ * `nan` and `inf`, start with a letter). Returns the value, setting
112
+ * `floatScan.end`; `Fail` if the float parser fails there (always with
113
+ * `Backtrack`); or `undefined` if the text does not start like a decimal
114
+ * number, for the caller to run the parser.
115
+ *
116
+ * Numbers with up to 19 significant digits and a decimal exponent up to 22
117
+ * are converted by {@link decimal}, the rest by `Number`, so the value is
118
+ * always what `Number` gives for the text.
119
+ */
120
+ export const scanFloatString = (s, i, end) => {
121
+ const start = i;
122
+ let c = i < end ? s.charCodeAt(i) : -1;
123
+ if (c === 45 || c === 43) {
124
+ c = i + 1 < end ? s.charCodeAt(i + 1) : -1;
125
+ if (!isDigit(c) && c !== 46)
126
+ return undefined;
127
+ i++;
128
+ }
129
+ else if (!isDigit(c) && c !== 46) {
130
+ return undefined;
131
+ }
132
+ // The first 15 significant digits, the next 4, how many there are in all,
133
+ // and the decimal exponent of the last one kept
134
+ let high = 0;
135
+ let low = 0;
136
+ let digits = 0;
137
+ let e10 = 0;
138
+ if (c !== 46) {
139
+ do {
140
+ if (digits < 15) {
141
+ if (high !== 0 || c !== 48) {
142
+ high = high * 10 + (c - 48);
143
+ digits++;
144
+ }
145
+ }
146
+ else {
147
+ if (digits < 19)
148
+ low = low * 10 + (c - 48);
149
+ else
150
+ e10++;
151
+ digits++;
152
+ }
153
+ c = ++i < end ? s.charCodeAt(i) : -1;
154
+ } while (isDigit(c));
155
+ if (c === 46)
156
+ c = ++i < end ? s.charCodeAt(i) : -1;
157
+ }
158
+ else {
159
+ // "." must be followed by a digit
160
+ c = ++i < end ? s.charCodeAt(i) : -1;
161
+ if (!isDigit(c)) {
162
+ floatScan.read = i;
163
+ return Fail;
164
+ }
165
+ }
166
+ while (isDigit(c)) {
167
+ if (digits < 15) {
168
+ if (high !== 0 || c !== 48) {
169
+ high = high * 10 + (c - 48);
170
+ digits++;
171
+ }
172
+ e10--;
173
+ }
174
+ else {
175
+ if (digits < 19) {
176
+ low = low * 10 + (c - 48);
177
+ e10--;
178
+ }
179
+ digits++;
180
+ }
181
+ c = ++i < end ? s.charCodeAt(i) : -1;
182
+ }
183
+ let read = i;
184
+ if (c === 101 || c === 69) {
185
+ // The exponent is optional: without digits, it is not consumed
186
+ let j = i + 1;
187
+ c = j < end ? s.charCodeAt(j) : -1;
188
+ const negative = c === 45;
189
+ if (negative || c === 43)
190
+ c = ++j < end ? s.charCodeAt(j) : -1;
191
+ if (isDigit(c)) {
192
+ let e = 0;
193
+ do {
194
+ // Past this, the number can only overflow or underflow
195
+ if (e < 1e6)
196
+ e = e * 10 + (c - 48);
197
+ c = ++j < end ? s.charCodeAt(j) : -1;
198
+ } while (isDigit(c));
199
+ e10 += negative ? -e : e;
200
+ i = j;
201
+ }
202
+ read = j;
203
+ }
204
+ floatScan.end = i;
205
+ floatScan.read = read;
206
+ const negative = s.charCodeAt(start) === 45;
207
+ if (high === 0)
208
+ return negative ? -0 : 0;
209
+ const v = digits > 19 ? undefined : decimal(negative, high, low, digits > 15 ? digits - 15 : 0, e10);
210
+ return v === undefined ? Number(s.slice(start, i)) : v;
211
+ };
212
+ /** {@link scanFloatString} on bytes, or the units of an ASCII compatible encoding. */
213
+ export const scanFloatBytes = (b, i, end) => {
214
+ const start = i;
215
+ let c = i < end ? b[i] : -1;
216
+ if (c === 45 || c === 43) {
217
+ c = i + 1 < end ? b[i + 1] : -1;
218
+ if (!isDigit(c) && c !== 46)
219
+ return undefined;
220
+ i++;
221
+ }
222
+ else if (!isDigit(c) && c !== 46) {
223
+ return undefined;
224
+ }
225
+ let high = 0;
226
+ let low = 0;
227
+ let digits = 0;
228
+ let e10 = 0;
229
+ if (c !== 46) {
230
+ do {
231
+ if (digits < 15) {
232
+ if (high !== 0 || c !== 48) {
233
+ high = high * 10 + (c - 48);
234
+ digits++;
235
+ }
236
+ }
237
+ else {
238
+ if (digits < 19)
239
+ low = low * 10 + (c - 48);
240
+ else
241
+ e10++;
242
+ digits++;
243
+ }
244
+ c = ++i < end ? b[i] : -1;
245
+ } while (isDigit(c));
246
+ if (c === 46)
247
+ c = ++i < end ? b[i] : -1;
248
+ }
249
+ else {
250
+ c = ++i < end ? b[i] : -1;
251
+ if (!isDigit(c)) {
252
+ floatScan.read = i;
253
+ return Fail;
254
+ }
255
+ }
256
+ while (isDigit(c)) {
257
+ if (digits < 15) {
258
+ if (high !== 0 || c !== 48) {
259
+ high = high * 10 + (c - 48);
260
+ digits++;
261
+ }
262
+ e10--;
263
+ }
264
+ else {
265
+ if (digits < 19) {
266
+ low = low * 10 + (c - 48);
267
+ e10--;
268
+ }
269
+ digits++;
270
+ }
271
+ c = ++i < end ? b[i] : -1;
272
+ }
273
+ let read = i;
274
+ if (c === 101 || c === 69) {
275
+ let j = i + 1;
276
+ c = j < end ? b[j] : -1;
277
+ const negative = c === 45;
278
+ if (negative || c === 43)
279
+ c = ++j < end ? b[j] : -1;
280
+ if (isDigit(c)) {
281
+ let e = 0;
282
+ do {
283
+ if (e < 1e6)
284
+ e = e * 10 + (c - 48);
285
+ c = ++j < end ? b[j] : -1;
286
+ } while (isDigit(c));
287
+ e10 += negative ? -e : e;
288
+ i = j;
289
+ }
290
+ read = j;
291
+ }
292
+ floatScan.end = i;
293
+ floatScan.read = read;
294
+ const negative = b[start] === 45;
295
+ if (high === 0)
296
+ return negative ? -0 : 0;
297
+ const v = digits > 19 ? undefined : decimal(negative, high, low, digits > 15 ? digits - 15 : 0, e10);
298
+ return v === undefined ? Number(asciiText(b, start, i)) : v;
299
+ };
300
+ /** The text of ASCII bytes. */
301
+ const asciiText = (b, start, end) => String.fromCharCode.apply(null, b.subarray(start, end));
302
+ //# sourceMappingURL=numbers.js.map