Skip to content

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

License

Notifications You must be signed in to change notification settings

anentropic/megaparsy

Repository files navigation

megaparsy

Build Status Latest PyPI version

Python 3.6 Python 3.7 Python 3.8

(Work In Progress - what is here is tested and works but nothing is documented yet, sorry.)

This is a port of some of the parser-combinators from Haskell's Megaparsec library into Python. For use with the Parsy parser library for Python.

My motivation for this project was to build an indentation-sensitive parser. This is problematic for any parser library which is limited to expressing only 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 https://markkarpov.com/tutorial/megaparsec.html#indentationsensitive-parsing

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

Parser-combinators are nicely and simply explained in this YouTube video:

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. (I haven't done all of them yet, but the indentation-sensitive ones are here).

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published