aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/doc/src/erl_parse.xml
blob: 2d5aff3c6c4f2b25d5801fbe344947f87ae75183 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>1996</year><year>2013</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      The contents of this file are subject to the Erlang Public License,
      Version 1.1, (the "License"); you may not use this file except in
      compliance with the License. You should have received a copy of the
      Erlang Public License along with this software. If not, it can be
      retrieved online at http://www.erlang.org/.

      Software distributed under the License is distributed on an "AS IS"
      basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
      the License for the specific language governing rights and limitations
      under the License.

    </legalnotice>

    <title>erl_parse</title>
    <prepared>Robert</prepared>
    <responsible>Bjarne D&auml;cker</responsible>
    <docno>1</docno>
    <approved>Bjarne D&auml;cker</approved>
    <checked></checked>
    <date>97-01-24</date>
    <rev>B</rev>
    <file>erl_parse.sgml</file>
  </header>
  <module>erl_parse</module>
  <modulesummary>The Erlang Parser</modulesummary>
  <description>
    <p>This module is the basic Erlang parser which converts tokens into
      the abstract form of either forms (i.e., top-level constructs),
      expressions, or terms. The Abstract Format is described in the
      <seealso marker="erts:absform">ERTS User's Guide</seealso>.
      Note that a token list must end with the <em>dot</em> token in order
      to be acceptable to the parse functions (see <seealso marker="erl_scan">erl_scan(3)</seealso>).</p>
  </description>
  <datatypes>
    <datatype>
      <name name="abstract_clause"></name>
      <desc><p>Parse tree for Erlang clause.</p>
      </desc>
    </datatype>
    <datatype>
      <name name="abstract_expr"></name>
      <desc><p>Parse tree for Erlang expression.</p>
      </desc>
    </datatype>
    <datatype>
      <name name="abstract_form"></name>
      <desc><p>Parse tree for Erlang form.</p>
      </desc>
    </datatype>
    <datatype>
      <name name="error_description"></name>
    </datatype>
    <datatype>
      <name name="error_info"></name>
    </datatype>
    <datatype>
      <name name="token"></name>
    </datatype>
  </datatypes>
  <funcs>
    <func>
      <name name="parse_form" arity="1"/>
      <fsummary>Parse an Erlang form</fsummary>
      <desc>
        <p>This function parses <c><anno>Tokens</anno></c> as if it were
          a form. It returns:</p>
        <taglist>
          <tag><c>{ok, <anno>AbsForm</anno>}</c></tag>
          <item>
            <p>The parsing was successful. <c><anno>AbsForm</anno></c> is the
              abstract form of the parsed form.</p>
          </item>
          <tag><c>{error, <anno>ErrorInfo</anno>}</c></tag>
          <item>
            <p>An error occurred.</p>
          </item>
        </taglist>
      </desc>
    </func>
    <func>
      <name name="parse_exprs" arity="1"/>
      <fsummary>Parse Erlang expressions</fsummary>
      <desc>
        <p>This function parses <c><anno>Tokens</anno></c> as if it were
          a list of expressions. It returns:</p>
        <taglist>
          <tag><c>{ok, <anno>ExprList</anno>}</c></tag>
          <item>
            <p>The parsing was successful. <c><anno>ExprList</anno></c> is a
              list of the abstract forms of the parsed expressions.</p>
          </item>
          <tag><c>{error, <anno>ErrorInfo</anno>}</c></tag>
          <item>
            <p>An error occurred.</p>
          </item>
        </taglist>
      </desc>
    </func>
    <func>
      <name name="parse_term" arity="1"/>
      <fsummary>Parse an Erlang term</fsummary>
      <desc>
        <p>This function parses <c><anno>Tokens</anno></c> as if it were
          a term. It returns:</p>
        <taglist>
          <tag><c>{ok, <anno>Term</anno>}</c></tag>
          <item>
            <p>The parsing was successful. <c><anno>Term</anno></c> is
              the Erlang term corresponding to the token list.</p>
          </item>
          <tag><c>{error, ErrorInfo}</c></tag>
          <item>
            <p>An error occurred.</p>
          </item>
        </taglist>
      </desc>
    </func>
    <func>
      <name>format_error(ErrorDescriptor) -> Chars</name>
      <fsummary>Format an error descriptor</fsummary>
      <type>
        <v>ErrorDescriptor = <seealso
          marker="#type-error_info">error_description()</seealso></v>
        <v>Chars = [char() | Chars]</v>
      </type>
      <desc>
        <p>Uses an <c>ErrorDescriptor</c> and returns a string
          which describes the error. This function is usually called
          implicitly when an <c>ErrorInfo</c> structure is processed
          (see below).</p>
      </desc>
    </func>
    <func>
      <name name="tokens" arity="1"/>
      <name name="tokens" arity="2"/>
      <fsummary>Generate a list of tokens for an expression</fsummary>
      <desc>
        <p>This function generates a list of tokens representing the abstract
          form <c><anno>AbsTerm</anno></c> of an expression. Optionally, it
          appends <c><anno>MoreTokens</anno></c>.</p>
      </desc>
    </func>
    <func>
      <name name="normalise" arity="1"/>
      <fsummary>Convert abstract form to an Erlang term</fsummary>
      <desc>
        <p>Converts the abstract form <c><anno>AbsTerm</anno></c> of a
          term into a
          conventional Erlang data structure (i.e., the term itself).
          This is the inverse of <c>abstract/1</c>.</p>
      </desc>
    </func>
    <func>
      <name name="abstract" arity="1"/>
      <fsummary>Convert an Erlang term into an abstract form</fsummary>
      <desc>
        <p>Converts the Erlang data structure <c><anno>Data</anno></c> into an
          abstract form of type <c><anno>AbsTerm</anno></c>.
          This is the inverse of <c>normalise/1</c>.</p>
        <p><c>erl_parse:abstract(T)</c> is equivalent to
          <c>erl_parse:abstract(T, 0)</c>.</p>
      </desc>
    </func>
    <func>
      <name name="abstract" arity="2"/>
      <fsummary>Convert an Erlang term into an abstract form</fsummary>
      <desc>
        <p>Converts the Erlang data structure <c><anno>Data</anno></c> into an
          abstract form of type <c><anno>AbsTerm</anno></c>.</p>
        <p>The <c><anno>Line</anno></c> option is the line that will
          be assigned to each node of the abstract form.</p>
        <p>The <c><anno>Encoding</anno></c> option is used for
          selecting which integer lists will be considered
          as strings. The default is to use the encoding returned by
          <seealso marker="epp#default_encoding/0">
          <c>epp:default_encoding/0</c></seealso></p>
      </desc>
    </func>
  </funcs>

  <section>
    <title>Error Information</title>
    <p>The <c>ErrorInfo</c> mentioned above is the standard
      <c>ErrorInfo</c> structure which is returned from all IO
      modules. It has the format:
      </p>
    <code type="none">
    {ErrorLine, Module, ErrorDescriptor}    </code>
    <p>A string which describes the error is obtained with the following call:
      </p>
    <code type="none">
    Module:format_error(ErrorDescriptor)    </code>
  </section>

  <section>
    <title>See Also</title>
    <p><seealso marker="io">io(3)</seealso>,
      <seealso marker="erl_scan">erl_scan(3)</seealso>,
      ERTS User's Guide</p>
  </section>
</erlref>