@thomasfosterau/effect-parse 0.4.0 → 0.5.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 +40 -14
- package/dist/Ascii.d.ts +11 -4
- package/dist/Ascii.d.ts.map +1 -1
- package/dist/Ascii.js +7 -1
- package/dist/Ascii.js.map +1 -1
- package/dist/Binary.d.ts.map +1 -1
- package/dist/Binary.js +64 -35
- package/dist/Binary.js.map +1 -1
- package/dist/Bits.d.ts.map +1 -1
- package/dist/Bits.js +7 -4
- package/dist/Bits.js.map +1 -1
- package/dist/Compiler.d.ts +74 -2
- package/dist/Compiler.d.ts.map +1 -1
- package/dist/Compiler.js +78 -1
- package/dist/Compiler.js.map +1 -1
- package/dist/Expression.d.ts.map +1 -1
- package/dist/Expression.js +86 -74
- package/dist/Expression.js.map +1 -1
- package/dist/Input.d.ts +37 -4
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +42 -0
- package/dist/Input.js.map +1 -1
- package/dist/Nom.d.ts +5 -15
- package/dist/Nom.d.ts.map +1 -1
- package/dist/Nom.js.map +1 -1
- package/dist/ParseError.d.ts +2 -2
- package/dist/ParseError.d.ts.map +1 -1
- package/dist/ParseError.js +1 -1
- package/dist/ParseError.js.map +1 -1
- package/dist/Parser.d.ts +370 -28
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +390 -19
- package/dist/Parser.js.map +1 -1
- package/dist/ParserSchema.js +2 -2
- package/dist/ParserSchema.js.map +1 -1
- package/dist/ParserStream.d.ts +3 -2
- package/dist/ParserStream.d.ts.map +1 -1
- package/dist/ParserStream.js +15 -10
- package/dist/ParserStream.js.map +1 -1
- package/dist/Syntax.d.ts +23 -5
- package/dist/Syntax.d.ts.map +1 -1
- package/dist/Syntax.js.map +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +9 -9
- package/dist/Text.js.map +1 -1
- package/dist/Token.d.ts +55 -10
- package/dist/Token.d.ts.map +1 -1
- package/dist/Token.js +59 -21
- package/dist/Token.js.map +1 -1
- package/dist/internal/compiler/closure.d.ts.map +1 -1
- package/dist/internal/compiler/closure.js +257 -97
- package/dist/internal/compiler/closure.js.map +1 -1
- package/dist/internal/compiler/entries.d.ts +3 -1
- package/dist/internal/compiler/entries.d.ts.map +1 -1
- package/dist/internal/compiler/entries.js +3 -2
- package/dist/internal/compiler/entries.js.map +1 -1
- package/dist/internal/compiler/first.d.ts.map +1 -1
- package/dist/internal/compiler/first.js +7 -1
- package/dist/internal/compiler/first.js.map +1 -1
- package/dist/internal/compiler/graph.d.ts +17 -0
- package/dist/internal/compiler/graph.d.ts.map +1 -0
- package/dist/internal/compiler/graph.js +56 -0
- package/dist/internal/compiler/graph.js.map +1 -0
- package/dist/internal/compiler/jit.d.ts +5 -0
- package/dist/internal/compiler/jit.d.ts.map +1 -1
- package/dist/internal/compiler/jit.js +185 -96
- package/dist/internal/compiler/jit.js.map +1 -1
- package/dist/internal/compiler/registry.d.ts +10 -2
- package/dist/internal/compiler/registry.d.ts.map +1 -1
- package/dist/internal/compiler/registry.js.map +1 -1
- package/dist/internal/compiler/search.d.ts +32 -0
- package/dist/internal/compiler/search.d.ts.map +1 -0
- package/dist/internal/compiler/search.js +68 -0
- package/dist/internal/compiler/search.js.map +1 -0
- package/dist/internal/compiler/sets.d.ts.map +1 -1
- package/dist/internal/compiler/sets.js +1 -1
- package/dist/internal/compiler/sets.js.map +1 -1
- package/dist/internal/compiler/wasm.d.ts +8 -0
- package/dist/internal/compiler/wasm.d.ts.map +1 -0
- package/dist/internal/compiler/wasm.js +2769 -0
- package/dist/internal/compiler/wasm.js.map +1 -0
- package/dist/internal/compiler/wasmAsm.d.ts +199 -0
- package/dist/internal/compiler/wasmAsm.d.ts.map +1 -0
- package/dist/internal/compiler/wasmAsm.js +427 -0
- package/dist/internal/compiler/wasmAsm.js.map +1 -0
- package/dist/internal/entries.d.ts +3 -1
- package/dist/internal/entries.d.ts.map +1 -1
- package/dist/internal/entries.js +1 -2
- package/dist/internal/entries.js.map +1 -1
- package/dist/internal/node.d.ts +58 -2
- package/dist/internal/node.d.ts.map +1 -1
- package/dist/internal/node.js +13 -3
- package/dist/internal/node.js.map +1 -1
- package/dist/internal/numbers.d.ts.map +1 -1
- package/dist/internal/numbers.js.map +1 -1
- package/dist/internal/run.d.ts +12 -0
- package/dist/internal/run.d.ts.map +1 -1
- package/dist/internal/run.js +51 -11
- package/dist/internal/run.js.map +1 -1
- package/dist/internal/stack.d.ts +6 -0
- package/dist/internal/stack.d.ts.map +1 -1
- package/dist/internal/stack.js +8 -2
- package/dist/internal/stack.js.map +1 -1
- package/dist/internal/syntax.d.ts +4 -4
- package/dist/internal/syntax.d.ts.map +1 -1
- package/dist/internal/syntax.js +18 -10
- package/dist/internal/syntax.js.map +1 -1
- package/dist/internal/text.d.ts +32 -0
- package/dist/internal/text.d.ts.map +1 -1
- package/dist/internal/text.js +68 -14
- package/dist/internal/text.js.map +1 -1
- package/dist/internal/tokens.d.ts +13 -0
- package/dist/internal/tokens.d.ts.map +1 -1
- package/dist/internal/tokens.js +59 -39
- package/dist/internal/tokens.js.map +1 -1
- package/package.json +5 -4
- package/src/Ascii.ts +42 -9
- package/src/Binary.ts +151 -71
- package/src/Bits.ts +12 -6
- package/src/Compiler.ts +101 -10
- package/src/Expression.ts +94 -81
- package/src/Input.ts +65 -6
- package/src/Nom.ts +15 -5
- package/src/ParseError.ts +9 -4
- package/src/Parser.ts +682 -129
- package/src/ParserSchema.ts +1 -1
- package/src/ParserStream.ts +40 -19
- package/src/Syntax.ts +60 -36
- package/src/Text.ts +16 -15
- package/src/Token.ts +138 -29
- package/src/internal/compiler/closure.ts +362 -135
- package/src/internal/compiler/entries.ts +4 -2
- package/src/internal/compiler/first.ts +10 -0
- package/src/internal/compiler/graph.ts +68 -0
- package/src/internal/compiler/jit.ts +284 -154
- package/src/internal/compiler/registry.ts +10 -2
- package/src/internal/compiler/search.ts +68 -0
- package/src/internal/compiler/sets.ts +7 -3
- package/src/internal/compiler/wasm.ts +3203 -0
- package/src/internal/compiler/wasmAsm.ts +484 -0
- package/src/internal/entries.ts +10 -4
- package/src/internal/node.ts +54 -4
- package/src/internal/numbers.ts +3 -1
- package/src/internal/run.ts +71 -12
- package/src/internal/stack.ts +8 -1
- package/src/internal/syntax.ts +39 -18
- package/src/internal/text.ts +97 -9
- package/src/internal/tokens.ts +96 -14
package/src/Token.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
describeLiteral,
|
|
31
31
|
End,
|
|
32
32
|
indexOf,
|
|
33
|
+
indexOfAny,
|
|
33
34
|
matchLiteral,
|
|
34
35
|
nextIf,
|
|
35
36
|
NoMatch,
|
|
@@ -116,12 +117,13 @@ export const codePoints = (
|
|
|
116
117
|
predicate: (codePoint: number) => boolean,
|
|
117
118
|
ranges?: ReadonlyArray<readonly [number, number]>
|
|
118
119
|
): CodePoints =>
|
|
119
|
-
// Wrapped, so the caller's function is left unmarked
|
|
120
|
+
// Wrapped, so the caller's function is left unmarked.
|
|
121
|
+
// SAFETY: `CodePointsBrand` is a declared, phantom key, so the marked function is all a `CodePoints` is at runtime
|
|
120
122
|
codePointPredicate(
|
|
121
123
|
name,
|
|
122
124
|
(c: number): boolean => predicate(c),
|
|
123
125
|
ranges?.map(([from, to]) => [from, to] as const)
|
|
124
|
-
) as
|
|
126
|
+
) as CodePoints
|
|
125
127
|
|
|
126
128
|
/**
|
|
127
129
|
* A set of string tokens: the characters of a string, a range, a predicate,
|
|
@@ -177,6 +179,7 @@ const anyStep = (state: State<Input>): unknown => {
|
|
|
177
179
|
if (pos >= state.end) return state.eoi("Token", expectedAny, 1)
|
|
178
180
|
switch (state.inputKind) {
|
|
179
181
|
case 0: {
|
|
182
|
+
// SAFETY: `inputKind` 0 is set only for a string input
|
|
180
183
|
const s = state.input as string
|
|
181
184
|
if (splitSurrogate(state, pos)) return state.incomplete(1, expectedAny)
|
|
182
185
|
const c = s.charCodeAt(pos)
|
|
@@ -189,13 +192,21 @@ const anyStep = (state: State<Input>): unknown => {
|
|
|
189
192
|
}
|
|
190
193
|
case 1:
|
|
191
194
|
state.pos = pos + 1
|
|
195
|
+
// SAFETY: `inputKind` 1 is set only for a `Uint8Array` input
|
|
192
196
|
return (state.input as Uint8Array)[pos]
|
|
193
197
|
default:
|
|
194
198
|
state.pos = pos + 1
|
|
199
|
+
// SAFETY: `inputKind` 2 is set for every input that is neither a string nor a `Uint8Array`, an array
|
|
195
200
|
return (state.input as ReadonlyArray<unknown>)[pos]
|
|
196
201
|
}
|
|
197
202
|
}
|
|
198
203
|
|
|
204
|
+
/** The parser behind `any` and `anyToken`, on every input kind. */
|
|
205
|
+
const anyInput: Parser<unknown, never, never, Input> = /*#__PURE__*/ described(anyStep, "any", {
|
|
206
|
+
_tag: "Any",
|
|
207
|
+
encoding: undefined
|
|
208
|
+
})
|
|
209
|
+
|
|
199
210
|
/**
|
|
200
211
|
* Matches any single token: a character of a string (winnow's `any`, nom's
|
|
201
212
|
* `anychar`).
|
|
@@ -203,7 +214,9 @@ const anyStep = (state: State<Input>): unknown => {
|
|
|
203
214
|
* @since 0.1.0
|
|
204
215
|
* @category tokens
|
|
205
216
|
*/
|
|
206
|
-
export const any: Parser<string> =
|
|
217
|
+
export const any: Parser<string> =
|
|
218
|
+
// SAFETY: on string input, `anyStep` returns the character (one or two code units) at the position, a string
|
|
219
|
+
anyInput as Parser<string>
|
|
207
220
|
|
|
208
221
|
/**
|
|
209
222
|
* Matches any single token of an input of type `I`.
|
|
@@ -219,7 +232,21 @@ export const any: Parser<string> = /*#__PURE__*/ described(anyStep as any, "any"
|
|
|
219
232
|
* @since 0.1.0
|
|
220
233
|
* @category tokens
|
|
221
234
|
*/
|
|
222
|
-
export const anyToken = <I extends Input = string>(): Parser<Token<NoInfer<I>>, never, never, NoInfer<I>> =>
|
|
235
|
+
export const anyToken = <I extends Input = string>(): Parser<Token<NoInfer<I>>, never, never, NoInfer<I>> =>
|
|
236
|
+
// SAFETY: `anyStep` handles every input kind, returning the token at the position (a character, byte or element)
|
|
237
|
+
anyInput as Parser<Token<NoInfer<I>>, never, never, NoInfer<I>>
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The overloads of {@link literal}.
|
|
241
|
+
*
|
|
242
|
+
* @since 0.5.0
|
|
243
|
+
* @category tokens
|
|
244
|
+
*/
|
|
245
|
+
export interface LiteralFn {
|
|
246
|
+
<const L extends string>(literal: L): Parser<L, never, never, string>
|
|
247
|
+
(literal: Uint8Array): Parser<Uint8Array, never, never, Uint8Array>
|
|
248
|
+
<const T>(literal: ReadonlyArray<T>): Parser<ReadonlyArray<T>, never, never, ReadonlyArray<T>>
|
|
249
|
+
}
|
|
223
250
|
|
|
224
251
|
/**
|
|
225
252
|
* Matches a literal sequence of tokens (winnow's `literal`, nom's `tag`).
|
|
@@ -237,11 +264,7 @@ export const anyToken = <I extends Input = string>(): Parser<Token<NoInfer<I>>,
|
|
|
237
264
|
* @since 0.1.0
|
|
238
265
|
* @category tokens
|
|
239
266
|
*/
|
|
240
|
-
export const literal:
|
|
241
|
-
<const L extends string>(literal: L): Parser<L, never, never, string>
|
|
242
|
-
(literal: Uint8Array): Parser<Uint8Array, never, never, Uint8Array>
|
|
243
|
-
<const T>(literal: ReadonlyArray<T>): Parser<ReadonlyArray<T>, never, never, ReadonlyArray<T>>
|
|
244
|
-
} = (lit: Input): Parser<any, never, never, any> => literalImpl(lit, false)
|
|
267
|
+
export const literal: LiteralFn = (lit: Input): Parser<any, never, never, any> => literalImpl(lit, false)
|
|
245
268
|
|
|
246
269
|
/** @internal */
|
|
247
270
|
export const literalImpl = (lit: Input, caseless: boolean): Parser<any, never, never, any> => {
|
|
@@ -253,6 +276,7 @@ export const literalImpl = (lit: Input, caseless: boolean): Parser<any, never, n
|
|
|
253
276
|
return described(
|
|
254
277
|
(state: State<Input>) => {
|
|
255
278
|
const pos = state.pos
|
|
279
|
+
// SAFETY: `literalKind` 0 is set only for a string literal
|
|
256
280
|
const l = literalKind === 0 && state.inputKind === 1 ? (asBytes ??= new TextEncoder().encode(lit as string)) : lit
|
|
257
281
|
const len = l.length
|
|
258
282
|
const r = matchLiteral(state, l, caseless)
|
|
@@ -295,6 +319,7 @@ export const oneOf = <I extends Input = string>(
|
|
|
295
319
|
const t = nextIf(state, m, false)
|
|
296
320
|
if (t === End) return state.eoi("OneOf", expected, 1)
|
|
297
321
|
if (t === NoMatch) return state.backtrack("OneOf", expected)
|
|
322
|
+
// SAFETY: past `End` and `NoMatch`, `nextIf` returns the token it consumed from the parser's input `I`
|
|
298
323
|
return t as Token<I>
|
|
299
324
|
},
|
|
300
325
|
m.description,
|
|
@@ -319,6 +344,7 @@ export const noneOf = <I extends Input = string>(
|
|
|
319
344
|
const t = nextIf(state, m, true)
|
|
320
345
|
if (t === End) return state.eoi("NoneOf", expected, 1)
|
|
321
346
|
if (t === NoMatch) return state.backtrack("NoneOf", expected)
|
|
347
|
+
// SAFETY: past `End` and `NoMatch`, `nextIf` returns the token it consumed from the parser's input `I`
|
|
322
348
|
return t as Token<I>
|
|
323
349
|
},
|
|
324
350
|
expected[0],
|
|
@@ -418,6 +444,18 @@ export const takeTill = <I extends Input = string>(
|
|
|
418
444
|
range?: Range
|
|
419
445
|
): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => takeWhileImpl(set, range, true, "takeTill")
|
|
420
446
|
|
|
447
|
+
/**
|
|
448
|
+
* The overloads of {@link takeUntil}.
|
|
449
|
+
*
|
|
450
|
+
* @since 0.5.0
|
|
451
|
+
* @category slices
|
|
452
|
+
*/
|
|
453
|
+
export interface TakeUntilFn {
|
|
454
|
+
(literal: string, range?: Range): Parser<string, never, never, string>
|
|
455
|
+
(literal: Uint8Array, range?: Range): Parser<Uint8Array, never, never, Uint8Array>
|
|
456
|
+
<T>(literal: ReadonlyArray<T>, range?: Range): Parser<ReadonlyArray<T>, never, never, ReadonlyArray<T>>
|
|
457
|
+
}
|
|
458
|
+
|
|
421
459
|
/**
|
|
422
460
|
* Takes tokens up to (not including) the first occurrence of a literal
|
|
423
461
|
* (winnow's `take_until`, nom's `take_until`). The literal is not
|
|
@@ -426,25 +464,40 @@ export const takeTill = <I extends Input = string>(
|
|
|
426
464
|
* @since 0.1.0
|
|
427
465
|
* @category slices
|
|
428
466
|
*/
|
|
429
|
-
export const takeUntil:
|
|
430
|
-
(
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
467
|
+
export const takeUntil: TakeUntilFn = (lit: Input, r?: Range): Parser<any, never, never, any> =>
|
|
468
|
+
untilParser(
|
|
469
|
+
(state, from) => indexOf(state, lit, from),
|
|
470
|
+
// A string literal is up to three bytes per unit of UTF-8
|
|
471
|
+
(state) => lit.length * (Predicate.isString(lit) && state.inputKind === 1 ? 3 : 1),
|
|
472
|
+
[describeLiteral(lit)],
|
|
473
|
+
r,
|
|
474
|
+
"takeUntil",
|
|
475
|
+
{ _tag: "TakeUntil", literal: lit, ...bounds(r), encoding: undefined }
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* The parser of `takeUntil` and `takeUntilAny`: `search` finds the first
|
|
480
|
+
* occurrence, which is not consumed (`read` is how far past it the search
|
|
481
|
+
* read). As in winnow, the first occurrence must lie within the range.
|
|
482
|
+
*/
|
|
483
|
+
const untilParser = (
|
|
484
|
+
search: (state: State<Input>, from: number) => number,
|
|
485
|
+
read: (state: State<Input>) => number,
|
|
486
|
+
expected: ReadonlyArray<string>,
|
|
487
|
+
r: Range | undefined,
|
|
488
|
+
name: string,
|
|
489
|
+
node: Parameters<typeof described>[2]
|
|
490
|
+
): Parser<any, never, never, any> => {
|
|
434
491
|
const [min, max] = normalize(r)
|
|
435
|
-
const description = describeLiteral(lit)
|
|
436
|
-
const expected = [description]
|
|
437
492
|
return described(
|
|
438
493
|
(state: State<Input>) => {
|
|
439
494
|
const start = state.pos
|
|
440
|
-
const idx =
|
|
495
|
+
const idx = search(state, start)
|
|
441
496
|
if (idx < 0) {
|
|
442
497
|
if (state.partial) return state.incomplete(0, expected)
|
|
443
498
|
return state.backtrack("TakeUntil", expected, state.end)
|
|
444
499
|
}
|
|
445
|
-
|
|
446
|
-
state.syntax?.read(idx + lit.length * (Predicate.isString(lit) && state.inputKind === 1 ? 3 : 1))
|
|
447
|
-
// As in winnow, the first occurrence must lie within the range
|
|
500
|
+
state.syntax?.read(idx + read(state))
|
|
448
501
|
if (min > 0 || max !== Infinity) {
|
|
449
502
|
const count = countTokens(state, start, idx)
|
|
450
503
|
if (count < min) return state.backtrack("TakeUntil", expected, idx)
|
|
@@ -453,34 +506,88 @@ export const takeUntil: {
|
|
|
453
506
|
state.pos = idx
|
|
454
507
|
return state.slice(start, idx)
|
|
455
508
|
},
|
|
456
|
-
|
|
457
|
-
|
|
509
|
+
name,
|
|
510
|
+
node
|
|
458
511
|
)
|
|
459
512
|
}
|
|
460
513
|
|
|
461
514
|
/**
|
|
462
|
-
*
|
|
515
|
+
* The overloads of {@link takeUntilAny}.
|
|
463
516
|
*
|
|
464
|
-
* @since 0.
|
|
517
|
+
* @since 0.5.0
|
|
518
|
+
* @category slices
|
|
519
|
+
*/
|
|
520
|
+
export interface TakeUntilAnyFn {
|
|
521
|
+
(literals: ReadonlyArray<string>, range?: Range): Parser<string, never, never, string>
|
|
522
|
+
(literals: ReadonlyArray<Uint8Array>, range?: Range): Parser<Uint8Array, never, never, Uint8Array>
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Takes tokens up to (not including) the first occurrence of any of
|
|
527
|
+
* several literals: {@link takeUntil} for a set of them, the search a
|
|
528
|
+
* multi-pattern prefilter makes. No literal is consumed. `range` constrains
|
|
529
|
+
* the number of tokens taken. On bytes, `Compiler.wasm` searches with SIMD
|
|
530
|
+
* (Teddy, from ripgrep), sixteen bytes at a time.
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```ts
|
|
534
|
+
* import { Parser, Token } from "@thomasfosterau/effect-parse"
|
|
535
|
+
* import * as Result from "effect/Result"
|
|
536
|
+
*
|
|
537
|
+
* const upTo = Parser.seq(Token.takeUntilAny(["Holmes", "Watson"]), Token.rest)
|
|
538
|
+
* console.log(Result.getOrThrow(Parser.parseSync(upTo, "Dr. Watson and Holmes")))
|
|
539
|
+
* // ["Dr. ", "Watson and Holmes"]
|
|
540
|
+
* ```
|
|
541
|
+
*
|
|
542
|
+
* @since 0.5.0
|
|
465
543
|
* @category slices
|
|
466
544
|
*/
|
|
467
|
-
export const
|
|
468
|
-
|
|
545
|
+
export const takeUntilAny: TakeUntilAnyFn = (
|
|
546
|
+
literals: ReadonlyArray<Input>,
|
|
547
|
+
r?: Range
|
|
548
|
+
): Parser<any, never, never, any> => {
|
|
549
|
+
const longest = Math.max(0, ...literals.map((lit) => lit.length))
|
|
550
|
+
return untilParser(
|
|
551
|
+
(state, from) => indexOfAny(state, literals, from),
|
|
552
|
+
// Every literal was read up to where it would end (a string literal is up to three bytes per unit of UTF-8)
|
|
553
|
+
(state) => longest * (state.inputKind === 1 ? 3 : 1),
|
|
554
|
+
literals.map(describeLiteral),
|
|
555
|
+
r,
|
|
556
|
+
"takeUntilAny",
|
|
557
|
+
{ _tag: "TakeUntilAny", literals, ...bounds(r), encoding: undefined }
|
|
558
|
+
)
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** The parser behind `rest` and `restOf`, on every input kind. */
|
|
562
|
+
const restInput: Parser<unknown, never, never, Input> = /*#__PURE__*/ described(
|
|
563
|
+
(state) => {
|
|
469
564
|
const start = state.pos
|
|
470
565
|
state.pos = state.end
|
|
471
|
-
return state.slice(start, state.end)
|
|
566
|
+
return state.slice(start, state.end)
|
|
472
567
|
},
|
|
473
568
|
"rest",
|
|
474
569
|
{ _tag: "Rest", encoding: undefined }
|
|
475
570
|
)
|
|
476
571
|
|
|
572
|
+
/**
|
|
573
|
+
* Takes the rest of the input (winnow's and nom's `rest`).
|
|
574
|
+
*
|
|
575
|
+
* @since 0.1.0
|
|
576
|
+
* @category slices
|
|
577
|
+
*/
|
|
578
|
+
export const rest: Parser<string> =
|
|
579
|
+
// SAFETY: on string input, `State.slice` returns a string
|
|
580
|
+
restInput as Parser<string>
|
|
581
|
+
|
|
477
582
|
/**
|
|
478
583
|
* Takes the rest of an input of type `I`.
|
|
479
584
|
*
|
|
480
585
|
* @since 0.1.0
|
|
481
586
|
* @category slices
|
|
482
587
|
*/
|
|
483
|
-
export const restOf = <I extends Input = string>(): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>
|
|
588
|
+
export const restOf = <I extends Input = string>(): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>
|
|
589
|
+
// SAFETY: `State.slice` returns the input's own slice type for every input kind, so `restInput` returns `Slice<I>`
|
|
590
|
+
restInput as Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>>
|
|
484
591
|
|
|
485
592
|
/**
|
|
486
593
|
* Returns the length of the remaining input without consuming it (winnow's
|
|
@@ -506,4 +613,6 @@ export const restLen: Parser<number, never, never, Input> = /*#__PURE__*/ descri
|
|
|
506
613
|
*/
|
|
507
614
|
export const satisfy = <I extends Input = string>(
|
|
508
615
|
predicate: (token: Token<I>) => boolean
|
|
509
|
-
): Parser<Token<NoInfer<I>>, never, never, NoInfer<I>> =>
|
|
616
|
+
): Parser<Token<NoInfer<I>>, never, never, NoInfer<I>> =>
|
|
617
|
+
// SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind
|
|
618
|
+
oneOf<I>(predicate as TokenSet<I>)
|