erl_pp

erl_pp

erl_pp
The Erlang pretty printer.

The functions in this module are used to generate aesthetically attractive representations of abstract forms, which are suitable for printing. All functions return (possibly deep) lists of characters and generate an error if the form is wrong.

All functions can have an optional argument, which specifies a hook that is called if an attempt is made to print an unknown form.

Note that if the functions in this module are used to convert abstract code back to Erlang source code, the enclosing function should first be processed by legalize_vars/1 in order to ensure that the output is semantically equivalent to the abstract code.

Optional argument HookFunction, shown in the functions described in this module, defines a function that is called when an unknown form occurs where there is to be a valid expression. If HookFunction is equal to none, there is no hook function.

The called hook function is to return a (possibly deep) list of characters. Function expr/4 is useful in a hook.

If CurrentIndentation is negative, there are no line breaks and only a space is used as a separator.

The option quote_singleton_atom_types is used to add quotes to all singleton atom types.

The option linewidth controls the maximum line width for formatted lines (defaults to 72 characters).

The option indent controls the indention for formatted lines (defaults to 4 spaces).

Types

The Erlang compiler will, when expanding records to tuples, introduce new variables in the abstract representation. As the expansion is done on the abstract representation, the compiler can safely name the new variables with names that are not syntactically valid in Erlang source code (the name starts with a lowercase letter), thus ensuring the uniqueness of the new names.

The above strategy leads to problems if a user wants to convert the abstract representation, using the functions of this module back to Erlang source code. Typically, pattern variables are output as atoms thus changing the sematics of the program. To solve this problem legalize_vars/1, when run on the abstract representation of a function, will return an equivalent function where all variables will have syntactically valid names.

It is not possible to have hook functions for unknown forms at other places than expressions.