Using Haskell's Parsec to parse a ByteString
I've managed to use Parsec to parse a String, but cannot manage to do the same with a ByteString.
How can I make Parsec work with ByteStrings without manually converting them to Strings?
I get the feeling this isn't hard to开发者_如何学Go accomplish. Am I wrong? (I'm new to Haskell. ^^)
Thanks!
Just import the Parser
type from Text.Parsec.ByteString
or Text.Parsec.ByteString.Lazy
, instead of from Text.Parsec.String
.
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.x.x I don't think you can.
http://hackage.haskell.org/packages/archive/parsec/3.0.1/doc/html/Text-Parsec-ByteString.html
Cheers
edit: The Parsec that STH suggest (Text.Parsec.ByteString) is actually version 3.0 the previous version 2.x.x is located in Text.ParserCombinators.Parsec.
import Text.Parsec.ByteString ()
will give you the instance
forall m. Stream ByteString m Char
hence if you use, instead of Parser a
:
p :: Stream s m Char => ParsecT s u m a
精彩评论