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

STDLIB
Reference Manual
Version 1.18.1


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,
                       HookFunction :: hook_function()) ->
                          io_lib:chars())

The optional argument HookFunction, shown in the functions described below, defines a function which is called when an unknown form occurs where there should be a valid expression.

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 CurrentIndentation is negative, there will be no line breaks and only a space is used as a separator.

EXPORTS

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

Types:

HookFunction = hook_function()

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

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

Types:

HookFunction = hook_function()

The same as form, but only for the attribute Attribute.

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

Types:

HookFunction = hook_function()

The same as form, but only for the function Function.

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

Types:

HookFunction = hook_function()

The same as form, but only for the guard test Guard.

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

Types:

Indent = integer()
HookFunction = hook_function()

The same as form, but only for the sequence of expressions in Expressions.

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

Types:

Indent = integer()
Precedence = integer() >= 0
HookFunction = hook_function()

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.

See Also