core: ParseCharE

This commit is contained in:
Nathan McCarty 2025-01-24 22:26:55 -05:00
parent fa5eb61d59
commit 40dd87a4f3

View file

@ -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