exfmt v0.1.0 Exfmt.Comment

We leverage Code.string_to_quoted/2 to get the AST from Elixir source code. This is great as it’s maintained by the core team (i.e. not me). This is not great as it doesn’t preserve comments, so we need to extract them ourselves and then merge them into the AST later.

Link to this section Summary

Functions

Extract comments from a string of Elixir source code

Merge the given comments into an Elixir abstract syntax tree

Link to this section Types

Link to this type t()
t() :: {:"#", non_neg_integer, String.t}

Link to this section Functions

Link to this function extract_comments(src)
extract_comments(String.t) :: {:ok, [t]} | :error

Extract comments from a string of Elixir source code.

Link to this function merge(comments, ast)
merge([t], Macro.t) :: Macro.t

Merge the given comments into an Elixir abstract syntax tree.

iex> comments = [{:"#", [line: 1], []}]
...> ast = {:ok, [line: 1], []}
...> merge(comments, ast)
{:__block__, [], [{:ok, [line: 1], []}, {:"#", [line: 1], []}]}