Using Haskell Parsec to parse a byte string

I managed to use Parsec to parse the string, but can't do the same with ByteString.

How can I get Parsec to work with ByteStrings without manually converting them to strings?

It seems to me that this is not difficult. Am I mistaken? (I'm new to Haskell. ^^)

Thanks!

+6
haskell parsec bytestring
source share
3 answers

Just import the Parser type from Text.Parsec.ByteString or Text.Parsec.ByteString.Lazy , instead of Text.Parsec.String .

+8
source share

The answer actually depends on the version of Parsec you are using. If you are using version 3.0 or later, then yes. For version 2.xx, I do not think you can.

http://hackage.haskell.org/packages/archive/parsec/3.0.1/doc/html/Text-Parsec-ByteString.html

Greetings

edit: Parsec, which STH offers (Text.Parsec.ByteString), is actually version 3.0, the previous version 2.xx is in Text.ParserCombinators.Parsec.

+2
source share
 import Text.Parsec.ByteString () 

will give you a copy

 forall m. Stream ByteString m Char 

therefore, if you use instead of Parser a :

 p :: Stream sm Char => ParsecT suma 
0
source share

All Articles