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 details)

Uploaded Source

File details

Details for the file oppen-pretty-printer-0.1.2.tar.gz.

File metadata

  • Download URL: oppen-pretty-printer-0.1.2.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1.post20200515 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for oppen-pretty-printer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0c58dca4cd226a077651cda4e2a42c430d5c4f666e3f13abfcc0a2a1a6a524f0
MD5 f70fcee15acf323f02213e629b1a1e0f
BLAKE2b-256 27ebc1dadb0d87c54f5aedf9010616bc48565b81dab125e5ba69b60e51221dfb

See more details on using hashes here.

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