Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

erl_syntax simple function

By: a guest on Mar 13th, 2013  |  syntax: Erlang  |  size: 0.89 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -module(esyntax).
  2. -compile(export_all).
  3.  
  4. f() ->
  5.         FunctionBuilder = function_builder(get_send_msg_info),
  6.         ClauseBuilder = clause_builder([], none),
  7.         FunctionBuilder([ClauseBuilder([erl_syntax:atom(abz)])]).
  8.  
  9. function_builder(FunctionName) ->
  10.         fun(Clauses) when is_list(Clauses) ->
  11.                         erl_syntax:function(erl_syntax:atom(FunctionName), Clauses)
  12.         end.
  13.  
  14. clause_builder(Patterns, Guard) ->
  15.         fun(Body) when is_list(Body) ->
  16.                         erl_syntax:clause(Patterns, Guard, Body)
  17.         end.
  18.  
  19. %%%%%%%%%%%%%
  20.  
  21. 102> SyntaxTree = esyntax:f().
  22. {tree,function,
  23.       {attr,0,[],none},
  24.       {function,{tree,atom,{attr,0,[],none},get_send_msg_info},
  25.                 [{tree,clause,
  26.                        {attr,0,[],none},
  27.                        {clause,[],none,[{tree,atom,{attr,0,[],none},abz}]}}]}}
  28. 103> erl_syntax:revert(SyntaxTree).
  29. {function,0,get_send_msg_info,0,
  30.           [{clause,0,[],[],[{atom,0,abz}]}]}