-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaero_errors.erl
38 lines (31 loc) · 1.2 KB
/
aero_errors.erl
1
2
3
4
5
6
7
8
9
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
%%% Displays various errors from the compiler.
-module(aero_errors).
-export([format_error/1]).
%% -----------------------------------------------------------------------------
%% Public API
%% -----------------------------------------------------------------------------
-spec format_error(term()) -> binary().
format_error(Error) ->
Message =
case message(Error) of
{Format, Args} -> lists:flatten(io_lib:fwrite(Format, [io_lib:write(T) || T <- Args]));
Format -> Format
end,
list_to_binary(Message).
%% -----------------------------------------------------------------------------
%% Helper Functions
%% -----------------------------------------------------------------------------
%% Parser messages.
message(no_tokens) ->
"no tokens provided to parser, at least EOF is required";
message({unexpected_token, Found}) ->
{"unexpected token '~p'", [Found]};
message({expected_token, Expected, Found}) ->
{"expected token '~p', found token '~p'", [Expected, Found]};
message({expected_token, Expected}) ->
{"expected token '~p'", [Expected]};
message({nonassoc_op, Op}) ->
{"operator token '~p' is not associative", [Op]};
%% Anything else...
message(_) ->
"unknown error".