peberminta - v0.10.0
    Preparing search index...

    Function takeWhile

    • This overload makes a Matcher that returns all (0 or more) sequential matches of the same given parser while the type guard test passes.

      Use many if there is no stop condition.

      Use takeWhileP if the stop condition is expressed as a parser.

      Use filter to take one match or a non-match based on a test function (can also be a type guard).

      Type Parameters

      • TToken
      • TOptions
      • TValue1
      • TValue2

      Parameters

      • p: Parser<TToken, TOptions, TValue1>

        A parser.

      • test: (
            value: TValue1,
            n: number,
            data: Data<TToken, TOptions>,
            i: number,
            j: number,
        ) => value is TValue2

        Matched results are accumulated while this type guard test passes.

          • (
                value: TValue1,
                n: number,
                data: Data<TToken, TOptions>,
                i: number,
                j: number,
            ): value is TValue2
          • Parameters

            • value: TValue1

              Current value matched by the parser.

            • n: number

              Number of matches so far (including the current value).

            • data: Data<TToken, TOptions>

              Data object (tokens and options).

            • i: number

              Position before the current value matched.

            • j: number

              Position after the current value matched.

            Returns value is TValue2

      Returns Matcher<TToken, TOptions, TValue2[]>

    • Make a Matcher that returns all (0 or more) sequential matches of the same given parser while the test function equates to true.

      Use many if there is no stop condition.

      Use takeWhileP if the stop condition is expressed as a parser.

      Use filter to take one match or a non-match based on a test function.

      Type Parameters

      • TToken
      • TOptions
      • TValue

      Parameters

      • p: Parser<TToken, TOptions, TValue>

        A parser.

      • test: (
            value: TValue,
            n: number,
            data: Data<TToken, TOptions>,
            i: number,
            j: number,
        ) => boolean

        Matched results are accumulated while the result of this function is true.

          • (
                value: TValue,
                n: number,
                data: Data<TToken, TOptions>,
                i: number,
                j: number,
            ): boolean
          • Parameters

            • value: TValue

              Current value matched by the parser.

            • n: number

              Number of matches so far (including the current value).

            • data: Data<TToken, TOptions>

              Data object (tokens and options).

            • i: number

              Parser position in the tokens array (before the current value matched).

            • j: number

              Parser position in the tokens array (after the current value matched).

            Returns boolean

      Returns Matcher<TToken, TOptions, TValue[]>