What about Data.Attoparsec.ByteString.Lazy.Char8?

302 views Asked by At

Attoparsec has modules specialized for Strict/Lazy, ByteString/Text, Char8 (ascii)/Char. But it doesn't have all the combinations.

I think Data.Attoparsec.ByteString.Lazy.Char8 which isn't provided would be particularly convenient for grinding through large reports which tend to be encoded as ascii.

Do you know why it doesn't exist?

1

There are 1 answers

0
DarthFennec On

I don't think this is needed, because the two modules don't appear to overlap with each other.

Data.Attoparsec.ByteString.Char8 provides extra parsers specifically for parsing ASCII data. These are just variations of their Word8 counterparts, and they use the same underlying monad, so you should be able to mix and match without issue.

Data.Attoparsec.ByteString.Lazy provides an alternative parse function that you can use to run a parser against a lazy bytestring. This isn't special in any way, it's just a wrapper around the strict version, iteratively pushing chunks of the lazy ByteString into your parser.

From what I can tell, there's no reason you shouldn't be able to just use both of them together. For example:

import Data.ByteString.Lazy
import qualified Data.Attoparsec.ByteString.Char8 as Char8
import qualified Data.Attoparsec.ByteString.Lazy as Lazy

myParser :: Char8.Parser T
myParser = -- use parsers from Char8 if you'd like

lazyParse :: Char8.Parser T -> ByteString -> Lazy.Result T
lazyParse p s = Lazy.parse p s -- parse a lazy ByteString

You use the combinators from Char8 to define your parser, and then you use the functions from Lazy to run it. So there's no need for a Data.Attoparsec.ByteString.Lazy.Char8.