From 40dd87a4f3858118f6e1dc43f53c9c1f135a586e Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Fri, 24 Jan 2025 22:26:55 -0500 Subject: [PATCH] core: ParseCharE --- src/Parser/ParserState.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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