Functions
The following functions are available globally.
-
Return a collection containing x and all elements of xs. Works with strings and arrays.
Declaration
Swift
public func extend <A, C: RangeReplaceableCollection> (_ xs: C) -> (A) -> C where C.Iterator.Element == A
-
Return a collection containing x and all elements of xs. Works with strings and arrays.
Declaration
Swift
public func extend <A, C: RangeReplaceableCollection > (_ x: A) -> (C) -> C where C.Iterator.Element == A
-
Join 2 collections together.
Declaration
Swift
public func extend <C1: RangeReplaceableCollection, C2: Collection > (_ xs1: C1) -> (C2) -> C1 where C1.Iterator.Element == C2.Iterator.Element
-
Create a tuple of the arguments.
Declaration
Swift
public func tuple<A, B>(_ a: A) -> (B) -> (A, B)
-
Undocumented
Declaration
Swift
public func tuple<A, B, C>(_ a: A) -> (B) -> (C) -> (A, B, C)
-
Undocumented
Declaration
Swift
public func tuple<A, B, C, D>(_ a: A) -> (B) -> (C) -> (D) -> (A, B, C, D)
-
Undocumented
Declaration
Swift
public func tuple<A, B, C, D, E>(_ a: A) -> (B) -> (C) -> (D) -> (E) -> (A, B, C, D, E)
-
Create a curried function of a normal function.
Usage:
func myFunc(a: A, b: B) -> C { ... } let parser = curry(myFunc) <^> string("hello") <*> string("world")
Declaration
Swift
public func curry<A,B,C>(_ f: @escaping (A, B) -> C) -> (A) -> (B) -> C
-
Create a curried function of a normal function.
Usage:
func myFunc(a: A, b: B, c: C) -> D { ... } let parser = curry(myFunc) <^> string("hello,") <*> string("dear") <*> string("world")
Declaration
Swift
public func curry<A,B,C,D>(_ f: @escaping (A, B, C) -> D) -> (A) -> (B) -> (C) -> D
-
Create a curried function of a normal function.
Usage:
func myFunc(a: A, b: B, c: C, d: D) -> E { ... } let parser = curry(myFunc) <^> string("a") <*> string("b") <*> string("c") <*> string("d")
Declaration
Swift
public func curry<A, B, C, D, E>(_ f: @escaping (A, B, C, D) -> E) -> (A) -> (B) -> (C) -> (D) -> E
-
Create a curried function of a normal function.
Usage:
func myFunc(a: A, b: B, c: C, d: D) -> E { ... } let parser = curry(myFunc) <^> string("a") <*> string("b") <*> string("c") <*> string("d")
Declaration
Swift
public func curry<A, B, C, D, E, F>(_ f: @escaping (A, B, C, D, E) -> F) -> (A) -> (B) -> (C) -> (D) -> (E) -> F
-
FlatMap a function over a parser.
- If the parser fails, the function will not be evaluated and the error is returned.
- If the parser succeeds, the function will be applied to the output, and the resulting parser is run with the remaining input.
Declaration
Parameters
p
A parser of type Parser
f
A transformation function from type A to Parser
Return Value
A parser of type Parser
-
Map a function over a parser
- If the parser fails, the function will not be evaluated and the parser error is returned.
- If the parser succeeds, the function will be applied to the output.
Declaration
Parameters
f
A function from type A to type B
p
A parser of type Parser
Return Value
A parser of type Parser
-
Apply a parser returning a function to another parser.
- If the first parser fails, its error will be returned.
If it succeeds, the resulting function will be applied to the 2nd parser.
Declaration
Parameters
fp
A parser with a function A->B as output
p
A parser of type Parser
Return Value
A parser of type Parser
-
Apply both parsers, but only return the output from the first one.
- If the first parser fails, its error will be returned.
If the 2nd parser fails, its error will be returned.
Return Value
A parser of the same type as the first parser.
-
Apply both parsers, but only return the output from the 2nd one.
- If the first parser fails, its error will be returned.
If the 2nd parser fails, its error will be returned.
Return Value
A parser of the same type as the 2nd parser.
-
Create a parser which doesn’t consume input and returns this parameter.
Declaration
Swift
public func pure<T, A>(_ a: A) -> Parser<T, A>
Parameters
a
A value of type A
-
Apply one of 2 parsers.
- If the first parser succeeds, return its results.
- Else if the 2nd parser succeeds, return its results.
- If they both fail, return the failure from the parser that got the furthest.
Has infinite lookahead. The 2nd parser starts from the same position in the input as the first one.
-
Undocumented
Declaration
Swift
public func satisfy<T> (expect: @autoclosure @escaping () -> String, condition: @escaping (T) -> Bool) -> Parser<T, T>
-
Undocumented
Declaration
Swift
public func token<T>(_ token: T) -> Parser<T, T> where T : Equatable
-
Match several tokens in a row.
Declaration
Swift
public func tokens<T, C>(_ xs: C) -> Parser<T, C> where T : Equatable, T == C.Element, C : Collection
-
Return whatever the next token is.
Declaration
Swift
public func any<T>() -> Parser<T, T>
-
Succeed if the next token is in the provided collection.
Declaration
Swift
public func oneOf<T, C>(_ collection: C) -> Parser<T, T> where T : Equatable, T == C.Element, C : Collection
-
Succeed if the next token is not in the provided collection.
Declaration
Swift
public func noneOf<T, C>(_ collection: C) -> Parser<T, T> where T : Equatable, T == C.Element, C : Collection
-
Match anything but this.
Declaration
Swift
public func not<T>(_ token: T) -> Parser<T, T> where T : Equatable
-
Verify that input is empty.
Declaration
Swift
public func eof<T>() -> Parser<T, ()>
-
Fail with the given error message. Ignores input.
Declaration
Swift
public func fail<T, A>(_ error: ParseError<T>) -> Parser<T, A>
-
Parse all of input with parser. Failure to consume all of input will result in a ParserError.
Throws
ParserError.Declaration
Swift
public func parse<A, T>(_ p: Parser<T, A>, _ c: [T]) throws -> A
Parameters
p
A parser.
input
A collection, like a string or an array.
Return Value
Output from the parser.
-
Match a single character.
Declaration
Swift
public func char(_ c: Character) -> Parser<Character, Character>
-
Join two strings
Declaration
Swift
public func extend(_ a: String) -> (String) -> String
-
Join a character with a string.
Declaration
Swift
public func extend(_ a: Character) -> (String) -> String
-
Match a string
Note
consumes either the full string or nothing, even on a partial match.Declaration
Swift
public func string(_ s: String) -> Parser<Character, String>
-
Succeed if the next character is in the provided string.
Declaration
Swift
public func oneOf(_ s: String) -> Parser<Character, Character>
-
Succeed if the next character is not in the provided string.
Declaration
Swift
public func noneOf(_ s: String) -> Parser<Character, Character>
-
Produces a character if the character and succeeding do not match any of the strings.
Note
consumes only produced charactersDeclaration
Swift
public func noneOf(_ strings: [String]) -> Parser<Character, Character>
-
Undocumented
Declaration
Swift
public func char(_ set: CharacterSet, name: String) -> Parser<Character, Character>
-
Parse all of the string with parser. Failure to consume all of input will result in a ParserError.
Throws
A ParserError.Declaration
Swift
public func parse<A>(_ p: Parser<Character, A>, _ s: String) throws -> A
Parameters
p
A parser of characters.
input
A string.
Return Value
Output from the parser.
-
Undocumented
Declaration
Swift
public func print(error: ParseError<Character>, in s: String)