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
16
votes
1 answer

Trivial parsec example produces a type error

I'm trying to get this trivial parsec code to compile import Text.Parsec simple = letter but I keep getting this error No instance for (Stream s0 m0 Char) arising from a use of `letter' Possible fix: add an instance declaration for (Stream s0 m0…
Peter
  • 1,334
  • 1
  • 11
  • 18
16
votes
5 answers

Parse XML in Haskell

I'm trying to get data from a webpage that serves a XML file periodically with stock market quotes (sample data). The structure of the XML is very simple, and is something like this:
Rafael S. Calsaverini
  • 12,352
  • 16
  • 69
  • 126
16
votes
1 answer

Parsec or happy (with alex) or uu-parsinglib

I am going to write a parser of verilog (or vhdl) language and will do a lot of manipulations (sort of transformations) of the parsed data. I intend to parse really big files (full Verilog designs, as big as 10K lines) and I will ultimately support…
Dilawar
  • 4,808
  • 9
  • 37
  • 54
16
votes
5 answers

What's the cleanest way to do case-insensitive parsing with Text.Combinators.Parsec?

I'm writing my first program with Parsec. I want to parse MySQL schema dumps and would like to come up with a nice way to parse strings representing certain keywords in case-insensitive fashion. Here is some code showing the approach I'm using to…
dan
  • 39,098
  • 40
  • 137
  • 234
16
votes
1 answer

Parsec.Expr repeated Prefix/Postfix operator not supported

The documentation for Parsec.Expr.buildExpressionParser says: Prefix and postfix operators of the same precedence can only occur once (i.e. --2 is not allowed if - is prefix negate). and indeed, this is biting me, since the language I am trying…
pat
  • 12,213
  • 1
  • 21
  • 49
15
votes
2 answers

Memory failure when transposing [(K,[V])] to [(V,[K])]

I've got a 279MB file that contains ~10 million key/value pairs, with ~500,000 unique keys. It's grouped by key (each key only needs to be written once), so all the values for a given key are together. What I want to do is transpose the…
rampion
  • 82,104
  • 41
  • 185
  • 301
14
votes
2 answers

Is there an established way to write parsers that can reconstruct their exact input?

Say I want to parse a file in language X. Really, I'm only interested in a small part of the information within. It's easy enough to write a parser in one of Haskell's many eDSLs for that purpose (e.g. Megaparsec). data Foo = Foo Int -- the…
leftaroundabout
  • 101,764
  • 3
  • 156
  • 291
14
votes
2 answers

Parsing Indentation-based syntaxes in Haskell's Parsec

I'm trying to parse an indentation-based language (think Python, Haskell itself, Boo, YAML) in Haskell using Parsec. I've seen the IndentParser library, and it looks like it's the perfect match, but what I can't figure out is how to make my…
pavpanchekha
  • 1,983
  • 1
  • 16
  • 23
14
votes
3 answers

ghc-7.10: Non type-variable argument (Use FlexibleContexts to permit this)

I was trying to use ghc-7.10 (RC 2) and got this message in a number of cases, e.g., src/Text/Regex/XMLSchema/Generic/RegexParser.hs:439:5: Non type-variable argument in the constraint: Text.Parsec.Prim.Stream s m Char (Use…
d8d0d65b3f7cf42
  • 2,501
  • 11
  • 27
14
votes
1 answer

Parsec: Consume all input

One common problem I have with Parsec is that it tends to ignore invalid input if it occurs in the "right" place. As a concrete example, suppose we have integer :: Parser Int, and I write expression = sepBy integer (char '+') (Ignore whitespace…
MathematicalOrchid
  • 58,942
  • 16
  • 110
  • 206
13
votes
6 answers

Python implementation of Parsec?

I recently wrote a parser in Python using Ply (it's a python reimplementation of yacc). When I was almost done with the parser I discovered that the grammar I need to parse requires me to do some look up during parsing to inform the lexer. Without…
Jason Dagit
  • 13,034
  • 8
  • 31
  • 54
13
votes
4 answers

In Parsec, is there a way to prevent lexeme from consuming newlines?

All of the parsers in Text.Parsec.Token politely use lexeme to eat whitespace after a token. Unfortunately for me, whitespace includes new lines, which I want to use as expression terminators. Is there a way to convince lexeme to leave a new line?
John F. Miller
  • 25,556
  • 8
  • 66
  • 120
13
votes
2 answers

A good ocaml parser?

I'm looking for a good ocaml parsing library that isn't a derivative of flex/bison. Ideally, I'd like a monadic combinator library along the lines of parsec, but I can't find anything. I would use haskell, but making llvm bindings for haskell is…
duane
  • 2,054
  • 1
  • 15
  • 17
12
votes
2 answers

Sample grammars in FParsec going beyond the samples?

I am looking for some sample grammars written in FParsec that would go beyond the samples in the project repository. I have found this very nice grammar of GLSL, but this is the only sample I found. What I need is a grammar for a language similar to…
Alexander Galkin
  • 10,800
  • 9
  • 56
  • 111
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
  • 464
  • 4
  • 12
1
2
3
37 38