1erl_prettypr(3)            Erlang Module Definition            erl_prettypr(3)
2
3
4

NAME

6       erl_prettypr - Pretty printing of abstract Erlang syntax trees.
7

DESCRIPTION

9       Pretty printing of abstract Erlang syntax trees.
10
11       This  module is a front end to the pretty-printing library module pret‐
12       typr, for text formatting of abstract syntax trees defined by the  mod‐
13       ule erl_syntax.
14

DATA TYPES

16         clause_t()  =  case_expr  |  fun_expr  |  if_expr  | maybe_expr | re‐
17         ceive_expr | try_expr | {function, prettypr:document()} | spec:
18
19
20         context()   =   #ctxt{prec=integer(),   sub_indent=non_neg_integer(),
21         break_indent=non_neg_integer(),    clause=clause_t()   |   undefined,
22         hook=hook(), paper=integer(), ribbon=integer(),  user=term(),  encod‐
23         ing=epp:source_encoding(), empty_lines=sets:set(integer())}:
24
25
26         hook()  =  none  | (erl_syntax:syntaxTree(), term(), term()) -> pret‐
27         typr:document():
28
29
30         syntaxTree() = erl_syntax:syntaxTree():
31
32
33           An abstract syntax tree. See the erl_syntax module for details.
34

EXPORTS

