-module(yum@yaml@error).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yum/yaml/error.gleam").
-export([from_lex_error/1, from_parse_errors/1, multiple_documents/0, unexpected_end_of_input/0, indent_normalization_error/0, message/1, span/1]).
-export_type([yaml_error/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(
" Errors returned by YAML parsing.\n"
"\n"
" Parse errors are opaque. Use [`message`](#message) for a human-readable\n"
" description and [`span`](#span) for the primary source location when one is\n"
" available.\n"
"\n"
).
-opaque yaml_error() :: indent_normalization_error |
{lexer_error, integer(), integer(), binary()} |
multiple_documents |
unexpected_end_of_input |
{unexpected_token, yum@yaml@token:token(), integer(), integer()} |
{other, nibble:error(yum@yaml@token:token()), integer(), integer()}.
-file("src/yum/yaml/error.gleam", 34).
?DOC(false).
-spec from_lex_error(nibble@lexer:error()) -> yaml_error().
from_lex_error(Error) ->
{no_match_found, Row, Col, Lexeme} = Error,
{lexer_error, Row, Col, Lexeme}.
-file("src/yum/yaml/error.gleam", 50).
-spec from_problem(nibble:error(yum@yaml@token:token()), nibble@lexer:span()) -> yaml_error().
from_problem(Problem, Pos) ->
case Problem of
{unexpected, Token} ->
{unexpected_token,
Token,
erlang:element(2, Pos),
erlang:element(3, Pos)};
end_of_input ->
unexpected_end_of_input;
{custom, _} ->
unexpected_end_of_input;
{bad_parser, _} ->
{other, Problem, erlang:element(2, Pos), erlang:element(3, Pos)};
{expected, _, _} ->
{other, Problem, erlang:element(2, Pos), erlang:element(3, Pos)}
end.
-file("src/yum/yaml/error.gleam", 40).
?DOC(false).
-spec from_parse_errors(
list(nibble:dead_end(yum@yaml@token:token(), yum@yaml@lexer@context:context()))
) -> yaml_error().
from_parse_errors(Errors) ->
case Errors of
[] ->
unexpected_end_of_input;
[{dead_end, Pos, Problem, _} | _] ->
from_problem(Problem, Pos)
end.
-file("src/yum/yaml/error.gleam", 67).
?DOC(false).
-spec multiple_documents() -> yaml_error().
multiple_documents() ->
multiple_documents.
-file("src/yum/yaml/error.gleam", 72).
?DOC(false).
-spec unexpected_end_of_input() -> yaml_error().
unexpected_end_of_input() ->
unexpected_end_of_input.
-file("src/yum/yaml/error.gleam", 77).
?DOC(false).
-spec indent_normalization_error() -> yaml_error().
indent_normalization_error() ->
indent_normalization_error.
-file("src/yum/yaml/error.gleam", 122).
-spec token_label(yum@yaml@token:token()) -> binary().
token_label(Token) ->
case Token of
hyphen ->
<<"-"/utf8>>;
question_mark ->
<<"?"/utf8>>;
colon ->
<<":"/utf8>>;
comma ->
<<","/utf8>>;
open_sequence ->
<<"["/utf8>>;
close_sequence ->
<<"]"/utf8>>;
open_mapping ->
<<"{"/utf8>>;
close_mapping ->
<<"}"/utf8>>;
hash ->
<<"#"/utf8>>;
document_start ->
<<"---"/utf8>>;
document_end ->
<<"..."/utf8>>;
ampersand ->
<<"&"/utf8>>;
asterisk ->
<<"*"/utf8>>;
exclamation ->
<<"!"/utf8>>;
vertical_bar ->
<<"|"/utf8>>;
greater_than ->
<<">"/utf8>>;
single_quote ->
<<"'"/utf8>>;
double_quote ->
<<"\""/utf8>>;
percent ->
<<"%"/utf8>>;
at ->
<<"@"/utf8>>;
grave_accent ->
<<"`"/utf8>>;
line_break ->
<<"\\n"/utf8>>;
{indentation, _} ->
<<"indentation"/utf8>>;
{double_quoted_scalar, _} ->
<<"double_quoted_scalar"/utf8>>;
{single_quoted_scalar, _} ->
<<"single_quoted_scalar"/utf8>>;
{mapping_key, _} ->
<<"mapping_key"/utf8>>;
{plain_scalar, _} ->
<<"plain_scalar"/utf8>>;
{anchor, _} ->
<<"anchor"/utf8>>;
{alias, _} ->
<<"alias"/utf8>>;
{tag, _} ->
<<"tag"/utf8>>;
{block_scalar_header, _, _, _} ->
<<"block_scalar_header"/utf8>>;
{block_scalar_line, _, _} ->
<<"block_scalar_line"/utf8>>;
{directive, Name, _} ->
<<<<"directive("/utf8, Name/binary>>/binary, ")"/utf8>>;
{escape, _} ->
<<"escape"/utf8>>;
invalid_escape ->
<<"invalid_escape"/utf8>>
end.
-file("src/yum/yaml/error.gleam", 83).
?DOC(" Renders a human-readable parse error message.\n").
-spec message(yaml_error()) -> binary().
message(Error) ->
case Error of
indent_normalization_error ->
<<"Could not normalize YAML indentation"/utf8>>;
{lexer_error, _, _, Lexeme} ->
<<<<"Could not lex YAML near `"/utf8, Lexeme/binary>>/binary,
"`"/utf8>>;
multiple_documents ->
<<"Expected a single YAML document"/utf8>>;
unexpected_end_of_input ->
<<"Unexpected end of YAML input"/utf8>>;
{unexpected_token, Token, _, _} ->
<<<<"Unexpected YAML token `"/utf8, (token_label(Token))/binary>>/binary,
"`"/utf8>>;
{other, _, _, _} ->
<<"Could not parse YAML"/utf8>>
end.
-file("src/yum/yaml/error.gleam", 110).
-spec point_span(integer(), integer(), integer()) -> yum@yaml@node:span().
point_span(Row, Col, Width) ->
Width@1 = case Width =< 0 of
true ->
1;
false ->
Width
end,
{span, {position, Row, Col}, {position, Row, Col + Width@1}}.
-file("src/yum/yaml/error.gleam", 97).
?DOC(" Returns the primary source span for a parse error, when one is available.\n").
-spec span(yaml_error()) -> gleam@option:option(yum@yaml@node:span()).
span(Error) ->
case Error of
{lexer_error, Row, Col, Lexeme} ->
{some, point_span(Row, Col, string:length(Lexeme))};
{unexpected_token, _, Row@1, Col@1} ->
{some, point_span(Row@1, Col@1, 1)};
indent_normalization_error ->
none;
multiple_documents ->
none;
unexpected_end_of_input ->
none;
{other, _, Row@2, Col@2} ->
{some, point_span(Row@2, Col@2, 1)}
end.