mirror of
https://github.com/valitydev/parse_trans.git
synced 2024-11-06 00:25:16 +00:00
Added revert_form/1; deal with revert bugs
This commit is contained in:
parent
895a157dc9
commit
c55c8861cd
@ -96,7 +96,7 @@ Performs a transform of <code>Forms</code> using the fun <code>Fun(Form)</code>.
|
||||
Reads debug_info from the beam file Beam and returns a string containing
|
||||
the pretty-printed corresponding erlang source code.</td></tr><tr><td valign="top"><a href="#pp_beam-2">pp_beam/2</a></td><td>
|
||||
Reads debug_info from the beam file Beam and pretty-prints it as
|
||||
Erlang source code, storing it in the file Out.</td></tr><tr><td valign="top"><a href="#pp_src-2">pp_src/2</a></td><td>Pretty-prints the erlang source code corresponding to Forms into Out.</td></tr><tr><td valign="top"><a href="#replace_function-4">replace_function/4</a></td><td></td></tr><tr><td valign="top"><a href="#return-2">return/2</a></td><td>Checks the transformed result for errors and warnings.</td></tr><tr><td valign="top"><a href="#revert-1">revert/1</a></td><td>Reverts back from Syntax Tools format to Erlang forms.</td></tr><tr><td valign="top"><a href="#top-3">top/3</a></td><td></td></tr><tr><td valign="top"><a href="#transform-4">transform/4</a></td><td>
|
||||
Erlang source code, storing it in the file Out.</td></tr><tr><td valign="top"><a href="#pp_src-2">pp_src/2</a></td><td>Pretty-prints the erlang source code corresponding to Forms into Out.</td></tr><tr><td valign="top"><a href="#replace_function-4">replace_function/4</a></td><td></td></tr><tr><td valign="top"><a href="#return-2">return/2</a></td><td>Checks the transformed result for errors and warnings.</td></tr><tr><td valign="top"><a href="#revert-1">revert/1</a></td><td>Reverts back from Syntax Tools format to Erlang forms.</td></tr><tr><td valign="top"><a href="#revert_form-1">revert_form/1</a></td><td>Reverts a single form back from Syntax Tools format to Erlang forms.</td></tr><tr><td valign="top"><a href="#top-3">top/3</a></td><td></td></tr><tr><td valign="top"><a href="#transform-4">transform/4</a></td><td>
|
||||
Makes one pass.</td></tr></table>
|
||||
|
||||
|
||||
@ -524,7 +524,30 @@ Reverts back from Syntax Tools format to Erlang forms.
|
||||
|
||||
Note that the Erlang forms are a subset of the Syntax Tools
|
||||
syntax tree, so this function is safe to call even on a list of
|
||||
regular Erlang forms.<a name="top-3"></a>
|
||||
regular Erlang forms.<a name="revert_form-1"></a>
|
||||
|
||||
###revert_form/1##
|
||||
|
||||
|
||||
|
||||
|
||||
<pre>revert_form(F::Tree) -> Form</pre>
|
||||
<br></br>
|
||||
|
||||
|
||||
|
||||
|
||||
Reverts a single form back from Syntax Tools format to Erlang forms.
|
||||
|
||||
|
||||
`erl_syntax:revert/1` has had a long-standing bug where it doesn't
|
||||
completely revert attribute forms. This function deals properly with those
|
||||
cases.
|
||||
|
||||
|
||||
Note that the Erlang forms are a subset of the Syntax Tools
|
||||
syntax tree, so this function is safe to call even on a regular Erlang
|
||||
form.<a name="top-3"></a>
|
||||
|
||||
###top/3##
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
transform/4,
|
||||
depth_first/4,
|
||||
revert/1,
|
||||
revert_form/1,
|
||||
format_exception/2, format_exception/3,
|
||||
return/2
|
||||
]).
|
||||
@ -513,8 +514,25 @@ get_orig_syntax_tree(File) ->
|
||||
%%%
|
||||
-spec revert(forms()) ->
|
||||
forms().
|
||||
revert(Tree) ->
|
||||
[erl_syntax:revert(T) || T <- lists:flatten(Tree)].
|
||||
revert(Tree) when is_list(Tree) ->
|
||||
[revert_form(T) || T <- lists:flatten(Tree)].
|
||||
|
||||
%%% @spec (Tree) -> Form
|
||||
%%%
|
||||
%%% @doc Reverts a single form back from Syntax Tools format to Erlang forms.
|
||||
%%% <p>`erl_syntax:revert/1' has had a long-standing bug where it doesn't
|
||||
%%% completely revert attribute forms. This function deals properly with those
|
||||
%%% cases.</p>
|
||||
%%% <p>Note that the Erlang forms are a subset of the Syntax Tools
|
||||
%%% syntax tree, so this function is safe to call even on a regular Erlang
|
||||
%%% form.</p>
|
||||
revert_form(F) ->
|
||||
case erl_syntax:revert(F) of
|
||||
{attribute,L,A,Tree} when element(1,Tree) == tree ->
|
||||
{attribute,L,A,erl_syntax:revert(Tree)};
|
||||
Result ->
|
||||
Result
|
||||
end.
|
||||
|
||||
%%% @spec (Forms, Context) -> Forms | {error,Es,Ws} | {warnings,Forms,Ws}
|
||||
%%%
|
||||
|
Loading…
Reference in New Issue
Block a user