Questions tagged [parsec]

Parsec is an industrial-strength, monadic parser combinator library for Haskell.

Parsec is an industrial strength, monadic parser combinator library for Haskell. Parsec lets you construct parsers by combining higher-order Combinators to create larger expressions. Combinator parsers are written and used within the same programming language as the rest of the program. The parsers are first-class citizens of the language , unlike Happy parsers, which must be generated via a preprocessor.

More information about Parsec, including usage examples, can be found on the Parsec website.

569 questions
77
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
  • 43,989
  • 14
  • 80
  • 146
66
votes
5 answers

What are the benefits of applicative parsing over monadic parsing?

There seems to be a consensus that you should use Parsec as an applicative rather than a monad. What are the benefits of applicative parsing over monadic parsing? style performance abstraction Is monadic parsing out?
gawi
  • 13,050
  • 7
  • 38
  • 74
45
votes
1 answer

Should I use a lexer when using a parser combinator library like Parsec?

When writing a parser in a parser combinator library like Haskell's Parsec, you usually have 2 choices: Write a lexer to split your String input into tokens, then perform parsing on [Token] Directly write parser combinators on String The first…
nh2
  • 22,055
  • 11
  • 64
  • 113
43
votes
2 answers

What's the difference between Text.ParserCombinators.Parsec and Text.Parsec

Text Text.Parsec Text.Parsec.ByteString Text.Parsec.ByteString.Lazy Text.Parsec.Char Text.Parsec.Combinator Text.Parsec.Error Text.Parsec.Expr Text.Parsec.Language …
wuxb
  • 2,512
  • 1
  • 18
  • 30
41
votes
3 answers

Parsec vs Yacc/Bison/Antlr: Why and when to use Parsec?

I'm new to Haskell and Parsec. After reading Chapter 16 Using Parsec of Real World Haskell, a question appeared in my mind: Why and when is Parsec better than other parser generators like Yacc/Bison/Antlr? My understanding is that Parsec creates a…
Ning Wang
  • 411
  • 1
  • 4
  • 3
35
votes
4 answers

Can parser combinators be made efficient?

Around 6 years ago, I benchmarked my own parser combinators in OCaml and found that they were ~5× slower than the parser generators on offer at the time. I recently revisited this subject and benchmarked Haskell's Parsec vs a simple hand-rolled…
J D
  • 46,493
  • 12
  • 162
  • 266
35
votes
3 answers

Using Parsec with Data.Text

Using Parsec 3.1, it is possible to parse several types of inputs: [Char] with Text.Parsec.String Data.ByteString with Text.Parsec.ByteString Data.ByteString.Lazy with Text.Parsec.ByteString.Lazy I don't see anything for the Data.Text module. I…
gawi
  • 13,050
  • 7
  • 38
  • 74
27
votes
5 answers

What is the advantage of using a parser generator like happy as opposed to using parser combinators?

To learn how to write and parse a context-free grammar I want to choose a tool. For Haskell, there are two big options: Happy, which generates a parser from a grammar description and *Parsec, which allows you to directly code a parser in…
fuz
  • 76,641
  • 24
  • 165
  • 316
25
votes
3 answers

Full parser examples with parsec?

I'm trying to make a parser for a simple functional language, a bit like Caml, but I seem to be stuck with the simplest things. So I'd like to know if there are some more complete examples of parsec parsers, something that goes beyond "this is how…
Lanbo
  • 13,437
  • 14
  • 67
  • 141
22
votes
3 answers

Parsec: Applicatives vs Monads

I'm just starting with Parsec (having little experience in Haskell), and I'm a little confused about using monads or applicatives. The overall feel I had after reading "Real World Haskell", "Write You a Haskell" and a question here is that…
José Miguel
  • 270
  • 3
  • 7
22
votes
2 answers

How do Scala parser combinators compare to Haskell's Parsec?

I have read that Haskell parser combinators (in Parsec) can parse context sensitive grammars. Is this also true for Scala parser combinators? If so, is this what the "into" (aka ">>") function is for? What are some strengths/weaknesses of Scala's…
artif
  • 897
  • 1
  • 7
  • 12
22
votes
1 answer

Parsec: difference between "try" and "lookAhead"?

What is the difference between "try" and "lookAhead" functions in parsec?
r.sendecky
  • 8,183
  • 7
  • 30
  • 57
18
votes
1 answer

Why does Parsec not use Control.Applicative operators

Using Control.Applicative is very useful with Parsec, but you need to always hide <|> and similar objects as they conflict with Parsec's own: import Control.Applicative hiding ((<|>), many, optional) import Text.Parsec.Combinator import…
luispedro
  • 6,669
  • 3
  • 33
  • 45
17
votes
2 answers

User state in Parsec

I'm parsing an expression using Parsec and I want to keep track of variables in these expressions using the user state in Parsec. Unfortunately I don't really get how to do it. Given the following code: import Data.Set as Set inp = "$x = $y +…
bzn
  • 2,322
  • 1
  • 16
  • 20
17
votes
1 answer

Haskell/Parsec: how do I use Text.Parsec.Token with Text.Parsec.Indent (from the indents package)

The indents package for Haskell's Parsec provides a way to parse indentation-style languages (like Haskell and Python). It redefines the Parser type, so how do you use the token parser functions exported by Parsec's Text.Parsec.Token module, which…
Beetle
  • 1,839
  • 15
  • 30
1
2 3
37 38