Current section

Files

Jump to
squirrel src squirrel@internal@gleam.erl
Raw

src/squirrel@internal@gleam.erl

-module(squirrel@internal@gleam).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([value_identifier/1, value_identifier_to_string/1, type_identifier/1, type_identifier_to_string/1, value_identifier_to_type_identifier/1, type_identifier_to_value_identifier/1, try_make_enum/2, similar_value_identifier_string/1]).
-export_type([type/0, enum_variant/0, field/0, value_identifier/0, type_identifier/0]).
-type type() :: {list, type()} |
{option, type()} |
date |
timestamp |
bit_array |
int |
float |
bool |
string |
json |
uuid |
{enum,
binary(),
type_identifier(),
non_empty_list:non_empty_list(enum_variant())}.
-type enum_variant() :: {enum_variant, type_identifier(), binary()}.
-type field() :: {field, value_identifier(), type()}.
-opaque value_identifier() :: {value_identifier, binary()}.
-opaque type_identifier() :: {type_identifier, binary()}.
-spec to_value_identifier_rest(binary(), binary(), integer()) -> {ok,
value_identifier()} |
{error, squirrel@internal@error:value_identifier_error()}.
to_value_identifier_rest(Name, Rest, Position) ->
case Rest of
<<"a"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"b"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"c"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"d"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"e"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"f"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"g"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"h"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"i"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"j"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"k"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"l"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"m"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"n"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"o"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"p"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"q"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"r"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"s"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"t"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"u"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"v"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"w"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"x"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"y"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"z"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"_"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"0"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"1"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"2"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"3"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"4"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"5"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"6"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"7"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"8"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<"9"/utf8, Rest@1/binary>> ->
to_value_identifier_rest(Name, Rest@1, Position + 1);
<<""/utf8>> ->
{ok, {value_identifier, Name}};
_ ->
case gleam@string:pop_grapheme(Rest) of
{ok, {G, _}} ->
{error, {value_contains_invalid_grapheme, Position, G}};
{error, _} ->
erlang:error(#{gleam_error => panic,
message => <<"unreachable: empty identifier rest should be ok"/utf8>>,
module => <<"squirrel/internal/gleam"/utf8>>,
function => <<"to_value_identifier_rest"/utf8>>,
line => 174})
end
end.
-spec value_identifier(binary()) -> {ok, value_identifier()} |
{error, squirrel@internal@error:value_identifier_error()}.
value_identifier(Name) ->
case Name of
<<"a"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"b"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"c"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"d"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"e"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"f"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"g"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"h"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"i"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"j"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"k"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"l"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"m"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"n"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"o"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"p"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"q"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"r"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"s"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"t"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"u"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"v"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"w"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"x"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"y"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
<<"z"/utf8, Rest/binary>> ->
to_value_identifier_rest(Name, Rest, 1);
_ ->
case gleam@string:pop_grapheme(Name) of
{ok, {G, _}} ->
{error, {value_contains_invalid_grapheme, 0, G}};
{error, _} ->
{error, value_is_empty}
end
end.
-spec value_identifier_to_string(value_identifier()) -> binary().
value_identifier_to_string(Identifier) ->
{value_identifier, Name} = Identifier,
Name.
-spec to_type_identifier_rest(binary(), binary(), integer()) -> {ok,
type_identifier()} |
{error, squirrel@internal@error:type_identifier_error()}.
to_type_identifier_rest(Name, Rest, Position) ->
case Rest of
<<"a"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"b"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"c"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"d"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"e"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"f"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"g"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"h"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"i"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"j"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"k"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"l"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"m"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"n"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"o"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"p"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"q"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"r"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"s"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"t"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"u"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"v"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"w"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"x"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"y"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"z"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"A"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"B"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"C"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"D"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"E"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"F"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"G"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"H"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"I"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"J"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"K"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"L"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"M"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"N"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"O"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"P"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"Q"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"R"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"S"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"T"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"U"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"V"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"W"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"X"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"Y"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"Z"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"0"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"1"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"2"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"3"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"4"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"5"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"6"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"7"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"8"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<"9"/utf8, Rest@1/binary>> ->
to_type_identifier_rest(Name, Rest@1, Position + 1);
<<""/utf8>> ->
{ok, {type_identifier, Name}};
_ ->
case gleam@string:pop_grapheme(Rest) of
{ok, {G, _}} ->
{error, {type_contains_invalid_grapheme, Position, G}};
{error, _} ->
erlang:error(#{gleam_error => panic,
message => <<"unreachable: empty identifier rest should be ok"/utf8>>,
module => <<"squirrel/internal/gleam"/utf8>>,
function => <<"to_type_identifier_rest"/utf8>>,
line => 304})
end
end.
-spec type_identifier(binary()) -> {ok, type_identifier()} |
{error, squirrel@internal@error:type_identifier_error()}.
type_identifier(Name) ->
case Name of
<<"A"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"B"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"C"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"D"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"E"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"F"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"G"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"H"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"I"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"J"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"K"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"L"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"M"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"N"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"O"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"P"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"Q"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"R"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"S"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"T"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"U"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"V"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"W"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"X"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"Y"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
<<"Z"/utf8, Rest/binary>> ->
to_type_identifier_rest(Name, Rest, 1);
_ ->
case gleam@string:pop_grapheme(Name) of
{ok, {G, _}} ->
{error, {type_contains_invalid_grapheme, 0, G}};
{error, _} ->
{error, type_is_empty}
end
end.
-spec type_identifier_to_string(type_identifier()) -> binary().
type_identifier_to_string(Identifier) ->
{type_identifier, Name} = Identifier,
Name.
-spec value_identifier_to_type_identifier(value_identifier()) -> type_identifier().
value_identifier_to_type_identifier(Identifier) ->
{value_identifier, Name} = Identifier,
Type_identifier = begin
_pipe = justin:pascal_case(Name),
_pipe@1 = gleam@string:to_graphemes(_pipe),
_pipe@2 = gleam@list:filter(_pipe@1, fun(C) -> C /= <<"_"/utf8>> end),
gleam@string:join(_pipe@2, <<""/utf8>>)
end,
{type_identifier, Type_identifier}.
-spec type_identifier_to_value_identifier(type_identifier()) -> value_identifier().
type_identifier_to_value_identifier(Identifier) ->
{type_identifier, Name} = Identifier,
{value_identifier, justin:snake_case(Name)}.
-spec try_make_enum(binary(), list(binary())) -> {ok, type()} |
{error, squirrel@internal@error:enum_error()}.
try_make_enum(Raw_name, Variants) ->
gleam@result:'try'(
begin
_pipe = justin:pascal_case(Raw_name),
_pipe@1 = type_identifier(_pipe),
gleam@result:replace_error(_pipe@1, {invalid_enum_name, Raw_name})
end,
fun(Name) ->
{Variants@1, Errors} = gleam@result:partition(
(gleam@list:map(
Variants,
fun(Variant) ->
case type_identifier(justin:pascal_case(Variant)) of
{ok, Name@1} ->
{ok, {enum_variant, Name@1, Variant}};
{error, _} ->
{error, Variant}
end
end
))
),
case Errors of
[] ->
case non_empty_list:from_list(Variants@1) of
{ok, Variants@2} ->
{ok, {enum, Raw_name, Name, Variants@2}};
{error, _} ->
{error, enum_with_no_variants}
end;
_ ->
{error, {invalid_enum_variants, Errors}}
end
end
).
-spec is_digit(binary()) -> boolean().
is_digit(Char) ->
case Char of
<<"0"/utf8>> ->
true;
<<"1"/utf8>> ->
true;
<<"2"/utf8>> ->
true;
<<"3"/utf8>> ->
true;
<<"4"/utf8>> ->
true;
<<"5"/utf8>> ->
true;
<<"6"/utf8>> ->
true;
<<"7"/utf8>> ->
true;
<<"8"/utf8>> ->
true;
<<"9"/utf8>> ->
true;
_ ->
false
end.
-spec is_identifier_char(binary()) -> boolean().
is_identifier_char(Char) ->
case Char of
<<"a"/utf8>> ->
true;
<<"b"/utf8>> ->
true;
<<"c"/utf8>> ->
true;
<<"d"/utf8>> ->
true;
<<"e"/utf8>> ->
true;
<<"f"/utf8>> ->
true;
<<"g"/utf8>> ->
true;
<<"h"/utf8>> ->
true;
<<"i"/utf8>> ->
true;
<<"j"/utf8>> ->
true;
<<"k"/utf8>> ->
true;
<<"l"/utf8>> ->
true;
<<"m"/utf8>> ->
true;
<<"n"/utf8>> ->
true;
<<"o"/utf8>> ->
true;
<<"p"/utf8>> ->
true;
<<"q"/utf8>> ->
true;
<<"r"/utf8>> ->
true;
<<"s"/utf8>> ->
true;
<<"t"/utf8>> ->
true;
<<"u"/utf8>> ->
true;
<<"v"/utf8>> ->
true;
<<"w"/utf8>> ->
true;
<<"x"/utf8>> ->
true;
<<"y"/utf8>> ->
true;
<<"z"/utf8>> ->
true;
<<"_"/utf8>> ->
true;
<<"0"/utf8>> ->
true;
<<"1"/utf8>> ->
true;
<<"2"/utf8>> ->
true;
<<"3"/utf8>> ->
true;
<<"4"/utf8>> ->
true;
<<"5"/utf8>> ->
true;
<<"6"/utf8>> ->
true;
<<"7"/utf8>> ->
true;
<<"8"/utf8>> ->
true;
<<"9"/utf8>> ->
true;
_ ->
false
end.
-spec similar_value_identifier_string(binary()) -> {ok, binary()} | {error, nil}.
similar_value_identifier_string(String) ->
Proposal = begin
_pipe = gleam@string:trim(String),
_pipe@1 = justin:snake_case(_pipe),
_pipe@2 = gleam@string:to_graphemes(_pipe@1),
_pipe@3 = gleam@list:drop_while(
_pipe@2,
fun(G) -> (G =:= <<"_"/utf8>>) orelse is_digit(G) end
),
_pipe@4 = gleam@list:filter(_pipe@3, fun is_identifier_char/1),
gleam@string:join(_pipe@4, <<""/utf8>>)
end,
case Proposal of
<<""/utf8>> ->
{error, nil};
_ ->
{ok, Proposal}
end.