Current section
Files
Jump to
Current section
Files
src/internal@codegen@types.erl
-module(internal@codegen@types).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/internal/codegen/types.gleam").
-export([nil/0, int/0, variant_type/2, variant/2, field/2, option/1, result/2, function/2, generate_type/1, generate_type_def/1]).
-export_type([gleam_type/0, variant/0, field/0]).
-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).
-type gleam_type() :: {anonymous_type, binary()} |
nil_type |
int_type |
{tuple_type, list(gleam_type())} |
{list_type, gleam_type()} |
{variant_type, binary(), list(variant())} |
{variant_dep_type, binary(), list(gleam_type()), list(variant())} |
{function_type, list(gleam_type()), gleam_type()}.
-type variant() :: {variant, binary(), list(field())}.
-type field() :: {field, binary(), gleam_type()}.
-file("src/internal/codegen/types.gleam", 27).
?DOC(false).
-spec nil() -> gleam_type().
nil() ->
nil_type.
-file("src/internal/codegen/types.gleam", 31).
?DOC(false).
-spec int() -> gleam_type().
int() ->
int_type.
-file("src/internal/codegen/types.gleam", 35).
?DOC(false).
-spec variant_type(binary(), list(variant())) -> gleam_type().
variant_type(Name, Variants) ->
{variant_type, Name, Variants}.
-file("src/internal/codegen/types.gleam", 39).
?DOC(false).
-spec variant(binary(), list(field())) -> variant().
variant(Name, Fields) ->
{variant, Name, Fields}.
-file("src/internal/codegen/types.gleam", 43).
?DOC(false).
-spec field(binary(), gleam_type()) -> field().
field(Name, Field_type) ->
{field, Name, Field_type}.
-file("src/internal/codegen/types.gleam", 47).
?DOC(false).
-spec option(gleam_type()) -> gleam_type().
option(Some_type) ->
{variant_dep_type,
<<"Option"/utf8>>,
[Some_type],
[variant(<<"Some"/utf8>>, [field(<<"some"/utf8>>, Some_type)]),
variant(<<"Error"/utf8>>, [])]}.
-file("src/internal/codegen/types.gleam", 54).
?DOC(false).
-spec result(gleam_type(), gleam_type()) -> gleam_type().
result(Ok_type, Error_type) ->
{variant_dep_type,
<<"Result"/utf8>>,
[Ok_type, Error_type],
[variant(<<"Ok"/utf8>>, [field(<<"ok"/utf8>>, Ok_type)]),
variant(<<"Error"/utf8>>, [field(<<"error"/utf8>>, Error_type)])]}.
-file("src/internal/codegen/types.gleam", 61).
?DOC(false).
-spec function(list(gleam_type()), gleam_type()) -> gleam_type().
function(Argument_types, Result_type) ->
{function_type, Argument_types, Result_type}.
-file("src/internal/codegen/types.gleam", 124).
?DOC(false).
-spec generate_type(gleam_type()) -> binary().
generate_type(Arg_type) ->
case Arg_type of
{anonymous_type, Name} ->
Name;
nil_type ->
<<"Nil"/utf8>>;
int_type ->
<<"Int"/utf8>>;
{list_type, List_type} ->
<<<<"List("/utf8, (generate_type_def(List_type))/binary>>/binary,
")"/utf8>>;
{variant_dep_type, Name@1, Dep_types, _} ->
<<<<<<Name@1/binary, "("/utf8>>/binary,
(begin
_pipe = Dep_types,
_pipe@1 = gleam@list:map(_pipe, fun generate_type/1),
gleam@string:join(_pipe@1, <<", "/utf8>>)
end)/binary>>/binary,
")"/utf8>>;
{tuple_type, Els} ->
generate_type_def({tuple_type, Els});
{variant_type, Name@2, _} ->
Name@2;
{function_type, Args, Result} ->
<<<<<<"fn("/utf8,
(begin
_pipe@2 = Args,
_pipe@3 = gleam@list:map(
_pipe@2,
fun generate_type/1
),
gleam@string:join(_pipe@3, <<", "/utf8>>)
end)/binary>>/binary,
") -> "/utf8>>/binary,
(generate_type(Result))/binary>>
end.
-file("src/internal/codegen/types.gleam", 69).
?DOC(false).
-spec generate_type_def(gleam_type()) -> binary().
generate_type_def(Gleam_type) ->
case Gleam_type of
{anonymous_type, Name} ->
Name;
nil_type ->
<<""/utf8>>;
int_type ->
<<""/utf8>>;
{list_type, List_type} ->
<<<<"List("/utf8, (generate_type_def(List_type))/binary>>/binary,
")"/utf8>>;
{tuple_type, Elements} ->
<<<<"#("/utf8,
(begin
_pipe = gleam@list:map(
Elements,
fun generate_type_def/1
),
gleam@string:join(_pipe, <<", "/utf8>>)
end)/binary>>/binary,
")"/utf8>>;
{variant_dep_type, Name@1, Dep_types, Variants} ->
<<<<<<<<<<<<"pub type "/utf8, Name@1/binary>>/binary, "("/utf8>>/binary,
(begin
_pipe@1 = Dep_types,
_pipe@2 = gleam@list:map(
_pipe@1,
fun generate_type_def/1
),
gleam@string:join(_pipe@2, <<", "/utf8>>)
end)/binary>>/binary,
") {\n"/utf8>>/binary,
(begin
_pipe@3 = Variants,
_pipe@4 = gleam@list:map(
_pipe@3,
fun generate_variant/1
),
gleam@string:join(_pipe@4, <<"\n"/utf8>>)
end)/binary>>/binary,
"\n}"/utf8>>;
{variant_type, Name@2, Variants@1} ->
<<<<<<<<"pub type "/utf8, Name@2/binary>>/binary, " {\n"/utf8>>/binary,
(begin
_pipe@5 = Variants@1,
_pipe@6 = gleam@list:map(
_pipe@5,
fun generate_variant/1
),
gleam@string:join(_pipe@6, <<"\n"/utf8>>)
end)/binary>>/binary,
"\n}"/utf8>>;
{function_type, Argument_types, Result_type} ->
<<<<<<"fn("/utf8,
(begin
_pipe@7 = Argument_types,
_pipe@8 = gleam@list:map(
_pipe@7,
fun generate_type/1
),
gleam@string:join(_pipe@8, <<", "/utf8>>)
end)/binary>>/binary,
") -> "/utf8>>/binary,
(generate_type(Result_type))/binary>>
end.
-file("src/internal/codegen/types.gleam", 120).
?DOC(false).
-spec generate_field(field()) -> binary().
generate_field(Field) ->
<<<<(erlang:element(2, Field))/binary, ": "/utf8>>/binary,
(generate_type(erlang:element(3, Field)))/binary>>.
-file("src/internal/codegen/types.gleam", 110).
?DOC(false).
-spec generate_variant(variant()) -> binary().
generate_variant(Variant) ->
<<<<<<<<" "/utf8, (erlang:element(2, Variant))/binary>>/binary, "("/utf8>>/binary,
(begin
_pipe = erlang:element(3, Variant),
_pipe@1 = gleam@list:map(_pipe, fun generate_field/1),
gleam@string:join(_pipe@1, <<", "/utf8>>)
end)/binary>>/binary,
")"/utf8>>.