Code Monkey home page Code Monkey logo

megaparsy's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.