erl_pp (stdlib v3.15.2)

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.

Known Limitations

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

See Also

erl_eval(3), erl_parse(3), io(3)

Link to this section Summary

Types

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 option quote_singleton_atom_types is used to add quotes to all singleton atom types.

Functions

Same as form/1,2, but only for attribute Attribute.

Prints one expression. It is useful for implementing hooks (see section Known Limitations).

Same as form/1,2, but only for the sequence of expressions in Expressions.

Pretty prints a Form, which is an abstract form of a type that is returned by erl_parse:parse_form/1.

Same as form/1,2, but only for function Function.

Same as form/1,2, but only for the guard test Guard.

Link to this section Types

Link to this type

-type hook_function() :: term().

Specs

hook_function() ::
    none |
    fun((Expr :: erl_parse:abstract_expr(),
         CurrentIndentation :: integer(),
         CurrentPrecedence :: non_neg_integer(),
         Options :: options()) ->
            io_lib:chars()).

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.

Link to this type

-type option() :: term().

Specs

option() ::
    {hook, hook_function()} |
    {encoding, latin1 | unicode | utf8} |
    {quote_singleton_atom_types, boolean()} |
    {linewidth, pos_integer()} |
    {indent, pos_integer()}.

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

Link to this type

-type options() :: term().

Specs

options() :: hook_function() | [option()].

Link to this section Functions

Specs

attribute(Attribute) -> io_lib:chars() when Attribute :: erl_parse:abstract_form().

Same as form/1,2, but only for attribute Attribute.

Specs

attribute(Attribute, Options) -> io_lib:chars()
             when Attribute :: erl_parse:abstract_form(), Options :: options().

Specs

expr(Expression) -> io_lib:chars() when Expression :: erl_parse:abstract_expr().

Prints one expression. It is useful for implementing hooks (see section Known Limitations).

Specs

expr(Expression, Options) -> io_lib:chars()
        when Expression :: erl_parse:abstract_expr(), Options :: options().

Specs

expr(Expression, Indent, Options) -> io_lib:chars()
        when Expression :: erl_parse:abstract_expr(), Indent :: integer(), Options :: options().

Specs

expr(Expression, Indent, Precedence, Options) -> io_lib:chars()
        when
            Expression :: erl_parse:abstract_expr(),
            Indent :: integer(),
            Precedence :: non_neg_integer(),
            Options :: options().

Specs

exprs(Expressions) -> io_lib:chars() when Expressions :: [erl_parse:abstract_expr()].

Same as form/1,2, but only for the sequence of expressions in Expressions.

Specs

exprs(Expressions, Options) -> io_lib:chars()
         when Expressions :: [erl_parse:abstract_expr()], Options :: options().

Specs

exprs(Expressions, Indent, Options) -> io_lib:chars()
         when
             Expressions :: [erl_parse:abstract_expr()], Indent :: integer(), Options :: options().

Specs

form(Form) -> io_lib:chars() when Form :: erl_parse:abstract_form() | erl_parse:form_info().

Pretty prints a Form, which is an abstract form of a type that is returned by erl_parse:parse_form/1.

Specs

form(Form, Options) -> io_lib:chars()
        when Form :: erl_parse:abstract_form() | erl_parse:form_info(), Options :: options().

Specs

function(Function) -> io_lib:chars() when Function :: erl_parse:abstract_form().

Same as form/1,2, but only for function Function.

Specs

function(Function, Options) -> io_lib:chars()
            when Function :: erl_parse:abstract_form(), Options :: options().

Specs

guard(Guard) -> io_lib:chars() when Guard :: [erl_parse:abstract_expr()].

Same as form/1,2, but only for the guard test Guard.

Specs

guard(Guard, Options) -> io_lib:chars()
         when Guard :: [erl_parse:abstract_expr()], Options :: options().