Skip to main content

src/yum@yaml@lexer@indentation.erl

-module(yum@yaml@lexer@indentation).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yum/yaml/lexer/indentation.gleam").
-export([lexer/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).

-file("src/yum/yaml/lexer/indentation.gleam", 33).
?DOC(false).
-spec current_indent(yum@yaml@lexer@context:context()) -> integer().
current_indent(Ctx) ->
    case Ctx of
        {block_style, Indent} ->
            Indent;

        {flow_style, Prev} ->
            current_indent(Prev);

        {flow_mapping, Prev} ->
            current_indent(Prev);

        {flow_sequence, Prev} ->
            current_indent(Prev);

        {block_scalar, Prev, _} ->
            current_indent(Prev);

        {double_quoted_scalar, Prev} ->
            current_indent(Prev);

        {single_quoted_scalar, Prev} ->
            current_indent(Prev);

        {double_quoted_escape, Prev} ->
            current_indent(Prev)
    end.

-file("src/yum/yaml/lexer/indentation.gleam", 6).
?DOC(false).
-spec lexer() -> nibble@lexer:matcher(yum@yaml@token:token(), yum@yaml@lexer@context:context()).
lexer() ->
    nibble@lexer:custom(
        fun(Ctx, Lexeme, Lookahead) -> case {Lexeme, Lookahead} of
                {<<" "/utf8>>, _} ->
                    {drop, Ctx};

                {<<"\t"/utf8>>, _} ->
                    {drop, Ctx};

                {<<"\r"/utf8>>, _} ->
                    {drop, Ctx};

                {<<"\n"/utf8, _/binary>>, <<" "/utf8>>} ->
                    skip;

                {<<"\n"/utf8, _/binary>>, <<"\t"/utf8>>} ->
                    skip;

                {<<"\n"/utf8, _/binary>>, <<"\n"/utf8>>} ->
                    {drop, Ctx};

                {<<"\n"/utf8, _/binary>>, <<""/utf8>>} ->
                    {drop, Ctx};

                {<<"\n"/utf8, Spaces/binary>>, _} ->
                    Indent = string:length(Spaces),
                    _pipe = Indent,
                    _pipe@1 = {indentation, _pipe},
                    {keep, _pipe@1, {flow_style, {block_style, Indent}}};

                {<<"-"/utf8>>, <<" "/utf8>>} ->
                    Indent@1 = current_indent(Ctx),
                    _pipe@2 = hyphen,
                    {keep, _pipe@2, {flow_style, {block_style, Indent@1}}};

                {<<"-"/utf8>>, <<"\n"/utf8>>} ->
                    Indent@1 = current_indent(Ctx),
                    _pipe@2 = hyphen,
                    {keep, _pipe@2, {flow_style, {block_style, Indent@1}}};

                {<<"-"/utf8>>, <<""/utf8>>} ->
                    Indent@1 = current_indent(Ctx),
                    _pipe@2 = hyphen,
                    {keep, _pipe@2, {flow_style, {block_style, Indent@1}}};

                {_, _} ->
                    no_match
            end end
    ).