slepher / astranaut

traverse erlang ast and elixir macro in erlang.
MIT License
15 stars 0 forks source link

add attrs for -use_macro #3

Closed slepher closed 5 years ago

slepher commented 5 years ago

while import attributes is imported to macro extra argument Attributes is added to macro function while called. it includes all attributes of module mentioned in proplist key attrs

special attrs:

module: module use_macro

line: line where macro used

-module(a).
-behaviour(gen_server).
-use_macro({macro_a, macro/2, [{attrs, [module, line, behaviour]}]}).

hello() ->
  macro_a:macro(world).
-module(macro_a).
-export([macro/2]).

macro(Ast, #{module => Module, line => Line, behaviour => Behaviours} = Attributes) ->
   io:format("module is ~p, behaviour is ~p", [Module, Behaviours]),
   Ast.
slepher commented 5 years ago

done