Function tryParse

  • Utility function that provides a bit cleaner interface for running a parser. Returns undefined in case parser did not match.

    Note: this doesn't capture errors thrown during parsing. Nonmatch is considered a part or normal flow. Errors mean unrecoverable state and it's up to client code to decide where to throw errors and how to get back to safe state.

    Returns

    A matched value or undefined in case of nonmatch.

    Type Parameters

    • TToken

    • TOptions

    • TValue

    Parameters

    • parser: Parser<TToken, TOptions, TValue>

      A parser to run.

    • tokens: TToken[]

      Input tokens.

    • options: TOptions

      Parser options.

    Returns TValue | undefined

Generated using TypeDoc