Questions tagged [parser-combinators]

In functional programming, a parser combinator is a higher-order function which accepts several parsers as input and returns a new parser as its output.

Papers

Monadic Parser Combinators by Graham Hutton and Erik Meijer
Functional Parsers by Jeroen Fokker
Parsec: Direct Style Monadic Parser Combinators For The Real World (DRAFT) by Daan Leijen and Erik Meijer
Parsing Permutation Phrases by Arthur Baars, Andres L¨oh, Doaitse Swierstra
Parsec, a fast combinator parser by Daan Leijen
Memoizing purely functional top-down backtracking language processors by Frost and Szydlowski
Deterministic, Error-Correcting Combinator Parsers by S. Doaitse Swierstra and Luc Duponcheel

Popular Parser Combinators

Haskell - Parsec
Scala - Scala built-in library
F# - FParsec

422 questions
43
votes
1 answer

Scala PackratParser ignores failure parser

I have a parser that was written using Scala's RegexParsers - link It had some serious performance problems when parsing a grammar which had deeply nested expressions. As such I have created a version where I mix in Scala's PackratParsers - link The…
adamretter
  • 3,885
  • 2
  • 23
  • 43
38
votes
3 answers

Use Scala parser combinator to parse CSV files

I'm trying to write a CSV parser using Scala parser combinators. The grammar is based on RFC4180. I came up with the following code. It almost works, but I cannot get it to correctly separate different records. What did I miss? object CSV extends…
Rio
  • 1,877
  • 3
  • 25
  • 25
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
  • 48,105
  • 13
  • 171
  • 274
28
votes
6 answers

Scala parser combinators vs ANTLR/Java generated parser?

I am writing an expression parser for an app written mostly in Scala. I have built AST objects in Scala, and now need to write the parser. I have heard of Scala's built-in parser combinators, and also of ANTLR3, and am wondering: which would provide…
Nathan Moos
  • 3,563
  • 2
  • 22
  • 27
25
votes
4 answers

Scala Parsers: Availability, Differences and Combining?

My question is about the Scala Parsers: Which ones are available (in the Standard library and outside), what's the difference between them, do they share a common API and can different Parsers be combined to parse one input string? I found at…
soc
  • 27,983
  • 20
  • 111
  • 215
23
votes
3 answers

Understanding the tilde in Scala's parser combinators

I'm fairly new to Scala and while reading about parser combinators(The Magic Behind Parser Combinators, Domain-Specific Languages in Scala) I came across method definitions like this: def classPrefix = "class" ~ ID ~ "(" ~ formals ~ ")" I've been…
Jano
  • 233
  • 1
  • 2
  • 4
23
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
  • 907
  • 1
  • 7
  • 12
22
votes
4 answers

Parser Combinators, separating grammar and AST construction

I'm writing a simple functional programming language in Scala using the parser-combinators library. The syntax is specified here: https://github.com/hejfelix/Frase/blob/master/src/main/scala/it/vigtig/lambda/ParserLike.scala There is one thing which…
Felix
  • 8,385
  • 10
  • 40
  • 59
17
votes
1 answer

GLL Parser Combinator or Generator in/for C or C++

Is there any existing implementation of the GLL algorithm, either in the form of parser combinators (preferred) or as a parser generator for C or C++? My requirements are that the output is a shared packed parse forest (SPPF) which I can later…
Joe
  • 6,497
  • 4
  • 29
  • 55
16
votes
1 answer

Scala: How to combine parser combinators from different objects

Given a family of objects that implement parser combinators, how do I combine the parsers? Since Parsers.Parser is an inner class, and in Scala inner classes are bound to the outer object, the story becomes slightly complicated. Here's an example…
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
16
votes
2 answers

How can I create a parser combinator in which line endings are significant?

I am creating a DSL, and using Scala's parser combinator library to parse the DSL. The DSL follows a simple, Ruby-like syntax. A source file can contain a series of blocks that look like this: create_model do at 0,0,0 end Line endings are…
mipadi
  • 398,885
  • 90
  • 523
  • 479
16
votes
1 answer

Is there any suitable way to generate a [jpg, png etc.] syntax diagram(and/or AST) directly from Scala Parser Combinators?

The only ways I am aware of, aren't "direct": converting to ANTLR format and using its own visualizer VISUALLANGLAB, which it seems to require an entire mouse-clicks "rewrite" implementing a converter by myself (which would be funny, but…
user445107
14
votes
1 answer

Extractor for a shapeless HList that mimics parser concatenation `~`

Question Is it somehow possible to create an extractor for shapeless' HList that looks like the following. val a ~ _ ~ b = 4 :: "so" :: 4.5 :: HNil => a == 4 && b == 4.5 Replace :: by ~, which shouldn't be the problem. Get rid of the terminating…
ziggystar
  • 28,410
  • 9
  • 72
  • 124
13
votes
2 answers

Are there any known parser combinator library's in F# that can parse binary (not text) files?

I am familiar with some of the basics of fparsec but it seems to be geared towards text files or streams. Are there any other F# library's that can efficiently parse binary files? Or can fparsec be easily modified to work efficiently with binary…
7sharp9
  • 2,147
  • 16
  • 27
13
votes
4 answers

Simply using parsec in python

I'm looking at this library, which has little documentation: https://pythonhosted.org/parsec/#examples I understand there are alternatives, but I'd like to use this library. I have the following string I'd like to parse: mystr = """ key1:…
Mittenchops
  • 18,633
  • 33
  • 128
  • 246
1
2 3
28 29