-module(yum@yaml@emitter).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yum/yaml/emitter.gleam").
-export([to_string/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(false).
-file("src/yum/yaml/emitter.gleam", 136).
?DOC(false).
-spec spaces(integer()) -> binary().
spaces(Count) ->
gleam@string:repeat(<<" "/utf8>>, Count).
-file("src/yum/yaml/emitter.gleam", 110).
?DOC(false).
-spec wrap_quotes(binary()) -> binary().
wrap_quotes(Value) ->
<<<<"\""/utf8, Value/binary>>/binary, "\""/utf8>>.
-file("src/yum/yaml/emitter.gleam", 102).
?DOC(false).
-spec quote(binary()) -> binary().
quote(Value) ->
_pipe = Value,
_pipe@1 = gleam@string:replace(_pipe, <<"\\"/utf8>>, <<"\\\\"/utf8>>),
_pipe@2 = gleam@string:replace(_pipe@1, <<"\""/utf8>>, <<"\\\""/utf8>>),
_pipe@3 = gleam@string:replace(_pipe@2, <<"\n"/utf8>>, <<"\\n"/utf8>>),
wrap_quotes(_pipe@3).
-file("src/yum/yaml/emitter.gleam", 129).
?DOC(false).
-spec plain_scalar_would_change_type(binary()) -> boolean().
plain_scalar_would_change_type(Value) ->
case yum@yaml@parser@scalar:parse(Value) of
{some, {string, Parsed}} when Parsed =:= Value ->
false;
_ ->
true
end.
-file("src/yum/yaml/emitter.gleam", 114).
?DOC(false).
-spec needs_quotes(binary()) -> boolean().
needs_quotes(Value) ->
((((((((((gleam@string:is_empty(Value) orelse (gleam@string:trim(Value) /= Value))
orelse gleam_stdlib:contains_string(Value, <<"\n"/utf8>>))
orelse gleam_stdlib:contains_string(Value, <<":"/utf8>>))
orelse gleam_stdlib:contains_string(Value, <<"#"/utf8>>))
orelse gleam_stdlib:contains_string(Value, <<"["/utf8>>))
orelse gleam_stdlib:contains_string(Value, <<"]"/utf8>>))
orelse gleam_stdlib:contains_string(Value, <<"{"/utf8>>))
orelse gleam_stdlib:contains_string(Value, <<"}"/utf8>>))
orelse gleam_stdlib:contains_string(Value, <<","/utf8>>))
orelse gleam_stdlib:contains_string(Value, <<"\""/utf8>>))
orelse plain_scalar_would_change_type(Value).
-file("src/yum/yaml/emitter.gleam", 95).
?DOC(false).
-spec emit_key_string(binary()) -> binary().
emit_key_string(Value) ->
case needs_quotes(Value) orelse gleam_stdlib:contains_string(
Value,
<<":"/utf8>>
) of
true ->
quote(Value);
false ->
Value
end.
-file("src/yum/yaml/emitter.gleam", 88).
?DOC(false).
-spec emit_string(binary()) -> binary().
emit_string(Value) ->
case needs_quotes(Value) of
true ->
quote(Value);
false ->
Value
end.
-file("src/yum/yaml/emitter.gleam", 81).
?DOC(false).
-spec emit_key(yum@yaml@node:node_()) -> binary().
emit_key(Value) ->
case yum@yaml@node:kind(Value) of
{string, Value@1} ->
emit_key_string(Value@1);
_ ->
emit(Value, 0)
end.
-file("src/yum/yaml/emitter.gleam", 59).
?DOC(false).
-spec emit_mapping(
list({yum@yaml@node:node_(), yum@yaml@node:node_()}),
integer()
) -> binary().
emit_mapping(Entries, Indent) ->
case Entries of
[] ->
<<"{}"/utf8>>;
[_ | _] ->
_pipe = Entries,
_pipe@1 = gleam@list:map(
_pipe,
fun(Entry) ->
{Key, Value} = Entry,
Rendered_key = emit_key(Key),
Rendered_value = emit(Value, Indent + 2),
case yum@yaml@node:kind(Value) of
{mapping, []} ->
<<<<<<(spaces(Indent))/binary, Rendered_key/binary>>/binary,
": "/utf8>>/binary,
Rendered_value/binary>>;
{sequence, []} ->
<<<<<<(spaces(Indent))/binary, Rendered_key/binary>>/binary,
": "/utf8>>/binary,
Rendered_value/binary>>;
{mapping, _} ->
<<<<<<(spaces(Indent))/binary, Rendered_key/binary>>/binary,
":\n"/utf8>>/binary,
Rendered_value/binary>>;
{sequence, _} ->
<<<<<<(spaces(Indent))/binary, Rendered_key/binary>>/binary,
":\n"/utf8>>/binary,
Rendered_value/binary>>;
_ ->
<<<<<<(spaces(Indent))/binary, Rendered_key/binary>>/binary,
": "/utf8>>/binary,
Rendered_value/binary>>
end
end
),
gleam@string:join(_pipe@1, <<"\n"/utf8>>)
end.
-file("src/yum/yaml/emitter.gleam", 45).
?DOC(false).
-spec emit_nested_sequence_entry(yum@yaml@node:node_(), integer()) -> binary().
emit_nested_sequence_entry(Entry, Indent) ->
Nested_indent = Indent + 2,
case gleam@string:split(emit(Entry, Nested_indent), <<"\n"/utf8>>) of
[] ->
<<(spaces(Indent))/binary, "- "/utf8>>;
[First | Rest] ->
_pipe = [<<<<(spaces(Indent))/binary, "- "/utf8>>/binary,
(gleam@string:drop_start(First, Nested_indent))/binary>> |
Rest],
gleam@string:join(_pipe, <<"\n"/utf8>>)
end.
-file("src/yum/yaml/emitter.gleam", 29).
?DOC(false).
-spec emit_sequence(list(yum@yaml@node:node_()), integer()) -> binary().
emit_sequence(Entries, Indent) ->
case Entries of
[] ->
<<"[]"/utf8>>;
[_ | _] ->
_pipe = Entries,
_pipe@1 = gleam@list:map(
_pipe,
fun(Entry) -> case yum@yaml@node:kind(Entry) of
{mapping, [_ | _]} ->
emit_nested_sequence_entry(Entry, Indent);
{sequence, [_ | _]} ->
emit_nested_sequence_entry(Entry, Indent);
_ ->
<<<<(spaces(Indent))/binary, "- "/utf8>>/binary,
(emit(Entry, Indent + 2))/binary>>
end end
),
gleam@string:join(_pipe@1, <<"\n"/utf8>>)
end.
-file("src/yum/yaml/emitter.gleam", 13).
?DOC(false).
-spec emit(yum@yaml@node:node_(), integer()) -> binary().
emit(Value, Indent) ->
case yum@yaml@node:kind(Value) of
null ->
<<"null"/utf8>>;
{bool, true} ->
<<"true"/utf8>>;
{bool, false} ->
<<"false"/utf8>>;
{int, Value@1} ->
erlang:integer_to_binary(Value@1);
{float, Value@2} ->
gleam_stdlib:float_to_string(Value@2);
pos_inf ->
<<".inf"/utf8>>;
neg_inf ->
<<"-.inf"/utf8>>;
nan ->
<<".nan"/utf8>>;
{string, Value@3} ->
emit_string(Value@3);
{sequence, Entries} ->
emit_sequence(Entries, Indent);
{mapping, Entries@1} ->
emit_mapping(Entries@1, Indent)
end.
-file("src/yum/yaml/emitter.gleam", 9).
?DOC(false).
-spec to_string(yum@yaml@node:node_()) -> binary().
to_string(Value) ->
emit(Value, 0).