sparsec

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

commit 08c78411b52b94e5c92c738ef5cce294422d349e
parent cfba4d81d6d85db40bad6c0e3d1885e4eb30faf2
Author: Robert Russell <robert@rr3.xyz>
Date:   Wed, 24 Dec 2025 20:24:44 -0800

Try optimizing many_

Diffstat:
Msrc/Sparsec.hs | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/Sparsec.hs b/src/Sparsec.hs @@ -209,11 +209,11 @@ mapParse = mapParseT -- Core combinators fail :: ParseT e a -fail = ParseT \_ -> Failure# +fail = ParseT \_s -> Failure# {-# INLINE fail #-} err :: e -> ParseT e a -err e = ParseT \_ -> Error# e +err e = ParseT \_s -> Error# e {-# INLINE err #-} succeed :: a -> ParseT e a @@ -363,7 +363,14 @@ chainr f pa pb = f <$> pa <*> chainr f pa pb <|> pb {-# INLINE chainr #-} many_ :: ParseT e a -> ParseT e () -many_ p = some_ p <|> pure () +-- many_ p = some_ p <|> pure () +many_ p = ParseT go + where + go s = case p `runParseT#` s of + Utf8Error# l -> Utf8Error# l + Failure# -> Success# () s + Error# e -> Error# e + Success# _ s' -> go s' {-# INLINE many_ #-} some_ :: ParseT e a -> ParseT e ()