37
37
<p>This module is the basic Erlang parser which converts tokens into
38
38
the abstract form of either forms (i.e., top-level constructs),
39
expressions, or terms. The Abstract Format is described in the ERTS
39
expressions, or terms. The Abstract Format is described in the
40
<seealso marker="erts:absform">ERTS User's Guide</seealso>.
41
41
Note that a token list must end with the <em>dot</em> token in order
42
42
to be acceptable to the parse functions (see <seealso marker="erl_scan">erl_scan(3)</seealso>).</p>
46
<name name="abstract_clause"></name>
47
<desc><p>Parse tree for Erlang clause.</p>
51
<name name="abstract_expr"></name>
52
<desc><p>Parse tree for Erlang expression.</p>
56
<name name="abstract_form"></name>
57
<desc><p>Parse tree for Erlang form.</p>
61
<name name="error_description"></name>
64
<name name="error_info"></name>
67
<name name="token"></name>
46
<name>parse_form(Tokens) -> {ok, AbsForm} | {error, ErrorInfo}</name>
72
<name name="parse_form" arity="1"/>
47
73
<fsummary>Parse an Erlang form</fsummary>
49
<v>Tokens = [Token]</v>
50
<v>Token = {Tag,Line} | {Tag,Line,term()}</v>
52
<v>AbsForm = term()</v>
53
<v>ErrorInfo = see section Error Information below.</v>
56
<p>This function parses <c>Tokens</c> as if it were a form. It returns:</p>
75
<p>This function parses <c><anno>Tokens</anno></c> as if it were
76
a form. It returns:</p>
58
<tag><c>{ok, AbsForm}</c></tag>
78
<tag><c>{ok, <anno>AbsForm</anno>}</c></tag>
60
<p>The parsing was successful. <c>AbsForm</c> is the
80
<p>The parsing was successful. <c><anno>AbsForm</anno></c> is the
61
81
abstract form of the parsed form.</p>
63
<tag><c>{error, ErrorInfo}</c></tag>
83
<tag><c>{error, <anno>ErrorInfo</anno>}</c></tag>
65
85
<p>An error occurred.</p>
71
<name>parse_exprs(Tokens) -> {ok, Expr_list} | {error, ErrorInfo}</name>
91
<name name="parse_exprs" arity="1"/>
72
92
<fsummary>Parse Erlang expressions</fsummary>
74
<v>Tokens = [Token]</v>
75
<v>Token = {Tag,Line} | {Tag,Line,term()}</v>
77
<v>Expr_list = [AbsExpr]</v>
78
<v>AbsExpr = term()</v>
79
<v>ErrorInfo = see section Error Information below.</v>
82
<p>This function parses <c>Tokens</c> as if it were a list of expressions. It returns:</p>
94
<p>This function parses <c><anno>Tokens</anno></c> as if it were
95
a list of expressions. It returns:</p>
84
<tag><c>{ok, Expr_list}</c></tag>
97
<tag><c>{ok, <anno>ExprList</anno>}</c></tag>
86
<p>The parsing was successful. <c>Expr_list</c> is a
99
<p>The parsing was successful. <c><anno>ExprList</anno></c> is a
87
100
list of the abstract forms of the parsed expressions.</p>
89
<tag><c>{error, ErrorInfo}</c></tag>
102
<tag><c>{error, <anno>ErrorInfo</anno>}</c></tag>
91
104
<p>An error occurred.</p>
97
<name>parse_term(Tokens) -> {ok, Term} | {error, ErrorInfo}</name>
110
<name name="parse_term" arity="1"/>
98
111
<fsummary>Parse an Erlang term</fsummary>
100
<v>Tokens = [Token]</v>
101
<v>Token = {Tag,Line} | {Tag,Line,term()}</v>
104
<v>ErrorInfo = see section Error Information below.</v>
107
<p>This function parses <c>Tokens</c> as if it were a term. It returns:</p>
113
<p>This function parses <c><anno>Tokens</anno></c> as if it were
114
a term. It returns:</p>
109
<tag><c>{ok, Term}</c></tag>
116
<tag><c>{ok, <anno>Term</anno>}</c></tag>
111
<p>The parsing was successful. <c>Term</c> is
118
<p>The parsing was successful. <c><anno>Term</anno></c> is
112
119
the Erlang term corresponding to the token list.</p>
114
121
<tag><c>{error, ErrorInfo}</c></tag>
122
129
<name>format_error(ErrorDescriptor) -> Chars</name>
123
130
<fsummary>Format an error descriptor</fsummary>
125
<v>ErrorDescriptor = errordesc()</v>
132
<v>ErrorDescriptor = <seealso
133
marker="#type-error_info">error_description()</seealso></v>
126
134
<v>Chars = [char() | Chars]</v>
136
<name>tokens(AbsTerm) -> Tokens</name>
137
<name>tokens(AbsTerm, MoreTokens) -> Tokens</name>
144
<name name="tokens" arity="1"/>
145
<name name="tokens" arity="2"/>
138
146
<fsummary>Generate a list of tokens for an expression</fsummary>
140
<v>Tokens = MoreTokens = [Token]</v>
141
<v>Token = {Tag,Line} | {Tag,Line,term()}</v>
143
<v>AbsTerm = term()</v>
144
<v>ErrorInfo = see section Error Information below.</v>
147
148
<p>This function generates a list of tokens representing the abstract
148
form <c>AbsTerm</c> of an expression. Optionally, it appends
149
<c>Moretokens</c>.</p>
149
form <c><anno>AbsTerm</anno></c> of an expression. Optionally, it
150
appends <c><anno>MoreTokens</anno></c>.</p>
153
<name>normalise(AbsTerm) -> Data</name>
154
<name name="normalise" arity="1"/>
154
155
<fsummary>Convert abstract form to an Erlang term</fsummary>
156
<v>AbsTerm = Data = term()</v>
159
<p>Converts the abstract form <c>AbsTerm</c> of a term into a
157
<p>Converts the abstract form <c><anno>AbsTerm</anno></c> of a
160
159
conventional Erlang data structure (i.e., the term itself).
161
160
This is the inverse of <c>abstract/1</c>.</p>
165
<name>abstract(Data) -> AbsTerm</name>
164
<name name="abstract" arity="1"/>
166
165
<fsummary>Convert an Erlang term into an abstract form</fsummary>
168
<v>Data = AbsTerm = term()</v>
171
<p>Converts the Erlang data structure <c>Data</c> into an
172
abstract form of type <c>AbsTerm</c>. This is the inverse of
173
<c>normalise/1</c>.</p>
167
<p>Converts the Erlang data structure <c><anno>Data</anno></c> into an
168
abstract form of type <c><anno>AbsTerm</anno></c>.
169
This is the inverse of <c>normalise/1</c>.</p>