@thomasfosterau/effect-parse 0.0.0 → 0.2.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 +247 -230
- 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 +143 -131
- package/dist/Expression.js.map +1 -1
- package/dist/Input.d.ts +206 -177
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +317 -299
- package/dist/Input.js.map +1 -1
- package/dist/Nom.d.ts +44 -84
- 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 +233 -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 +2010 -1802
- package/dist/Parser.js.map +1 -1
- package/dist/ParserSchema.d.ts +8 -7
- package/dist/ParserSchema.d.ts.map +1 -1
- package/dist/ParserSchema.js +49 -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 +26 -0
- package/dist/internal/stack.js.map +1 -0
- package/dist/internal/syntax.d.ts +146 -0
- package/dist/internal/syntax.d.ts.map +1 -0
- package/dist/internal/syntax.js +305 -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/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 +10 -5
- package/src/Input.ts +106 -28
- package/src/Nom.ts +4 -3
- package/src/ParseError.ts +48 -51
- package/src/Parser.ts +1163 -795
- 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 +36 -0
- package/src/internal/syntax.ts +421 -0
- package/src/internal/text.ts +32 -25
- package/src/internal/tokens.ts +96 -51
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type { Input } from "../Input.js";
|
|
6
|
-
import { Fail } from "../Input.js";
|
|
1
|
+
import { Fail, Input } from "../Input.js";
|
|
2
|
+
//#region src/internal/numbers.d.ts
|
|
3
|
+
/** The text of an input slice: as is for a string, Latin-1 for bytes, joined for tokens. */
|
|
4
|
+
export declare const toText: (s: Input) => string;
|
|
7
5
|
/** The value of the text matched by `Ascii.float` and `Text.float`. */
|
|
8
6
|
export declare const toFloat: (s: Input) => number;
|
|
9
7
|
/**
|
|
@@ -20,8 +18,8 @@ export declare const floatText: <P extends object>(p: P) => P;
|
|
|
20
18
|
* when that is near the end of a partial input.
|
|
21
19
|
*/
|
|
22
20
|
export declare const floatScan: {
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
end: number;
|
|
22
|
+
read: number;
|
|
25
23
|
};
|
|
26
24
|
/**
|
|
27
25
|
* Matches and converts what `Ascii.float` matches at `i`, when it is in
|
|
@@ -38,4 +36,5 @@ export declare const floatScan: {
|
|
|
38
36
|
export declare const scanFloatString: (s: string, i: number, end: number) => number | Fail | undefined;
|
|
39
37
|
/** {@link scanFloatString} on bytes, or the units of an ASCII compatible encoding. */
|
|
40
38
|
export declare const scanFloatBytes: (b: Uint8Array, i: number, end: number) => number | Fail | undefined;
|
|
39
|
+
//#endregion
|
|
41
40
|
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numbers.d.ts","
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","names":[],"sources":["../../src/internal/numbers.ts"],"mappings":";;;qBAUa,SAAU,GAAG;;qBAIb,UAAW,GAAG;;;;;;qBAmBd,YAAU;;qBAGV,YAAa,kBAAkB,GAAG,MAAI;;;;;;qBAatC;;;;;;;;;;;;;;;;qBAiFA,kBAAmB,WAAW,WAAW,yBAAuB;;qBAmFhE,iBAAkB,GAAG,YAAY,WAAW,yBAAuB"}
|
package/dist/internal/numbers.js
CHANGED
|
@@ -1,302 +1,272 @@
|
|
|
1
|
+
import * as Predicate from "effect/Predicate";
|
|
1
2
|
import { Fail } from "../Input.js";
|
|
2
3
|
import { latin1 } from "./text.js";
|
|
3
|
-
|
|
4
|
+
//#region src/internal/numbers.ts
|
|
5
|
+
/**
|
|
6
|
+
* Number conversions shared by the `Ascii` and `Text` parsers and the
|
|
7
|
+
* compilers.
|
|
8
|
+
*/
|
|
9
|
+
/** The text of an input slice: as is for a string, Latin-1 for bytes, joined for tokens. */
|
|
10
|
+
const toText = (s) => Predicate.isString(s) ? s : s instanceof Uint8Array ? latin1.text(s, 0, s.length) : s.join("");
|
|
4
11
|
/** The value of the text matched by `Ascii.float` and `Text.float`. */
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return NaN;
|
|
17
|
-
if (body.startsWith("inf"))
|
|
18
|
-
return negative ? -Infinity : Infinity;
|
|
19
|
-
return Number(t);
|
|
12
|
+
const toFloat = (s) => {
|
|
13
|
+
if (Predicate.isString(s)) {
|
|
14
|
+
const last = s.charCodeAt(s.length - 1);
|
|
15
|
+
if (last >= 48 && last <= 57 || last === 46) return Number(s);
|
|
16
|
+
}
|
|
17
|
+
const t = toText(s).toLowerCase();
|
|
18
|
+
const negative = t.startsWith("-");
|
|
19
|
+
const body = t.startsWith("-") || t.startsWith("+") ? t.slice(1) : t;
|
|
20
|
+
if (body === "nan") return NaN;
|
|
21
|
+
if (body.startsWith("inf")) return negative ? -Infinity : Infinity;
|
|
22
|
+
return Number(t);
|
|
20
23
|
};
|
|
21
24
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
* The parsers that `Ascii.float` and `Text.float` map with `toFloat`: the
|
|
26
|
+
* compilers replace them by {@link scanFloatString} and
|
|
27
|
+
* {@link scanFloatBytes} when the text is in decimal notation.
|
|
28
|
+
*/
|
|
29
|
+
const floatTexts = /*#__PURE__*/ new WeakSet();
|
|
27
30
|
/** Adds a parser to {@link floatTexts}. */
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
const floatText = (p) => {
|
|
32
|
+
floatTexts.add(p);
|
|
33
|
+
return p;
|
|
31
34
|
};
|
|
32
35
|
/** The powers of ten that doubles represent exactly. */
|
|
33
|
-
const exact = Array.from({ length: 23 }, (_, i) => Number(`1e${i}`));
|
|
36
|
+
const exact = /*#__PURE__*/ Array.from({ length: 23 }, (_, i) => Number(`1e${i}`));
|
|
34
37
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
* Where the latest scan ended, when it succeeded, and the furthest offset it
|
|
39
|
+
* read (when it succeeded or failed): streaming builds re-run the parser
|
|
40
|
+
* when that is near the end of a partial input.
|
|
41
|
+
*/
|
|
42
|
+
const floatScan = {
|
|
43
|
+
end: 0,
|
|
44
|
+
read: 0
|
|
45
|
+
};
|
|
40
46
|
const isDigit = (c) => c >= 48 && c <= 57;
|
|
41
|
-
|
|
42
|
-
// `productHi + productLo` exactly, barring overflow and underflow
|
|
43
|
-
const Split = 134217729; // 2^27 + 1
|
|
47
|
+
const Split = 134217729;
|
|
44
48
|
let productHi = 0;
|
|
45
49
|
let productLo = 0;
|
|
46
50
|
const twoProduct = (a, b) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
const p = a * b;
|
|
52
|
+
let t = Split * a;
|
|
53
|
+
const ah = t - (t - a);
|
|
54
|
+
const al = a - ah;
|
|
55
|
+
t = Split * b;
|
|
56
|
+
const bh = t - (t - b);
|
|
57
|
+
const bl = b - bh;
|
|
58
|
+
productHi = p;
|
|
59
|
+
productLo = ah * bh - p + ah * bl + al * bh + al * bl;
|
|
56
60
|
};
|
|
57
61
|
/** 2^-96: a bound on the relative error of {@link decimal}'s 19-digit path. */
|
|
58
62
|
const Error19 = 1 / 2 ** 96;
|
|
59
63
|
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
* The double nearest to `±(high * 10^low digits + low) * 10^e10`, where
|
|
65
|
+
* `high` holds the first 15 significant digits, and `low` the next `lowDigits`
|
|
66
|
+
* (at most 4). Returns `undefined` when this can't tell it apart from the
|
|
67
|
+
* neighbouring doubles, for the caller to use `Number`.
|
|
68
|
+
*
|
|
69
|
+
* Up to 15 digits, the digits and a power of ten up to 10^22 are exact
|
|
70
|
+
* doubles, so one multiplication or division rounds correctly (Clinger's
|
|
71
|
+
* fast path). Up to 19 digits, the digits are an exact sum of two doubles,
|
|
72
|
+
* and multiplying or dividing that by an exact power of ten gives the value
|
|
73
|
+
* to within a relative 2^-96 (double-double arithmetic). It is then rounded
|
|
74
|
+
* once, and kept only if the bounds of that error round to the same double:
|
|
75
|
+
* this is never the case for an exact tie, so ties go to `Number` too.
|
|
76
|
+
*/
|
|
73
77
|
const decimal = (negative, high, low, lowDigits, e10) => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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;
|
|
78
|
+
let v;
|
|
79
|
+
if (lowDigits === 0) {
|
|
80
|
+
if (e10 > 22 || e10 < -22) return void 0;
|
|
81
|
+
v = e10 === 0 ? high : e10 > 0 ? high * exact[e10] : high / exact[-e10];
|
|
82
|
+
} else {
|
|
83
|
+
if (e10 > 22 || e10 < -22) return void 0;
|
|
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
|
+
} else {
|
|
95
|
+
const p = exact[-e10];
|
|
96
|
+
xh = wh / p;
|
|
97
|
+
twoProduct(xh, p);
|
|
98
|
+
xl = (wh - productHi - productLo + wl) / p;
|
|
99
|
+
}
|
|
100
|
+
v = xh + xl;
|
|
101
|
+
const error = (xh < 0 ? -xh : xh) * Error19;
|
|
102
|
+
if (xh + (xl + error) !== v || xh + (xl - error) !== v) return void 0;
|
|
103
|
+
}
|
|
104
|
+
return negative ? -v : v;
|
|
107
105
|
};
|
|
108
106
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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;
|
|
107
|
+
* Matches and converts what `Ascii.float` matches at `i`, when it is in
|
|
108
|
+
* decimal notation: an optional sign, then digits or "." (the other forms,
|
|
109
|
+
* `nan` and `inf`, start with a letter). Returns the value, setting
|
|
110
|
+
* `floatScan.end`; `Fail` if the float parser fails there (always with
|
|
111
|
+
* `Backtrack`); or `undefined` if the text does not start like a decimal
|
|
112
|
+
* number, for the caller to run the parser.
|
|
113
|
+
*
|
|
114
|
+
* Numbers with up to 19 significant digits and a decimal exponent up to 22
|
|
115
|
+
* are converted by {@link decimal}, the rest by `Number`, so the value is
|
|
116
|
+
* always what `Number` gives for the text.
|
|
117
|
+
*/
|
|
118
|
+
const scanFloatString = (s, i, end) => {
|
|
119
|
+
const start = i;
|
|
120
|
+
let c = i < end ? s.charCodeAt(i) : -1;
|
|
121
|
+
if (c === 45 || c === 43) {
|
|
122
|
+
c = i + 1 < end ? s.charCodeAt(i + 1) : -1;
|
|
123
|
+
if (!isDigit(c) && c !== 46) return void 0;
|
|
124
|
+
i++;
|
|
125
|
+
} else if (!isDigit(c) && c !== 46) return;
|
|
126
|
+
let high = 0;
|
|
127
|
+
let low = 0;
|
|
128
|
+
let digits = 0;
|
|
129
|
+
let e10 = 0;
|
|
130
|
+
if (c !== 46) {
|
|
131
|
+
do {
|
|
132
|
+
if (digits < 15) {
|
|
133
|
+
if (high !== 0 || c !== 48) {
|
|
134
|
+
high = high * 10 + (c - 48);
|
|
135
|
+
digits++;
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
if (digits < 19) low = low * 10 + (c - 48);
|
|
139
|
+
else e10++;
|
|
140
|
+
digits++;
|
|
141
|
+
}
|
|
142
|
+
c = ++i < end ? s.charCodeAt(i) : -1;
|
|
143
|
+
} while (isDigit(c));
|
|
144
|
+
if (c === 46) c = ++i < end ? s.charCodeAt(i) : -1;
|
|
145
|
+
} else {
|
|
146
|
+
c = ++i < end ? s.charCodeAt(i) : -1;
|
|
147
|
+
if (!isDigit(c)) {
|
|
148
|
+
floatScan.read = i;
|
|
149
|
+
return Fail;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
while (isDigit(c)) {
|
|
153
|
+
if (digits < 15) {
|
|
154
|
+
if (high !== 0 || c !== 48) {
|
|
155
|
+
high = high * 10 + (c - 48);
|
|
156
|
+
digits++;
|
|
157
|
+
}
|
|
158
|
+
e10--;
|
|
159
|
+
} else {
|
|
160
|
+
if (digits < 19) {
|
|
161
|
+
low = low * 10 + (c - 48);
|
|
162
|
+
e10--;
|
|
163
|
+
}
|
|
164
|
+
digits++;
|
|
165
|
+
}
|
|
166
|
+
c = ++i < end ? s.charCodeAt(i) : -1;
|
|
167
|
+
}
|
|
168
|
+
let read = i;
|
|
169
|
+
if (c === 101 || c === 69) {
|
|
170
|
+
let j = i + 1;
|
|
171
|
+
c = j < end ? s.charCodeAt(j) : -1;
|
|
172
|
+
const negative = c === 45;
|
|
173
|
+
if (negative || c === 43) c = ++j < end ? s.charCodeAt(j) : -1;
|
|
174
|
+
if (isDigit(c)) {
|
|
175
|
+
let e = 0;
|
|
176
|
+
do {
|
|
177
|
+
if (e < 1e6) e = e * 10 + (c - 48);
|
|
178
|
+
c = ++j < end ? s.charCodeAt(j) : -1;
|
|
179
|
+
} while (isDigit(c));
|
|
180
|
+
e10 += negative ? -e : e;
|
|
181
|
+
i = j;
|
|
182
|
+
}
|
|
183
|
+
read = j;
|
|
184
|
+
}
|
|
185
|
+
floatScan.end = i;
|
|
186
|
+
floatScan.read = read;
|
|
187
|
+
const negative = s.charCodeAt(start) === 45;
|
|
188
|
+
if (high === 0) return negative ? -0 : 0;
|
|
189
|
+
const v = digits > 19 ? void 0 : decimal(negative, high, low, digits > 15 ? digits - 15 : 0, e10);
|
|
190
|
+
return v === void 0 ? Number(s.slice(start, i)) : v;
|
|
211
191
|
};
|
|
212
192
|
/** {@link scanFloatString} on bytes, or the units of an ASCII compatible encoding. */
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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;
|
|
193
|
+
const scanFloatBytes = (b, i, end) => {
|
|
194
|
+
const start = i;
|
|
195
|
+
let c = i < end ? b[i] : -1;
|
|
196
|
+
if (c === 45 || c === 43) {
|
|
197
|
+
c = i + 1 < end ? b[i + 1] : -1;
|
|
198
|
+
if (!isDigit(c) && c !== 46) return void 0;
|
|
199
|
+
i++;
|
|
200
|
+
} else if (!isDigit(c) && c !== 46) return;
|
|
201
|
+
let high = 0;
|
|
202
|
+
let low = 0;
|
|
203
|
+
let digits = 0;
|
|
204
|
+
let e10 = 0;
|
|
205
|
+
if (c !== 46) {
|
|
206
|
+
do {
|
|
207
|
+
if (digits < 15) {
|
|
208
|
+
if (high !== 0 || c !== 48) {
|
|
209
|
+
high = high * 10 + (c - 48);
|
|
210
|
+
digits++;
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
if (digits < 19) low = low * 10 + (c - 48);
|
|
214
|
+
else e10++;
|
|
215
|
+
digits++;
|
|
216
|
+
}
|
|
217
|
+
c = ++i < end ? b[i] : -1;
|
|
218
|
+
} while (isDigit(c));
|
|
219
|
+
if (c === 46) c = ++i < end ? b[i] : -1;
|
|
220
|
+
} else {
|
|
221
|
+
c = ++i < end ? b[i] : -1;
|
|
222
|
+
if (!isDigit(c)) {
|
|
223
|
+
floatScan.read = i;
|
|
224
|
+
return Fail;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
while (isDigit(c)) {
|
|
228
|
+
if (digits < 15) {
|
|
229
|
+
if (high !== 0 || c !== 48) {
|
|
230
|
+
high = high * 10 + (c - 48);
|
|
231
|
+
digits++;
|
|
232
|
+
}
|
|
233
|
+
e10--;
|
|
234
|
+
} else {
|
|
235
|
+
if (digits < 19) {
|
|
236
|
+
low = low * 10 + (c - 48);
|
|
237
|
+
e10--;
|
|
238
|
+
}
|
|
239
|
+
digits++;
|
|
240
|
+
}
|
|
241
|
+
c = ++i < end ? b[i] : -1;
|
|
242
|
+
}
|
|
243
|
+
let read = i;
|
|
244
|
+
if (c === 101 || c === 69) {
|
|
245
|
+
let j = i + 1;
|
|
246
|
+
c = j < end ? b[j] : -1;
|
|
247
|
+
const negative = c === 45;
|
|
248
|
+
if (negative || c === 43) c = ++j < end ? b[j] : -1;
|
|
249
|
+
if (isDigit(c)) {
|
|
250
|
+
let e = 0;
|
|
251
|
+
do {
|
|
252
|
+
if (e < 1e6) e = e * 10 + (c - 48);
|
|
253
|
+
c = ++j < end ? b[j] : -1;
|
|
254
|
+
} while (isDigit(c));
|
|
255
|
+
e10 += negative ? -e : e;
|
|
256
|
+
i = j;
|
|
257
|
+
}
|
|
258
|
+
read = j;
|
|
259
|
+
}
|
|
260
|
+
floatScan.end = i;
|
|
261
|
+
floatScan.read = read;
|
|
262
|
+
const negative = b[start] === 45;
|
|
263
|
+
if (high === 0) return negative ? -0 : 0;
|
|
264
|
+
const v = digits > 19 ? void 0 : decimal(negative, high, low, digits > 15 ? digits - 15 : 0, e10);
|
|
265
|
+
return v === void 0 ? Number(asciiText(b, start, i)) : v;
|
|
299
266
|
};
|
|
300
267
|
/** The text of ASCII bytes. */
|
|
301
268
|
const asciiText = (b, start, end) => String.fromCharCode.apply(null, b.subarray(start, end));
|
|
269
|
+
//#endregion
|
|
270
|
+
export { floatScan, floatText, floatTexts, scanFloatBytes, scanFloatString, toFloat, toText };
|
|
271
|
+
|
|
302
272
|
//# sourceMappingURL=numbers.js.map
|