- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
-export([parse_transform/2, abstract/2]).
parse_transform(Forms, _Options) ->
normal(Forms).
normal({call, _Line, {atom, _, '$$'}, [Outer]}) ->
case Outer of
{'fun', _, {clauses, Quoted}} ->
%% Remove outer `fun' and only leave its clauses:
ok;
Quoted ->
%% A plain term has been quoted, leave it as is:
ok
end,
Result = abstract(Quoted),
%% io:format("Quoted block ~p~n", [Result]),
Result;
normal(L) when is_list(L) ->
lists:map(fun normal/1, L);
normal(T) when is_tuple(T) ->
list_to_tuple(lists:map(fun normal/1, tuple_to_list(T)));
normal(T) ->
T.
-define(line, 0).
%% @doc Create AST of the AST
abstract({call, _Line, {atom, _, '$'}, [Splice]}) ->
normal(Splice);
abstract(Orig = {var, Line, VarName}) ->
case lists:suffix("__AST", atom_to_list(VarName)) of
true ->
Orig;
false ->
{tuple, ?line, [ {atom, ?line, var}
, {integer, ?line, Line}
, {atom, ?line, VarName}
]}
end;
abstract(T) when is_tuple(T) ->
{tuple, ?line, lists:map(fun abstract/1, tuple_to_list(T))};
abstract([]) ->
{nil, ?line};
abstract([Hd|Tail]) ->
{cons, ?line, abstract(Hd), abstract(Tail)};
abstract(A) when is_atom(A) ->
{atom, ?line, A};
abstract(I) when is_integer(I) ->
{integer, ?line, I}.
CHayT 23.04.2021 14:34 # 0
CHayT 23.04.2021 14:43 # 0
JloJle4Ka 23.04.2021 15:28 # 0
Soul_re@ver 23.04.2021 16:17 # +2
CHayT 23.04.2021 16:22 # +1
bormand 23.04.2021 17:26 # 0
Какая гомоиконщина )))
CHayT 23.04.2021 19:37 # 0
Но всё равно лучше, чем крестошаблоны.