module Codec.Phaser.ByteString (
unpackBS,
unpackLBS,
parseFile_
) where
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
import Data.Word
import Control.Monad
import Control.Applicative
import Codec.Phaser.Core
unpackBS :: Phase p BS.ByteString Word8 ()
unpackBS = (go >> unpackBS) <|> return () where
go = get >>= BS.foldr (\w r -> yield w >> r) (return ())
unpackLBS :: Phase p BL.ByteString Word8 ()
unpackLBS = (go >> unpackLBS) <|> return () where
go = get >>= BL.foldr (\w r -> yield w >> r) (return ())
parseFile_ :: p -> Phase p Word8 o a -> FilePath ->
IO (Either [(p,[String])] [a])
parseFile_ p c n = do
i <- BL.readFile n
return $ parse1_ p (unpackLBS >># c) i