Questions tagged [attoparsec]

A fast Haskell library for parsing ByteStrings

https://github.com/bos/attoparsec

131 questions
1
vote
1 answer

Attoparsec /= version of stringCI

I'm parsing robots.txt files and I've written the parser to successfully parse a "well-formed" robots.txt file. I've been able to adjust the parser to skip lines that start with a symbol (like # or / for comments) but only using inClass "#/". One…
Ixmatus
  • 1,051
  • 9
  • 15
1
vote
1 answer

Parse fixed length text with attoparsec

I need to parse fixed length fields with attoparsec but im now struggling with the compiler. Im still a newbie, the code below is the closest solution I have: > {-# LANGUAGE OverloadedStrings #-} > import Control.Applicative > import Data.Text as…
georgina
  • 13
  • 2
0
votes
1 answer

Conditional parsing and casting in Attoparsec

I'm parsing a length-encoded binary stream and I'm trying to get this code compiling. The combinatorrent code ( https://github.com/jlouis/combinatorrent/blob/master/src/Protocol/Wire.hs ) was very helpful to get me moving along but now I'm stuck.…
xrl
  • 2,155
  • 5
  • 26
  • 40
0
votes
1 answer

How can I access the whole input from an arbitrary parser in a sequence?

I'm working through a DNS message parser. I have defined the following using megaparsec: Header data DNSHeader = DNSHeader { hid :: !Word16, hflags :: !Word16, hnumQuestions :: !Word16, hnumAnswers :: !Word16, hnumAuthorities ::…
DavSanchez
  • 831
  • 8
  • 13
0
votes
1 answer

Efficient attoparsec parser combinating general parsers and anyChar

This is similar to my previous question Attoparsec efficient parser for multiple char, but I oversimplified the example parser I provided. I really apologize if it is considered spamming. If I define charToText :: Char -> Text charToText c = pack…
vkubicki
  • 1,104
  • 1
  • 11
  • 26
0
votes
1 answer

Attoparsec efficient parser for multiple char

If I define charToText :: Char -> Text charToText c = pack [c] anyCharParser :: Parser Text anyCharParser = mconcat <$> manyTill (charToText <$> anyChar) endOfInput it seems to me that lifting charToText is inefficient, because for each character…
vkubicki
  • 1,104
  • 1
  • 11
  • 26
0
votes
1 answer

Why `optional` in a Parser can err out

https://github.com/complyue/dcp is a minimum working example to reprod this error $ cabal run dcp:dcp < samples/basic.txt Up to date dcp: 10:1: | 10 | method doXXX() pass | ^ unexpected 'm' expecting ';' CallStack (from HasCallStack): …
Compl Yue
  • 164
  • 1
  • 3
  • 16
0
votes
1 answer

Slices with attoparsec

I'm looking at this example from attoparsec docs: simpleComment = string "") This will build a [Char] instead of a ByteString slice. That's not good with huge comments, right? The other alternative,…
levant pied
  • 3,886
  • 5
  • 37
  • 56
0
votes
2 answers

How can I make a Haskell parser from a list of words?

I'm a Haskell beginner, using Attoparsec to find some color expressions in a text. I want to be able to match, for example, "light blue-green" and "light blue green" in a text. But of course I need a generalized solution for any string like that. So…
Jonathan
  • 10,571
  • 13
  • 67
  • 103
0
votes
1 answer

How to adapt the many' to return Left in attoparsec of Haskel

For example parseTest :: Parser Int parseTest = char '(' *> return 1 <* char ')' parseTests :: Parser [Int] parseTests = many' $ char '(' *> return 1 <* char ')' parseOnly ParseIni.parseTest "(" -- returns Left with error parseOnly…
handora
  • 559
  • 5
  • 14
0
votes
1 answer

Haskell Attoparsec infinite loop

The code is based on Haskell Attoparsec, and when I use parseOnly pString "v", it gives me the right answer as Right (DontNeedTrim, "v"). While when I use the instruction parseOnly (many' pString) "v", it seems drops into the infinite loop and…
handora
  • 559
  • 5
  • 14
0
votes
1 answer

Error parsing a char (――) in Haskell

I'm writing a parser to parse huge chunks of English text using attoparsec. Everything has been great so far, except for parsing this char "――". I know it is just 2 dashes together "--". The weird thing is, the parser catches it in this…
centrinok
  • 300
  • 2
  • 11
0
votes
1 answer

Issue with overloading strings in Haskell using attoparsec

First of all I would like to let you know that I'm fairly new to Haskell and I'm trying to understand how parsers work in haskell . So I'm basically trying to parse this e-book from http://www.gutenberg.org/files/57071/57071-0.txt and analyze the…
centrinok
  • 300
  • 2
  • 11
0
votes
1 answer

Can I easily wrap attoparsec in transformer?

I want to write code doing something like C preprocessing. So I looked for libraries and got two candidates, attoparsec, megaparsec. I need the feature reporting error position and megaparsec already has that. But attoparsec would be desirable for…
0
votes
1 answer

Parsing the first occurrence of a word that is not precded by white space

Setting I need to find the first occurrence of a word in some .txt file that is not preceded by white space. Here are the possible cases: -- * should succed t1 = "hello\t999\nworld\t\900" t2 = "world\t\900\nhello\t999\n" t3 = "world…
xiaolingxiao
  • 4,793
  • 5
  • 41
  • 88
1 2 3
8
9