Skip to content

Instantly share code, notes, and snippets.

@krainboltgreene
Created April 27, 2020 03:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krainboltgreene/a49b6a0359c51a071e90847aee2ea3d1 to your computer and use it in GitHub Desktop.
Save krainboltgreene/a49b6a0359c51a071e90847aee2ea3d1 to your computer and use it in GitHub Desktop.
@spec as_ast(%{
body: binary,
declaration: bitstring,
documentation: bitstring,
elixir_module: %{documentation: bitstring, slug: bitstring},
elixir_typespec: %{inputs: bitstring, return: bitstring},
guards: binary,
inputs: bitstring,
name: bitstring,
slug: integer,
version: integer
}) :: {:defmodule, [], [[{any, any}, ...] | {:__aliases__, [], [...]}, ...]}
def as_ast(
%{
declaration: declaration,
documentation: documentation,
elixir_typespec: %{
inputs: elixir_typespec_inputs,
return: elixir_typespec_return
},
guards: guards,
inputs: inputs,
name: name,
body: body,
elixir_module: %{
slug: elixir_module_slug,
documentation: elixir_module_documentation,
},
slug: slug,
version: version,
})
when
is_bitstring(declaration)
and
is_bitstring(documentation)
and
is_bitstring(elixir_typespec_inputs)
and
is_bitstring(elixir_typespec_return)
and
is_bitstring(guards)
and
is_bitstring(inputs)
and
is_bitstring(name)
and
is_bitstring(body)
and
is_bitstring(elixir_module_slug)
and
is_bitstring(elixir_module_documentation)
and
is_integer(slug)
and
is_integer(version)
do
{
:defmodule,
[],
[
{:__aliases__, [], [String.to_atom(elixir_module_slug)]},
[
do: {:__block__, [],
[
{:@, [], [{:moduledoc, [], [elixir_module_documentation]}]},
{:@, [], [{:doc, [], [documentation]}]},
{:@, [], [{:spec, [], [{:"::", [], [{String.to_atom(slug), [], [elixir_typespec_inputs]}, elixir_typespec_return]}]}]},
{declaration, [], [{:when, [], [guards |> to_quote]}, [do: body |> to_quote]]}
]}
]
]}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment