qfpl / hpython

Haskell language tools for Python
Other
157 stars 16 forks source link

hpython

Haskell-based language tools for Python

CSIRO's Data61 Logo

hpython provides an abstract syntax tree for Python 3.5, along with a parser, printer, and syntax checker. It also contains optics for working with the AST, and a DSL for writing Python programs directly in Haskell.

Features

Examples

See the example directory

FAQ

Why not just use language-python?

There are two main reasons:

  1. We think the print-parse identity is important. language-python discards lexical information like indentation levels and spacing, which means there is big cost to using it to modify human-written code. hpython retains formatting information in a way that has minimal impact when using the library. This means that program transformations change as little formatting as possible.

  2. We want to use types to precisely model the domain. language-python unifies Python 2 and 3 into a single data structure. We disagree with this choice, because Python 2 and 3 have different, non-compatible features. In Haskell terms, they are different datatypes with a large amount of overlap. Our goal is to make this difference visible in the type system without increasing code repetition.

    There are other minor places where language-python has made similar concessions, like in the treatment of 'starred expressions' (which are not really expressions at all).

Development Pipeline

Contribution

Feel free to file an issue or pull request on Github, or contact us at:

IRC - #qfpl on Freenode Email - oᴉ˙ldɟb@llǝʞsɐɥ