Skip to main content

src/yum@yaml@lexer@single_quoted_scalar.erl

-module(yum@yaml@lexer@single_quoted_scalar).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yum/yaml/lexer/single_quoted_scalar.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/single_quoted_scalar.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) ->
            Prev@1 = case Ctx of
                {single_quoted_scalar, Prev} -> Prev;
                _assert_fail ->
                    erlang:error(#{gleam_error => let_assert,
                                message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
                                file => <<?FILEPATH/utf8>>,
                                module => <<"yum/yaml/lexer/single_quoted_scalar"/utf8>>,
                                function => <<"lexer"/utf8>>,
                                line => 7,
                                value => _assert_fail,
                                start => 209,
                                'end' => 259,
                                pattern_start => 220,
                                pattern_end => 253})
            end,
            case {Lexeme, Lookahead} of
                {<<"'"/utf8>>, <<"'"/utf8>>} ->
                    skip;

                {<<"''"/utf8>>, _} ->
                    _pipe = {single_quoted_scalar, <<"'"/utf8>>},
                    {keep, _pipe, Ctx};

                {<<"'"/utf8>>, _} ->
                    {drop, Prev@1};

                {<<""/utf8>>, <<"'"/utf8>>} ->
                    skip;

                {Lexeme@1, <<"'"/utf8>>} ->
                    _pipe@1 = Lexeme@1,
                    _pipe@2 = {single_quoted_scalar, _pipe@1},
                    {keep, _pipe@2, Ctx};

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