diff --git a/src/Parser/ParserState.md b/src/Parser/ParserState.md index c8eb361..323b6d5 100644 --- a/src/Parser/ParserState.md +++ b/src/Parser/ParserState.md @@ -216,6 +216,19 @@ parseChar : Has ParserState fs => (predicate : Char -> Bool) -> (err : Char -> e -> Eff fs (ParseCharResult e) parseChar predicate err = send $ ParseChar predicate err +||| Wrapper for parseChar that folds the error message into effect stack with the +||| provided callback +export +parseCharE : Has ParserState fs => Has (Except e) fs => + (predicate : Char -> Bool) -> (err : Char -> e) -> (eof : Lazy e) + -> Eff fs Char +parseCharE predicate err eof = do + result <- parseChar predicate id + case result of + GotChar char => pure char + GotError x => throw $ err x + EndOfInput => throw eof + ||| "Parse" the end of input, returning `True` if the parser state is currently ||| at the end of the input export