sifflet-lib-1.1: Library of modules shared by sifflet and its
tests and its exporters.

Sifflet.Foreign.Python

Description

Abstract syntax tree and pretty-printing for Python.
Works for Python 2 and 3.
A lot of the data structures are inspired by the language-python package;
I have chosen not to have language-python as a dependency of sifflet-lib,
however, because it would be overkill and still allows to little control
over pretty-printing of Python expressionsw.

Documentation

Expr as an instance of PyPretty.
This instance is only for Exprs as Python exprs,
for export to Python! It will conflict with the
one in ToHaskell.hs (or Haskell.hs).

The EOp case needs work to deal with precedences
and avoid unnecessary parens.
Note that this instance declaration is for *Python* Exprs.
Haskell Exprs of course should not be pretty-printed
the same way!

Binary operators
Precedence levels are rather *informally* described in
The Python Language Reference,
http:docs.python.orgreference.
I am adopting the infixr levels from Haskell,
which seem to be consistent with Python,
at least for the operators that Sifflet uses.

| Operator information
Arithmetic operators:
+ and - have lower precedence than *, , /, %
| Comparison operators have precedence lower than any arithmetic
operator. Here, I've specified associative = False,
because association doesn't even make sense (well, it does in Python
but not in other languages);
(a == b) == c is in general not well typed.