Function otherwise

  • This overload makes a Matcher from a parser and a matcher. If the parser matched - return the match, otherwise return the match from the matcher.

    Can be used to keep the matcher type when you have multiple parsing options and the last one always matches.

    Combine with choice if you need multiple alternative parsers of the same value type.

    Nest calls to have union of more than two different value types derived automatically.

    Use option if you just want a constant alternative value without consuming input.

    Type Parameters

    • TToken

    • TOptions

    • TValueA

    • TValueB

    Parameters

    • pa: Parser<TToken, TOptions, TValueA>

      A parser.

    • pb: Matcher<TToken, TOptions, TValueB>

      A matcher that is only called if the parser didn't match.

    Returns Matcher<TToken, TOptions, TValueA | TValueB>

  • Make a parser that tries two parsers at the same position and returns the first successful match or a nonmatch if there was none.

    Use this if you want to combine parsers of different value types.

    Nest calls to have more than two different value types.

    Use choice if you have parsers of the same value type.

    Type Parameters

    • TToken

    • TOptions

    • TValueA

    • TValueB

    Parameters

    • pa: Parser<TToken, TOptions, TValueA>

      A parser that is tried first.

    • pb: Parser<TToken, TOptions, TValueB>

      A parser that is only tried if the first one didn't match.

    Returns Parser<TToken, TOptions, TValueA | TValueB>

Generated using TypeDoc