Skip to main content

src/yum@yaml@lexer@document_marker.erl

-module(yum@yaml@lexer@document_marker).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yum/yaml/lexer/document_marker.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/document_marker.gleam", 15).
?DOC(false).
-spec boundary(binary()) -> boolean().
boundary(Value) ->
    case Value of
        <<""/utf8>> ->
            true;

        <<"\n"/utf8>> ->
            true;

        <<"\r"/utf8>> ->
            true;

        <<" "/utf8>> ->
            true;

        <<"\t"/utf8>> ->
            true;

        _ ->
            false
    end.

-file("src/yum/yaml/lexer/document_marker.gleam", 22).
?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/document_marker.gleam", 5).
?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 {current_indent(Ctx), Lexeme, boundary(Lookahead)} of
                {0, <<"---"/utf8>>, true} ->
                    _pipe = document_start,
                    {keep, _pipe, Ctx};

                {0, <<"..."/utf8>>, true} ->
                    _pipe@1 = document_end,
                    {keep, _pipe@1, Ctx};

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