Skip to main content

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.

Metadata

Release files for oppen-pretty-printer 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oppen-pretty-printer 0.1.2
File Size Uploaded
oppen-pretty-printer-0.1.2.tar.gz 11.3 kB Details

Release files / oppen-pretty-printer-0.1.2.tar.gz

Download URL oppen-pretty-printer-0.1.2.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0c58dca4cd226a077651cda4e2a42c430d5c4f666e3f13abfcc0a2a1a6a524f0
BLAKE2b-256 checksum
How to use checksums
27ebc1dadb0d87c54f5aedf9010616bc48565b81dab125e5ba69b60e51221dfb
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file

0.1.1

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page