@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
package/src/Ascii.ts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*
|
|
22
22
|
* @since 0.1.0
|
|
23
23
|
*/
|
|
24
|
+
import * as Predicate from "effect/Predicate"
|
|
24
25
|
import * as Result from "effect/Result"
|
|
25
26
|
import type { Encoding } from "./Encoding.js"
|
|
26
27
|
import type { Input, Slice, State } from "./Input.js"
|
|
@@ -30,7 +31,6 @@ import type { Parser } from "./Parser.js"
|
|
|
30
31
|
import * as P from "./Parser.js"
|
|
31
32
|
import * as numbers from "./internal/numbers.js"
|
|
32
33
|
import * as Resume from "./internal/resume.js"
|
|
33
|
-
import { latin1 } from "./internal/text.js"
|
|
34
34
|
import { codePointPredicate } from "./internal/tokens.js"
|
|
35
35
|
import { literalImpl, range, takeWhileImpl } from "./Token.js"
|
|
36
36
|
import * as Token from "./Token.js"
|
|
@@ -39,7 +39,7 @@ import * as Token from "./Token.js"
|
|
|
39
39
|
// Character predicates
|
|
40
40
|
// -----------------------------------------------------------------------------
|
|
41
41
|
|
|
42
|
-
const code = (c: string | number): number =>
|
|
42
|
+
const code = (c: string | number): number => (Predicate.isNumber(c) ? c : c.charCodeAt(0))
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* `[a-zA-Z]`
|
|
@@ -47,10 +47,17 @@ const code = (c: string | number): number => typeof c === "number" ? c : c.charC
|
|
|
47
47
|
* @since 0.1.0
|
|
48
48
|
* @category predicates
|
|
49
49
|
*/
|
|
50
|
-
export const isAlpha: (c: string | number) => boolean = codePointPredicate(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
export const isAlpha: (c: string | number) => boolean = /*#__PURE__*/ codePointPredicate(
|
|
51
|
+
"isAlpha",
|
|
52
|
+
(c: string | number): boolean => {
|
|
53
|
+
const x = code(c)
|
|
54
|
+
return (x >= 65 && x <= 90) || (x >= 97 && x <= 122)
|
|
55
|
+
},
|
|
56
|
+
[
|
|
57
|
+
[65, 90],
|
|
58
|
+
[97, 122]
|
|
59
|
+
]
|
|
60
|
+
)
|
|
54
61
|
|
|
55
62
|
/**
|
|
56
63
|
* `[0-9]`
|
|
@@ -58,10 +65,14 @@ export const isAlpha: (c: string | number) => boolean = codePointPredicate("isAl
|
|
|
58
65
|
* @since 0.1.0
|
|
59
66
|
* @category predicates
|
|
60
67
|
*/
|
|
61
|
-
export const isDigit: (c: string | number) => boolean = codePointPredicate(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
export const isDigit: (c: string | number) => boolean = /*#__PURE__*/ codePointPredicate(
|
|
69
|
+
"isDigit",
|
|
70
|
+
(c: string | number): boolean => {
|
|
71
|
+
const x = code(c)
|
|
72
|
+
return x >= 48 && x <= 57
|
|
73
|
+
},
|
|
74
|
+
[[48, 57]]
|
|
75
|
+
)
|
|
65
76
|
|
|
66
77
|
/**
|
|
67
78
|
* `[0-9a-fA-F]`
|
|
@@ -69,10 +80,18 @@ export const isDigit: (c: string | number) => boolean = codePointPredicate("isDi
|
|
|
69
80
|
* @since 0.1.0
|
|
70
81
|
* @category predicates
|
|
71
82
|
*/
|
|
72
|
-
export const isHexDigit: (c: string | number) => boolean = codePointPredicate(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
export const isHexDigit: (c: string | number) => boolean = /*#__PURE__*/ codePointPredicate(
|
|
84
|
+
"isHexDigit",
|
|
85
|
+
(c: string | number): boolean => {
|
|
86
|
+
const x = code(c)
|
|
87
|
+
return (x >= 48 && x <= 57) || (x >= 65 && x <= 70) || (x >= 97 && x <= 102)
|
|
88
|
+
},
|
|
89
|
+
[
|
|
90
|
+
[48, 57],
|
|
91
|
+
[65, 70],
|
|
92
|
+
[97, 102]
|
|
93
|
+
]
|
|
94
|
+
)
|
|
76
95
|
|
|
77
96
|
/**
|
|
78
97
|
* `[0-7]`
|
|
@@ -80,10 +99,14 @@ export const isHexDigit: (c: string | number) => boolean = codePointPredicate("i
|
|
|
80
99
|
* @since 0.1.0
|
|
81
100
|
* @category predicates
|
|
82
101
|
*/
|
|
83
|
-
export const isOctDigit: (c: string | number) => boolean = codePointPredicate(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
102
|
+
export const isOctDigit: (c: string | number) => boolean = /*#__PURE__*/ codePointPredicate(
|
|
103
|
+
"isOctDigit",
|
|
104
|
+
(c: string | number): boolean => {
|
|
105
|
+
const x = code(c)
|
|
106
|
+
return x >= 48 && x <= 55
|
|
107
|
+
},
|
|
108
|
+
[[48, 55]]
|
|
109
|
+
)
|
|
87
110
|
|
|
88
111
|
/**
|
|
89
112
|
* `[0-9a-zA-Z]`
|
|
@@ -91,10 +114,14 @@ export const isOctDigit: (c: string | number) => boolean = codePointPredicate("i
|
|
|
91
114
|
* @since 0.1.0
|
|
92
115
|
* @category predicates
|
|
93
116
|
*/
|
|
94
|
-
export const isAlphanumeric: (c: string | number) => boolean = codePointPredicate(
|
|
117
|
+
export const isAlphanumeric: (c: string | number) => boolean = /*#__PURE__*/ codePointPredicate(
|
|
95
118
|
"isAlphanumeric",
|
|
96
119
|
(c: string | number): boolean => isAlpha(c) || isDigit(c),
|
|
97
|
-
[
|
|
120
|
+
[
|
|
121
|
+
[48, 57],
|
|
122
|
+
[65, 90],
|
|
123
|
+
[97, 122]
|
|
124
|
+
]
|
|
98
125
|
)
|
|
99
126
|
|
|
100
127
|
/**
|
|
@@ -103,10 +130,17 @@ export const isAlphanumeric: (c: string | number) => boolean = codePointPredicat
|
|
|
103
130
|
* @since 0.1.0
|
|
104
131
|
* @category predicates
|
|
105
132
|
*/
|
|
106
|
-
export const isSpace: (c: string | number) => boolean = codePointPredicate(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
133
|
+
export const isSpace: (c: string | number) => boolean = /*#__PURE__*/ codePointPredicate(
|
|
134
|
+
"isSpace",
|
|
135
|
+
(c: string | number): boolean => {
|
|
136
|
+
const x = code(c)
|
|
137
|
+
return x === 32 || x === 9
|
|
138
|
+
},
|
|
139
|
+
[
|
|
140
|
+
[9, 9],
|
|
141
|
+
[32, 32]
|
|
142
|
+
]
|
|
143
|
+
)
|
|
110
144
|
|
|
111
145
|
/**
|
|
112
146
|
* `[ \t\r\n]`
|
|
@@ -114,10 +148,18 @@ export const isSpace: (c: string | number) => boolean = codePointPredicate("isSp
|
|
|
114
148
|
* @since 0.1.0
|
|
115
149
|
* @category predicates
|
|
116
150
|
*/
|
|
117
|
-
export const isMultispace: (c: string | number) => boolean = codePointPredicate(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
151
|
+
export const isMultispace: (c: string | number) => boolean = /*#__PURE__*/ codePointPredicate(
|
|
152
|
+
"isMultispace",
|
|
153
|
+
(c: string | number): boolean => {
|
|
154
|
+
const x = code(c)
|
|
155
|
+
return x === 32 || x === 9 || x === 10 || x === 13
|
|
156
|
+
},
|
|
157
|
+
[
|
|
158
|
+
[9, 10],
|
|
159
|
+
[13, 13],
|
|
160
|
+
[32, 32]
|
|
161
|
+
]
|
|
162
|
+
)
|
|
121
163
|
|
|
122
164
|
/**
|
|
123
165
|
* `\n`
|
|
@@ -125,14 +167,18 @@ export const isMultispace: (c: string | number) => boolean = codePointPredicate(
|
|
|
125
167
|
* @since 0.1.0
|
|
126
168
|
* @category predicates
|
|
127
169
|
*/
|
|
128
|
-
export const isNewline: (c: string | number) => boolean = codePointPredicate(
|
|
170
|
+
export const isNewline: (c: string | number) => boolean = /*#__PURE__*/ codePointPredicate(
|
|
171
|
+
"isNewline",
|
|
172
|
+
(c: string | number): boolean => code(c) === 10,
|
|
173
|
+
[[10, 10]]
|
|
174
|
+
)
|
|
129
175
|
|
|
130
176
|
// Token sets usable for both string and byte input
|
|
131
|
-
const alphaSet = [range("a", "z"), range("A", "Z")]
|
|
132
|
-
const digitSet = range("0", "9")
|
|
133
|
-
const hexSet = [range("0", "9"), range("a", "f"), range("A", "F")]
|
|
134
|
-
const octSet = range("0", "7")
|
|
135
|
-
const alnumSet = [range("a", "z"), range("A", "Z"), range("0", "9")]
|
|
177
|
+
const alphaSet = [/*#__PURE__*/ range("a", "z"), /*#__PURE__*/ range("A", "Z")]
|
|
178
|
+
const digitSet = /*#__PURE__*/ range("0", "9")
|
|
179
|
+
const hexSet = [/*#__PURE__*/ range("0", "9"), /*#__PURE__*/ range("a", "f"), /*#__PURE__*/ range("A", "F")]
|
|
180
|
+
const octSet = /*#__PURE__*/ range("0", "7")
|
|
181
|
+
const alnumSet = [/*#__PURE__*/ range("a", "z"), /*#__PURE__*/ range("A", "Z"), /*#__PURE__*/ range("0", "9")]
|
|
136
182
|
const spaceSet = " \t"
|
|
137
183
|
const multispaceSet = " \t\r\n"
|
|
138
184
|
|
|
@@ -149,7 +195,7 @@ const cls = (set: unknown, min: 0 | 1, description: string, kind: ErrorKind, hin
|
|
|
149
195
|
* @since 0.1.0
|
|
150
196
|
* @category character classes
|
|
151
197
|
*/
|
|
152
|
-
export const alpha0: Parser<string> = cls(alphaSet, 0, "letter", "Alpha")
|
|
198
|
+
export const alpha0: Parser<string> = /*#__PURE__*/ cls(alphaSet, 0, "letter", "Alpha")
|
|
153
199
|
|
|
154
200
|
/**
|
|
155
201
|
* One or more ASCII letters, `[a-zA-Z]+`.
|
|
@@ -157,7 +203,7 @@ export const alpha0: Parser<string> = cls(alphaSet, 0, "letter", "Alpha")
|
|
|
157
203
|
* @since 0.1.0
|
|
158
204
|
* @category character classes
|
|
159
205
|
*/
|
|
160
|
-
export const alpha1: Parser<string> = cls(alphaSet, 1, "letter", "Alpha")
|
|
206
|
+
export const alpha1: Parser<string> = /*#__PURE__*/ cls(alphaSet, 1, "letter", "Alpha")
|
|
161
207
|
|
|
162
208
|
/**
|
|
163
209
|
* Zero or more ASCII digits, `[0-9]*`.
|
|
@@ -165,7 +211,7 @@ export const alpha1: Parser<string> = cls(alphaSet, 1, "letter", "Alpha")
|
|
|
165
211
|
* @since 0.1.0
|
|
166
212
|
* @category character classes
|
|
167
213
|
*/
|
|
168
|
-
export const digit0: Parser<string> = cls(digitSet, 0, "digit", "Digit")
|
|
214
|
+
export const digit0: Parser<string> = /*#__PURE__*/ cls(digitSet, 0, "digit", "Digit")
|
|
169
215
|
|
|
170
216
|
/**
|
|
171
217
|
* One or more ASCII digits, `[0-9]+`.
|
|
@@ -173,7 +219,7 @@ export const digit0: Parser<string> = cls(digitSet, 0, "digit", "Digit")
|
|
|
173
219
|
* @since 0.1.0
|
|
174
220
|
* @category character classes
|
|
175
221
|
*/
|
|
176
|
-
export const digit1: Parser<string> = cls(digitSet, 1, "digit", "Digit")
|
|
222
|
+
export const digit1: Parser<string> = /*#__PURE__*/ cls(digitSet, 1, "digit", "Digit")
|
|
177
223
|
|
|
178
224
|
/**
|
|
179
225
|
* Zero or more hexadecimal digits, `[0-9a-fA-F]*`.
|
|
@@ -181,7 +227,7 @@ export const digit1: Parser<string> = cls(digitSet, 1, "digit", "Digit")
|
|
|
181
227
|
* @since 0.1.0
|
|
182
228
|
* @category character classes
|
|
183
229
|
*/
|
|
184
|
-
export const hexDigit0: Parser<string> = cls(hexSet, 0, "hexadecimal digit", "HexDigit")
|
|
230
|
+
export const hexDigit0: Parser<string> = /*#__PURE__*/ cls(hexSet, 0, "hexadecimal digit", "HexDigit")
|
|
185
231
|
|
|
186
232
|
/**
|
|
187
233
|
* One or more hexadecimal digits, `[0-9a-fA-F]+`.
|
|
@@ -189,7 +235,7 @@ export const hexDigit0: Parser<string> = cls(hexSet, 0, "hexadecimal digit", "He
|
|
|
189
235
|
* @since 0.1.0
|
|
190
236
|
* @category character classes
|
|
191
237
|
*/
|
|
192
|
-
export const hexDigit1: Parser<string> = cls(hexSet, 1, "hexadecimal digit", "HexDigit")
|
|
238
|
+
export const hexDigit1: Parser<string> = /*#__PURE__*/ cls(hexSet, 1, "hexadecimal digit", "HexDigit")
|
|
193
239
|
|
|
194
240
|
/**
|
|
195
241
|
* Zero or more octal digits, `[0-7]*`.
|
|
@@ -197,7 +243,7 @@ export const hexDigit1: Parser<string> = cls(hexSet, 1, "hexadecimal digit", "He
|
|
|
197
243
|
* @since 0.1.0
|
|
198
244
|
* @category character classes
|
|
199
245
|
*/
|
|
200
|
-
export const octDigit0: Parser<string> = cls(octSet, 0, "octal digit", "OctDigit")
|
|
246
|
+
export const octDigit0: Parser<string> = /*#__PURE__*/ cls(octSet, 0, "octal digit", "OctDigit")
|
|
201
247
|
|
|
202
248
|
/**
|
|
203
249
|
* One or more octal digits, `[0-7]+`.
|
|
@@ -205,7 +251,7 @@ export const octDigit0: Parser<string> = cls(octSet, 0, "octal digit", "OctDigit
|
|
|
205
251
|
* @since 0.1.0
|
|
206
252
|
* @category character classes
|
|
207
253
|
*/
|
|
208
|
-
export const octDigit1: Parser<string> = cls(octSet, 1, "octal digit", "OctDigit")
|
|
254
|
+
export const octDigit1: Parser<string> = /*#__PURE__*/ cls(octSet, 1, "octal digit", "OctDigit")
|
|
209
255
|
|
|
210
256
|
/**
|
|
211
257
|
* Zero or more ASCII letters or digits, `[0-9a-zA-Z]*`.
|
|
@@ -213,7 +259,7 @@ export const octDigit1: Parser<string> = cls(octSet, 1, "octal digit", "OctDigit
|
|
|
213
259
|
* @since 0.1.0
|
|
214
260
|
* @category character classes
|
|
215
261
|
*/
|
|
216
|
-
export const alphanumeric0: Parser<string> = cls(alnumSet, 0, "letter or digit", "AlphaNumeric")
|
|
262
|
+
export const alphanumeric0: Parser<string> = /*#__PURE__*/ cls(alnumSet, 0, "letter or digit", "AlphaNumeric")
|
|
217
263
|
|
|
218
264
|
/**
|
|
219
265
|
* One or more ASCII letters or digits, `[0-9a-zA-Z]+`.
|
|
@@ -221,7 +267,7 @@ export const alphanumeric0: Parser<string> = cls(alnumSet, 0, "letter or digit",
|
|
|
221
267
|
* @since 0.1.0
|
|
222
268
|
* @category character classes
|
|
223
269
|
*/
|
|
224
|
-
export const alphanumeric1: Parser<string> = cls(alnumSet, 1, "letter or digit", "AlphaNumeric")
|
|
270
|
+
export const alphanumeric1: Parser<string> = /*#__PURE__*/ cls(alnumSet, 1, "letter or digit", "AlphaNumeric")
|
|
225
271
|
|
|
226
272
|
/**
|
|
227
273
|
* Zero or more spaces and tabs, `[ \t]*`.
|
|
@@ -229,7 +275,7 @@ export const alphanumeric1: Parser<string> = cls(alnumSet, 1, "letter or digit",
|
|
|
229
275
|
* @since 0.1.0
|
|
230
276
|
* @category character classes
|
|
231
277
|
*/
|
|
232
|
-
export const space0: Parser<string> = cls(spaceSet, 0, "space", "Space", false)
|
|
278
|
+
export const space0: Parser<string> = /*#__PURE__*/ cls(spaceSet, 0, "space", "Space", false)
|
|
233
279
|
|
|
234
280
|
/**
|
|
235
281
|
* One or more spaces and tabs, `[ \t]+`.
|
|
@@ -237,7 +283,7 @@ export const space0: Parser<string> = cls(spaceSet, 0, "space", "Space", false)
|
|
|
237
283
|
* @since 0.1.0
|
|
238
284
|
* @category character classes
|
|
239
285
|
*/
|
|
240
|
-
export const space1: Parser<string> = cls(spaceSet, 1, "space", "Space", false)
|
|
286
|
+
export const space1: Parser<string> = /*#__PURE__*/ cls(spaceSet, 1, "space", "Space", false)
|
|
241
287
|
|
|
242
288
|
/**
|
|
243
289
|
* Zero or more spaces, tabs, carriage returns and line feeds,
|
|
@@ -246,7 +292,7 @@ export const space1: Parser<string> = cls(spaceSet, 1, "space", "Space", false)
|
|
|
246
292
|
* @since 0.1.0
|
|
247
293
|
* @category character classes
|
|
248
294
|
*/
|
|
249
|
-
export const multispace0: Parser<string> = cls(multispaceSet, 0, "whitespace", "MultiSpace", false)
|
|
295
|
+
export const multispace0: Parser<string> = /*#__PURE__*/ cls(multispaceSet, 0, "whitespace", "MultiSpace", false)
|
|
250
296
|
|
|
251
297
|
/**
|
|
252
298
|
* One or more spaces, tabs, carriage returns and line feeds,
|
|
@@ -255,7 +301,7 @@ export const multispace0: Parser<string> = cls(multispaceSet, 0, "whitespace", "
|
|
|
255
301
|
* @since 0.1.0
|
|
256
302
|
* @category character classes
|
|
257
303
|
*/
|
|
258
|
-
export const multispace1: Parser<string> = cls(multispaceSet, 1, "whitespace", "MultiSpace", false)
|
|
304
|
+
export const multispace1: Parser<string> = /*#__PURE__*/ cls(multispaceSet, 1, "whitespace", "MultiSpace", false)
|
|
259
305
|
|
|
260
306
|
// -----------------------------------------------------------------------------
|
|
261
307
|
// Line endings
|
|
@@ -267,7 +313,7 @@ export const multispace1: Parser<string> = cls(multispaceSet, 1, "whitespace", "
|
|
|
267
313
|
* @since 0.1.0
|
|
268
314
|
* @category line endings
|
|
269
315
|
*/
|
|
270
|
-
export const crlf: Parser<"\r\n"> = Token.literal("\r\n")
|
|
316
|
+
export const crlf: Parser<"\r\n"> = /*#__PURE__*/ Token.literal("\r\n")
|
|
271
317
|
|
|
272
318
|
/**
|
|
273
319
|
* A line feed, `\n` (nom's `newline`).
|
|
@@ -275,7 +321,7 @@ export const crlf: Parser<"\r\n"> = Token.literal("\r\n")
|
|
|
275
321
|
* @since 0.1.0
|
|
276
322
|
* @category line endings
|
|
277
323
|
*/
|
|
278
|
-
export const newline: Parser<"\n"> = Token.literal("\n")
|
|
324
|
+
export const newline: Parser<"\n"> = /*#__PURE__*/ Token.literal("\n")
|
|
279
325
|
|
|
280
326
|
/**
|
|
281
327
|
* A tab, `\t`.
|
|
@@ -283,7 +329,7 @@ export const newline: Parser<"\n"> = Token.literal("\n")
|
|
|
283
329
|
* @since 0.1.0
|
|
284
330
|
* @category line endings
|
|
285
331
|
*/
|
|
286
|
-
export const tab: Parser<"\t"> = Token.literal("\t")
|
|
332
|
+
export const tab: Parser<"\t"> = /*#__PURE__*/ Token.literal("\t")
|
|
287
333
|
|
|
288
334
|
/**
|
|
289
335
|
* A line ending: `\n` or `\r\n`.
|
|
@@ -291,7 +337,9 @@ export const tab: Parser<"\t"> = Token.literal("\t")
|
|
|
291
337
|
* @since 0.1.0
|
|
292
338
|
* @category line endings
|
|
293
339
|
*/
|
|
294
|
-
export const lineEnding: Parser<"\n" | "\r\n"> = P.alt(newline, crlf).pipe(
|
|
340
|
+
export const lineEnding: Parser<"\n" | "\r\n"> = /*#__PURE__*/ P.alt(newline, crlf).pipe(
|
|
341
|
+
/*#__PURE__*/ P.expected("line ending")
|
|
342
|
+
)
|
|
295
343
|
|
|
296
344
|
const expectedLineEnding = ["line ending"]
|
|
297
345
|
|
|
@@ -303,38 +351,40 @@ const expectedLineEnding = ["line ending"]
|
|
|
303
351
|
* @since 0.1.0
|
|
304
352
|
* @category line endings
|
|
305
353
|
*/
|
|
306
|
-
export const tillLineEnding: Parser<string> = P.described<string>(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (
|
|
316
|
-
|
|
354
|
+
export const tillLineEnding: Parser<string> = /*#__PURE__*/ P.described<string>(
|
|
355
|
+
(state: State<any>) => {
|
|
356
|
+
const start = state.pos
|
|
357
|
+
const input = state.input
|
|
358
|
+
const isString = state.inputKind === 0
|
|
359
|
+
let i = start
|
|
360
|
+
while (i < state.end) {
|
|
361
|
+
const c = isString ? (input as string).charCodeAt(i) : (input as Uint8Array)[i]
|
|
362
|
+
if (c === 10) break
|
|
363
|
+
if (c === 13) {
|
|
364
|
+
// The line feed after it is read, not consumed
|
|
365
|
+
state.syntax?.read(i + 2)
|
|
366
|
+
if (i + 1 >= state.end) {
|
|
367
|
+
if (state.partial) return state.incomplete(1, expectedLineEnding)
|
|
368
|
+
return state.backtrack("LineEnding", expectedLineEnding, i)
|
|
369
|
+
}
|
|
370
|
+
const d = isString ? (input as string).charCodeAt(i + 1) : (input as Uint8Array)[i + 1]
|
|
371
|
+
if (d === 10) break
|
|
317
372
|
return state.backtrack("LineEnding", expectedLineEnding, i)
|
|
318
373
|
}
|
|
319
|
-
|
|
320
|
-
if (d === 10) break
|
|
321
|
-
return state.backtrack("LineEnding", expectedLineEnding, i)
|
|
374
|
+
i++
|
|
322
375
|
}
|
|
323
|
-
i
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
376
|
+
if (i >= state.end && state.partial) return state.incomplete(1, expectedLineEnding)
|
|
377
|
+
state.pos = i
|
|
378
|
+
return state.slice(start, i) as string
|
|
379
|
+
},
|
|
380
|
+
"tillLineEnding",
|
|
381
|
+
{ _tag: "TillLineEnding", encoding: undefined }
|
|
382
|
+
)
|
|
329
383
|
|
|
330
384
|
// -----------------------------------------------------------------------------
|
|
331
385
|
// Numbers
|
|
332
386
|
// -----------------------------------------------------------------------------
|
|
333
387
|
|
|
334
|
-
const toText = (s: Input): string =>
|
|
335
|
-
typeof s === "string" ? s : s instanceof Uint8Array ? latin1.text(s, 0, s.length) : s.join("")
|
|
336
|
-
|
|
337
|
-
|
|
338
388
|
/** @internal */
|
|
339
389
|
export const overflow = (value: number): Result.Result<number, string> =>
|
|
340
390
|
Number.isSafeInteger(value) ? Result.succeed(value) : Result.fail("integer overflow")
|
|
@@ -346,9 +396,9 @@ export const overflow = (value: number): Result.Result<number, string> =>
|
|
|
346
396
|
* @since 0.1.0
|
|
347
397
|
* @category numbers
|
|
348
398
|
*/
|
|
349
|
-
export const decUint: Parser<number, string> = digit1.pipe(
|
|
350
|
-
P.tryMap((s) => overflow(Number(toText(s)))),
|
|
351
|
-
P.named("decUint")
|
|
399
|
+
export const decUint: Parser<number, string> = /*#__PURE__*/ digit1.pipe(
|
|
400
|
+
/*#__PURE__*/ P.tryMap((s) => overflow(Number(numbers.toText(s)))),
|
|
401
|
+
/*#__PURE__*/ P.named("decUint")
|
|
352
402
|
)
|
|
353
403
|
|
|
354
404
|
/**
|
|
@@ -359,9 +409,11 @@ export const decUint: Parser<number, string> = digit1.pipe(
|
|
|
359
409
|
* @since 0.1.0
|
|
360
410
|
* @category numbers
|
|
361
411
|
*/
|
|
362
|
-
export const decInt: Parser<number, string> = P.taken(
|
|
363
|
-
P.
|
|
364
|
-
|
|
412
|
+
export const decInt: Parser<number, string> = /*#__PURE__*/ P.taken(
|
|
413
|
+
/*#__PURE__*/ P.seq(/*#__PURE__*/ P.opt(/*#__PURE__*/ Token.oneOf("+-")), digit1)
|
|
414
|
+
).pipe(
|
|
415
|
+
/*#__PURE__*/ P.tryMap((s) => overflow(Number(numbers.toText(s)))),
|
|
416
|
+
/*#__PURE__*/ P.named("decInt")
|
|
365
417
|
)
|
|
366
418
|
|
|
367
419
|
/**
|
|
@@ -370,7 +422,9 @@ export const decInt: Parser<number, string> = P.taken(P.seq(P.opt(Token.oneOf("+
|
|
|
370
422
|
* @since 0.1.0
|
|
371
423
|
* @category numbers
|
|
372
424
|
*/
|
|
373
|
-
export const decBigUint: Parser<bigint> = digit1.pipe(
|
|
425
|
+
export const decBigUint: Parser<bigint> = /*#__PURE__*/ digit1.pipe(
|
|
426
|
+
/*#__PURE__*/ P.map((s) => BigInt(numbers.toText(s)))
|
|
427
|
+
)
|
|
374
428
|
|
|
375
429
|
/**
|
|
376
430
|
* A signed decimal integer as a `bigint`, of any size.
|
|
@@ -378,9 +432,11 @@ export const decBigUint: Parser<bigint> = digit1.pipe(P.map((s) => BigInt(toText
|
|
|
378
432
|
* @since 0.1.0
|
|
379
433
|
* @category numbers
|
|
380
434
|
*/
|
|
381
|
-
export const decBigInt: Parser<bigint> = P.taken(
|
|
382
|
-
P.
|
|
383
|
-
|
|
435
|
+
export const decBigInt: Parser<bigint> = /*#__PURE__*/ P.taken(
|
|
436
|
+
/*#__PURE__*/ P.seq(/*#__PURE__*/ P.opt(/*#__PURE__*/ Token.oneOf("+-")), digit1)
|
|
437
|
+
).pipe(
|
|
438
|
+
/*#__PURE__*/ P.map((s) => {
|
|
439
|
+
const t = numbers.toText(s)
|
|
384
440
|
return BigInt(t.startsWith("+") ? t.slice(1) : t)
|
|
385
441
|
})
|
|
386
442
|
)
|
|
@@ -392,22 +448,30 @@ export const decBigInt: Parser<bigint> = P.taken(P.seq(P.opt(Token.oneOf("+-")),
|
|
|
392
448
|
* @since 0.1.0
|
|
393
449
|
* @category numbers
|
|
394
450
|
*/
|
|
395
|
-
export const hexUint: Parser<number, string> = hexDigit1.pipe(
|
|
396
|
-
P.tryMap((s) => overflow(parseInt(toText(s), 16))),
|
|
397
|
-
P.named("hexUint")
|
|
451
|
+
export const hexUint: Parser<number, string> = /*#__PURE__*/ hexDigit1.pipe(
|
|
452
|
+
/*#__PURE__*/ P.tryMap((s) => overflow(parseInt(numbers.toText(s), 16))),
|
|
453
|
+
/*#__PURE__*/ P.named("hexUint")
|
|
398
454
|
)
|
|
399
455
|
|
|
400
|
-
const sign = P.opt(Token.oneOf("+-"))
|
|
401
|
-
const exponent = P.opt(P.seq(Token.oneOf("eE"), sign, digit1))
|
|
402
|
-
const unsignedFloat = P.alt(
|
|
403
|
-
P.seq(
|
|
404
|
-
|
|
405
|
-
|
|
456
|
+
const sign = /*#__PURE__*/ P.opt(/*#__PURE__*/ Token.oneOf("+-"))
|
|
457
|
+
const exponent = /*#__PURE__*/ P.opt(/*#__PURE__*/ P.seq(/*#__PURE__*/ Token.oneOf("eE"), sign, digit1))
|
|
458
|
+
const unsignedFloat = /*#__PURE__*/ P.alt(
|
|
459
|
+
/*#__PURE__*/ P.seq(
|
|
460
|
+
/*#__PURE__*/ literalImpl("inf", true),
|
|
461
|
+
/*#__PURE__*/ P.opt(/*#__PURE__*/ literalImpl("inity", true))
|
|
462
|
+
),
|
|
463
|
+
/*#__PURE__*/ P.seq(/*#__PURE__*/ Token.literal("."), digit1, exponent),
|
|
464
|
+
/*#__PURE__*/ P.seq(
|
|
465
|
+
digit1,
|
|
466
|
+
/*#__PURE__*/ P.opt(/*#__PURE__*/ P.seq(/*#__PURE__*/ Token.literal("."), /*#__PURE__*/ P.opt(digit1))),
|
|
467
|
+
exponent
|
|
468
|
+
)
|
|
469
|
+
)
|
|
470
|
+
const floatText = /*#__PURE__*/ numbers.floatText(
|
|
471
|
+
/*#__PURE__*/ P.taken(
|
|
472
|
+
/*#__PURE__*/ P.alt(/*#__PURE__*/ literalImpl("nan", true), /*#__PURE__*/ P.seq(sign, unsignedFloat))
|
|
473
|
+
).pipe(/*#__PURE__*/ P.expected("number")) as Parser<string>
|
|
406
474
|
)
|
|
407
|
-
const floatText = numbers.floatText(P.taken(P.alt(
|
|
408
|
-
literalImpl("nan", true),
|
|
409
|
-
P.seq(sign, unsignedFloat)
|
|
410
|
-
)).pipe(P.expected("number")) as Parser<string>)
|
|
411
475
|
|
|
412
476
|
/** @internal */
|
|
413
477
|
export const toFloat: (s: Input) => number = numbers.toFloat
|
|
@@ -427,7 +491,10 @@ export const toFloat: (s: Input) => number = numbers.toFloat
|
|
|
427
491
|
* @since 0.1.0
|
|
428
492
|
* @category numbers
|
|
429
493
|
*/
|
|
430
|
-
export const float: Parser<number> = floatText.pipe(
|
|
494
|
+
export const float: Parser<number> = /*#__PURE__*/ floatText.pipe(
|
|
495
|
+
/*#__PURE__*/ P.map(toFloat),
|
|
496
|
+
/*#__PURE__*/ P.named("float")
|
|
497
|
+
)
|
|
431
498
|
|
|
432
499
|
// -----------------------------------------------------------------------------
|
|
433
500
|
// Literals
|
|
@@ -449,7 +516,7 @@ export const caseless: {
|
|
|
449
516
|
// Escapes
|
|
450
517
|
// -----------------------------------------------------------------------------
|
|
451
518
|
|
|
452
|
-
const controlCode = (c: string | number): number =>
|
|
519
|
+
const controlCode = (c: string | number): number => (Predicate.isNumber(c) ? c : c.charCodeAt(0))
|
|
453
520
|
|
|
454
521
|
const atControl = (state: State<Input>, control: number): boolean => {
|
|
455
522
|
if (state.pos >= state.end) return false
|
|
@@ -483,11 +550,18 @@ export const takeEscaped = <A, E, R, I extends Input, B, E2, R2, I2 extends Inpu
|
|
|
483
550
|
escapable: Parser<B, E2, R2, I2>
|
|
484
551
|
): Parser<Slice<I & I2>, E | E2, R | R2, I & I2> => {
|
|
485
552
|
const ctrl = controlCode(control)
|
|
486
|
-
return takeEscapedImpl(
|
|
487
|
-
|
|
488
|
-
state
|
|
489
|
-
|
|
490
|
-
|
|
553
|
+
return takeEscapedImpl(
|
|
554
|
+
normal,
|
|
555
|
+
(state) => {
|
|
556
|
+
if (!atControl(state, ctrl)) return false
|
|
557
|
+
state.pos++
|
|
558
|
+
return true
|
|
559
|
+
},
|
|
560
|
+
escapable,
|
|
561
|
+
(state, start) => state.slice(start, state.pos) as Slice<I & I2>,
|
|
562
|
+
ctrl,
|
|
563
|
+
undefined
|
|
564
|
+
)
|
|
491
565
|
}
|
|
492
566
|
|
|
493
567
|
const isIncomplete = (state: State<any>): boolean => state.mode === "Incomplete"
|
|
@@ -513,42 +587,47 @@ export const takeEscapedImpl = <A, E, R, I extends Input, B, E2, R2, I2 extends
|
|
|
513
587
|
const normalStep = normal.step
|
|
514
588
|
const escStep = escapable.step
|
|
515
589
|
const key = {}
|
|
516
|
-
return P.described(
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
590
|
+
return P.described(
|
|
591
|
+
(state: State<any>) => {
|
|
592
|
+
const start = state.pos
|
|
593
|
+
let resumed = false
|
|
594
|
+
if (state.resume !== undefined) {
|
|
595
|
+
const checkpoint = Resume.take(state, key, start) as number | Resume.Done | undefined
|
|
596
|
+
if (checkpoint instanceof Resume.Done) {
|
|
597
|
+
state.pos = checkpoint.pos
|
|
598
|
+
return checkpoint.value as S
|
|
599
|
+
}
|
|
600
|
+
if (checkpoint !== undefined) {
|
|
601
|
+
state.pos = checkpoint
|
|
602
|
+
resumed = true
|
|
603
|
+
}
|
|
528
604
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
605
|
+
while (state.pos < state.end) {
|
|
606
|
+
const before = state.pos
|
|
607
|
+
const a = normalStep(state)
|
|
608
|
+
if (a !== Fail) {
|
|
609
|
+
if (state.pos === before)
|
|
610
|
+
return state.failMessage("Cut", "Assert", "`takeEscaped` parsers must always consume")
|
|
611
|
+
continue
|
|
612
|
+
}
|
|
613
|
+
if (state.mode === "Incomplete") return suspendAt(state, key, start, before)
|
|
614
|
+
if (state.mode !== "Backtrack") return Fail
|
|
615
|
+
state.pos = before
|
|
616
|
+
if (matchControl(state)) {
|
|
617
|
+
if (escStep(state) === Fail) return isIncomplete(state) ? suspendAt(state, key, start, before) : Fail
|
|
618
|
+
} else {
|
|
619
|
+
return Resume.done(state, key, start, resumed, slice(state, start))
|
|
620
|
+
}
|
|
536
621
|
}
|
|
537
|
-
if (state.
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
if (matchControl(state)) {
|
|
541
|
-
if (escStep(state) === Fail) return isIncomplete(state) ? suspendAt(state, key, start, before) : Fail
|
|
542
|
-
} else {
|
|
543
|
-
return Resume.done(state, key, start, resumed, slice(state, start))
|
|
622
|
+
if (state.partial) {
|
|
623
|
+
state.incomplete(0)
|
|
624
|
+
return suspendAt(state, key, start, state.pos)
|
|
544
625
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
return Resume.done(state, key, start, resumed, slice(state, start))
|
|
551
|
-
}, "takeEscaped", { _tag: "Escaped", normal, control, escape: escapable, raw: true, encoding })
|
|
626
|
+
return Resume.done(state, key, start, resumed, slice(state, start))
|
|
627
|
+
},
|
|
628
|
+
"takeEscaped",
|
|
629
|
+
{ _tag: "Escaped", normal, control, escape: escapable, raw: true, encoding }
|
|
630
|
+
)
|
|
552
631
|
}
|
|
553
632
|
|
|
554
633
|
/**
|
|
@@ -585,11 +664,17 @@ export const escaped = <E, R, I extends Input, E2, R2, I2 extends Input>(
|
|
|
585
664
|
escape: Parser<string, E2, R2, I2>
|
|
586
665
|
): Parser<string, E | E2, R | R2, I & I2> => {
|
|
587
666
|
const ctrl = controlCode(control)
|
|
588
|
-
return escapedImpl(
|
|
589
|
-
|
|
590
|
-
state
|
|
591
|
-
|
|
592
|
-
|
|
667
|
+
return escapedImpl(
|
|
668
|
+
normal,
|
|
669
|
+
(state) => {
|
|
670
|
+
if (!atControl(state, ctrl)) return false
|
|
671
|
+
state.pos++
|
|
672
|
+
return true
|
|
673
|
+
},
|
|
674
|
+
escape,
|
|
675
|
+
ctrl,
|
|
676
|
+
undefined
|
|
677
|
+
)
|
|
593
678
|
}
|
|
594
679
|
|
|
595
680
|
/** How far `escaped` got: the text so far, and where to carry on. */
|
|
@@ -609,58 +694,64 @@ export const escapedImpl = <E, R, I extends Input, E2, R2, I2 extends Input>(
|
|
|
609
694
|
const normalStep = normal.step
|
|
610
695
|
const escStep = escape.step
|
|
611
696
|
const key = {}
|
|
612
|
-
return P.described(
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
697
|
+
return P.described(
|
|
698
|
+
(state: State<any>) => {
|
|
699
|
+
const start = state.pos
|
|
700
|
+
let out = ""
|
|
701
|
+
let resumed = false
|
|
702
|
+
if (state.resume !== undefined) {
|
|
703
|
+
const checkpoint = Resume.take(state, key, start) as EscapedCheckpoint | Resume.Done | undefined
|
|
704
|
+
if (checkpoint instanceof Resume.Done) {
|
|
705
|
+
state.pos = checkpoint.pos
|
|
706
|
+
return checkpoint.value as string
|
|
707
|
+
}
|
|
708
|
+
if (checkpoint !== undefined) {
|
|
709
|
+
out = checkpoint.out
|
|
710
|
+
state.pos = checkpoint.pos
|
|
711
|
+
resumed = true
|
|
712
|
+
}
|
|
626
713
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
714
|
+
while (state.pos < state.end) {
|
|
715
|
+
const before = state.pos
|
|
716
|
+
const a = normalStep(state)
|
|
717
|
+
if (a !== Fail) {
|
|
718
|
+
if (state.pos !== before) {
|
|
719
|
+
out += a
|
|
720
|
+
continue
|
|
721
|
+
}
|
|
722
|
+
// `normal` matched nothing: fall through to the control character
|
|
723
|
+
} else {
|
|
724
|
+
if (state.mode === "Incomplete") return suspendAt(state, key, start, { out, pos: before })
|
|
725
|
+
if (state.mode !== "Backtrack") return Fail
|
|
726
|
+
state.pos = before
|
|
727
|
+
}
|
|
728
|
+
if (matchControl(state)) {
|
|
729
|
+
const b = escStep(state)
|
|
730
|
+
if (b === Fail) return isIncomplete(state) ? suspendAt(state, key, start, { out, pos: before }) : Fail
|
|
731
|
+
out += b
|
|
732
|
+
} else {
|
|
733
|
+
return Resume.done(state, key, start, resumed, out)
|
|
635
734
|
}
|
|
636
|
-
// `normal` matched nothing: fall through to the control character
|
|
637
|
-
} else {
|
|
638
|
-
if (state.mode === "Incomplete") return suspendAt(state, key, start, { out, pos: before })
|
|
639
|
-
if (state.mode !== "Backtrack") return Fail
|
|
640
|
-
state.pos = before
|
|
641
735
|
}
|
|
642
|
-
if (
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
out += b
|
|
646
|
-
} else {
|
|
647
|
-
return Resume.done(state, key, start, resumed, out)
|
|
736
|
+
if (state.partial) {
|
|
737
|
+
state.incomplete(0)
|
|
738
|
+
return suspendAt(state, key, start, { out, pos: state.pos })
|
|
648
739
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
return Resume.done(state, key, start, resumed, out)
|
|
655
|
-
}, "escaped", { _tag: "Escaped", normal, control, escape, raw: false, encoding })
|
|
740
|
+
return Resume.done(state, key, start, resumed, out)
|
|
741
|
+
},
|
|
742
|
+
"escaped",
|
|
743
|
+
{ _tag: "Escaped", normal, control, escape, raw: false, encoding }
|
|
744
|
+
)
|
|
656
745
|
}
|
|
657
746
|
|
|
658
747
|
// -----------------------------------------------------------------------------
|
|
659
748
|
// Byte views
|
|
660
749
|
// -----------------------------------------------------------------------------
|
|
661
750
|
|
|
662
|
-
type Bytes<P> =
|
|
663
|
-
|
|
751
|
+
type Bytes<P> =
|
|
752
|
+
P extends Parser<infer A, infer E, infer R, infer _I>
|
|
753
|
+
? Parser<A extends string ? Uint8Array : A, E, R, Uint8Array>
|
|
754
|
+
: never
|
|
664
755
|
|
|
665
756
|
/**
|
|
666
757
|
* The parsers of this module, typed for `Uint8Array` input. Slices are
|
|
@@ -707,7 +798,7 @@ export const bytes: {
|
|
|
707
798
|
readonly decBigInt: Parser<bigint, never, never, Uint8Array>
|
|
708
799
|
readonly hexUint: Parser<number, string, never, Uint8Array>
|
|
709
800
|
readonly float: Parser<number, never, never, Uint8Array>
|
|
710
|
-
} = (() => {
|
|
801
|
+
} = /*#__PURE__*/ (() => {
|
|
711
802
|
const lit = (s: string) => Token.literal(new TextEncoder().encode(s))
|
|
712
803
|
const crlfB = lit("\r\n")
|
|
713
804
|
const newlineB = lit("\n")
|