Parser
public struct Parser<Token, Result>: ParserType
A parser whose parse function mutates a ParseState<Token> and returns a Result.
-
Construct a
Parserthat will runimplementation.Declaration
Swift
public init(_ implementation: ParseState<Token> throws -> Result) -
Runs the parser on the passed in
state, potentially mutating the state.Parameter
Parameter state: The state representing remaining input to be parsed.
Throws
ParseErrorif unable to parse.Returns
The resulting parsed value.
Declaration
Swift
public func parse(state: ParseState<Token>) throws -> ResultParameters
stateThe state representing remaining input to be parsed.
Return Value
The resulting parsed value.
-
Converts a parser that results in an elemnt into a parser that results in an Array.
Declaration
Swift
@warn_unused_result public func lift() -> Parser<Token, [Result]>
-
Constructs a
Parserthat catches an error and returnsrecoveryinstead.Parameter
Parameter recovery: Result to be returned in case of an error.Declaration
Swift
@warn_unused_result public func otherwise(recovery: Result) -> ParserParameters
recoveryResult to be returned in case of an error.
-
Converts a parser that results in a sequence of characters into a parser that results in a String.
Declaration
Swift
@warn_unused_result public func stringify() -> Parser<Token, String>
Parser Struct Reference