-module(yum@yaml@lexer@flow_collection).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yum/yaml/lexer/flow_collection.gleam").
-export([ends_with_whitespace/1, keep_plain_scalar/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/yum/yaml/lexer/flow_collection.gleam", 9).
?DOC(false).
-spec ends_with_whitespace(binary()) -> boolean().
ends_with_whitespace(S) ->
((gleam_stdlib:string_ends_with(S, <<" "/utf8>>) orelse gleam_stdlib:string_ends_with(
S,
<<"\t"/utf8>>
))
orelse gleam_stdlib:string_ends_with(S, <<"\r"/utf8>>))
orelse gleam_stdlib:string_ends_with(S, <<"\n"/utf8>>).
-file("src/yum/yaml/lexer/flow_collection.gleam", 44).
?DOC(false).
-spec fold_plain_lines(list(binary()), list(binary()), integer()) -> list(binary()).
fold_plain_lines(Lines, Parts, Empty_lines) ->
case Lines of
[] ->
lists:reverse(Parts);
[Line | Rest] ->
Line@1 = gleam@string:trim(Line),
case {gleam@string:is_empty(Line@1), Parts} of
{true, _} ->
fold_plain_lines(Rest, Parts, Empty_lines + 1);
{false, []} ->
fold_plain_lines(Rest, [Line@1], 0);
{false, [_ | _]} ->
Separator = case Empty_lines > 0 of
true ->
gleam@string:repeat(<<"\n"/utf8>>, Empty_lines);
false ->
<<" "/utf8>>
end,
fold_plain_lines(Rest, [Line@1, Separator | Parts], 0)
end
end.
-file("src/yum/yaml/lexer/flow_collection.gleam", 23).
?DOC(false).
-spec keep_scalar(binary(), yum@yaml@lexer@context:context()) -> nibble@lexer:match(yum@yaml@token:token(), yum@yaml@lexer@context:context()).
keep_scalar(Lexeme, Ctx) ->
Scalar = begin
_pipe = Lexeme,
_pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>),
_pipe@2 = fold_plain_lines(_pipe@1, [], 0),
erlang:list_to_binary(_pipe@2)
end,
case gleam_stdlib:string_ends_with(Scalar, <<":"/utf8>>) of
true ->
_pipe@3 = Scalar,
_pipe@4 = gleam@string:drop_end(_pipe@3, 1),
_pipe@5 = gleam@string:trim_end(_pipe@4),
_pipe@6 = {mapping_key, _pipe@5},
{keep, _pipe@6, Ctx};
false ->
_pipe@7 = Scalar,
_pipe@8 = {plain_scalar, _pipe@7},
{keep, _pipe@8, Ctx}
end.
-file("src/yum/yaml/lexer/flow_collection.gleam", 16).
?DOC(false).
-spec keep_plain_scalar(binary(), yum@yaml@lexer@context:context()) -> nibble@lexer:match(yum@yaml@token:token(), yum@yaml@lexer@context:context()).
keep_plain_scalar(Lexeme, Ctx) ->
case yum@yaml@lexer@node_property:token(Lexeme) of
{some, Token} ->
_pipe = Token,
{keep, _pipe, Ctx};
_ ->
keep_scalar(Lexeme, Ctx)
end.