A fast Haskell library for parsing ByteStrings
Questions tagged [attoparsec]
131 questions
1
vote
1 answer
Attoparsec: matching any of strings with common prefix
I am trying to parse a limited set of valid strings which have a common prefix with attoparsec. However, My attempts result in either a Partial result or a premature Done:
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import…

sjp
- 382
- 4
- 15
1
vote
1 answer
example or tutorial for Zepto parser in attoparsec
The title says it all: I look for examples or tutorial for Zepto parser in attoparsec.
I have a reasonably simple parser for a network protocol (BGP, as it happens), which runs reasonably quickly, but still significantly slower than 'C'. I've…

hdb3
- 239
- 1
- 10
1
vote
1 answer
Attoparsec - ensure entire contents consumed with sepBy1
I would like the below code to return [LoadInt 1,LoadDub 2.5,LoadInt 3], but it fails after parsing [LoadInt 1,LoadDub 2] and facing .5,3. How do I make it so it must parse all the way to the comma for a parse to succeed, and an int parse on 2.5 is…

Carbon
- 3,828
- 3
- 24
- 51
1
vote
1 answer
Parsing multi line log with attoparsec
I'm trying to parse a multiline log like this
[xxx] This is 1
[xxx] This is also 1
[yyy] This is 2
I have these types defined
{-# LANGUAGE OverloadedStrings #-}
module Parser where
import Prelude hiding(takeWhile)
import Data.Text
import…

Batou99
- 869
- 10
- 19
1
vote
1 answer
Haskell attoparsec does not recognize newline while parsing from a text file
I've been trying to parse a .txt file with some English text in it. My code tries to return back the number of paragraphs in that .txt file. For some reason, attoparsec can't seem recognize a newline or any other characters such as \n\r\t. Below is…

centrinok
- 300
- 2
- 11
1
vote
0 answers
Parsing sentences in Haskell more effectively using attoparsec
I'm trying to parse an ebook in .txt form, to learn more about attoparsec and Haskell (I'm a newbie). In this case, I'm trying to count the number of sentences in the given text file. Here's my code:
{-# LANGUAGE OverloadedStrings #-}
import…

centrinok
- 300
- 2
- 11
1
vote
2 answers
Recursively return all words from .txt file using attoparsec
I am fairly new to Haskell and I'm just starting to learn how to work with attoparsec for parsing huge chunks of english text from a .txt file. I know how to get the number of words in a .txt file without using attoparsec, but I'm kinda stuck with…

centrinok
- 300
- 2
- 11
1
vote
1 answer
How can I use sepBy with an ending character in attoparsec?
I'm trying to parse the following line:
ItemCount count@Int: You have purchased #{showInt count} #{plural count "item" "items"}
Essentially I'm trying to get:
Message {
key = "ItemCount",
value = "You have purchased #{showInt count}…

Chris Stryczynski
- 30,145
- 48
- 175
- 286
1
vote
1 answer
Passing State from a Producer to a Parser
I'm using pipes, attoparsec, and pipes-attoparsec to write a database dump file converter. The general format of the file is to have a create table command followed by an optional insert command. In addition to transforming the statements in…

cimmanon
- 67,211
- 17
- 165
- 171
1
vote
0 answers
Lazy parsing of large files with millions of data points
I have a parser I'm trying to write and I've gone over multiple versions of it and I can't seem to keep the memory usage down. I'm trying to parse the wikipedia sql dumps and in this example take the page entries file and throw them all in one giant…

Charles Durham
- 1,707
- 11
- 17
1
vote
1 answer
Parser: Enforcing unicity when order is not known
Using Attoparsec, I am trying to match strings containing exactly 1 'x', 1 'y', and 1 'z', and any number of 'a', 'b', or 'c', without any constraint on the order of each char.
For instance, "abbbzacyaaaxcba" and "abbbzacxaaaycba" should be a match…

Janthelme
- 989
- 10
- 23
1
vote
3 answers
How to make a custom Attoparsec parser combinator that returns a Vector instead of a list?
{-# LANGUAGE OverloadedStrings #-}
import Data.Attoparsec.Text
import Control.Applicative(many)
import Data.Word
parseManyNumbers :: Parser [Int] -- I'd like many to return a Vector instead
parseManyNumbers = many (decimal <* skipSpace)
main ::…

Marko Grdinić
- 3,798
- 3
- 18
- 21
1
vote
1 answer
Transform an attoparsec parser into a parser which fails if the number of bytes it consumes is not of a certain length
Say I have an attoparsec parser, x.
I am looking to create a function f :: Int -> Parser a -> Parser a, such that if y = f n x, then:
y fails if x fails
y fails if x succeeds and x does not consume n bytes
y succeeds otherwise
How would I go about…

Cameron Martin
- 5,952
- 2
- 40
- 53
1
vote
2 answers
How to parse an entropy-coded JPEG block efficiently?
I'm just trying to jump through a SOS_MT block in a .JPEG file, I don't want to use the data for anything, I just want to know where it ends. According to what I understand from JPEG's article in Wikipedia, while all other blocks in the JPEG file…

dsign
- 12,340
- 6
- 59
- 82
1
vote
1 answer
How to skip unwanted text with attoparsec
I'd like to parse E-Mails similar to this
Random Info: ........
From: email@domain.com
Other Info: .......
Subject: ima subject
Some More Info: .....
This is a message.
But I don't need all the information from this E-Mail. Only "From", "Subject"…

TomTom
- 2,820
- 4
- 28
- 46