Current section

Files

Jump to
roundabout src roundabout@internal@common.erl
Raw

src/roundabout@internal@common.erl

-module(roundabout@internal@common).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/roundabout/internal/common.gleam").
-export([string_join/0, pipe_join/0, case_arrow/0, generate_function_name/2, generate_type_name/2, segment_to_param/1, get_function_arguments/2]).
-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(false).
-file("src/roundabout/internal/common.gleam", 19).
?DOC(false).
-spec string_join() -> glam@doc:document().
string_join() ->
_pipe = glam@doc:flex_break(<<" "/utf8>>, <<""/utf8>>),
glam@doc:append(_pipe, glam@doc:from_string(<<"<> "/utf8>>)).
-file("src/roundabout/internal/common.gleam", 24).
?DOC(false).
-spec pipe_join() -> glam@doc:document().
pipe_join() ->
_pipe = glam@doc:flex_break(<<" "/utf8>>, <<""/utf8>>),
glam@doc:append(_pipe, glam@doc:from_string(<<"|> "/utf8>>)).
-file("src/roundabout/internal/common.gleam", 29).
?DOC(false).
-spec case_arrow() -> glam@doc:document().
case_arrow() ->
_pipe = glam@doc:from_string(<<" ->"/utf8>>),
glam@doc:append(_pipe, glam@doc:flex_break(<<" "/utf8>>, <<""/utf8>>)).
-file("src/roundabout/internal/common.gleam", 68).
?DOC(false).
-spec qualify(
roundabout@internal@ancestors:ancestors(roundabout@internal@name:name()),
roundabout@internal@name:name(),
roundabout@internal@name:as_name()
) -> binary().
qualify(Ancestors, Node, Using) ->
To_name = case Using of
as_parameter_name ->
fun roundabout@internal@name:parameter_name/1;
as_type_name ->
fun roundabout@internal@name:type_name/1
end,
Join = case Using of
as_parameter_name ->
<<"_"/utf8>>;
as_type_name ->
<<""/utf8>>
end,
_pipe = Ancestors,
_pipe@1 = roundabout@internal@ancestors:filter(
_pipe,
fun(A) -> not roundabout@internal@name:is_root(A) end
),
_pipe@2 = roundabout@internal@ancestors:push(_pipe@1, Node),
_pipe@3 = roundabout@internal@ancestors:map(_pipe@2, To_name),
_pipe@4 = roundabout@internal@ancestors:to_list(_pipe@3),
gleam@string:join(_pipe@4, Join).
-file("src/roundabout/internal/common.gleam", 36).
?DOC(false).
-spec generate_function_name(
roundabout@internal@ancestors:ancestors(roundabout@internal@node:info()),
roundabout@internal@node:info()
) -> binary().
generate_function_name(Ancestors, Info) ->
Ancestors@1 = roundabout@internal@ancestors:map(
Ancestors,
fun(A) -> erlang:element(2, A) end
),
qualify(Ancestors@1, erlang:element(2, Info), as_parameter_name).
-file("src/roundabout/internal/common.gleam", 46).
?DOC(false).
-spec generate_type_name(
roundabout@internal@ancestors:ancestors(roundabout@internal@node:info()),
roundabout@internal@node:info()
) -> binary().
generate_type_name(Ancestors, Info) ->
Ancestors@1 = roundabout@internal@ancestors:map(
Ancestors,
fun(A) -> erlang:element(2, A) end
),
qualify(Ancestors@1, erlang:element(2, Info), as_type_name).
-file("src/roundabout/internal/common.gleam", 91).
?DOC(false).
-spec segment_to_param(roundabout@internal@node:segment()) -> {ok,
roundabout@internal@parameter:parameter(roundabout@internal@qualified:unqualified())} |
{error, nil}.
segment_to_param(Segment) ->
case Segment of
{seg_fixed, _} ->
{error, nil};
{seg_param, Param} ->
{ok, Param}
end.
-file("src/roundabout/internal/common.gleam", 109).
?DOC(false).
-spec get_function_arguments_rec(
roundabout@internal@ancestors:ancestors(roundabout@internal@node:info()),
list(roundabout@internal@parameter:parameter(roundabout@internal@qualified:qualified())),
roundabout@internal@node:info()
) -> list(roundabout@internal@parameter:parameter(roundabout@internal@qualified:qualified())).
get_function_arguments_rec(Ancestors, Acc, Info) ->
Ancestors_names = roundabout@internal@ancestors:map(
Ancestors,
fun(A) -> erlang:element(2, A) end
),
New_params = begin
_pipe = erlang:element(3, Info),
_pipe@1 = gleam@list:filter_map(_pipe, fun segment_to_param/1),
gleam@list:map(
_pipe@1,
fun(_capture) ->
roundabout@internal@parameter:qualify_name(
Ancestors_names,
erlang:element(2, Info),
_capture
)
end
)
end,
Next_acc = lists:append(New_params, Acc),
case roundabout@internal@ancestors:pop(Ancestors) of
{ok, {Next_ancestor, Rest_ancestors}} ->
get_function_arguments_rec(Rest_ancestors, Next_acc, Next_ancestor);
{error, _} ->
Next_acc
end.
-file("src/roundabout/internal/common.gleam", 102).
?DOC(false).
-spec get_function_arguments(
roundabout@internal@ancestors:ancestors(roundabout@internal@node:info()),
roundabout@internal@node:info()
) -> list(roundabout@internal@parameter:parameter(roundabout@internal@qualified:qualified())).
get_function_arguments(Ancestors, Info) ->
get_function_arguments_rec(Ancestors, [], Info).