1erl_parse(3) Erlang Module Definition erl_parse(3)
2
3
4
6 erl_parse - The Erlang parser.
7
9 This module is the basic Erlang parser that converts tokens into the
10 abstract form of either forms (that is, top-level constructs), expres‐
11 sions, or terms. The Abstract Format is described in the ERTS User's
12 Guide. Notice that a token list must end with the dot token to be ac‐
13 ceptable to the parse functions (see the erl_scan(3)) module.
14
16 abstract_clause()
17
18 Abstract form of an Erlang clause.
19
20 abstract_expr()
21
22 Abstract form of an Erlang expression.
23
24 abstract_form()
25
26 Abstract form of an Erlang form.
27
28 abstract_type()
29
30 Abstract form of an Erlang type.
31
32 erl_parse_tree() =
33 abstract_clause() |
34 abstract_expr() |
35 abstract_form() |
36 abstract_type()
37
38 af_binelement(_)
39
40 Abstract representation of an element of a bitstring.
41
42 af_field_decl()
43
44 Abstract representation of a record field.
45
46 af_generator()
47
48 Abstract representation of a generator or a bitstring generator.
49
50 af_remote_function()>
51
52 Abstract representation of a remote function call.
53
54 error_description() = term()
55
56 error_info() = {erl_anno:line(), module(), error_description()}
57
58 form_info() =
59 {eof, erl_anno:line()} |
60 {error, erl_scan:error_info() | error_info()} |
61 {warning, erl_scan:error_info() | error_info()}
62
63 Tuples {error, error_info()} and {warning, error_info()}, denot‐
64 ing syntactically incorrect forms and warnings, and {eof,
65 line()}, denoting an end-of-stream encountered before a complete
66 form had been parsed.
67
68 token() = erl_scan:token()
69
71 abstract(Data) -> AbsTerm
72
73 Types:
74
75 Data = term()
76 AbsTerm = abstract_expr()
77
78 Converts the Erlang data structure Data into an abstract form of
79 type AbsTerm. This function is the inverse of normalise/1.
80
81 erl_parse:abstract(T) is equivalent to erl_parse:abstract(T, 0).
82
83 abstract(Data, Options) -> AbsTerm
84
85 Types:
86
87 Data = term()
88 Options = Line | [Option]
89 Option = {line, Line} | {encoding, Encoding}
90 Encoding = latin1 | unicode | utf8 | none | encoding_func()
91 Line = erl_anno:line()
92 AbsTerm = abstract_expr()
93 encoding_func() = fun((integer() >= 0) -> boolean())
94
95 Converts the Erlang data structure Data into an abstract form of
96 type AbsTerm.
97
98 Option Line is the line to be assigned to each node of AbsTerm.
99
100 Option Encoding is used for selecting which integer lists to be
101 considered as strings. The default is to use the encoding re‐
102 turned by function epp:default_encoding/0. Value none means that
103 no integer lists are considered as strings. encoding_func() is
104 called with one integer of a list at a time; if it returns true
105 for every integer, the list is considered a string.
106
107 anno_from_term(Term) -> erl_parse_tree() | form_info()
108
109 Types:
110
111 Term = term()
112
113 Assumes that Term is a term with the same structure as a
114 erl_parse tree, but with terms, say T, where a erl_parse tree
115 has collections of annotations. Returns a erl_parse tree where
116 each term T is replaced by the value returned by
117 erl_anno:from_term(T). The term Term is traversed in a depth-
118 first, left-to-right fashion.
119
120 anno_to_term(Abstr) -> term()
121
122 Types:
123
124 Abstr = erl_parse_tree() | form_info()
125
126 Returns a term where each collection of annotations Anno of the
127 nodes of the erl_parse tree Abstr is replaced by the term re‐
128 turned by erl_anno:to_term(Anno). The erl_parse tree is tra‐
129 versed in a depth-first, left-to-right fashion.
130
131 fold_anno(Fun, Acc0, Abstr) -> Acc1
132
133 Types:
134
135 Fun = fun((Anno, AccIn) -> AccOut)
136 Anno = erl_anno:anno()
137 Acc0 = Acc1 = AccIn = AccOut = term()
138 Abstr = erl_parse_tree() | form_info()
139
140 Updates an accumulator by applying Fun on each collection of an‐
141 notations of the erl_parse tree Abstr. The first call to Fun has
142 AccIn as argument, the returned accumulator AccOut is passed to
143 the next call, and so on. The final value of the accumulator is
144 returned. The erl_parse tree is traversed in a depth-first,
145 left-to-right fashion.
146
147 format_error(ErrorDescriptor) -> Chars
148
149 Types:
150
151 ErrorDescriptor = error_description()
152 Chars = [char() | Chars]
153
154 Uses an ErrorDescriptor and returns a string that describes the
155 error. This function is usually called implicitly when an Error‐
156 Info structure is processed (see section Error Information).
157
158 map_anno(Fun, Abstr) -> NewAbstr
159
160 Types:
161
162 Fun = fun((Anno) -> NewAnno)
163 Anno = NewAnno = erl_anno:anno()
164 Abstr = NewAbstr = erl_parse_tree() | form_info()
165
166 Modifies the erl_parse tree Abstr by applying Fun on each col‐
167 lection of annotations of the nodes of the erl_parse tree. The
168 erl_parse tree is traversed in a depth-first, left-to-right
169 fashion.
170
171 mapfold_anno(Fun, Acc0, Abstr) -> {NewAbstr, Acc1}
172
173 Types:
174
175 Fun = fun((Anno, AccIn) -> {NewAnno, AccOut})
176 Anno = NewAnno = erl_anno:anno()
177 Acc0 = Acc1 = AccIn = AccOut = term()
178 Abstr = NewAbstr = erl_parse_tree() | form_info()
179
180 Modifies the erl_parse tree Abstr by applying Fun on each col‐
181 lection of annotations of the nodes of the erl_parse tree, while
182 at the same time updating an accumulator. The first call to Fun
183 has AccIn as second argument, the returned accumulator AccOut is
184 passed to the next call, and so on. The modified erl_parse tree
185 and the final value of the accumulator are returned. The
186 erl_parse tree is traversed in a depth-first, left-to-right
187 fashion.
188
189 new_anno(Term) -> Abstr
190
191 Types:
192
193 Term = term()
194 Abstr = erl_parse_tree() | form_info()
195
196 Assumes that Term is a term with the same structure as a
197 erl_parse tree, but with locations where a erl_parse tree has
198 collections of annotations. Returns a erl_parse tree where each
199 location L is replaced by the value returned by erl_anno:new(L).
200 The term Term is traversed in a depth-first, left-to-right fash‐
201 ion.
202
203 normalise(AbsTerm) -> Data
204
205 Types:
206
207 AbsTerm = abstract_expr()
208 Data = term()
209
210 Converts the abstract form AbsTerm of a term into a conventional
211 Erlang data structure (that is, the term itself). This function
212 is the inverse of abstract/1.
213
214 parse_exprs(Tokens) -> {ok, ExprList} | {error, ErrorInfo}
215
216 Types:
217
218 Tokens = [token()]
219 ExprList = [abstract_expr()]
220 ErrorInfo = error_info()
221
222 Parses Tokens as if it was a list of expressions. Returns one of
223 the following:
224
225 {ok, ExprList}:
226 The parsing was successful. ExprList is a list of the ab‐
227 stract forms of the parsed expressions.
228
229 {error, ErrorInfo}:
230 An error occurred.
231
232 parse_form(Tokens) -> {ok, AbsForm} | {error, ErrorInfo}
233
234 Types:
235
236 Tokens = [token()]
237 AbsForm = abstract_form()
238 ErrorInfo = error_info()
239
240 Parses Tokens as if it was a form. Returns one of the following:
241
242 {ok, AbsForm}:
243 The parsing was successful. AbsForm is the abstract form of
244 the parsed form.
245
246 {error, ErrorInfo}:
247 An error occurred.
248
249 parse_term(Tokens) -> {ok, Term} | {error, ErrorInfo}
250
251 Types:
252
253 Tokens = [token()]
254 Term = term()
255 ErrorInfo = error_info()
256
257 Parses Tokens as if it was a term. Returns one of the following:
258
259 {ok, Term}:
260 The parsing was successful. Term is the Erlang term corre‐
261 sponding to the token list.
262
263 {error, ErrorInfo}:
264 An error occurred.
265
266 tokens(AbsTerm) -> Tokens
267
268 tokens(AbsTerm, MoreTokens) -> Tokens
269
270 Types:
271
272 AbsTerm = abstract_expr()
273 MoreTokens = Tokens = [token()]
274
275 Generates a list of tokens representing the abstract form Ab‐
276 sTerm of an expression. Optionally, MoreTokens is appended.
277
279 ErrorInfo is the standard ErrorInfo structure that is returned from all
280 I/O modules. The format is as follows:
281
282 {ErrorLine, Module, ErrorDescriptor}
283
284 A string describing the error is obtained with the following call:
285
286 Module:format_error(ErrorDescriptor)
287
289 erl_anno(3), erl_scan(3), io(3), section The Abstract Format in the
290 ERTS User's Guide
291
292
293
294Ericsson AB stdlib 3.14.2.1 erl_parse(3)