Skip to main content

Megaparsec tutorial

About 2 minHaskellcrashcoursehaskellparsecattoparsectrifecta

Megaparsec tutorial ๊ด€๋ จ


Megaparsec tutorial

Mark Karpov > Megaparsec tutorial

Info

This is the Megaparsec tutorial which originally was written as a chapter for the Intermediate Haskellopen in new window book. Due to lack of progress with the book in the last year, other authors agreed to let me publish the text as a standalone tutorial so that people can benefit at least from this part of our work.


Table of Contents

The toy parser combinators developed in chapter โ€œAn Example: Writing Your Own Parser Combinatorsโ€ are not suitable for real-world use, so letโ€™s continue by taking a look at the libraries in the Haskell ecosystem that solve the same problem, and note various trade-offs they make:

  • parsecopen in new window has been the โ€œdefaultโ€ parsing library in Haskell for a long time. The library is said to be focused on quality of error messages. It however does not have good test coverage and is currently in maintenance mode.

  • attoparsecopen in new window is a robust, fast parsing library with focus on performance. It is the only library from this list that has full support for incremental parsing. Its downsides are poor quality of error messages, inability to be used as a monad transformer, and limited set of types that can be used as input stream.

  • trifectaopen in new window features good error messages but is under-documented and hard to figure out. It can parse String and ByteString out-of-the-box, but not Text.

  • megaparsecopen in new window is a fork of parsec that has been actively developed in the last few years. The current version tries to find a nice balance between speed, flexibility, and quality of parse errors. As an unofficial successor of parsec, it stays conventional and immediately familiar for users who have used that library or who have read parsec tutorials.

It would be impractical to try to cover all these libraries, and so we will focus on megaparsec. More precisely, we are going to cover the version 9, which by the time this book is published will probably have replaced the older versions almost everywhere.


์ด์ฐฌํฌ (MarkiiimarK)
Never Stop Learning.