A fast Haskell library for parsing ByteStrings
Questions tagged [attoparsec]
131 questions
80
votes
1 answer
attoparsec or parsec in haskell
I have to parse some files and convert them to some predefined datatypes.
Haskell seems to be providing two packages for that:
attoparsec
parsec
What is the difference between the two of them and which one is better suited for parsing a text file…

Sibi
- 47,472
- 16
- 95
- 163
20
votes
1 answer
Why do library designers use ByteString where Text seems to be appropriate?
Working on my app I've stumbled into a problem of Aeson not decoding UTF8 input. Digging deeper I found out that it relies on Parser ByteString of Attoparsec, which seems to be the source of the problem to me. But it's actually not what I'm asking…

Nikita Volkov
- 42,792
- 11
- 94
- 169
19
votes
1 answer
Attoparsec allocates a ton of memory on large 'take' call
So I am writing a packet sniffing app. Basically I wanted it to sniff for tcp sessions, and then parse them to see if they are http, and if they are, and if they have the right content type, etc, save them as a file on my hard drive.
So, to that…

David McHealy
- 2,471
- 18
- 34
14
votes
1 answer
Why do I see Partial results with attoparsec when I expect to see Failure?
I'm a little confused by this behaviour of attoparsec.
$ ghci
> :m Data.Attoparsec.Text
> :m + Data.Text
> parse (string (pack "module")) (pack "mox")
Partial _
> parse (string (pack "module")) (pack "moxxxx")
Fail "moxxxx" [] "Failed reading:…

timbod
- 791
- 5
- 16
10
votes
1 answer
Attoparsec Iteratee
I wanted, just to learn a bit about Iteratees, reimplement a simple parser I made, using Data.Iteratee and Data.Attoparsec.Iteratee. I'm pretty much stumped though. Below I have a simple example that is able to parse one line from a file. My parser…

Johanna Larsson
- 10,531
- 6
- 39
- 50
10
votes
2 answers
Haskell Parser Combinators
I was reading a lot about Haskell Parser Combinators and found a lot of topics like:
Parsec vs Yacc/Bison/Antlr: Why and when to use Parsec?
Which Haskell parsing technology is most pleasant to use, and why?
Parsec or happy (with alex) or…

Wojciech Danilo
- 11,573
- 17
- 66
- 132
9
votes
4 answers
Generalized Bottom up Parser Combinators in Haskell
I am wondered why there is no generalized parser combinators for Bottom-up parsing in Haskell like a Parsec combinators for top down parsing.
( I could find some research work went during 2004 but nothing after…

Panini
- 91
- 6
7
votes
2 answers
Simple parser running out of memory
I'd like to understand why this simple parser runs out of memory for large files. I'm really clueless what am I doing wrong.
import Data.Attoparsec.ByteString.Char8
import qualified Data.Attoparsec.ByteString.Lazy as Lazy
import…

user3608068
- 424
- 2
- 13
7
votes
1 answer
Fast parsing of string that allows escaped characters?
I'm trying to parse a string that can contain escaped characters, here's an example:
import qualified Data.Text as T
exampleParser :: Parser T.Text
exampleParser = T.pack <$> many (char '\\' *> escaped <|> anyChar)
where escaped = satisfy (\c ->…

danielrs
- 341
- 1
- 10
7
votes
2 answers
efficiently reading a large file into a Map
I'm trying to write code to perform the following simple task in Haskell: looking up the etymologies of words using this dictionary, stored as a large tsv file (http://www1.icsi.berkeley.edu/~demelo/etymwn/). I thought I'd parse (with attoparsec)…

Reuben
- 609
- 3
- 9
7
votes
1 answer
attoparsec: "nested" parsers -- parse a subset of the input with a different parser
Well in fact I'm pretty sure I'm using the wrong terminology. Here is the problem I want to solve: a parser for the markdown format, well a subset of it.
My problem is with the blockquote feature. Each line in a blockquote starts with >; otherwise…

Emmanuel Touzery
- 9,008
- 3
- 65
- 81
7
votes
3 answers
Problem with incomplete input when using Attoparsec
I am converting some functioning Haskell code that uses Parsec to instead use Attoparsec in the hope of getting better performance. I have made the changes and everything compiles but my parser does not work correctly.
I am parsing a file that…

Dan Dyer
- 53,737
- 19
- 129
- 165
6
votes
1 answer
Why does attoparsec need manyTill if it backtracks?
Consider the usage of these different parser combinators.
import Control.Applicative.Combinators
import Text.Regex.Applicative
main :: IO ()
main = do
let parser1 = sym '"' *> manyTill anySym (sym '"')
print $ match parser1 "\"abc\""
let…

Joseph Sible-Reinstate Monica
- 45,431
- 5
- 48
- 98
6
votes
3 answers
Operating on parsed data with attoparsec
Background
I've written a logfile parser using attoparsec. All my smaller parsers succeed, as does the composed final parser. I've confirmed this with tests. But I'm stumbling over performing operations with the parsed stream.
What I've tried
I…

Garry Cairns
- 3,005
- 1
- 18
- 33
6
votes
1 answer
Does Attoparsec support saving and modifying user state?
I'm using Attoparsec, and I would like to track a user state value throughout a parsing task.
I'm familiar with the monadic functions getState, putState, and modifyState of Parsec, but I can't seem to find an analogue within Attoparsec. Is there a…

Robert Bermani
- 197
- 6