Giter Site home page Giter Site logo

hpython's Introduction

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

  • Formatting-preserving syntax tree
  • Parser and printer, with a round-trip law: print ∘ parse ≡ id
  • Optics for manipulating the syntax tree
  • Indentation, syntax, and scope checking
  • The syntax tree is indexed by its level of validation, to distinguish between syntactically valid Python and unvalidated code
  • Convenient DSL for building Python programs

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

  • Support other versions of Python while re-using as much common code as possible
  • Style configs for the DSL
  • Human readable validation errors, with source spans

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ɐɥ>

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.