Skip to content

Commit

Permalink
#189 macro processing
Browse files Browse the repository at this point in the history
  • Loading branch information
c-bik committed Apr 18, 2018
1 parent 172d658 commit dcae8bd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
{lager, {git, "https://github.com/K2InformaticsGmbH/lager.git", {tag, "3.4.2"}}},
{ranch, {git, "https://github.com/K2InformaticsGmbH/ranch.git", {tag, "1.3.2"}}},
{sext, {git, "https://github.com/K2InformaticsGmbH/sext.git", {tag, "1.4.1"}}},
{sqlparse, {git, "https://github.com/K2InformaticsGmbH/sqlparse.git", {branch, "master"}}}
{sqlparse, {git, "https://github.com/K2InformaticsGmbH/sqlparse.git", {branch, "master"}}},
{aleppo, {git, "https://github.com/K2InformaticsGmbH/aleppo", {tag, "v0.9.3"}}}
]}.

{erl_first_files, ["src/imem_rec_pretty_pt.erl"]}.
Expand Down
3 changes: 2 additions & 1 deletion src/imem.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
lager,
ranch,
sext,
sqlparse
sqlparse,
aleppo
]},
{env, [
{erl_cluster_mgrs, []},
Expand Down
22 changes: 18 additions & 4 deletions src/imem_compiler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ nonLocalHFun({Mod, Fun} = FSpec, Args, SafeFuns) ->
compile_mod(ModuleCodeBinStr) -> compile_mod(ModuleCodeBinStr, [], []).
compile_mod(ModuleCodeBinStr, Opts) -> compile_mod(ModuleCodeBinStr, [], Opts).
compile_mod(ModuleCodeBinStr, Restrict, Opts) when is_binary(ModuleCodeBinStr) ->
case erl_scan:string(binary_to_list(ModuleCodeBinStr)) of
{ok, Tokens, _} ->
TokenGroups = cut_dot(Tokens),
case tokenize(ModuleCodeBinStr) of
{ok, TokenGroups} ->
case lists:foldl(
fun(TokenGroup, Acc) when is_list(Acc) ->
case erl_parse:parse_form(TokenGroup) of
Expand Down Expand Up @@ -169,6 +168,20 @@ compile_mod(ModuleCodeBinStr, Restrict, Opts) when is_binary(ModuleCodeBinStr) -
end;
Error -> Error
end;
Error -> Error
end.

tokenize(ModuleCodeBinStr) ->
case erl_scan:string(binary_to_list(ModuleCodeBinStr), {0,1}) of
{ok, RawTokens, _} ->
case aleppo:process_tokens(RawTokens) of
{ok, TokensEOF} ->
[{eof,_} | RevTokens] = lists:reverse(TokensEOF),
Tokens = lists:reverse(RevTokens),
{ok, cut_dot(Tokens)};
{error, Error} ->
{error, {preprocess, {{0, 1}, ?MODULE, Error}, {0, 1}}}
end;
{error, ErrorInfo, ErrorLocation} ->
{error, {scan, ErrorInfo, ErrorLocation}}
end.
Expand All @@ -185,10 +198,11 @@ error_info(Type, [{_, _, _} = ErrorInfo | ErrorInfos]) ->
[error_info(Type, ErrorInfo) | error_info(Type, ErrorInfos)];
error_info(Type, [{_,ErrorInfos}|Tail]) ->
error_info(Type, ErrorInfos) ++ error_info(Type, Tail);
error_info(Type, {Line, Module, ErrorDesc}) ->
error_info(Type, {{Line, Column}, Module, ErrorDesc}) ->
#{
type => Type,
row => Line,
col => Column,
text => list_to_binary(Module:format_error(ErrorDesc))
}.

Expand Down

0 comments on commit dcae8bd

Please sign in to comment.