Skip to content

Commit c4f5d02

Browse files
committed
Add docs
1 parent c722afe commit c4f5d02

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/gradient/debug.ex

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
defmodule Gradient.Debug do
2-
@moduledoc false
2+
@moduledoc ~S"""
3+
Helpers for convenient debugging Erlang and Elixir ASTs.
4+
"""
35

6+
## TODO: specify elixir_form
7+
@type elixir_form() :: any()
8+
@type erlang_form() :: Gradient.SpecifyErlAst.form()
9+
10+
@doc ~S"""
11+
Return the Elixir AST of an Elixir module.
12+
"""
13+
@spec elixir_ast(module()) :: {:ok, [elixir_form()]}
414
def elixir_ast(mod) do
515
{:ok, {_, [{:debug_info, {:debug_info_v1, :elixir_erl, abstract_code}}]}} =
616
:beam_lib.chunks(get_beam_path_as_charlist(mod), [:debug_info])
717
{:ok, _forms} = :elixir_erl.debug_info(:elixir_v1, :module_name, abstract_code, [])
818
end
919

20+
@doc ~S"""
21+
Return the Erlang AST of an Erlang or Elixir module.
22+
"""
23+
@spec erlang_ast(module()) :: {:ok, [erlang_form()]}
1024
def erlang_ast(mod) do
1125
{:ok, _forms} = get_beam_path_as_charlist(mod) |> Gradient.ElixirFileUtils.get_forms_from_beam()
1226
end
1327

28+
@doc ~S"""
29+
Print module as Erlang source code.
30+
"""
31+
@spec print_erlang(module()) :: :ok
1432
def print_erlang(mod) do
1533
{:ok, forms} = erlang_ast(mod)
1634
IO.puts(:erl_prettypr.format(:erl_syntax.form_list(forms)))

0 commit comments

Comments
 (0)