Skip to content

Commit

Permalink
Merge pull request #46 from inaka/elbrujohalcon.41.ktn_dodger_can_t_p…
Browse files Browse the repository at this point in the history
…arse_stringi

[Fix #41] Parse stringyfied macros
  • Loading branch information
elbrujohalcon committed Nov 14, 2020
2 parents f857ab4 + 91317ee commit 9ae6f99
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/ktn_dodger.erl
Expand Up @@ -870,16 +870,32 @@ fix_form([{atom, _, ?pp_form}, {'(', _}, {')', _}, {'->', _},
{atom, _, define}, {'(', _} | _]=Ts) ->
case lists:reverse(Ts) of
[{dot, _}, {')', _} | _] ->
{retry, Ts, fun fix_define/1};
{retry, Ts, fun fix_stringyfied_macros/1};
[{dot, L} | Ts1] ->
Ts2 = lists:reverse([{dot, L}, {')', L} | Ts1]),
{retry, Ts2, fun fix_define/1};
{retry, Ts2, fun fix_stringyfied_macros/1};
_ ->
error
end;
fix_form(_Ts) ->
error.

fix_stringyfied_macros(Ts) ->
{retry, fix_stringyfied_macros(Ts, []), fun fix_define/1}.

fix_stringyfied_macros([], Ts) -> lists:reverse(Ts);
fix_stringyfied_macros([{'?', Pos}, {atom, Pos, MacroName} | Rest], Ts) ->
NextTs =
case atom_to_list(MacroName) of
?var_prefix ++ Name ->
[{atom, Pos, list_to_atom(?var_prefix ++ [$?|Name])} | Ts];
_ ->
[{atom, Pos, MacroName}, {'?', Pos} | Ts]
end,
fix_stringyfied_macros(Rest, NextTs);
fix_stringyfied_macros([Other|Rest], Ts) ->
fix_stringyfied_macros(Rest, [Other|Ts]).

fix_define([{atom, L, ?pp_form}, {'(', _}, {')', _}, {'->', _},
{atom, La, define}, {'(', _}, N, {',', _} | Ts]) ->
[{dot, _}, {')', _} | Ts1] = lists:reverse(Ts),
Expand Down

0 comments on commit 9ae6f99

Please sign in to comment.