36       best(Node::erl_syntax:syntaxTree()) -> empty | prettypr:document()
37
38              Equivalent to best(Tree, []).
39
40       best(Node::erl_syntax:syntaxTree(), Options::[term()]) -> empty | pret‐
41       typr:document()
42
43              Creates  a  fixed "best" abstract layout for a syntax tree. This
44              is similar to the layout/2 function, except that here, the final
45              layout  has been selected with respect to the given options. The
46              atom empty is returned if no such layout could be produced.  For
47              information on the options, see the format/2 function.
48
49              See also: best/1, format/2, layout/2, prettypr:best/3.
50
51       format(Node::erl_syntax:syntaxTree()) -> string()
52
53              Equivalent to format(Tree, []).
54
55       format(Node::erl_syntax:syntaxTree(), Options::[term()]) -> string()
56
57              Prettyprint-formats  an abstract Erlang syntax tree as text. For
58              example, if you have a .beam file that has  been  compiled  with
59              debug_info,  the  following should print the source code for the
60              module (as it looks in the debug info representation):
61
62                   {ok,{_,[{abstract_code,{_,AC}}]}} =
63                           beam_lib:chunks("myfile.beam",[abstract_code]),
64                   io:put_chars(erl_prettypr:format(erl_syntax:form_list(AC)))
65
66              Available options:
67
68                {hook, none | hook()}:
69                  Unless the value is none, the given function is  called  for
70                  each  node whose list of annotations is not empty; see below
71                  for details. The default value is none.
72
73                {paper, integer()}:
74                  Specifies the preferred maximum number of characters on  any
75                  line, including indentation. The default value is 80.
76
77                {ribbon, integer()}:
78                  Specifies  the preferred maximum number of characters on any
79                  line, not counting indentation. The default value is 65.
80
81                {user, term()}:
82                  User-specific data for use in hook  functions.  The  default
83                  value is undefined.
84
85                {encoding, epp:source_encoding()}:
86                  Specifies the encoding of the generated file.
87
88              A hook function (cf. the hook() type) is passed the current syn‐
89              tax tree node, the context, and a continuation. The context  can
90              be examined and manipulated by functions such as get_ctxt_user/1
91              and set_ctxt_user/2. The hook  must  return  a  "document"  data
92              structure  (see layout/2 and best/2); this may be constructed in
93              part or in whole by applying the continuation function. For  ex‐
94              ample, the following is a trivial hook:
95
96                    fun (Node, Ctxt, Cont) -> Cont(Node, Ctxt) end
97
98              which  yields  the same result as if no hook was given. The fol‐
99              lowing, however:
100
101                    fun (Node, Ctxt, Cont) ->
102                        Doc = Cont(Node, Ctxt),
103                        prettypr:beside(prettypr:text("<b>"),
104                                        prettypr:beside(Doc,
105                                                        prettypr:text("</b>")))
106                    end
107
108              will place the text of any annotated node (regardless of the an‐
109              notation  data) between HTML "boldface begin" and "boldface end"
110              tags.
111
112              See also: erl_syntax, best/2,  format/1,  get_ctxt_user/1,  lay‐
113              out/2, set_ctxt_user/2.
114
115       get_ctxt_hook(Ctxt::context()) -> hook()
116
117              Returns the hook function field of the prettyprinter context.
118
119              See also: set_ctxt_hook/2.
120
121       get_ctxt_linewidth(Ctxt::context()) -> integer()
122
123              Returns the line widh field of the prettyprinter context.
124
125              See also: set_ctxt_linewidth/2.
126
127       get_ctxt_paperwidth(Ctxt::context()) -> integer()
128
129              Returns the paper widh field of the prettyprinter context.
130
131              See also: set_ctxt_paperwidth/2.
132
133       get_ctxt_precedence(Ctxt::context()) -> integer()
134
135              Returns  the operator precedence field of the prettyprinter con‐
136              text.
137
138              See also: set_ctxt_precedence/2.
139
140       get_ctxt_user(Ctxt::context()) -> term()
141
142              Returns the user data field of the prettyprinter context.
143
144              See also: set_ctxt_user/2.
145
146       layout(Node::erl_syntax:syntaxTree()) -> prettypr:document()
147
148              Equivalent to layout(Tree, []).
149
150       layout(Node::erl_syntax:syntaxTree(),   Options::[term()])   ->   pret‐
151       typr:document()
152
153              Creates  an  abstract document layout for a syntax tree. The re‐
154              sult represents a set of possible layouts (cf. module prettypr).
155              For  information  on  the  options, see format/2; note, however,
156              that the paper and ribbon options are ignored by this function.
157
158              This function provides  a  low-level  interface  to  the  pretty
159              printer,  returning  a  flexible representation of possible lay‐
160              outs, independent of the paper width eventually to be  used  for
161              formatting.  This  can  be  included as part of another document
162              and/or further processed directly by the functions in the  pret‐
163              typr  module,  or  used in a hook function (see format/2 for de‐
164              tails).
165
166              See also: prettypr, format/2, layout/1.
167
168       set_ctxt_hook(Ctxt::context(), Hook::hook()) -> context()
169
170              Updates the hook function field of the prettyprinter context.
171
172              See also: get_ctxt_hook/1.
173
174       set_ctxt_linewidth(Ctxt::context(), W::integer()) -> context()
175
176              Updates the line widh field of the prettyprinter context.
177
178              Note: changing this value (and passing the resulting context  to
179              a  continuation function) does not affect the normal formatting,
180              but may affect user-defined behaviour in hook functions.
181
182              See also: get_ctxt_linewidth/1.
183
184       set_ctxt_paperwidth(Ctxt::context(), W::integer()) -> context()
185
186              Updates the paper widh field of the prettyprinter context.
187
188              Note: changing this value (and passing the resulting context  to
189              a  continuation function) does not affect the normal formatting,
190              but may affect user-defined behaviour in hook functions.
191
192              See also: get_ctxt_paperwidth/1.
193
194       set_ctxt_precedence(Ctxt::context(), Prec::integer()) -> context()
195
196              Updates the operator precedence field of the prettyprinter  con‐
197              text. See the erl_parse(3) module for operator precedences.
198
199              See also: erl_parse(3), get_ctxt_precedence/1.
200
201       set_ctxt_user(Ctxt::context(), X::term()) -> context()
202
203              Updates the user data field of the prettyprinter context.
204
205              See also: get_ctxt_user/1.
206

AUTHORS

208       Richard Carlsson <carlsson.richard@gmail.com>
209
210
211
212                               syntax_tools 3.0                erl_prettypr(3)
Impressum