Current section

Files

Jump to
eyg_parser src eyg@parser@debug.erl
Raw

src/eyg@parser@debug.erl

-module(eyg@parser@debug).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/eyg/parser/debug.gleam").
-export([describe/1, hint/1]).
-file("src/eyg/parser/debug.gleam", 6).
-spec describe(eyg@parser@parser:reason()) -> binary().
describe(Reason) ->
case Reason of
{unexpected_token, Token, Position} ->
<<<<<<"unexpected `"/utf8,
(eyg@parser@token:to_string(Token))/binary>>/binary,
"` at position "/utf8>>/binary,
(erlang:integer_to_binary(Position))/binary>>;
unexpect_end ->
<<"unexpected end of input"/utf8>>;
{invalid_character, Char, Position@1} ->
<<<<<<"invalid character '"/utf8, Char/binary>>/binary,
"' at position "/utf8>>/binary,
(erlang:integer_to_binary(Position@1))/binary>>;
{unterminated_string_literal, Position@2} ->
<<"unterminated string literal at position "/utf8,
(erlang:integer_to_binary(Position@2))/binary>>;
{invalid_escape_sequence, Escape_char, Position@3} ->
<<<<<<"invalid escape sequence `\\"/utf8, Escape_char/binary>>/binary,
"` in string at position "/utf8>>/binary,
(erlang:integer_to_binary(Position@3))/binary>>;
{missing_equals, Position@4} ->
<<"expected `=` after let binding name at position "/utf8,
(erlang:integer_to_binary(Position@4))/binary>>;
{missing_arrow, Position@5} ->
<<"expected `->` followed by `{` in function definition at position "/utf8,
(erlang:integer_to_binary(Position@5))/binary>>;
{unclosed_function_body, Open_at} ->
<<"unclosed function body — expected `}` to close the `{` opened at position "/utf8,
(erlang:integer_to_binary(Open_at))/binary>>;
{expected_effect_name, Keyword, Position@6} ->
<<<<<<"expected an uppercase effect name after `"/utf8,
Keyword/binary>>/binary,
"` at position "/utf8>>/binary,
(erlang:integer_to_binary(Position@6))/binary>>;
{expected_builtin_name, Position@7} ->
<<"expected a builtin identifier after `!` at position "/utf8,
(erlang:integer_to_binary(Position@7))/binary>>;
{invalid_cid_reference, Position@8} ->
<<"invalid content identifier (CID) at position "/utf8,
(erlang:integer_to_binary(Position@8))/binary>>;
{invalid_release_version, Position@9} ->
<<"expected an integer release version after `:` at position "/utf8,
(erlang:integer_to_binary(Position@9))/binary>>;
{invalid_import_path, Position@10} ->
<<"expected a string path after `import` at position "/utf8,
(erlang:integer_to_binary(Position@10))/binary>>;
{trailing_tokens, Token@1, Position@11} ->
Token_str = case Token@1 of
{unexpected_grapheme, Raw} ->
gleam@string:slice(Raw, 0, 1);
_ ->
eyg@parser@token:to_string(Token@1)
end,
<<<<<<<<"unexpected `"/utf8, Token_str/binary>>/binary,
"` at position "/utf8>>/binary,
(erlang:integer_to_binary(Position@11))/binary>>/binary,
" — the expression is complete but there are leftover tokens"/utf8>>
end.
-file("src/eyg/parser/debug.gleam", 65).
-spec hint(eyg@parser@parser:reason()) -> binary().
hint(Reason) ->
case Reason of
{unexpected_token, _, _} ->
<<"view the syntax guide"/utf8>>;
unexpect_end ->
<<"program must end with valid expression"/utf8>>;
{invalid_character, _, _} ->
<<"remove or replace this character — EYG does not use it"/utf8>>;
{unterminated_string_literal, _} ->
<<"close the string with a double-quote `\"`"/utf8>>;
{invalid_escape_sequence, _, _} ->
<<"valid escapes are \\n (newline), \\t (tab), \\r (carriage return), \\\" (quote), \\\\ (backslash)"/utf8>>;
{missing_equals, _} ->
<<"let bindings use the form `let name = expression`"/utf8>>;
{missing_arrow, _} ->
<<"functions are written as `(arg) -> { body }`"/utf8>>;
{unclosed_function_body, _} ->
<<"every `{` in a function body must be closed with `}`"/utf8>>;
{expected_effect_name, Keyword, _} ->
<<<<"effect names must start with an uppercase letter, e.g. `"/utf8,
Keyword/binary>>/binary,
" Log`"/utf8>>;
{expected_builtin_name, _} ->
<<"builtins use lowercase names, e.g. `!int_add`"/utf8>>;
{invalid_cid_reference, _} ->
<<"CID references use a valid base32-encoded CID, e.g. `#bafyreig...`"/utf8>>;
{invalid_release_version, _} ->
<<"pin a release with `@package:N` (e.g. `@tandard:3`) or omit `:` to track the latest"/utf8>>;
{invalid_import_path, _} ->
<<"import paths must be string literals, e.g. `import \"./module.eyg.json\"`"/utf8>>;
{trailing_tokens, Token, _} ->
case Token of
'let' ->
<<"the previous expression already completed the block. If you meant the block to continue, bind that expression to `let _ = ...` first."/utf8>>;
_ ->
<<"EYG uses function calls for operations (e.g. !int_add(a, b)), not infix operators"/utf8>>
end
end.