• Make a parser based on a token-to-value function.

    Nonmatch is produced if undefined value is returned by a function.

    Use make if you want to produce a value without consuming a token.

    You can use satisfy if you just want to test but not transform the value.

    Type Parameters

    • TToken

    • TOptions

    • TValue

    Parameters

    • onToken: ((token: TToken, data: Data<TToken, TOptions>, i: number) => undefined | TValue)

      Function that either transforms a token to a result value or returns undefined.

        • (token: TToken, data: Data<TToken, TOptions>, i: number): undefined | TValue
        • Parameters

          • token: TToken

            A token at the parser position.

          • data: Data<TToken, TOptions>

            Data object (tokens and options).

          • i: number

            Parser position in the tokens array (points at the same token).

          Returns undefined | TValue

    • Optional onEnd: ((data: Data<TToken, TOptions>, i: number) => void)

      Optional function to be called if there are no tokens left. It can be used to throw an error when required token is missing.

        • (data: Data<TToken, TOptions>, i: number): void
        • Parameters

          • data: Data<TToken, TOptions>

            Data object (tokens and options).

          • i: number

            Parser position in the tokens array (naturally points after the end of array).

          Returns void

    Returns Parser<TToken, TOptions, TValue>

Generated using TypeDoc