@@ -15,6 +15,7 @@ module Data.Attoparsec.Internal
15 ( compareResults
15 ( compareResults
17 , demandInput
17 , demandInput
18 , wantInput
19 , wantInput
19 , endOfInput
20 , endOfInput
@@ -40,8 +41,8 @@ compareResults (Done t0 r0) (Done t1 r1) =
40compareResults (Partial _) (Partial _) = Nothing
41compareResults (Partial _) (Partial _) = Nothing
41compareResults _ _ = Just False
42compareResults _ _ = Just False
43−-- | Ask for input. If we receive any, pass it to a success
44+-- | Ask for input. If we receive any, pass the augmented input to a
44−-- continuation, otherwise to a failure continuation.
45+-- success continuation, otherwise to a failure continuation.
45prompt :: Chunk t
46prompt :: Chunk t
46 => State t -> Pos -> More
47 => State t -> Pos -> More
47 -> (State t -> Pos -> More -> IResult t r)
48 -> (State t -> Pos -> More -> IResult t r)
@@ -68,12 +69,25 @@ demandInput :: Chunk t => Parser t ()
68demandInput = Parser $ \t pos more lose succ ->
69demandInput = Parser $ \t pos more lose succ ->
69 case more of
70 case more of
70 Complete -> lose t pos more [] "not enough input"
71 Complete -> lose t pos more [] "not enough input"
71− _ -> let lose' t' pos' more' = lose t' pos' more' [] "not enough input"
72+ _ -> let lose' _ pos' more' = lose t pos' more' [] "not enough input"
72 succ' t' pos' more' = succ t' pos' more' ()
73 succ' t' pos' more' = succ t' pos' more' ()
73 in prompt t pos more lose' succ'
74 in prompt t pos more lose' succ'
74{-# SPECIALIZE demandInput :: Parser ByteString () #-}
75{-# SPECIALIZE demandInput :: Parser ByteString () #-}
75{-# SPECIALIZE demandInput :: Parser Text () #-}
76{-# SPECIALIZE demandInput :: Parser Text () #-}
78+-- | Immediately demand more input via a 'Partial' continuation
79+-- result. Return the new input.
80+demandInput_ :: Chunk t => Parser t t
81+demandInput_ = Parser $ \t pos more lose succ ->
83+ Complete -> lose t pos more [] "not enough input"
86+ then lose t pos Complete [] "not enough input"
87+ else succ (pappendChunk t s) pos more s
88+{-# SPECIALIZE demandInput_ :: Parser ByteString ByteString #-}
89+{-# SPECIALIZE demandInput_ :: Parser Text Text #-}
77-- | This parser always succeeds. It returns 'True' if any input is
91-- | This parser always succeeds. It returns 'True' if any input is
78-- available either immediately or on demand, and 'False' if the end
92-- available either immediately or on demand, and 'False' if the end
79-- of all input has been reached.
93-- of all input has been reached.