interface / @typed/router/Parser

Parser.Zip

Runs two parsers sequentially and returns both values.

Package version
1.0.0-beta.13
Category
Parser composition
Since
1.0.0
Member of
Parser

Import

import { Parser } from "@typed/router/Parser";

Access Parser.Zip through the imported Parser export. Its declaration below describes the member.

Signatures

interface Zip<P extends Any, Q extends Any> extends Parser<unknown> {
    readonly return: InputOf<this> extends infer Input extends string ? Apply<P, Input> extends infer R1 ? [
        R1
    ] extends [
        never
    ] ? never : R1 extends readonly [
        infer Value1,
        infer Rest1 extends string
    ] ? Pipe<Rest1, Q> extends infer R2 ? [
        R2
    ] extends [
        never
    ] ? never : R2 extends readonly [
        infer Value2,
        infer Rest2 extends string
    ] ? readonly [
        readonly [
            Value1,
            Value2
        ],
        Rest2
    ] : never : never : never : never : never;
}

Why

Ordered grammar composition passes the first parser’s remainder into the second.

Ownership and lifetime

TypeScript instantiates Zip while parsing a string-literal input; partial results and unconsumed text exist only in the resulting type.

Property: return

Computes this type lambda’s parse result for its current input.

Property: return: Why

The local type-function protocol evaluates each parser combinator through this member without a parallel runtime object.

Property: return: Ownership and lifetime

TypeScript evaluates Zip.return when the surrounding parser is applied; the associated result is erased and retains no input at runtime.

Source