Make aeso_compiler errors structured as well

This commit is contained in:
Hans Svensson
2019-09-05 14:20:40 +02:00
parent 37a37a169d
commit 5a1acd9d18
4 changed files with 113 additions and 57 deletions
+7 -4
View File
@@ -15,7 +15,8 @@
}).
-type pos() :: #pos{}.
-type error_type() :: type_error | parse_error | code_error | file_error | internal_error.
-type error_type() :: type_error | parse_error | code_error
| file_error | data_error | internal_error.
-record(err, { pos = #pos{} :: pos()
, type :: error_type()
@@ -71,9 +72,11 @@ str_pos(#pos{file = F, line = L, col = C}) ->
type(#err{ type = Type }) -> Type.
pp(#err{ pos = Pos } = Err) ->
lists:flatten(io_lib:format("~s\n~s", [pp_pos(Pos), msg(Err)])).
lists:flatten(io_lib:format("~s~s", [pp_pos(Pos), msg(Err)])).
pp_pos(#pos{file = no_file, line = 0, col = 0}) ->
"";
pp_pos(#pos{file = no_file, line = L, col = C}) ->
io_lib:format("At line ~p, col ~p:", [L, C]);
io_lib:format("At line ~p, col ~p:\n", [L, C]);
pp_pos(#pos{file = F, line = L, col = C}) ->
io_lib:format("In '~s' at line ~p, col ~p:", [F, L, C]).
io_lib:format("In '~s' at line ~p, col ~p:\n", [F, L, C]).