Functions

The following functions are available globally.

  • Sequential conjunction of two parsers while ignoring the result of lhs

    See more

    Declaration

    Swift

    public func ~><Token, A, B>(lhs: Parser<Token, A>, rhs: @escaping @autoclosure () -> Parser<Token, B>) -> Parser<Token, B>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns the result of rhs

  • Sequential conjunction of two parsers while ignoring the result of rhs

    See more

    Declaration

    Swift

    public func <~<Token, A, B>(lhs: Parser<Token, B>, rhs: @escaping @autoclosure () -> Parser<Token, A>) -> Parser<Token, B>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns the result of lhs

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B>(lhs: Parser<Token, (A)>, rhs: @escaping @autoclosure () -> Parser<Token, B>) -> Parser<Token, (A, B)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C>(lhs: Parser<Token, (A, B)>, rhs: @escaping @autoclosure () -> Parser<Token, C>) -> Parser<Token, (A, B, C)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C>(lhs: Parser<Token, C>, rhs: @escaping @autoclosure () -> Parser<Token, (A, B)>) -> Parser<Token, (C, A, B)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D>(lhs: Parser<Token, (A, B, C)>, rhs: @escaping @autoclosure () -> Parser<Token, D>) -> Parser<Token, (A, B, C, D)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D>(lhs: Parser<Token, D>, rhs: @escaping @autoclosure () -> Parser<Token, (A, B, C)>) -> Parser<Token, (D, A, B, C)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E>(lhs: Parser<Token, (A, B, C, D)>, rhs: @escaping @autoclosure () -> Parser<Token, E>) -> Parser<Token, (A, B, C, D, E)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E>(lhs: Parser<Token, E>, rhs: @escaping @autoclosure () -> Parser<Token, (A, B, C, D)>) -> Parser<Token, (E, A, B, C, D)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F>(lhs: Parser<Token, (A, B, C, D, E)>, rhs: @escaping @autoclosure () -> Parser<Token, F>) -> Parser<Token, (A, B, C, D, E, F)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F>(lhs: Parser<Token, F>, rhs: @escaping @autoclosure () -> Parser<Token, (A, B, C, D, E)>) -> Parser<Token, (F, A, B, C, D, E)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F, G>(lhs: Parser<Token, (A, B, C, D, E, F)>, rhs: @escaping @autoclosure () -> Parser<Token, G>) -> Parser<Token, (A, B, C, D, E, F, G)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F, G>(lhs: Parser<Token, G>, rhs: @escaping @autoclosure () -> Parser<Token, (A, B, C, D, E, F)>) -> Parser<Token, (G, A, B, C, D, E, F)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F, G, H>(lhs: Parser<Token, (A, B, C, D, E, F, G)>, rhs: @escaping @autoclosure () -> Parser<Token, H>) -> Parser<Token, (A, B, C, D, E, F, G, H)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F, G, H>(lhs: Parser<Token, H>, rhs: @escaping @autoclosure () -> Parser<Token, (A, B, C, D, E, F, G)>) -> Parser<Token, (H, A, B, C, D, E, F, G)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F, G, H, I>(lhs: Parser<Token, (A, B, C, D, E, F, G, H)>, rhs: @escaping @autoclosure () -> Parser<Token, I>) -> Parser<Token, (A, B, C, D, E, F, G, H, I)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F, G, H, I>(lhs: Parser<Token, I>, rhs: @escaping @autoclosure () -> Parser<Token, (A, B, C, D, E, F, G, H)>) -> Parser<Token, (I, A, B, C, D, E, F, G, H)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F, G, H, I, J>(lhs: Parser<Token, (A, B, C, D, E, F, G, H, I)>, rhs: @escaping @autoclosure () -> Parser<Token, J>) -> Parser<Token, (A, B, C, D, E, F, G, H, I, J)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F, G, H, I, J>(lhs: Parser<Token, J>, rhs: @escaping @autoclosure () -> Parser<Token, (A, B, C, D, E, F, G, H, I)>) -> Parser<Token, (J, A, B, C, D, E, F, G, H, I)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F, G, H, I, J, K>(lhs: Parser<Token, (A, B, C, D, E, F, G, H, I, J)>, rhs: @escaping @autoclosure () -> Parser<Token, K>) -> Parser<Token, (A, B, C, D, E, F, G, H, I, J, K)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Sequential conjunction of lhs and rhs with combining of the results in a tuple

    See more

    Declaration

    Swift

    public func ~<Token, A, B, C, D, E, F, G, H, I, J, K>(lhs: Parser<Token, K>, rhs: @escaping @autoclosure () -> Parser<Token, (A, B, C, D, E, F, G, H, I, J)>) -> Parser<Token, (K, A, B, C, D, E, F, G, H, I, J)>

    Parameters

    lhs

    the first parser that has to succeed

    rhs

    the second parser that has to succeed

    Return Value

    a parser that parses lhs, then rhs on the rest and returns a tuple of the combined results

  • Convenience operator for ‘or’ conjunction.

    See more

    Declaration

    Swift

    public func |<T, R>(lhs: Parser<T, R>, rhs: @escaping @autoclosure () -> Parser<T, R>) -> Parser<T, R>

    Parameters

    lhs

    the first parser to evaluate

    rhs

    the second parser to evaluate

    Return Value

    a parser that evaluates both, rhs and lhs, starting with lhs

  • Convenience operator for ‘then’ concatenation.

    See more

    Declaration

    Swift

    public func >><T, R, B>(lhs: Parser<T, R>, rhs: @escaping @autoclosure () -> Parser<T, B>) -> Parser<T, B>

    Parameters

    lhs

    the first parser to evaluate

    rhs

    the second parser to evaluate on lhs’ rest

    Return Value

    a parser that evaluates lhs and on it’s rest rhs

  • Convenience operator for map operations.

    See more

    Declaration

    Swift

    public func ^^<T, R, B>(lhs: Parser<T, R>, rhs: @escaping (R) -> B) -> Parser<T, B>

    Parameters

    lhs

    a parser to evaluate

    rhs

    a mapping operation to call on lhs’ result

    Return Value

    a parser that calls lhs and transforms its result with rhs afterwards.

  • Convenience operator for map operation. Replaces the result of lhs with rhs if lhs succeeded.

    See more

    Declaration

    Swift

    public func ^^^<T, R, B>(lhs: Parser<T, R>, rhs: @escaping @autoclosure () -> B) -> Parser<T, B>

    Parameters

    lhs

    the parser which result should be replaced

    rhs

    the value that should replace the result of lhs

    Return Value

    a parser that parses lhs and replaces its result with rhs if it succeeds

  • Convenience operator for atLeastOnce operation.

    See more

    Declaration

    Swift

    public postfix func +<T, R>(lhs: Parser<T, R>) -> Parser<T, [R]>

    Parameters

    lhs

    the parser that should succeed at least once.

    Return Value

    a parser that parses lhs repetitive with at least one successful result.

  • Convenience oeprator for rep operation. (repetitive parsing.

    See more

    Declaration

    Swift

    public postfix func *<T, R>(lhs: Parser<T, R>) -> Parser<T, [R]>

    Parameters

    lhs

    the parser that should be parses repetitive

    Return Value

    a parser that parses lhs as long as it succeeds

  • Convenience operator for fallback operation.

    See more

    Declaration

    Swift

    public func ??<T, R>(lhs: Parser<T, R>, rhs: @escaping @autoclosure () -> R) -> Parser<T, R>

    Parameters

    lhs

    the parser that could possibly fail

    rhs

    the default value that should be used instead

    Return Value

    a parser that tries to parse self and uses rhs if parsing failed.

  • Convenience operator for fallback with parser operation.

    See more

    Declaration

    Swift

    public func ??<T, R>(lhs: Parser<T, R>, rhs: @escaping @autoclosure () -> Parser<T, R>) -> Parser<T, R>

    Parameters

    lhs

    the parser that could fail

    rhs

    the parser that should be used instead

    Return Value

    a parser that tries to parse self and parses rhs if self failed.

  • ~= allows the usage of Parsers in switch-case pattern matching statements.

    example:

    switch "a" {
        case L.char: print("it's a char \o/")
        case L.digit: print("it's a digit!")
        default: print("it's something unexpected :/")
    

    NOTE: Be aware that this also checks if the rest is empty to ensure the whole input matches!

    See more

    Declaration

    Swift

    public func ~=<T, U>(lhs: Parser<T, U>, rhs: T) -> Bool

    Parameters

    lhs

    the pattern, in this case the parser that should succeed

    rhs

    the value that the pattern should be matched with

    Return Value

    true if the parsing succeeds, false otherwise

  • Compares two ParseResults for equality NOTE: two failed ParseResults are always equal!

    Hack until extensions with protocol conformance with constraints are possible

    See more

    Declaration

    Swift

    public func ==<T, R>(lhs: ParseResult<T, R>, rhs: ParseResult<T, R>) -> Bool where T: Equatable, R: Equatable

    Parameters

    lhs

    first argument

    rhs

    second argument

    Return Value

    true if both are equal

  • Convenience operator overload to use fallback on fail.

    See more

    Declaration

    Swift

    public func ??<T, R>(lhs: ParseResult<T, R>, rhs: @autoclosure () -> R) -> R

    Parameters

    lhs

    the parse result that could fail

    rhs

    the fallback that should be used in that case

    Return Value

    either the unwrapped result or fallback