Skip to content

Commit dcae8bd

Browse files
committed
#189 macro processing
1 parent 172d658 commit dcae8bd

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

rebar.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
{lager, {git, "https://github.com/K2InformaticsGmbH/lager.git", {tag, "3.4.2"}}},
4343
{ranch, {git, "https://github.com/K2InformaticsGmbH/ranch.git", {tag, "1.3.2"}}},
4444
{sext, {git, "https://github.com/K2InformaticsGmbH/sext.git", {tag, "1.4.1"}}},
45-
{sqlparse, {git, "https://github.com/K2InformaticsGmbH/sqlparse.git", {branch, "master"}}}
45+
{sqlparse, {git, "https://github.com/K2InformaticsGmbH/sqlparse.git", {branch, "master"}}},
46+
{aleppo, {git, "https://github.com/K2InformaticsGmbH/aleppo", {tag, "v0.9.3"}}}
4647
]}.
4748

4849
{erl_first_files, ["src/imem_rec_pretty_pt.erl"]}.

src/imem.app.src

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
lager,
1717
ranch,
1818
sext,
19-
sqlparse
19+
sqlparse,
20+
aleppo
2021
]},
2122
{env, [
2223
{erl_cluster_mgrs, []},

src/imem_compiler.erl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,8 @@ nonLocalHFun({Mod, Fun} = FSpec, Args, SafeFuns) ->
138138
compile_mod(ModuleCodeBinStr) -> compile_mod(ModuleCodeBinStr, [], []).
139139
compile_mod(ModuleCodeBinStr, Opts) -> compile_mod(ModuleCodeBinStr, [], Opts).
140140
compile_mod(ModuleCodeBinStr, Restrict, Opts) when is_binary(ModuleCodeBinStr) ->
141-
case erl_scan:string(binary_to_list(ModuleCodeBinStr)) of
142-
{ok, Tokens, _} ->
143-
TokenGroups = cut_dot(Tokens),
141+
case tokenize(ModuleCodeBinStr) of
142+
{ok, TokenGroups} ->
144143
case lists:foldl(
145144
fun(TokenGroup, Acc) when is_list(Acc) ->
146145
case erl_parse:parse_form(TokenGroup) of
@@ -169,6 +168,20 @@ compile_mod(ModuleCodeBinStr, Restrict, Opts) when is_binary(ModuleCodeBinStr) -
169168
end;
170169
Error -> Error
171170
end;
171+
Error -> Error
172+
end.
173+
174+
tokenize(ModuleCodeBinStr) ->
175+
case erl_scan:string(binary_to_list(ModuleCodeBinStr), {0,1}) of
176+
{ok, RawTokens, _} ->
177+
case aleppo:process_tokens(RawTokens) of
178+
{ok, TokensEOF} ->
179+
[{eof,_} | RevTokens] = lists:reverse(TokensEOF),
180+
Tokens = lists:reverse(RevTokens),
181+
{ok, cut_dot(Tokens)};
182+
{error, Error} ->
183+
{error, {preprocess, {{0, 1}, ?MODULE, Error}, {0, 1}}}
184+
end;
172185
{error, ErrorInfo, ErrorLocation} ->
173186
{error, {scan, ErrorInfo, ErrorLocation}}
174187
end.
@@ -185,10 +198,11 @@ error_info(Type, [{_, _, _} = ErrorInfo | ErrorInfos]) ->
185198
[error_info(Type, ErrorInfo) | error_info(Type, ErrorInfos)];
186199
error_info(Type, [{_,ErrorInfos}|Tail]) ->
187200
error_info(Type, ErrorInfos) ++ error_info(Type, Tail);
188-
error_info(Type, {Line, Module, ErrorDesc}) ->
201+
error_info(Type, {{Line, Column}, Module, ErrorDesc}) ->
189202
#{
190203
type => Type,
191204
row => Line,
205+
col => Column,
192206
text => list_to_binary(Module:format_error(ErrorDesc))
193207
}.
194208

0 commit comments

Comments
 (0)