SHARE
TWEET

erl_syntax simple function

a guest Mar 13th, 2013 38 Never
  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}]}]}
RAW Paste Data
Top