Skip to main content

src/yum@yaml@lexer@directive.erl

-module(yum@yaml@lexer@directive).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yum/yaml/lexer/directive.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/directive.gleam", 31).
?DOC(false).
-spec directive(binary()) -> gleam@option:option(yum@yaml@token:token()).
directive(Lexeme) ->
    Parts = begin
        _pipe = Lexeme,
        _pipe@1 = gleam@string:drop_start(_pipe, 1),
        _pipe@2 = gleam@string:trim(_pipe@1),
        _pipe@3 = gleam@string:split(_pipe@2, <<" "/utf8>>),
        gleam@list:filter(
            _pipe@3,
            fun(Part) -> not gleam@string:is_empty(Part) end
        )
    end,
    case Parts of
        [Name | Parameters] ->
            {some, {directive, Name, Parameters}};

        _ ->
            none
    end.

-file("src/yum/yaml/lexer/directive.gleam", 45).
?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/directive.gleam", 9).
?DOC(false).
-spec lexer() -> nibble@lexer:matcher(yum@yaml@token:token(), yum@yaml@lexer@context:context()).
lexer() ->
    nibble@lexer:custom(
        fun(Ctx, Lexeme, Lookahead) ->
            gleam@bool:guard(
                current_indent(Ctx) /= 0,
                no_match,
                fun() -> gleam@bool:guard(case Lexeme of
                            <<"%"/utf8, _/binary>> ->
                                false;

                            _ ->
                                true
                        end, no_match, fun() -> case Lookahead of
                                <<"\n"/utf8>> ->
                                    case directive(Lexeme) of
                                        {some, Directive} ->
                                            _pipe = Directive,
                                            {keep, _pipe, Ctx};

                                        none ->
                                            no_match
                                    end;

                                <<""/utf8>> ->
                                    case directive(Lexeme) of
                                        {some, Directive} ->
                                            _pipe = Directive,
                                            {keep, _pipe, Ctx};

                                        none ->
                                            no_match
                                    end;

                                _ ->
                                    no_match
                            end end) end
            )
        end
    ).