git.iko.soy/typeable/attoparsec
on master help sign in
IResult does not need to be parameterised on internal state
commit3833f11fcb2276de92979177eff56760cf8e133a authorBryan O'Sullivan <bos@serpentine.com> dateTue 27 May 2014, 09:42 (12 years ago) parentdf86fbf
5 files changed+18−18
Data/Attoparsec/ByteString/Internal.hs+4−4 Data/Attoparsec/Combinator.hs+1−1 Data/Attoparsec/Internal.hs+1−1 Data/Attoparsec/Internal/Types.hs+8−8 Data/Attoparsec/Text/Internal.hs+4−4
Data/Attoparsec/ByteString/Internal.hs+4−4
@@ -87,7 +87,7 @@ import qualified Data.ByteString.Lazy as L
8787import qualified Data.ByteString.Unsafe as B
8888
8989type Parser = T.Parser B.ByteString Buffer
90−type Result = IResult B.ByteString Buffer
90+type Result = IResult B.ByteString
9191type Failure r = T.Failure B.ByteString Buffer r
9292type Success a r = T.Success B.ByteString Buffer a r
9393
@@ -465,9 +465,9 @@ ensure n = T.Parser $ \t pos more lose succ ->
465465-- | Ask for input. If we receive any, pass it to a success
466466-- continuation, otherwise to a failure continuation.
467467prompt :: Buffer -> Pos -> More
468− -> (Buffer -> Pos -> More -> IResult ByteString Buffer r)
469− -> (Buffer -> Pos -> More -> IResult ByteString Buffer r)
470− -> IResult ByteString Buffer r
468+ -> (Buffer -> Pos -> More -> IResult ByteString r)
469+ -> (Buffer -> Pos -> More -> IResult ByteString r)
470+ -> IResult ByteString r
471471prompt t pos _more lose succ = Partial $ \s ->
472472 if B.null s
473473 then lose t pos Complete
Data/Attoparsec/Combinator.hs+1−1
@@ -231,7 +231,7 @@ eitherP a b = (Left <$> a) <|> (Right <$> b)
231231
232232-- | If a parser has returned a 'T.Partial' result, supply it with more
233233-- input.
234−feed :: Monoid i => IResult i t r -> i -> IResult i t r
234+feed :: Monoid i => IResult i r -> i -> IResult i r
235235feed f@(Fail _ _ _) _ = f
236236feed (Partial k) d = k d
237237feed (Done t r) d = Done (mappend t d) r
Data/Attoparsec/Internal.hs+1−1
@@ -24,7 +24,7 @@ import Prelude hiding (succ)
2424-- If both 'IResult's are 'Partial', the result will be 'Nothing', as
2525-- they are incomplete and hence their equality cannot be known.
2626-- (This is why there is no 'Eq' instance for 'IResult'.)
27−compareResults :: (Eq i, Eq r) => IResult i t r -> IResult i t r -> Maybe Bool
27+compareResults :: (Eq i, Eq r) => IResult i r -> IResult i r -> Maybe Bool
2828compareResults (Fail t0 ctxs0 msg0) (Fail t1 ctxs1 msg1) =
2929 Just (t0 == t1 && ctxs0 == ctxs1 && msg0 == msg1)
3030compareResults (Done t0 r0) (Done t1 r1) =
Data/Attoparsec/Internal/Types.hs+8−8
@@ -37,14 +37,14 @@ newtype Pos = Pos { fromPos :: Int }
3737--
3838-- This type is an instance of 'Functor', where 'fmap' transforms the
3939-- value in a 'Done' result.
40−data IResult i t r =
40+data IResult i r =
4141 Fail i [String] String
4242 -- ^ The parse failed. The @i@ parameter is the input that had
4343 -- not yet been consumed when the failure occurred. The
4444 -- @[@'String'@]@ is a list of contexts in which the error
4545 -- occurred. The 'String' is the message describing the error, if
4646 -- any.
47− | Partial (i -> IResult i t r)
47+ | Partial (i -> IResult i r)
4848 -- ^ Supply this continuation with more input so that the parser
4949 -- can resume. To indicate that no more input is available, pass
5050 -- an empty string to the continuation.
@@ -55,19 +55,19 @@ data IResult i t r =
5555 -- ^ The parse succeeded. The @i@ parameter is the input that had
5656 -- not yet been consumed (if any) when the parse succeeded.
5757
58−instance (Show i, Show r) => Show (IResult i t r) where
58+instance (Show i, Show r) => Show (IResult i r) where
5959 show (Fail t stk msg) =
6060 unwords [ "Fail", show t, show stk, show msg]
6161 show (Partial _) = "Partial _"
6262 show (Done t r) = unwords ["Done", show t, show r]
6363
64−instance (NFData i, NFData r) => NFData (IResult i t r) where
64+instance (NFData i, NFData r) => NFData (IResult i r) where
6565 rnf (Fail t stk msg) = rnf t `seq` rnf stk `seq` rnf msg
6666 rnf (Partial _) = ()
6767 rnf (Done t r) = rnf t `seq` rnf r
6868 {-# INLINE rnf #-}
6969
70−instance Functor (IResult i t) where
70+instance Functor (IResult i) where
7171 fmap _ (Fail t stk msg) = Fail t stk msg
7272 fmap f (Partial k) = Partial (fmap f . k)
7373 fmap f (Done t r) = Done t (f r)
@@ -94,12 +94,12 @@ newtype Parser i t a = Parser {
9494 runParser :: forall r. t -> Pos -> More
9595 -> Failure i t r
9696 -> Success i t a r
97− -> IResult i t r
97+ -> IResult i r
9898 }
9999
100100type Failure i t r = t -> Pos -> More -> [String] -> String
101− -> IResult i t r
102−type Success i t a r = t -> Pos -> More -> a -> IResult i t r
101+ -> IResult i r
102+type Success i t a r = t -> Pos -> More -> a -> IResult i r
103103
104104-- | Have we read all available input?
105105data More = Complete | Incomplete
Data/Attoparsec/Text/Internal.hs+4−4
@@ -82,7 +82,7 @@ import qualified Data.Text.Lazy as L
8282import qualified Data.Text.Unsafe as T
8383
8484type Parser = T.Parser Text Buffer
85−type Result = IResult Text Buffer
85+type Result = IResult Text
8686type Failure r = T.Failure Text Buffer r
8787type Success a r = T.Success Text Buffer a r
8888
@@ -472,9 +472,9 @@ ensure n = T.Parser $ \t pos more lose succ ->
472472-- | Ask for input. If we receive any, pass it to a success
473473-- continuation, otherwise to a failure continuation.
474474prompt :: Buffer -> Pos -> More
475− -> (Buffer -> Pos -> More -> IResult Text Buffer r)
476− -> (Buffer -> Pos -> More -> IResult Text Buffer r)
477− -> IResult Text Buffer r
475+ -> (Buffer -> Pos -> More -> IResult Text r)
476+ -> (Buffer -> Pos -> More -> IResult Text r)
477+ -> IResult Text r
478478prompt t pos _more lose succ = Partial $ \s ->
479479 if T.null s
480480 then lose t pos Complete