git.iko.soy/typeable/attoparsec
on master help sign in
Add feed combinator.
commitece4eec4605512868b12b248a372c603a78aec16 authorBryan O'Sullivan <bos@serpentine.com> dateFri 22 Jan 2010, 17:26 (17 years ago) parenteb9b01e
2 files changed+19−1
Data/Attoparsec/Incremental.hs+17 Data/Attoparsec/Incremental/Char8.hs+2−1
Data/Attoparsec/Incremental.hs+17
@@ -29,6 +29,7 @@ module Data.Attoparsec.Incremental
2929 , parse
3030 , parseWith
3131 , parseTest
32+ , feed
3233
3334 -- * Combinators
3435 , (<?>)
@@ -323,5 +324,21 @@ parseWith refill p s =
323324parseTest :: (Show r) => Parser r r -> L.ByteString -> IO ()
324325parseTest p s = print (parse p s)
325326
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+
326343#define PARSER Parser r
327344#include "Word8Boilerplate.h"
Data/Attoparsec/Incremental/Char8.hs+2−1
@@ -29,6 +29,7 @@ module Data.Attoparsec.Incremental.Char8
2929 , parse
3030 , parseWith
3131 , parseTest
32+ , feed
3233
3334 -- * Combinators
3435 , (<?>)
@@ -78,7 +79,7 @@ import Data.Char (isDigit, isLetter, isSpace)
7879import Data.Attoparsec.FastSet (charClass, memberChar)
7980import qualified Data.Attoparsec.Incremental as I
8081import Data.Attoparsec.Incremental
81− (Parser, Result(..), (<?>), endOfInput, parse, parseWith, parseTest,
82+ (Parser, Result(..), (<?>), endOfInput, feed, parse, parseWith, parseTest,
8283 pushBack, string, takeCount, try, yield)
8384import Data.ByteString.Lex.Lazy.Double (readDouble)
8485import Prelude hiding (takeWhile)