Questions tagged [attoparsec]

A fast Haskell library for parsing ByteStrings

https://github.com/bos/attoparsec

131 questions
3
votes
1 answer

finally tagless parsing and recursive monadic actions

i deserialize a data structure from disc in the finally tagless style. i.e. class SYM repl where a :: repl include :: FilePath -> repl myParser :: SYM r => Parser r the language i am parsing has include directives. i am using attoparsec…
ibotty
  • 707
  • 4
  • 10
3
votes
1 answer

Does Data.Attoparsec.ByteString use "zero copy"ing?

Take for example takeWhile. Internally it uses span. Does that mean it just references the input bytestring? Probably not, if so, is there a way to achieve this? The motivating usecase is a large (>2gb) file that I want to map into memory and…
fho
  • 6,787
  • 26
  • 71
3
votes
1 answer

How can you make the latest Attoparsec match strings in a case-insensitive way?

attoparsec 0.72 had this function but it seems to have disappeared in later versions: stringTransform :: (ByteString -> ByteString) -> ByteString -> Parser ByteString "Match a literal string, after applying a transformation to both it and the…
dan
  • 43,914
  • 47
  • 153
  • 254
3
votes
1 answer

Attoparsec: Skipping bracketed terms?

I'm trying to make large TSV files with JSON in the 5th column suitable for import to mongoDB. In particular I want to change top level and only top level key fields to _id. This is what I have so far, it seems to work but is slow: {-# LANGUAGE…
FAWS
  • 33
  • 3
3
votes
1 answer

Parsing Karva notation in haskell

Karva notation is used in Gene Expression Programming to represent mathematical expressions. See here http://www.gene-expression-programming.com/Tutorial002.asp You create an expression tree by reading the off the gene and filling in nodes from…
3
votes
1 answer

How to properly add IO to attoparsec Parser?

I want to do some tracing/debugging in my attoparsec parser. Here's minimal [not] working example: import Data.Text as T import Data.Attoparsec.Text import Data.Attoparsec.Combinator import Control.Applicative ((<*), (*>)) parseSentences :: Parser…
wiz
  • 499
  • 4
  • 17
2
votes
2 answers

Equivalent of attoparsecs `inClass` in Parsec

I am translating some code from attoparsec to Parsec, because the parser needs to produce better error messages. The attoparsec code uses inClass (and notInClass) extensively. Is there a similar function for Parsec that lets me translate…
dflemstr
  • 25,947
  • 5
  • 70
  • 105
2
votes
1 answer

Incomplete input using endOfInput parser

Consider the string "(=x250) toto e", and the function: charToText :: Char -> Text charToText c = pack [c] The string is successfully parsed by: mconcat <$> manyTill (charToText <$> anyChar) (char 'e') with the expected result "(=x250) toto…
vkubicki
  • 1,104
  • 1
  • 11
  • 26
2
votes
1 answer

Parsing custom fields with Cassava and Attoparsec

I have a CSV with fields in it which contain unit values which I have to parse out. As a simple example: data EValue = Farads Double | MicroFarads Double | PicoFarads Double Thus I need to parse something like the following: parseEValue = farads…
GTF
  • 8,031
  • 5
  • 36
  • 59
2
votes
2 answers

Convert Attoparsec parser to parse from another string type

Is there some "easy" way (e.g. something I am missing in Attoparsec or some other library) to convert a defined Attoparsec parser that parses from ByteString to the one that parses from Text? For example I have: import…
esp
  • 7,314
  • 6
  • 49
  • 79
2
votes
2 answers

Performance analysis of a fold using map and ByteString keys

I have a little script to read in, parse and derive some kind of interesting (not really) statistics from an apache log file. So far I've made two simple options, the total number of bytes sent in all requests in the log file, and a top 10 of the…
Johanna Larsson
  • 10,531
  • 6
  • 39
  • 50
2
votes
1 answer

Matching values that carry onto multiple following lines with attoparsec

I'm trying to parse the following: message: 123 test abc xys messageA: hmm messageA: testing messageB: aueo qkhwueoaz Into something like: [ ("message", "123 test\nabcxyz"), , ("messageA", "hmm") , ("messageA","testing") ,…
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
2
votes
1 answer

Conduit parser is interrupted prematurely

I'm working on a program where I need to parse data from a USB connection and write it to a circular buffer. The issue I keep running into is that the parser is not consuming the input. Do I need to use another operator to connect the parser conduit…
SwiftsNamesake
  • 1,540
  • 2
  • 11
  • 25
2
votes
0 answers

CSV Parsing Issue with Attoparsec

Here is my code that does CSV parsing, using the text and attoparsec libraries: import qualified Data.Attoparsec.Text as A import qualified Data.Text as T -- | Parse a field of a record. field :: A.Parser T.Text -- ^ parser field = fmap T.concat…
Daniel Lovasko
  • 471
  • 2
  • 10
2
votes
0 answers

Is there a way to force an attoparsec not to backtrack?

I've written some parsers using Attoparsec but only now realised that I don't always want them to backtrack on failure, but attoparsec parsers always backtrack on failure. Is there a way to force a parser not to backtrack? For example, this…
1 2 3
8 9