@@ -15,6 +15,7 @@ module Data.Attoparsec.Internal
1515 ( compareResults
1616 , prompt
1717 , demandInput
18+ , demandInput_
1819 , wantInput
1920 , endOfInput
2021 , atEnd
@@ -40,8 +41,8 @@ compareResults (Done t0 r0) (Done t1 r1) =
4041compareResults (Partial _) (Partial _) = Nothing
4142compareResults _ _ = Just False
4243
43−-- | Ask for input. If we receive any, pass it to a success
44−-- continuation, otherwise to a failure continuation.
44+-- | Ask for input. If we receive any, pass the augmented input to a
45+-- success continuation, otherwise to a failure continuation.
4546prompt :: Chunk t
4647 => State t -> Pos -> More
4748 -> (State t -> Pos -> More -> IResult t r)
@@ -68,12 +69,25 @@ demandInput :: Chunk t => Parser t ()
6869demandInput = Parser $ \t pos more lose succ ->
6970 case more of
7071 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"
7273 succ' t' pos' more' = succ t' pos' more' ()
7374 in prompt t pos more lose' succ'
7475{-# SPECIALIZE demandInput :: Parser ByteString () #-}
7576{-# SPECIALIZE demandInput :: Parser Text () #-}
7677
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 ->
82+ case more of
83+ Complete -> lose t pos more [] "not enough input"
84+ _ -> Partial $ \s ->
85+ if nullChunk s
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 #-}
90+
7791-- | This parser always succeeds. It returns 'True' if any input is
7892-- available either immediately or on demand, and 'False' if the end
7993-- of all input has been reached.