Skip to content

Instantly share code, notes, and snippets.

@djui
Created October 1, 2012 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djui/3814369 to your computer and use it in GitHub Desktop.
Save djui/3814369 to your computer and use it in GitHub Desktop.
create Erlang Modules
-define(A(A), erl_syntax:atom(A)).
-define(I(I), erl_syntax:integer(I)).
-define(S(S), erl_syntax:string(S)).
-define(V(V), erl_syntax:variable(V)).
s_f(N, P, B) -> erl_syntax:function(N, erl_syntax:clause(P, [], B)).
s_c(M, F, A) -> [erl_syntax:application(?A(M), ?A(F), [A])].
s_m(M) -> s_d(module, [?A(M)]).
s_i(P) -> s_d(include, [?S(P)]).
s_e(E) ->
Exports = [erl_syntax:arity_qualifier(?A(F), ?I(A)) || {F,A} <- E],
s_d(export, [erl_syntax:list(Exports)]).
s_d(K, V) -> erl_syntax:attribute(?A(K), V).
s_c(C) -> erl_syntax:comment(C).
pretty_print(ST) ->
{text, S} = erl_prettypr:best(ST),
S.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment