842
836
%% | module | records | rules | warnings
844
838
%% @doc Analyzes a sequence of "program forms". The given
845
%% <code>Forms</code> may be a single syntax tree of type
846
%% <code>form_list</code>, or a list of "program form" syntax trees. The
847
%% returned value is a list of pairs <code>{Key, Info}</code>, where
848
%% each value of <code>Key</code> occurs at most once in the list; the
839
%% `Forms' may be a single syntax tree of type
840
%% `form_list', or a list of "program form" syntax trees. The
841
%% returned value is a list of pairs `{Key, Info}', where
842
%% each value of `Key' occurs at most once in the list; the
849
843
%% absence of a particular key indicates that there is no well-defined
850
844
%% value for that key.
852
%% <p>Each entry in the resulting list contains the following
846
%% Each entry in the resulting list contains the following
853
847
%% corresponding information about the program forms:
855
%% <dt><code>{attributes, Attributes}</code></dt>
849
%% <dt>`{attributes, Attributes}'</dt>
857
%% <li><code>Attributes = [{atom(), term()}]</code></li>
851
%% <li>`Attributes = [{atom(), term()}]'</li>
859
%% <code>Attributes</code> is a list of pairs representing the
853
%% `Attributes' is a list of pairs representing the
860
854
%% names and corresponding values of all so-called "wild"
861
%% attributes (as e.g. "<code>-compile(...)</code>") occurring in
862
%% <code>Forms</code> (cf. <code>analyze_wild_attribute/1</code>).
855
%% attributes (as e.g. "`-compile(...)'") occurring in
856
%% `Forms' (cf. `analyze_wild_attribute/1').
863
857
%% We do not guarantee that each name occurs at most once in the
864
858
%% list. The order of listing is not defined.</dd>
866
%% <dt><code>{errors, Errors}</code></dt>
860
%% <dt>`{errors, Errors}'</dt>
868
%% <li><code>Errors = [term()]</code></li>
862
%% <li>`Errors = [term()]'</li>
870
%% <code>Errors</code> is the list of error descriptors of all
871
%% <code>error_marker</code> nodes that occur in
872
%% <code>Forms</code>. The order of listing is not defined.</dd>
864
%% `Errors' is the list of error descriptors of all
865
%% `error_marker' nodes that occur in
866
%% `Forms'. The order of listing is not defined.</dd>
874
%% <dt><code>{exports, Exports}</code></dt>
868
%% <dt>`{exports, Exports}'</dt>
876
%% <li><code>Exports = [FunctionName]</code></li>
877
%% <li><code>FunctionName = atom()
870
%% <li>`Exports = [FunctionName]'</li>
871
%% <li>`FunctionName = atom()
878
872
%% | {atom(), integer()}
879
%% | {ModuleName, FunctionName}</code></li>
880
%% <li><code>ModuleName = atom()</code></li>
873
%% | {ModuleName, FunctionName}'</li>
874
%% <li>`ModuleName = atom()'</li>
882
%% <code>Exports</code> is a list of representations of those
876
%% `Exports' is a list of representations of those
883
877
%% function names that are listed by export declaration attributes
884
%% in <code>Forms</code> (cf.
885
%% <code>analyze_export_attribute/1</code>). We do not guarantee
879
%% `analyze_export_attribute/1'). We do not guarantee
886
880
%% that each name occurs at most once in the list. The order of
887
881
%% listing is not defined.</dd>
889
%% <dt><code>{functions, Functions}</code></dt>
883
%% <dt>`{functions, Functions}'</dt>
891
%% <li><code>Functions = [{atom(), integer()}]</code></li>
885
%% <li>`Functions = [{atom(), integer()}]'</li>
893
%% <code>Functions</code> is a list of the names of the functions
894
%% that are defined in <code>Forms</code> (cf.
895
%% <code>analyze_function/1</code>). We do not guarantee that each
887
%% `Functions' is a list of the names of the functions
888
%% that are defined in `Forms' (cf.
889
%% `analyze_function/1'). We do not guarantee that each
896
890
%% name occurs at most once in the list. The order of listing is
897
891
%% not defined.</dd>
899
%% <dt><code>{imports, Imports}</code></dt>
893
%% <dt>`{imports, Imports}'</dt>
901
%% <li><code>Imports = [{Module, Names}]</code></li>
902
%% <li><code>Module = atom()</code></li>
903
%% <li><code>Names = [FunctionName]</code></li>
904
%% <li><code>FunctionName = atom()
895
%% <li>`Imports = [{Module, Names}]'</li>
896
%% <li>`Module = atom()'</li>
897
%% <li>`Names = [FunctionName]'</li>
898
%% <li>`FunctionName = atom()
905
899
%% | {atom(), integer()}
906
%% | {ModuleName, FunctionName}</code></li>
907
%% <li><code>ModuleName = atom()</code></li>
900
%% | {ModuleName, FunctionName}'</li>
901
%% <li>`ModuleName = atom()'</li>
909
%% <code>Imports</code> is a list of pairs representing those
903
%% `Imports' is a list of pairs representing those
910
904
%% module names and corresponding function names that are listed
911
%% by import declaration attributes in <code>Forms</code> (cf.
912
%% <code>analyze_import_attribute/1</code>), where each
913
%% <code>Module</code> occurs at most once in
914
%% <code>Imports</code>. We do not guarantee that each name occurs
905
%% by import declaration attributes in `Forms' (cf.
906
%% `analyze_import_attribute/1'), where each
907
%% `Module' occurs at most once in
908
%% `Imports'. We do not guarantee that each name occurs
915
909
%% at most once in the lists of function names. The order of
916
910
%% listing is not defined.</dd>
918
%% <dt><code>{module, ModuleName}</code></dt>
912
%% <dt>`{module, ModuleName}'</dt>
920
%% <li><code>ModuleName = atom()</code></li>
914
%% <li>`ModuleName = atom()'</li>
922
%% <code>ModuleName</code> is the name declared by a module
923
%% attribute in <code>Forms</code>. If no module name is defined
924
%% in <code>Forms</code>, the result will contain no entry for the
925
%% <code>module</code> key. If multiple module name declarations
916
%% `ModuleName' is the name declared by a module
917
%% attribute in `Forms'. If no module name is defined
918
%% in `Forms', the result will contain no entry for the
919
%% `module' key. If multiple module name declarations
926
920
%% should occur, all but the first will be ignored.</dd>
928
%% <dt><code>{records, Records}</code></dt>
922
%% <dt>`{records, Records}'</dt>
930
%% <li><code>Records = [{atom(), Fields}]</code></li>
931
%% <li><code>Fields = [{atom(), Default}]</code></li>
932
%% <li><code>Default = none | syntaxTree()</code></li>
924
%% <li>`Records = [{atom(), Fields}]'</li>
925
%% <li>`Fields = [{atom(), Default}]'</li>
926
%% <li>`Default = none | syntaxTree()'</li>
934
%% <code>Records</code> is a list of pairs representing the names
928
%% `Records' is a list of pairs representing the names
935
929
%% and corresponding field declarations of all record declaration
936
%% attributes occurring in <code>Forms</code>. For fields declared
930
%% attributes occurring in `Forms'. For fields declared
937
931
%% without a default value, the corresponding value for
938
%% <code>Default</code> is the atom <code>none</code> (cf.
939
%% <code>analyze_record_attribute/1</code>). We do not guarantee
932
%% `Default' is the atom `none' (cf.
933
%% `analyze_record_attribute/1'). We do not guarantee
940
934
%% that each record name occurs at most once in the list. The
941
935
%% order of listing is not defined.</dd>
943
%% <dt><code>{rules, Rules}</code></dt>
937
%% <dt>`{rules, Rules}'</dt>
945
%% <li><code>Rules = [{atom(), integer()}]</code></li>
939
%% <li>`Rules = [{atom(), integer()}]'</li>
947
%% <code>Rules</code> is a list of the names of the rules that are
948
%% defined in <code>Forms</code> (cf.
949
%% <code>analyze_rule/1</code>). We do not guarantee that each
941
%% `Rules' is a list of the names of the rules that are
942
%% defined in `Forms' (cf.
943
%% `analyze_rule/1'). We do not guarantee that each
950
944
%% name occurs at most once in the list. The order of listing is
951
945
%% not defined.</dd>
953
%% <dt><code>{warnings, Warnings}</code></dt>
947
%% <dt>`{warnings, Warnings}'</dt>
955
%% <li><code>Warnings = [term()]</code></li>
949
%% <li>`Warnings = [term()]'</li>
957
%% <code>Warnings</code> is the list of error descriptors of all
958
%% <code>warning_marker</code> nodes that occur in
959
%% <code>Forms</code>. The order of listing is not defined.</dd>
951
%% `Warnings' is the list of error descriptors of all
952
%% `warning_marker' nodes that occur in
953
%% `Forms'. The order of listing is not defined.</dd>
962
%% <p>The evaluation throws <code>syntax_error</code> if an ill-formed
963
%% Erlang construct is encountered.</p>
956
%% The evaluation throws `syntax_error' if an ill-formed
957
%% Erlang construct is encountered.
965
959
%% @see analyze_wild_attribute/1
966
960
%% @see analyze_export_attribute/1
1095
1089
%% =====================================================================
1096
1090
%% @spec analyze_form(Node::syntaxTree()) -> {atom(), term()} | atom()
1098
%% @doc Analyzes a "source code form" node. If <code>Node</code> is a
1099
%% "form" type (cf. <code>erl_syntax:is_form/1</code>), the returned
1100
%% value is a tuple <code>{Type, Info}</code> where <code>Type</code> is
1101
%% the node type and <code>Info</code> depends on <code>Type</code>, as
1092
%% @doc Analyzes a "source code form" node. If `Node' is a
1093
%% "form" type (cf. `erl_syntax:is_form/1'), the returned
1094
%% value is a tuple `{Type, Info}' where `Type' is
1095
%% the node type and `Info' depends on `Type', as
1104
%% <dt><code>{attribute, Info}</code></dt>
1106
%% <dd>where <code>Info = analyze_attribute(Node)</code>.</dd>
1108
%% <dt><code>{error_marker, Info}</code></dt>
1110
%% <dd>where <code>Info =
1111
%% erl_syntax:error_marker_info(Node)</code>.</dd>
1113
%% <dt><code>{function, Info}</code></dt>
1115
%% <dd>where <code>Info = analyze_function(Node)</code>.</dd>
1117
%% <dt><code>{rule, Info}</code></dt>
1119
%% <dd>where <code>Info = analyze_rule(Node)</code>.</dd>
1121
%% <dt><code>{warning_marker, Info}</code></dt>
1123
%% <dd>where <code>Info =
1124
%% erl_syntax:warning_marker_info(Node)</code>.</dd>
1098
%% <dt>`{attribute, Info}'</dt>
1100
%% <dd>where `Info = analyze_attribute(Node)'.</dd>
1102
%% <dt>`{error_marker, Info}'</dt>
1104
%% <dd>where `Info =
1105
%% erl_syntax:error_marker_info(Node)'.</dd>
1107
%% <dt>`{function, Info}'</dt>
1109
%% <dd>where `Info = analyze_function(Node)'.</dd>
1111
%% <dt>`{rule, Info}'</dt>
1113
%% <dd>where `Info = analyze_rule(Node)'.</dd>
1115
%% <dt>`{warning_marker, Info}'</dt>
1117
%% <dd>where `Info =
1118
%% erl_syntax:warning_marker_info(Node)'.</dd>
1126
1120
%% For other types of forms, only the node type is returned.
1128
%% <p>The evaluation throws <code>syntax_error</code> if
1129
%% <code>Node</code> is not well-formed.</p>
1122
%% The evaluation throws `syntax_error' if
1123
%% `Node' is not well-formed.
1131
1125
%% @see analyze_attribute/1
1132
1126
%% @see analyze_function/1
1160
1154
%% @spec analyze_attribute(Node::syntaxTree()) ->
1161
1155
%% preprocessor | {atom(), atom()}
1163
%% @doc Analyzes an attribute node. If <code>Node</code> represents a
1164
%% preprocessor directive, the atom <code>preprocessor</code> is
1165
%% returned. Otherwise, if <code>Node</code> represents a module
1166
%% attribute "<code>-<em>Name</em>...</code>", a tuple <code>{Name,
1167
%% Info}</code> is returned, where <code>Info</code> depends on
1168
%% <code>Name</code>, as follows:
1157
%% @doc Analyzes an attribute node. If `Node' represents a
1158
%% preprocessor directive, the atom `preprocessor' is
1159
%% returned. Otherwise, if `Node' represents a module
1160
%% attribute "`-<em>Name</em>...'", a tuple `{Name,
1161
%% Info}' is returned, where `Info' depends on
1162
%% `Name', as follows:
1170
%% <dt><code>{module, Info}</code></dt>
1172
%% <dd>where <code>Info =
1173
%% analyze_module_attribute(Node)</code>.</dd>
1175
%% <dt><code>{export, Info}</code></dt>
1177
%% <dd>where <code>Info =
1178
%% analyze_export_attribute(Node)</code>.</dd>
1180
%% <dt><code>{import, Info}</code></dt>
1182
%% <dd>where <code>Info =
1183
%% analyze_import_attribute(Node)</code>.</dd>
1185
%% <dt><code>{file, Info}</code></dt>
1187
%% <dd>where <code>Info =
1188
%% analyze_file_attribute(Node)</code>.</dd>
1190
%% <dt><code>{record, Info}</code></dt>
1192
%% <dd>where <code>Info =
1193
%% analyze_record_attribute(Node)</code>.</dd>
1195
%% <dt><code>{Name, Info}</code></dt>
1197
%% <dd>where <code>{Name, Info} =
1198
%% analyze_wild_attribute(Node)</code>.</dd>
1164
%% <dt>`{module, Info}'</dt>
1166
%% <dd>where `Info =
1167
%% analyze_module_attribute(Node)'.</dd>
1169
%% <dt>`{export, Info}'</dt>
1171
%% <dd>where `Info =
1172
%% analyze_export_attribute(Node)'.</dd>
1174
%% <dt>`{import, Info}'</dt>
1176
%% <dd>where `Info =
1177
%% analyze_import_attribute(Node)'.</dd>
1179
%% <dt>`{file, Info}'</dt>
1181
%% <dd>where `Info =
1182
%% analyze_file_attribute(Node)'.</dd>
1184
%% <dt>`{record, Info}'</dt>
1186
%% <dd>where `Info =
1187
%% analyze_record_attribute(Node)'.</dd>
1189
%% <dt>`{Name, Info}'</dt>
1191
%% <dd>where `{Name, Info} =
1192
%% analyze_wild_attribute(Node)'.</dd>
1200
%% The evaluation throws <code>syntax_error</code> if <code>Node</code>
1194
%% The evaluation throws `syntax_error' if `Node'
1201
1195
%% does not represent a well-formed module attribute.
1203
1197
%% @see analyze_module_attribute/1
1515
1509
%% Value = none | syntaxTree()
1517
1511
%% @doc Returns the record name and field name/names of a record
1518
%% expression. If <code>Node</code> has type <code>record_expr</code>,
1519
%% <code>record_index_expr</code> or <code>record_access</code>, a pair
1520
%% <code>{Type, Info}</code> is returned, otherwise an atom
1521
%% <code>Type</code> is returned. <code>Type</code> is the node type of
1522
%% <code>Node</code>, and <code>Info</code> depends on
1523
%% <code>Type</code>, as follows:
1512
%% expression. If `Node' has type `record_expr',
1513
%% `record_index_expr' or `record_access', a pair
1514
%% `{Type, Info}' is returned, otherwise an atom
1515
%% `Type' is returned. `Type' is the node type of
1516
%% `Node', and `Info' depends on
1517
%% `Type', as follows:
1525
%% <dt><code>record_expr</code>:</dt>
1526
%% <dd><code>{atom(), [{atom(), Value}]}</code></dd>
1527
%% <dt><code>record_access</code>:</dt>
1528
%% <dd><code>{atom(), atom()} | atom()</code></dd>
1529
%% <dt><code>record_index_expr</code>:</dt>
1530
%% <dd><code>{atom(), atom()}</code></dd>
1519
%% <dt>`record_expr':</dt>
1520
%% <dd>`{atom(), [{atom(), Value}]}'</dd>
1521
%% <dt>`record_access':</dt>
1522
%% <dd>`{atom(), atom()} | atom()'</dd>
1523
%% <dt>`record_index_expr':</dt>
1524
%% <dd>`{atom(), atom()}'</dd>
1533
%% <p>For a <code>record_expr</code> node, <code>Info</code> represents
1527
%% For a `record_expr' node, `Info' represents
1534
1528
%% the record name and the list of descriptors for the involved fields,
1535
1529
%% listed in the order they appear. (See
1536
%% <code>analyze_record_field/1</code> for details on the field
1537
%% descriptors). For a <code>record_access</code> node,
1538
%% <code>Info</code> represents the record name and the field name (or
1530
%% `analyze_record_field/1' for details on the field
1531
%% descriptors). For a `record_access' node,
1532
%% `Info' represents the record name and the field name (or
1539
1533
%% if the record name is not included, only the field name; this is
1540
1534
%% allowed only in Mnemosyne-query syntax). For a
1541
%% <code>record_index_expr</code> node, <code>Info</code> represents the
1542
%% record name and the name field name.</p>
1535
%% `record_index_expr' node, `Info' represents the
1536
%% record name and the name field name.
1544
%% <p>The evaluation throws <code>syntax_error</code> if
1545
%% <code>Node</code> represents a record expression that is not
1538
%% The evaluation throws `syntax_error' if
1539
%% `Node' represents a record expression that is not
1548
1542
%% @see analyze_record_attribute/1
1549
1543
%% @see analyze_record_field/1
1925
1919
%% Node::syntaxTree()) -> syntaxTree()
1927
1921
%% @doc Limits a syntax tree to a specified depth. Replaces all non-leaf
1928
%% subtrees in <code>Tree</code> at the given <code>Depth</code> by
1929
%% <code>Node</code>. If <code>Depth</code> is negative, the result is
1930
%% always <code>Node</code>, even if <code>Tree</code> has no subtrees.
1922
%% subtrees in `Tree' at the given `Depth' by
1923
%% `Node'. If `Depth' is negative, the result is
1924
%% always `Node', even if `Tree' has no subtrees.
1932
%% <p>When a group of subtrees (as e.g., the argument list of an
1933
%% <code>application</code> node) is at the specified depth, and there
1926
%% When a group of subtrees (as e.g., the argument list of an
1927
%% `application' node) is at the specified depth, and there
1934
1928
%% are two or more subtrees in the group, these will be collectively
1935
%% replaced by <code>Node</code> even if they are leaf nodes. Groups of
1929
%% replaced by `Node' even if they are leaf nodes. Groups of
1936
1930
%% subtrees that are above the specified depth will be limited in size,
1937
1931
%% as if each subsequent tree in the group were one level deeper than
1938
%% the previous. E.g., if <code>Tree</code> represents a list of
1939
%% integers "<code>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</code>", the result
1940
%% of <code>limit(Tree, 5)</code> will represent <code>[1, 2, 3, 4,
1932
%% the previous. E.g., if `Tree' represents a list of
1933
%% integers "`[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]'", the result
1934
%% of `limit(Tree, 5)' will represent `[1, 2, 3, 4,
1943
%% <p>The resulting syntax tree is typically only useful for
1944
%% pretty-printing or similar visual formatting.</p>
1937
%% The resulting syntax tree is typically only useful for
1938
%% pretty-printing or similar visual formatting.
1946
1940
%% @see limit/2