Questions tagged [attoparsec]

A fast Haskell library for parsing ByteStrings

https://github.com/bos/attoparsec

131 questions
2
votes
1 answer

Attoparsec: Easier way to parse data types from Data.Word and Data.Int?

I'm currently using bytestring and attoparsec for the serialization and deserialization respectfully in a game netcode. I was originally attracted to using these libraries over cereal because bytestring gives pretty fine-grain control over Builders,…
carpemb
  • 691
  • 1
  • 8
  • 19
2
votes
2 answers

Parse IP address with attoparsec

The parser given at https://www.fpcomplete.com/school/starting-with-haskell/libraries-and-frameworks/text-manipulation/attoparsec appears to work, but it has a problem. The code (repeated here) is: {-# LANGUAGE OverloadedStrings #-} -- This…
donatello
  • 5,727
  • 6
  • 32
  • 56
2
votes
1 answer

How attoparsec can return values of different types?

I'm stuck with attoparsec where I can't return a value regarding it's "embedded type". I attempt to parse a file of kind: type value type value ... For example: 0 -- code for a string value hello 70 -- code for an int value 10 0 world 20 -- code…
grwp
  • 97
  • 7
2
votes
1 answer

parsing n hex digits using attoparsec

Okay so I need to parse n digits of hex and I am having a problem where I cant stop the standard attoparsec hex parser hexadecimal. My first idea was this: nHex n = take n *> hexadecimal but that doesnt work because it takes off 4 digits then…
Kyle McKean
  • 445
  • 2
  • 11
2
votes
0 answers

Attoparsec atEnd behavior

I am trying to write a bytestring parser with Attoparsec and I've been running into some puzzling behavior with the atEnd function. Just playing around, I tried to parse the empty bytestring with atEnd to see if it would return True, but instead it…
Frank Wang
  • 181
  • 9
2
votes
2 answers

conduit sink with leftover

I have a sink and want to do some parsing with attoparsec in it. It happens that I get a Partial result. So I thought that I might just use leftover to put the insufficient content back upstream so it would come back with more appended later. But no…
Schoon
  • 394
  • 1
  • 9
2
votes
1 answer

Parsing simple molecule names with Attoparsec

I find it extremely difficult to learn how to use Attoparsec, because the documentation is really just an API documentation and there are basically no tutorials around (except the one from FPComplete). If you know other places where I can learn…
rubik
  • 8,814
  • 9
  • 58
  • 88
2
votes
1 answer

Attoparsec: Skip rest of current line

I'm writing a parser using attoparsec. The parser is parsing a line-based format, for example this file 1,2,3 4,5,6 Let's assume the parser is currently placed just before 2 in the first line. How can I skip the rest of the line including the \n…
Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
2
votes
2 answers

Implementing skipWhile1 in attoparsec

Attoparsec provides the function takeWhile1 that consumes at least one character. However, there is no analog for skipWhile. How can I implement this function skipWhile1? Note: This question intentionally shows no research effort as it was answered…
Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
2
votes
0 answers

Best way to find first parse success in a string using attoparsec Haskell library

I want to do that: findFirst :: Parser a -> String -> Maybe a findFirst parser text = search (maybeResult . parse parser . pack $ text) text where search _ [] = Nothing search Nothing _ = findFirst parser…
The_Ghost
  • 2,070
  • 15
  • 26
2
votes
1 answer

Haskell: How to use attoparsec in order to read a nested list from a ByteString

I have a text file (~ 300 MB large) with a nested list, similar to this one: [[4, 9, 11, 28, 30, 45, 55, 58, 61, 62, 63, 69, 74, 76, 77, 82, 87, 92, 93, 94, 95], [4, 9, 11, 28, 30, 45, 55, 58, 61, 62, 63, 69, 74, 76, 77, 82, 87, 92, 93, 94],[4, 9,…
mrsteve
  • 4,082
  • 1
  • 26
  • 63
2
votes
1 answer

Attoparsec `many` method not found

I tried running the tests for Bryan O'Sullivan's Attoparsec-based HTTP parser (http://www.serpentine.com/blog/2010/03/03/whats-in-a-parser-attoparsec-rewired-2/), and I got this error: > runhaskell TestRFC2616.hs TestRFC2616.hs:13:30: Not in…
limp_chimp
  • 13,475
  • 17
  • 66
  • 105
2
votes
3 answers

Haskell: Traverse through a String/Text File

I am trying to read a script file then process and output it to a html file. In my script file, whenever there is a @title(this is a title), I will add tag [header] this is a title [/header] in my html output. So my approach is to first read the…
Charlie Victor
  • 115
  • 2
  • 12
2
votes
1 answer

Parsing Haskell custom data types

I have worked my way through the Haskell Koans provided here: https://github.com/roman/HaskellKoans I am stuck on the last two Koans, both involving parsing custom algebraic data types. Here is the first: data Atom = AInt Int | ASym Text deriving…
Jonathan Evans
  • 974
  • 2
  • 8
  • 18
1
vote
1 answer

How to do proper case folding with Parsec

Is there a way to do proper case folding with Parsec (say I want a parser that behaves like stringCI from Data.Attoparsec.Text). The code that does case insensitive parsing in Text.Parsec.Token just uses char (toLower c) <|> char (toUpper c), but no…
user1078763
  • 728
  • 5
  • 15
1 2 3
8 9