Created
February 11, 2013 11:02
-
-
Save ricston-git/4753865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(blog). | |
-compile(export_all). | |
transform(Forms) -> | |
Tree = erl_syntax:form_list(Forms), | |
ModifiedTree = postorder(Fun, Tree), | |
erl_syntax:revert_forms(ModifiedTree). | |
parse_transform(Forms, Options) -> | |
TransFun = | |
case lists:keysearch(trans_fun, 1, Options) of | |
{value, {trans_fun, Fun}} -> | |
Fun; | |
false -> | |
fun blog:replaceSend/1 | |
end, | |
transform(Forms, Fun). | |
replaceSend(Node) -> | |
case erl_syntax:type(Node) of | |
infix_expr -> | |
OpNode = erl_syntax:infix_expr_operator(Node), | |
case erl_syntax:operator_name(OpNode) of | |
'!' -> | |
erl_syntax:block_expr([ | |
erl_syntax:application( | |
erl_syntax:module_qualifier(erl_syntax:atom(io), erl_syntax:atom(format)),[erl_syntax:string("About to send:~n")]), | |
Node | |
]); | |
_ -> | |
Node | |
end; | |
_ -> | |
Node | |
end. | |
postorder(F, Tree) -> | |
F(case erl_syntax:subtrees(Tree) of | |
[] -> Tree; | |
List -> erl_syntax:update_tree(Tree, | |
[[postorder(F, Subtree) | |
|| Subtree <- Group] | |
|| Group <- List]) | |
end). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment