sparsec

simple Haskell parser combinator library
git clone git://git.rr3.xyz/sparsec
Log | Files | Refs | README | LICENSE

commit 19d87c54f3f72712a7802ba0da12ff17cc3f3aae
parent 8eef46865094ea53e3f7608608eb18440efa8cfd
Author: Robert Russell <robert@rr3.xyz>
Date:   Tue, 27 Aug 2024 14:06:52 -0700

Add new branch combinator

Diffstat:
MSparsec.hs | 5+++++
1 file changed, 5 insertions(+), 0 deletions(-)

diff --git a/Sparsec.hs b/Sparsec.hs @@ -245,6 +245,11 @@ eof = (ByteString.null <$> read) >>= guard iter :: Monad m => (a -> ParseT e m a) -> a -> ParseT e m a iter f a = (f a >>= iter f) <|> pure a +-- (branch pc pt pf) runs pc; if it succeeds, it continues with pc, and +-- otherwise it continues with pf. +branch :: Monad m => ParseT e m a -> ParseT e m b -> ParseT e m b -> ParseT e m b +branch pc pt pf = pc *> pt <|> pf + someUntil :: Monad m => ParseT e m a -> ParseT e m b -> ParseT e m [a] someUntil p end = some (notp end *> p)