Function lazy

  • Defers evaluation of a parser, allowing recursive parser definitions. Without lazy, you can't reference a parser before it's defined:

    // ReferenceError: expr is not defined
    const expr = or(number, seqR(char("("), expr, char(")")));

    // Works: the reference to expr is deferred
    const expr = or(number, seqR(char("("), lazy(() => expr), char(")")));

    Type Parameters

    • T

    Parameters

    Returns Parser<T>

    • a parser that evaluates the thunk on each parse attempt

Generated using TypeDoc