Using Haskell's Parsec to parse a ByteString
Asked Answered
H

3

6

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 accomplish. Am I wrong? (I'm new to Haskell. ^^)

Thanks!

Hunk answered 19/1, 2010 at 1:9 Comment(1)
Based on [the other question][1] you asked, you should learn to read the documentation of the library you're using. It's available on Hackage. [1]: #2087342Heuser
V
8

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

Vogt answered 19/1, 2010 at 1:18 Comment(2)
What is numbers in Text.Parsec.ByteString.Lazy(hackage.haskell.org/packages/archive/parsec/3.0.0/doc/html/…)?Crenulation
see (#15455584 for where to go from hereLachesis
M
2

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.

Mra answered 19/1, 2010 at 1:19 Comment(1)
Oh, then I seem to currently lack the newest version, and have been using the older one. I will upgrade. Thank you both!Hunk
P
0
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
Pyridine answered 25/6, 2011 at 20:22 Comment(1)
were you trying to explain how to get Word8 instead of Char, by any chance. I can't figure that out.Endora

© 2022 - 2024 — McMap. All rights reserved.