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 implementation

    Undocumented

    Default Implementation

    Runs the parser on the passed in sequence.

    Parameter

    Parameter sequence: The sequence to be parsed.

    Throws

    ParseError if 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 method

    Returns a Parser that, on successful parse, continues parsing with the parser resulting from mapping transform over 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

    transform

    The transform to map over the result.

  • map(_:) Extension method

    Returns a Parser that, on successful parse, returns the result of mapping transform over its previous result value

    Parameter

    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

    transform

    The transform to map over the result.

  • replace(_:) Extension method

    Returns a Parser that, on successful parse, discards its previous result and returns value instead.

    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

    value

    The value to return on successful parse.

  • discard() Extension method

    Returns a Parser that, on successful parse, discards its result.

    Declaration

    Swift

    @warn_unused_result public func discard() -> Parser<Token, ()>
  • peek(_:) Extension method

    Returns a Parser that calls the callback glimpse before 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

    glimpse

    Callback that recieves the parser’s result as input.

  • require(_:) Extension method

    Returns a Parser that 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

    condition

    The condition used to test the result.

  • unwrap() Extension method

    Undocumented

    Declaration

    Swift

    public protocol ParserType
  • recover(_:) Extension method

    Constructs a Parser that, on error, catches the error and attempts to recover by running the Parser obtained from passing the error to recovery.

    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

    recovery

    A function that, given the error, will return a new parser to attempt.

  • mapError(_:) Extension method

    Constructs a Parser that, 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

    transform

    The transform to map onto the caught message.

  • withError(_:) Extension method

    Constructs a Parser that, on error, discards the previously thrown error and throws instead a new UnableToMatch error 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

    description

    The description to include in the error.