Current section
Files
Jump to
Current section
Files
src/gbr@shared@toml.erl
-module(gbr@shared@toml).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src\\gbr\\shared\\toml.gleam").
-export([get_string/2, parse/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
"\n"
" Gleam shared file toml parser.\n"
"\n"
).
-file("src\\gbr\\shared\\toml.gleam", 65).
-spec join_key(list(binary())) -> binary().
join_key(Key) ->
gleam@string:join(Key, <<"."/utf8>>).
-file("src\\gbr\\shared\\toml.gleam", 43).
-spec tom_error_get(tom:get_error()) -> binary().
tom_error_get(Err) ->
case Err of
{not_found, Key} ->
<<<<"Error not found key '"/utf8, (join_key(Key))/binary>>/binary,
"'"/utf8>>;
{wrong_type, Key@1, Expected, Got} ->
<<<<<<<<<<"Error wrong type key '"/utf8, (join_key(Key@1))/binary>>/binary,
"' type="/utf8>>/binary,
Expected/binary>>/binary,
" got="/utf8>>/binary,
Got/binary>>
end.
-file("src\\gbr\\shared\\toml.gleam", 31).
?DOC(
" Get name from toml file.\n"
"\n"
" - `file` The string/path location of toml file.\n"
).
-spec get_string(gleam@dict:dict(binary(), tom:toml()), list(binary())) -> {ok,
binary()} |
{error, binary()}.
get_string(Toml, Key) ->
gleam@result:map(
begin
_pipe = tom:get_string(Toml, Key),
gleam@result:map_error(_pipe, fun tom_error_get/1)
end,
fun(Name) -> Name end
).
-file("src\\gbr\\shared\\toml.gleam", 56).
-spec tom_error_parse(tom:parse_error()) -> binary().
tom_error_parse(Err) ->
case Err of
{key_already_in_use, Key} ->
<<<<"Error parser already in use key '"/utf8,
(join_key(Key))/binary>>/binary,
"'"/utf8>>;
{unexpected, Got, Expected} ->
<<<<<<"Error parser unexpected char="/utf8, Got/binary>>/binary,
" expected="/utf8>>/binary,
Expected/binary>>
end.
-file("src\\gbr\\shared\\toml.gleam", 18).
?DOC(
" Parse toml file.\n"
"\n"
" - `file` The string/path location of toml file.\n"
).
-spec parse(binary()) -> {ok, gleam@dict:dict(binary(), tom:toml())} |
{error, binary()}.
parse(File) ->
gleam@result:map(
begin
_pipe = tom:parse(File),
gleam@result:map_error(_pipe, fun tom_error_parse/1)
end,
fun(Parsed) -> Parsed end
).