Current section

Files

Jump to
oas_generator src oas@generator@ast.erl
Raw

src/oas@generator@ast.erl

-module(oas@generator@ast).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/oas/generator/ast.gleam").
-export([access/2, call/2, call0/2, call1/3, call2/4, pipe/2, name_for_gleam_type/1, name_for_gleam_field_or_var/1]).
-file("src/oas/generator/ast.gleam", 7).
-spec access(binary(), binary()) -> glance:expression().
access(Object_or_mod, Field) ->
{field_access, {variable, Object_or_mod}, Field}.
-file("src/oas/generator/ast.gleam", 11).
-spec call(glance:expression(), glance:expression()) -> glance:expression().
call(F, Arg) ->
case F of
{fn_capture, none, F@1, Before, After} ->
Args = gleam@list:flatten(
[Before, [{unlabelled_field, Arg}], After]
),
{call, F@1, Args};
_ ->
{call, F, [{unlabelled_field, Arg}]}
end.
-file("src/oas/generator/ast.gleam", 21).
-spec call0(binary(), binary()) -> glance:expression().
call0(M, F) ->
{call, access(M, F), []}.
-file("src/oas/generator/ast.gleam", 25).
-spec call1(binary(), binary(), glance:expression()) -> glance:expression().
call1(M, F, A) ->
{call, access(M, F), [{unlabelled_field, A}]}.
-file("src/oas/generator/ast.gleam", 29).
-spec call2(binary(), binary(), glance:expression(), glance:expression()) -> glance:expression().
call2(M, F, A, B) ->
{call, access(M, F), [{unlabelled_field, A}, {unlabelled_field, B}]}.
-file("src/oas/generator/ast.gleam", 36).
-spec pipe(glance:expression(), glance:expression()) -> glance:expression().
pipe(A, B) ->
{binary_operator, pipe, A, B}.
-file("src/oas/generator/ast.gleam", 41).
-spec replace_gleam_keywords(binary()) -> binary().
replace_gleam_keywords(Key) ->
case Key of
<<"as"/utf8>> ->
<<"as_"/utf8>>;
<<"assert"/utf8>> ->
<<"assert_"/utf8>>;
<<"auto"/utf8>> ->
<<"auto_"/utf8>>;
<<"case"/utf8>> ->
<<"case_"/utf8>>;
<<"const"/utf8>> ->
<<"const_"/utf8>>;
<<"delegate"/utf8>> ->
<<"delegate_"/utf8>>;
<<"derive"/utf8>> ->
<<"derive_"/utf8>>;
<<"echo"/utf8>> ->
<<"echo_"/utf8>>;
<<"else"/utf8>> ->
<<"else_"/utf8>>;
<<"fn"/utf8>> ->
<<"fn_"/utf8>>;
<<"if"/utf8>> ->
<<"if_"/utf8>>;
<<"implement"/utf8>> ->
<<"implement_"/utf8>>;
<<"import"/utf8>> ->
<<"import_"/utf8>>;
<<"let"/utf8>> ->
<<"let_"/utf8>>;
<<"macro"/utf8>> ->
<<"macro_"/utf8>>;
<<"opaque"/utf8>> ->
<<"opaque_"/utf8>>;
<<"panic"/utf8>> ->
<<"panic_"/utf8>>;
<<"pub"/utf8>> ->
<<"pub_"/utf8>>;
<<"test"/utf8>> ->
<<"test_"/utf8>>;
<<"todo"/utf8>> ->
<<"todo_"/utf8>>;
<<"type"/utf8>> ->
<<"type_"/utf8>>;
<<"use"/utf8>> ->
<<"use_"/utf8>>;
<<"base"/utf8>> ->
<<"base_"/utf8>>;
<<"path"/utf8>> ->
<<"path_"/utf8>>;
<<"method"/utf8>> ->
<<"method_"/utf8>>;
<<"token"/utf8>> ->
<<"token_"/utf8>>;
_ ->
Key
end.
-file("src/oas/generator/ast.gleam", 74).
-spec replace_disallowed_charachters(binary()) -> binary().
replace_disallowed_charachters(In) ->
_pipe = In,
_pipe@1 = gleam@string:replace(_pipe, <<"/"/utf8>>, <<"_"/utf8>>),
_pipe@2 = gleam@string:replace(_pipe@1, <<"+"/utf8>>, <<"_"/utf8>>),
_pipe@3 = gleam@string:replace(_pipe@2, <<"^"/utf8>>, <<""/utf8>>),
gleam@string:replace(_pipe@3, <<"$"/utf8>>, <<""/utf8>>).
-file("src/oas/generator/ast.gleam", 84).
-spec prefix_numbers(binary()) -> binary().
prefix_numbers(In) ->
Needs_prefix = gleam@list:any(
[<<"1"/utf8>>,
<<"2"/utf8>>,
<<"3"/utf8>>,
<<"4"/utf8>>,
<<"5"/utf8>>,
<<"6"/utf8>>,
<<"7"/utf8>>,
<<"8"/utf8>>,
<<"9"/utf8>>,
<<"0"/utf8>>],
fun(_capture) -> gleam_stdlib:string_starts_with(In, _capture) end
),
case Needs_prefix of
true ->
<<"n"/utf8, In/binary>>;
false ->
In
end.
-file("src/oas/generator/ast.gleam", 96).
-spec prefix_signs(binary()) -> binary().
prefix_signs(In) ->
In@1 = case gleam_stdlib:string_starts_with(In, <<"-"/utf8>>) of
true ->
<<"negative"/utf8, In/binary>>;
false ->
In
end,
case gleam_stdlib:string_starts_with(In@1, <<"+"/utf8>>) of
true ->
<<"positive"/utf8, In@1/binary>>;
false ->
In@1
end.
-file("src/oas/generator/ast.gleam", 107).
-spec name_for_gleam_type(binary()) -> binary().
name_for_gleam_type(In) ->
_pipe = In,
_pipe@1 = prefix_signs(_pipe),
_pipe@2 = replace_disallowed_charachters(_pipe@1),
_pipe@3 = justin:pascal_case(_pipe@2),
prefix_numbers(_pipe@3).
-file("src/oas/generator/ast.gleam", 115).
-spec name_for_gleam_field_or_var(binary()) -> binary().
name_for_gleam_field_or_var(In) ->
_pipe = In,
_pipe@1 = prefix_signs(_pipe),
_pipe@2 = justin:snake_case(_pipe@1),
_pipe@3 = prefix_numbers(_pipe@2),
_pipe@4 = replace_disallowed_charachters(_pipe@3),
replace_gleam_keywords(_pipe@4).