@@ -94,16 +94,6 @@ type Success a r = S -> a -> Result r
9494data More = Complete | Incomplete
9595 deriving (Eq, Show)
9696
97−plusMore :: More -> More -> More
98−plusMore Complete _ = Complete
99−plusMore _ Complete = Complete
100−plusMore _ _ = Incomplete
101−{-# INLINE plusMore #-}
102−
103−instance Monoid More where
104− mempty = Incomplete
105− mappend = plusMore
106−
10797data S = S {
10898 input :: !B.ByteString
10999 , _added :: B.ByteString
@@ -116,13 +106,13 @@ instance Show r => Show (Result r) where
116106 show (Done bs r) = "Done " ++ show bs ++ " " ++ show r
117107
118108addS :: S -> S -> S
119−addS (S s0 a0 c0) (S _s1 a1 c1) = S (s0 +++ a1) (a0 +++ a1) (mappend c0 c1)
109+addS (S s0 a0 c0) (S _s1 a1 c1) = S (s0 +++ a1) (a0 +++ a1) (c0 <> c1)
110+ where
111+ Complete <> _ = Complete
112+ _ <> Complete = Complete
113+ _ <> _ = Incomplete
120114{-# INLINE addS #-}
121115
122−instance Monoid S where
123− mempty = S B.empty B.empty Incomplete
124− mappend = addS
125−
126116bindP :: Parser a -> (a -> Parser b) -> Parser b
127117bindP m g =
128118 Parser (\st0 kf ks -> runParser m st0 kf (\s a -> runParser (g a) s kf ks))
@@ -143,7 +133,7 @@ noAdds (S s0 _a0 c0) = S s0 B.empty c0
143133
144134plus :: Parser a -> Parser a -> Parser a
145135plus a b = Parser $ \st0 kf ks ->
146− let kf' st1 _ _ = runParser b (mappend st0 st1) kf ks
136+ let kf' st1 _ _ = runParser b (addS st0 st1) kf ks
147137 !st2 = noAdds st0
148138 in runParser a st2 kf' ks
149139{-# INLINE plus #-}
@@ -244,7 +234,7 @@ put s = Parser (\(S _s0 a0 c0) _kf ks -> ks (S s a0 c0) ())
244234-- retain input for longer than is desirable.
245235try :: Parser a -> Parser a
246236try p = Parser $ \st0 kf ks ->
247− runParser p (noAdds st0) (kf . mappend st0) ks
237+ runParser p (noAdds st0) (kf . addS st0) ks
248238
249239-- | The parser @satisfy p@ succeeds for any byte for which the
250240-- predicate @p@ returns 'True'. Returns the byte that is actually
@@ -475,8 +465,8 @@ endOfInput = Parser $ \st0@S{..} kf ks ->
475465 if B.null input
476466 then if more == Complete
477467 then ks st0 ()
478− else let kf' st1 _ _ = ks (mappend st0 st1) ()
479− ks' st1 _ = kf (mappend st0 st1) [] "endOfInput"
468+ else let kf' st1 _ _ = ks (addS st0 st1) ()
469+ ks' st1 _ = kf (addS st0 st1) [] "endOfInput"
480470 in runParser demandInput st0 kf' ks'
481471 else kf st0 [] "endOfInput"
482472