Skip to main content

Library porting many of the combinators from Haskell's Megaparsec for use with Python's Parsy.

Project description

Build Status Latest PyPI version

Python 3.6 Python 3.7 Python 3.8

Work In Progress - ignore for now ;)

Initial motivation for this project was to build an indentation-sensitive parser. This is problematic for any parser library which is limited to expressing context-free grammars (which is most of them), unless you use a separate pre-processing step (like e.g. the parser for the Python language does).

Googling around this topic I came upon

So in Haskell-land we can find ‘Monadic Parser Combinators’, which do not have this restriciton to CFGs. And the Megaparsec library defines many useful combinators, including some which designed specifically to help with building indentation-sensitive parsers.

But… it was difficult for me to learn to make a parser for the first time and learn Haskell simultaneously. So I looked around for a Python option and found the brilliant Parsy library. It provides an implementation of ‘Monadic Parser Combinators’ in Python.

Nicely and simply explained here:

Functional or Combinator Parsing explained by Professor Graham Hutton.

Functional or Combinator Parsing explained by Professor Graham Hutton.

So in Megaparsy I have ported a bunch of the Megaparsec combinators over to Parsy. It is surprising how smoothly it went and how similar they come out - this is testament to the genius of Parsy, which is where all the clever part is.

(I haven’t done all of them yet, but the indentation-sensitive ones are here)

I’ve also roughly translated across the property-based tests from their Haskell QuickCheck originals into Python Hypothesis ones.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

megaparsy-0.1.4.tar.gz (7.4 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page