Function condition

  • This overload makes a Matcher that chooses between two given matchers based on a condition. This makes possible to allow/disallow a grammar based on context/options.

    decide and chain allow for more complex dynamic rules.

    Type Parameters

    • TToken

    • TOptions

    • TValueA

    • TValueB

    Parameters

    • cond: ((data: Data<TToken, TOptions>, i: number) => boolean)

      Condition.

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

          • data: Data<TToken, TOptions>

            Data object (tokens and options).

          • i: number

            Parser position in the tokens array (before parsing).

          Returns boolean

    • pTrue: Matcher<TToken, TOptions, TValueA>

      Matcher to run when the condition is true.

    • pFalse: Matcher<TToken, TOptions, TValueB>

      Matcher to run when the condition is false.

    Returns Matcher<TToken, TOptions, TValueA | TValueB>

  • Make a parser that chooses between two given parsers based on a condition. This makes possible to allow/disallow a grammar based on context/options.

    decide and chain allow for more complex dynamic rules.

    Type Parameters

    • TToken

    • TOptions

    • TValueA

    • TValueB

    Parameters

    • cond: ((data: Data<TToken, TOptions>, i: number) => boolean)

      Condition.

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

          • data: Data<TToken, TOptions>

            Data object (tokens and options).

          • i: number

            Parser position in the tokens array (before parsing).

          Returns boolean

    • pTrue: Parser<TToken, TOptions, TValueA>

      Parser to run when the condition is true.

    • pFalse: Parser<TToken, TOptions, TValueB>

      Parser to run when the condition is false.

    Returns Parser<TToken, TOptions, TValueA | TValueB>

Generated using TypeDoc