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
Link to this section Summary
Functions
Same as form/1,2
, but only for attribute Attribute
.
Prints one expression. It is useful for implementing hooks (see section Known Limitations).
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
.
Link to this section Types
-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.
-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).
-type options() :: term().
Specs
options() :: hook_function() | [option()].
Link to this section Functions
attribute/1
Specs
attribute(Attribute) -> io_lib:chars() when Attribute :: erl_parse:abstract_form().
Same as form/1,2
, but only for attribute Attribute
.
attribute/2
Specs
attribute(Attribute, Options) -> io_lib:chars() when Attribute :: erl_parse:abstract_form(), Options :: options().
expr/1
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).
expr/2
Specs
expr(Expression, Options) -> io_lib:chars() when Expression :: erl_parse:abstract_expr(), Options :: options().
expr/3
Specs
expr(Expression, Indent, Options) -> io_lib:chars() when Expression :: erl_parse:abstract_expr(), Indent :: integer(), Options :: options().
expr/4
Specs
expr(Expression, Indent, Precedence, Options) -> io_lib:chars() when Expression :: erl_parse:abstract_expr(), Indent :: integer(), Precedence :: non_neg_integer(), Options :: options().
exprs/1
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
.
exprs/2
Specs
exprs(Expressions, Options) -> io_lib:chars() when Expressions :: [erl_parse:abstract_expr()], Options :: options().
exprs/3
Specs
exprs(Expressions, Indent, Options) -> io_lib:chars() when Expressions :: [erl_parse:abstract_expr()], Indent :: integer(), Options :: options().
form/1
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
.
form/2
Specs
form(Form, Options) -> io_lib:chars() when Form :: erl_parse:abstract_form() | erl_parse:form_info(), Options :: options().
function/1
Specs
function(Function) -> io_lib:chars() when Function :: erl_parse:abstract_form().
Same as form/1,2
, but only for function Function
.
function/2
Specs
function(Function, Options) -> io_lib:chars() when Function :: erl_parse:abstract_form(), Options :: options().
guard/1
Specs
guard(Guard) -> io_lib:chars() when Guard :: [erl_parse:abstract_expr()].
Same as form/1,2
, but only for the guard test Guard
.
guard/2
Specs
guard(Guard, Options) -> io_lib:chars() when Guard :: [erl_parse:abstract_expr()], Options :: options().