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.
Types
hook_function() =
none |
fun((Expr :: erl_parse:abstract_expr(),
CurrentIndentation :: integer(),
CurrentPrecedence :: integer() >= 0,
Options :: options()) ->
io_lib:chars())
The optional argument HookFunction
If HookFunction
is equal to none
there is no hook
function.
The called hook function should return a (possibly deep) list
of characters. expr/4
is useful in a hook.
If
is negative, there will be no line
breaks and only a space is used as a separator.
option() =
{hook, hook_function()} | {encoding, latin1 | unicode | utf8}
options() = hook_function() | [option()]
Functions
form(Form) -> io_lib:chars()
Form = erl_parse:abstract_form()
form(Form, Options) -> io_lib:chars()
Form = erl_parse:abstract_form()
Options = options()
Pretty prints a
which is an abstract form of a type which is
returned by
erl_parse:parse_form/1
.
attribute(Attribute) -> io_lib:chars()
Attribute = erl_parse:abstract_form()
attribute(Attribute, Options) -> io_lib:chars()
Attribute = erl_parse:abstract_form()
Options = options()
The same as form
, but only for the attribute
.
function(Function) -> io_lib:chars()
Function = erl_parse:abstract_form()
function(Function, Options) -> io_lib:chars()
Function = erl_parse:abstract_form()
Options = options()
The same as form
, but only for the function
.
guard(Guard) -> io_lib:chars()
Guard = [erl_parse:abstract_expr()]
guard(Guard, Options) -> io_lib:chars()
Guard = [erl_parse:abstract_expr()]
Options = options()
The same as form
, but only for the guard test
.
exprs(Expressions) -> io_lib:chars()
Expressions = [erl_parse:abstract_expr()]
exprs(Expressions, Options) -> io_lib:chars()
Expressions = [erl_parse:abstract_expr()]
Options = options()
exprs(Expressions, Indent, Options) -> io_lib:chars()
Expressions = [erl_parse:abstract_expr()]
Indent = integer()
Options = options()
The same as form
, but only for the sequence of
expressions in
.
expr(Expression) -> io_lib:chars()
Expression = erl_parse:abstract_expr()
expr(Expression, Options) -> io_lib:chars()
Expression = erl_parse:abstract_expr()
Options = options()
expr(Expression, Indent, Options) -> io_lib:chars()
Expression = erl_parse:abstract_expr()
Indent = integer()
Options = options()
expr(Expression, Indent, Precedence, Options) -> io_lib:chars()
Expression = erl_parse:abstract_expr()
Indent = integer()
Precedence = integer() >= 0
Options = options()
This function prints one expression. It is useful for implementing hooks (see below).
Bugs
It should be possible to have hook functions for unknown forms at places other than expressions.