|
|
|
| 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.
|
|
| Synopsis |
|
|
|
| Documentation |
|
|
| Python module -- essentially a list of statements;
should it also have a name?
| | Constructors | | Instances | |
|
|
|
| Python statement
| | Constructors | | Instances | |
|
|
|
| Python expression
| | Constructors | | Instances | |
|
|
|
| Python identifier (variable name, etc.)
| | Constructors | | Instances | |
|
|
|
| Python function formal parameter
| | Constructors | | Instances | |
|
|
|
| Python operator, such as * or +
| | Constructors | | Instances | |
|
|
|
| Operator priority, actually should be > 0 or >= 0
|
|
|
| Alter the parentheses of a statement by applying a
transformer t to the expressions in the statement.
|
|
|
|
|
|
|
| Python return statement
|
|
|
| Python if STATEMENT
|
|
|
| Python if EXPRESSION
|
|
|
| Python variable
|
|
|
| Python identifier
|
|
|
| Python integer expression
|
|
|
| Python float expression
|
|
|
| Python boolean expression
|
|
|
| Python character expression = string expression with one character
|
|
|
| Python string expression
|
|
|
| Python expression in parentheses.
|
|
|
| Remove all grouping parentheses in expression.
Does not affect parentheses required for function arguments
or parameters.
This will sometimes alter the semantics.
|
|
|
| Wrap each subexpression in grouping parentheses.
This will typically look like too many parentheses.
|
|
|
| Use parentheses for grouping where needed,
but cautiously, erring on the side of extra parentheses if not sure
they can be removed.
|
|
|
| Remove grouping parentheses that are provably not needed.
This may not remove *all* unnecessary grouping parentheses.
You can always add more cases to make it better!
|
|
|
Adding and removing top-level parentheses.
Axioms: par (unpar e) == e; unpar (par e) == e.
Add parentheses around an expression. Top level only.
|
|
|
| Remove parentheses around an expression. Top level only.
|
|
|
| Python function call expression
|
|
|
| Python function formal parameter
|
|
|
| Defines function definition
|
|
|
|
|
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.
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;
(a == b) == c is in general not well typed.
|
|
|
|
|
|
|
|
|
|
| Produced by Haddock version 2.6.1 |