Erlang logo
User's Guide
Reference Manual
Release Notes
PDF
Top

STDLIB
Reference Manual
Version 3.3


Expand All
Contract All

Table of Contents

erl_pp

MODULE

erl_pp

MODULE SUMMARY

The Erlang pretty printer.

DESCRIPTION

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.

DATA TYPES

hook_function() =
    none |
    fun((Expr :: erl_parse:abstract_expr(),
         CurrentIndentation :: integer(),
         CurrentPrecedence :: integer() >= 0,
         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.

option() =
    {hook, hook_function()} | {encoding, latin1 | unicode | utf8}

options() = hook_function() | [option()]

EXPORTS

attribute(Attribute) -> io_lib:chars()
attribute(Attribute, Options) -> io_lib:chars()

Types:

Options = options()

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

expr(Expression) -> io_lib:chars()
expr(Expression, Options) -> io_lib:chars()
expr(Expression, Indent, Options) -> io_lib:chars()
expr(Expression, Indent, Precedence, Options) -> io_lib:chars()

Types:

Indent = integer()
Precedence = integer() >= 0
Options = options()

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

exprs(Expressions) -> io_lib:chars()
exprs(Expressions, Options) -> io_lib:chars()
exprs(Expressions, Indent, Options) -> io_lib:chars()

Types:

Indent = integer()
Options = options()

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

form(Form) -> io_lib:chars()
form(Form, Options) -> io_lib:chars()

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

function(Function) -> io_lib:chars()
function(Function, Options) -> io_lib:chars()

Types:

Options = options()

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

guard(Guard) -> io_lib:chars()
guard(Guard, Options) -> io_lib:chars()

Types:

Options = options()

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

Known Limitations

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

See Also