Skip to main content

pretty-printing algorithm developed by DEREK C. OPPEN

Project description

oppen-pretty-printer

This package is a faithful translation, to python, of the pretty-printing algorithm developed by DEREK C. OPPEN at Stanford University in the late 1970s. The appendix of PRETTY PRINTING, Derek C. Oppen, 1979 contains the original prettyprint program written in MESA

A much quoted, more recent algorithm, A prettier printer, Philip Wadler 2003 refers to Oppen, saying, "The pretty printer presented here uses an algorithm equivalent to Oppen’s, but presented in a functional rather than an imperative style". Many of todays pretty printer implementations are based on the Wadler algorithm. So, in a way, the road leads back to Derek C. Oppen, 1979.

Two python versions are included. pretty_oppen.py is, as far as possible, a line-by-line translation of the Oppen algorithm from MESA to Python. pretty.py is functionally identical to pretty_oppen.py but written using a more Pythonic idiom.

Pytest tests and example output are included for both versions.

Usage

pip install oppen-pretty-printer

Example:

from oppen_pretty_printer import pprint, Token as T

tokens = [
    T.BEGIN(),
    T.STRING("begin"),
    T.STRING("x"),
    T.BREAK(), T.STRING(":="), T.BREAK(),
    T.STRING("40"),
    T.BREAK(), T.STRING("+"), T.BREAK(),
    T.STRING("2"),
    T.STRING("end"),
    T.END(),
    T.EOF()]

pprint(tokens)

Documentation

Head over to the README for more details.

Contributing

The source code for oppen-pretty-printer is available on GitHub. If you find a bug or something is unclear, we encourage you to raise an issue. We also welcome contributions, to contribute, fork the repository and open a pull request.

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

oppen-pretty-printer-0.1.2.tar.gz (11.3 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