git.iko.soy/typeable/attoparsec
on master help sign in
Add feed combinator.
ece4eecBryan O'Sullivan
Data/Attoparsec/Incremental.hs+17
@@ -29,6 +29,7 @@ module Data.Attoparsec.Incremental
29 , parse
29 , parse
30 , parseWith
30 , parseWith
31 , parseTest
31 , parseTest
32+ , feed
32
33
33 -- * Combinators
34 -- * Combinators
34 , (<?>)
35 , (<?>)
@@ -323,5 +324,21 @@ parseWith refill p s =
323parseTest :: (Show r) => Parser r r -> L.ByteString -> IO ()
324parseTest :: (Show r) => Parser r r -> L.ByteString -> IO ()
324parseTest p s = print (parse p s)
325parseTest p s = print (parse p s)
325
326
327+-- | Attempt to feed more data to a 'Result'.
328+--
329+-- * If the original parse 'Failed', the string is not inspected, and
330+-- the result remains a failed parse.
331+--
332+-- * If the parse was 'Done', the string is appended to the remainder,
333+-- and the result of the parse is otherwise the same 'Done' as
334+-- before.
335+--
336+-- * If the parse was 'Partial', the string is fed to the continuation
337+-- and the new 'Result' returned.
338+feed :: Result a -> L.ByteString -> Result a
339+feed f@(Failed _) _ = f
340+feed (Done bs a) c = Done (L.append bs c) a
341+feed (Partial k) c = k c
342+
326#define PARSER Parser r
343#define PARSER Parser r
327#include "Word8Boilerplate.h"
344#include "Word8Boilerplate.h"
Data/Attoparsec/Incremental/Char8.hs+2−1
@@ -29,6 +29,7 @@ module Data.Attoparsec.Incremental.Char8
29 , parse
29 , parse
30 , parseWith
30 , parseWith
31 , parseTest
31 , parseTest
32+ , feed
32
33
33 -- * Combinators
34 -- * Combinators
34 , (<?>)
35 , (<?>)
@@ -78,7 +79,7 @@ import Data.Char (isDigit, isLetter, isSpace)
78import Data.Attoparsec.FastSet (charClass, memberChar)
79import Data.Attoparsec.FastSet (charClass, memberChar)
79import qualified Data.Attoparsec.Incremental as I
80import qualified Data.Attoparsec.Incremental as I
80import Data.Attoparsec.Incremental
81import Data.Attoparsec.Incremental
81− (Parser, Result(..), (<?>), endOfInput, parse, parseWith, parseTest,
82+ (Parser, Result(..), (<?>), endOfInput, feed, parse, parseWith, parseTest,
82 pushBack, string, takeCount, try, yield)
83 pushBack, string, takeCount, try, yield)
83import Data.ByteString.Lex.Lazy.Double (readDouble)
84import Data.ByteString.Lex.Lazy.Double (readDouble)
84import Prelude hiding (takeWhile)
85import Prelude hiding (takeWhile)