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.

609 questions
12
votes
1 answer

How to define multiple type of comment block in Parsec

I am trying to learn how to use Parsec to write a Delphi parser, but I am getting stuck at defining the LanguageDef. In Delphi, there are two types of comment blocks, (* comments *) and { comments }. But the types of commentStart & commentEnd of…
ePak
  • 484
  • 5
  • 12
12
votes
2 answers

Is there an haskell EDSL for writing lexers?

Mixing the lexer and parsing phases in one phase sometimes makes Parsec parsers less readable but also slows them down. One solution is to use Alex as a tokenizer and then Parsec as a parser of the token stream. This is fine but it would be even…
Paul Brauner
  • 1,307
  • 1
  • 10
  • 17
12
votes
3 answers

How to use Control.Monad.State with Parsec?

I'm surprised that I could not find any info on this. I must be the only person having any trouble with it. So, let's say I have a dash counter. I want it to count the number of dashes in the string, and return the string. Pretend I gave an…
David McHealy
  • 2,471
  • 18
  • 34
12
votes
2 answers

Can Haskell's Parsec library be used to implement a recursive descent parser with backup?

I've been considering using Haskell's Parsec parsing library to parse a subset of Java as a recursive descent parser as an alternative to more traditional parser-generator solutions like Happy. Parsec seems very easy to use, and parse speed is…
Derek Thurn
  • 14,953
  • 9
  • 42
  • 64
11
votes
1 answer

Haskell Text.Parsec.Combinator choice doesn't backtrack

I'm trying to parse some Text with parsec: data Cmd = LoginCmd String | JoinCmd String | LeaveCmd String deriving (Show) singleparam :: Parser Cmd singleparam = do cmd <- choice [string "leave", string "login", string…
sinan
  • 6,809
  • 6
  • 38
  • 67
11
votes
4 answers

Haskell: FRP Reactive Parsec?

Is there (or is it possible to have) a reactive Parsec (or any other pure functional parser) in Haskell? Simply put, I want to feed parser myself char by char and get results as much as I feed enough to get output. Or much simpler, how can I do it…
KA1
  • 643
  • 6
  • 15
11
votes
1 answer

Recursive grammars in FParsec

I've decided to check out FParsec, and tried to write a parser for λ expressions. As it turns out, eagerness makes recursive parsing difficult. How can I solve this? Code: open FParsec type λExpr = | Variable of char | Application of λExpr…
Ramon Snir
  • 7,520
  • 3
  • 43
  • 61
11
votes
1 answer

Parsing function in haskell

I'm new to Haskell and I am trying to parse expressions. I found out about Parsec and I also found some articles but I don't seem to understand what I have to do. My problem is that I want to give an expression like "x^2+2*x+3" and the result to be…
izayoi
  • 405
  • 1
  • 4
  • 9
11
votes
1 answer

Haskell/Parsec: How do you use the functions in Text.Parsec.Indent?

I'm having trouble working out how to use any of the functions in the Text.Parsec.Indent module provided by the indents package for Haskell, which is a sort of add-on for Parsec. What do all these functions do? How are they to be used? I can…
Beetle
  • 1,959
  • 16
  • 32
10
votes
1 answer

How do you use parsec in a greedy fashion?

In my work I come across a lot of gnarly sql, and I had the bright idea of writing a program to parse the sql and print it out neatly. I made most of it pretty quickly, but I ran into a problem that I don't know how to solve. So let's pretend the…
David McHealy
  • 2,471
  • 18
  • 34
10
votes
2 answers

The type signature of Parsec function 'parse' and the class 'Stream'

What does the constraint (Stream s Identity t) mean in the following type declaration? parse :: (Stream s Identity t) => Parsec s () a -> SourceName -> s -> Either ParseError a What is Stream in the following class declaration, what does it mean.…
wuxb
  • 2,572
  • 1
  • 21
  • 30
10
votes
1 answer

Parsing and pretty printing the same file format in Haskell

I was wondering, if there is a standard, canonical way in Haskell to write not only a parser for a specific file format, but also a writer. In my case, I need to parse a data file for analysis. However, I also simulate data to be analyzed and save…
Dominik Schrempf
  • 827
  • 8
  • 14
10
votes
1 answer

Parsec: Getting start and end source positions of expressions?

I'm writing a programming language which uses Parsec for its parsing. For reporting error messages, I've got each element of my syntax tree labelled with its source location, using the getPosition function from the Pos module of Parsec. However, it…
jmite
  • 8,171
  • 6
  • 40
  • 81
10
votes
3 answers

How to parse an Integer with parsec

I was expecting to find a function integer :: Stream s m Char => ParsecT s u m Integer or maybe even natural :: Stream s m Char => ParsecT s u m Integer in the standard libraries, but I did not find one. What is the standard way of parsing plain…
Joachim Breitner
  • 25,395
  • 6
  • 78
  • 139
10
votes
2 answers

Haskell Parser Combinators

I was reading a lot about Haskell Parser Combinators and found a lot of topics like: Parsec vs Yacc/Bison/Antlr: Why and when to use Parsec? Which Haskell parsing technology is most pleasant to use, and why? Parsec or happy (with alex) or…
Wojciech Danilo
  • 11,573
  • 17
  • 66
  • 132
1 2
3
40 41