ParserType
public protocol ParserType
A protocol to which Parser conforms. Exists as a workaround to the current
Swift limitation that extensions cannot make concrete type non-generic.
-
parse(_:)Default implementationUndocumented
Default Implementation
Runs the parser on the passed in
sequence.Parameter
Parameter sequence: The sequence to be parsed.
Throws
ParseErrorif unable to parse.Returns
The resulting parsed value.
Declaration
Swift
public protocol ParserType -
The type that results from the parsing.
Declaration
Swift
typealias Result -
The type whose sequence is parsed by the parser.
Declaration
Swift
typealias Token
-
flatMap(_:)Extension methodReturns a
Parserthat, on successful parse, continues parsing with the parser resulting from mappingtransformover its result value; returns the result of this new parser.Can be used to chain parsers together sequentially.
Parameter
Parameter transform: The transform to map over the result.Declaration
Swift
@warn_unused_result public func flatMap<MappedResult>(transform: Result throws -> Parser<Token, MappedResult>) -> Parser<Token, MappedResult>Parameters
transformThe transform to map over the result.
-
map(_:)Extension methodReturns a
Parserthat, on successful parse, returns the result of mappingtransformover its previous result valueParameter
Parameter transform: The transform to map over the result.Declaration
Swift
@warn_unused_result public func map<MappedResult>(transform: Result throws -> MappedResult) -> Parser<Token, MappedResult>Parameters
transformThe transform to map over the result.
-
replace(_:)Extension methodReturns a
Parserthat, on successful parse, discards its previous result and returnsvalueinstead.Parameter
Parameter value: The value to return on successful parse.Declaration
Swift
@warn_unused_result public func replace<NewResult>(value: NewResult) -> Parser<Token, NewResult>Parameters
valueThe value to return on successful parse.
-
discard()Extension methodReturns a
Parserthat, on successful parse, discards its result.Declaration
Swift
@warn_unused_result public func discard() -> Parser<Token, ()> -
peek(_:)Extension methodReturns a
Parserthat calls the callbackglimpsebefore returning its result.Parameter
Parameter glimpse: Callback that recieves the parser’s result as input.Declaration
Swift
@warn_unused_result public func peek(glimpse: Result throws -> ()) -> Parser<Token, Result>Parameters
glimpseCallback that recieves the parser’s result as input.
-
require(_:)Extension methodReturns a
Parserthat verifies that its result passes the condition before returning its result. If the result fails the condition, throws an error.Parameter
Parameter condition: The condition used to test the result.Declaration
Swift
@warn_unused_result public func require(condition: Result -> Bool) -> Parser<Token, Result>Parameters
conditionThe condition used to test the result.
-
unwrap()Extension methodUndocumented
Declaration
Swift
public protocol ParserType
-
recover(_:)Extension methodConstructs a
Parserthat, on error, catches the error and attempts to recover by running theParserobtained from passing the error torecovery.Parameter
Parameter recovery: A function that, given the error, will return a new parser to attempt.Declaration
Swift
@warn_unused_result public func recover(recovery: ParseError throws -> Parser<Token, Result>) -> Parser<Token, Result>Parameters
recoveryA function that, given the error, will return a new parser to attempt.
-
mapError(_:)Extension methodConstructs a
Parserthat, on error, catches the error and rethrows the transformed error.Parameter
Parameter transform: The transform to map onto the caught message.Declaration
Swift
@warn_unused_result public func mapError(transform: ParseError -> ParseError) -> Parser<Token, Result>Parameters
transformThe transform to map onto the caught message.
-
withError(_:)Extension methodConstructs a
Parserthat, on error, discards the previously thrown error and throws instead a newUnableToMatcherror with the given message.Parameter
Parameter description: The description to include in the error.Declaration
Swift
@warn_unused_result public func withError(description: String) -> Parser<Token, Result>Parameters
descriptionThe description to include in the error.
ParserType Protocol Reference