Current section

Files

Jump to
glrss_parser src glrss_parser@rss.erl
Raw

src/glrss_parser@rss.erl

-module(glrss_parser@rss).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([empty_rss/0, parse/2, parse_bits/2]).
-export_type([rss/0, channel/0, cloud/0, image/0, text_input/0, item/0, source/0, enclosure/0, category/0, parse_error/0]).
-type rss() :: {rss, binary(), channel()}.
-type channel() :: {channel,
binary(),
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(glrss_parser@rss@date:rss_date()),
gleam@option:option(glrss_parser@rss@date:rss_date()),
gleam@option:option(category()),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(cloud()),
gleam@option:option(integer()),
gleam@option:option(image()),
gleam@option:option(binary()),
gleam@option:option(text_input()),
list(integer()),
list(glrss_parser@rss@date:day_of_week()),
list(item())}.
-type cloud() :: {cloud, binary(), integer(), binary(), binary(), binary()}.
-type image() :: {image,
binary(),
binary(),
binary(),
gleam@option:option(integer()),
gleam@option:option(integer()),
gleam@option:option(binary())}.
-type text_input() :: {text_input, binary(), binary(), binary(), binary()}.
-type item() :: {item,
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(category()),
gleam@option:option(binary()),
gleam@option:option(enclosure()),
gleam@option:option(binary()),
gleam@option:option(glrss_parser@rss@date:rss_date()),
gleam@option:option(source())}.
-type source() :: {source, binary(), gleam@option:option(binary())}.
-type enclosure() :: {enclosure, binary(), integer(), binary()}.
-type category() :: {category, gleam@option:option(binary()), list(binary())}.
-type parse_error() :: {unexpected_signal, xmlm:signal()} |
{unexpected_attribute, list(xmlm:attribute())} |
{unexpected_data, binary()} |
{xmlm_error, xmlm:input_error()} |
{party_error, party:parse_error(nil)} |
nil_error.
-spec empty_channel() -> channel().
empty_channel() ->
{channel,
<<""/utf8>>,
<<""/utf8>>,
<<""/utf8>>,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
[],
[],
[]}.
-spec empty_rss() -> rss().
empty_rss() ->
{rss, <<""/utf8>>, empty_channel()}.
-spec empty_image() -> image().
empty_image() ->
{image, <<""/utf8>>, <<""/utf8>>, <<""/utf8>>, none, none, none}.
-spec empty_text_input() -> text_input().
empty_text_input() ->
{text_input, <<""/utf8>>, <<""/utf8>>, <<""/utf8>>, <<""/utf8>>}.
-spec empty_item() -> item().
empty_item() ->
{item, none, none, none, none, none, none, none, none, none, none}.
-spec party_error({ok, LQE} | {error, party:parse_error(nil)}) -> {ok, LQE} |
{error, parse_error()}.
party_error(Res) ->
_pipe = Res,
gleam@result:map_error(_pipe, fun(Err) -> {party_error, Err} end).
-spec skip_unknown(xmlm:input()) -> {ok, xmlm:input()} | {error, parse_error()}.
skip_unknown(In) ->
case xmlm:signal(In) of
{ok, {element_end, In@1}} ->
{ok, In@1};
{ok, {{element_start, _}, In@2}} ->
gleam@result:'try'(skip_unknown(In@2), fun skip_unknown/1);
{ok, {_, In@3}} ->
skip_unknown(In@3);
{error, E} ->
{error, {xmlm_error, E}}
end.
-spec handle_unknown(
xmlm:input(),
LQQ,
boolean(),
xmlm:signal(),
fun((xmlm:input(), LQQ, boolean()) -> {ok, LWI} | {error, parse_error()})
) -> {ok, LWI} | {error, parse_error()}.
handle_unknown(In, Acc, Skip, Sig, Next) ->
case Skip of
true ->
gleam@result:'try'(
skip_unknown(In),
fun(In@1) -> Next(In@1, Acc, Skip) end
);
false ->
{error, {unexpected_signal, Sig}}
end.
-spec do_read_data(xmlm:input(), binary(), boolean()) -> {ok,
{binary(), xmlm:input()}} |
{error, parse_error()}.
do_read_data(In, Acc, Skip) ->
case xmlm:signal(In) of
{ok, {{data, Acc@1}, In@1}} ->
do_read_data(In@1, Acc@1, Skip);
{ok, {element_end, In@2}} ->
{ok, {Acc, In@2}};
{ok, {Sig, In@3}} ->
handle_unknown(In@3, Acc, Skip, Sig, fun do_read_data/3);
{error, E} ->
{error, {xmlm_error, E}}
end.
-spec read_data(xmlm:input(), boolean()) -> {ok, {binary(), xmlm:input()}} |
{error, parse_error()}.
read_data(In, Skip) ->
do_read_data(In, <<""/utf8>>, Skip).
-spec handle_exceptions(
xmlm:input(),
LQK,
boolean(),
fun((xmlm:input(), LQK, boolean()) -> {ok, {LQK, xmlm:input()}} |
{error, parse_error()}),
fun((xmlm:input(), list(xmlm:attribute()), binary(), binary()) -> {ok,
{LQK, xmlm:input()}} |
{error, parse_error()})
) -> {ok, {LQK, xmlm:input()}} | {error, parse_error()}.
handle_exceptions(In, Acc, Skip, Next, Fun) ->
case xmlm:signal(In) of
{ok, {{element_start, {tag, {name, Uri, Name}, Attrs}} = Sig, In_1}} ->
case Fun(In_1, Attrs, Uri, Name) of
{ok, Acc@1} ->
{ok, Acc@1};
{error, nil_error} ->
handle_unknown(In, Acc, Skip, Sig, Next);
{error, Err} ->
{error, Err}
end;
{ok, {element_end, In@1}} ->
{ok, {Acc, In@1}};
{ok, {{dtd, _} = Sig@1, In@2}} ->
handle_unknown(In@2, Acc, Skip, Sig@1, Next);
{ok, {{data, _} = Sig@1, In@2}} ->
handle_unknown(In@2, Acc, Skip, Sig@1, Next);
{error, E} ->
{error, {xmlm_error, E}}
end.
-spec do_input_image(xmlm:input(), image(), boolean()) -> {ok,
{image(), xmlm:input()}} |
{error, parse_error()}.
do_input_image(In, Acc, Skip) ->
handle_exceptions(
In,
Acc,
Skip,
fun do_input_image/3,
fun(In@1, _, Uri, Name) -> case Uri of
<<""/utf8>> ->
case Name of
<<"url"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0) ->
{Url, In@2} = _use0,
do_input_image(
In@2,
erlang:setelement(2, Acc, Url),
Skip
)
end
);
<<"title"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@1) ->
{Title, In@3} = _use0@1,
do_input_image(
In@3,
erlang:setelement(3, Acc, Title),
Skip
)
end
);
<<"link"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@2) ->
{Link, In@4} = _use0@2,
do_input_image(
In@4,
erlang:setelement(4, Acc, Link),
Skip
)
end
);
<<"width"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@3) ->
{Width, In@5} = _use0@3,
gleam@result:'try'(
begin
_pipe = gleam@int:parse(Width),
gleam@result:map_error(
_pipe,
fun(_) ->
{unexpected_data, Width}
end
)
end,
fun(Width@1) ->
do_input_image(
In@5,
erlang:setelement(
5,
Acc,
{some, Width@1}
),
Skip
)
end
)
end
);
<<"height"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@4) ->
{Height, In@6} = _use0@4,
gleam@result:'try'(
begin
_pipe@1 = gleam@int:parse(Height),
gleam@result:map_error(
_pipe@1,
fun(_) ->
{unexpected_data, Height}
end
)
end,
fun(Height@1) ->
do_input_image(
In@6,
erlang:setelement(
6,
Acc,
{some, Height@1}
),
Skip
)
end
)
end
);
<<"description"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@5) ->
{Description, In@7} = _use0@5,
do_input_image(
In@7,
erlang:setelement(
7,
Acc,
{some, Description}
),
Skip
)
end
);
_ ->
{error, nil_error}
end;
_ ->
{error, nil_error}
end end
).
-spec input_image(xmlm:input(), boolean()) -> {ok, {image(), xmlm:input()}} |
{error, parse_error()}.
input_image(In, Skip) ->
do_input_image(In, empty_image(), Skip).
-spec do_input_text_input(xmlm:input(), text_input(), boolean()) -> {ok,
{text_input(), xmlm:input()}} |
{error, parse_error()}.
do_input_text_input(In, Acc, Skip) ->
handle_exceptions(
In,
Acc,
Skip,
fun do_input_text_input/3,
fun(In@1, _, Uri, Name) -> case Uri of
<<""/utf8>> ->
case Name of
<<"title"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0) ->
{Title, In@2} = _use0,
do_input_text_input(
In@2,
erlang:setelement(2, Acc, Title),
Skip
)
end
);
<<"description"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@1) ->
{Description, In@3} = _use0@1,
do_input_text_input(
In@3,
erlang:setelement(3, Acc, Description),
Skip
)
end
);
<<"name"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@2) ->
{Name@1, In@4} = _use0@2,
do_input_text_input(
In@4,
erlang:setelement(4, Acc, Name@1),
Skip
)
end
);
<<"link"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@3) ->
{Link, In@5} = _use0@3,
do_input_text_input(
In@5,
erlang:setelement(5, Acc, Link),
Skip
)
end
);
_ ->
{error, nil_error}
end;
_ ->
{error, nil_error}
end end
).
-spec input_text_input(xmlm:input(), boolean()) -> {ok,
{text_input(), xmlm:input()}} |
{error, parse_error()}.
input_text_input(In, Skip) ->
do_input_text_input(In, empty_text_input(), Skip).
-spec do_input_item(xmlm:input(), item(), boolean()) -> {ok,
{item(), xmlm:input()}} |
{error, parse_error()}.
do_input_item(In, Acc, Skip) ->
handle_exceptions(
In,
Acc,
Skip,
fun do_input_item/3,
fun(In@1, Attrs, Uri, Name) -> case Uri of
<<""/utf8>> ->
case Name of
<<"title"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0) ->
{Title, In@2} = _use0,
do_input_item(
In@2,
erlang:setelement(2, Acc, {some, Title}),
Skip
)
end
);
<<"link"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@1) ->
{Link, In@3} = _use0@1,
do_input_item(
In@3,
erlang:setelement(3, Acc, {some, Link}),
Skip
)
end
);
<<"description"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@2) ->
{Description, In@4} = _use0@2,
do_input_item(
In@4,
erlang:setelement(
4,
Acc,
{some, Description}
),
Skip
)
end
);
<<"author"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@3) ->
{Author, In@5} = _use0@3,
do_input_item(
In@5,
erlang:setelement(
5,
Acc,
{some, Author}
),
Skip
)
end
);
<<"category"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@4) ->
{Categories, In@6} = _use0@4,
Domain@1 = case Attrs of
[{attribute,
{name,
<<""/utf8>>,
<<"domain"/utf8>>},
Domain}] ->
{some, Domain};
_ ->
none
end,
Categories@1 = gleam@string:split(
Categories,
<<"/"/utf8>>
),
Category = {some,
{category, Domain@1, Categories@1}},
do_input_item(
In@6,
erlang:setelement(6, Acc, Category),
Skip
)
end
);
<<"comments"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@5) ->
{Comments, In@7} = _use0@5,
do_input_item(
In@7,
erlang:setelement(
7,
Acc,
{some, Comments}
),
Skip
)
end
);
<<"enclosure"/utf8>> ->
gleam@result:'try'(
skip_unknown(In@1),
fun(In@8) ->
Attrs_d = begin
_pipe = Attrs,
_pipe@1 = gleam@list:map(
_pipe,
fun(Attr) ->
{erlang:element(
3,
erlang:element(2, Attr)
),
erlang:element(3, Attr)}
end
),
maps:from_list(_pipe@1)
end,
G = fun(A) -> _pipe@2 = Attrs_d,
gleam@dict:get(_pipe@2, A) end,
case {G(<<"url"/utf8>>),
G(<<"length"/utf8>>),
G(<<"type"/utf8>>)} of
{{ok, Url}, {ok, Length}, {ok, Type_}} ->
gleam@result:'try'(
begin
_pipe@3 = gleam@int:parse(
Length
),
gleam@result:map_error(
_pipe@3,
fun(_) ->
{unexpected_attribute,
Attrs}
end
)
end,
fun(Length@1) ->
Enclosure = {some,
{enclosure,
Url,
Length@1,
Type_}},
do_input_item(
In@8,
erlang:setelement(
8,
Acc,
Enclosure
),
Skip
)
end
);
{_, _, _} ->
{error,
{unexpected_attribute, Attrs}}
end
end
);
<<"guid"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@6) ->
{Guid, In@9} = _use0@6,
do_input_item(
In@9,
erlang:setelement(9, Acc, {some, Guid}),
Skip
)
end
);
<<"pubDate"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@7) ->
{Pub_date, In@10} = _use0@7,
gleam@result:'try'(
begin
_pipe@4 = glrss_parser@rss@date:parse(
Pub_date
),
party_error(_pipe@4)
end,
fun(Pub_date@1) ->
do_input_item(
In@10,
erlang:setelement(
10,
Acc,
{some, Pub_date@1}
),
Skip
)
end
)
end
);
<<"source"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@8) ->
{Name@1, In@11} = _use0@8,
Name@2 = case Name@1 of
<<""/utf8>> ->
none;
A@1 ->
{some, A@1}
end,
case Attrs of
[{attribute,
{name,
<<""/utf8>>,
<<"url"/utf8>>},
Url@1}] ->
Source = {source, Url@1, Name@2},
do_input_item(
In@11,
erlang:setelement(
11,
Acc,
{some, Source}
),
Skip
);
_ ->
{error,
{unexpected_attribute, Attrs}}
end
end
);
_ ->
{error, nil_error}
end;
_ ->
{error, nil_error}
end end
).
-spec input_item(xmlm:input(), boolean()) -> {ok, {item(), xmlm:input()}} |
{error, parse_error()}.
input_item(In, Skip) ->
do_input_item(In, empty_item(), Skip).
-spec do_read_multiple(xmlm:input(), list(binary()), boolean()) -> {ok,
{list(binary()), xmlm:input()}} |
{error, parse_error()}.
do_read_multiple(In, Acc, Skip) ->
case xmlm:signal(In) of
{ok, {Sig, In@1}} ->
case Sig of
{element_start, _} ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0) ->
{Data, In@2} = _use0,
do_read_multiple(In@2, [Data | Acc], Skip)
end
);
element_end ->
{ok, {Acc, In@1}};
_ ->
handle_unknown(In@1, Acc, Skip, Sig, fun do_read_multiple/3)
end;
{error, E} ->
{error, {xmlm_error, E}}
end.
-spec read_multiple(xmlm:input(), boolean()) -> {ok,
{list(binary()), xmlm:input()}} |
{error, parse_error()}.
read_multiple(In, Skip) ->
do_read_multiple(In, [], Skip).
-spec do_input_channel(xmlm:input(), channel(), boolean()) -> {ok,
{channel(), xmlm:input()}} |
{error, parse_error()}.
do_input_channel(In, Acc, Skip) ->
handle_exceptions(
In,
Acc,
Skip,
fun do_input_channel/3,
fun(In@1, Attrs, Uri, Name) -> case Uri of
<<""/utf8>> ->
case Name of
<<"title"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0) ->
{Title, In@2} = _use0,
do_input_channel(
In@2,
erlang:setelement(2, Acc, Title),
Skip
)
end
);
<<"link"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@1) ->
{Link, In@3} = _use0@1,
do_input_channel(
In@3,
erlang:setelement(3, Acc, Link),
Skip
)
end
);
<<"description"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@2) ->
{Description, In@4} = _use0@2,
do_input_channel(
In@4,
erlang:setelement(4, Acc, Description),
Skip
)
end
);
<<"language"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@3) ->
{Language, In@5} = _use0@3,
do_input_channel(
In@5,
erlang:setelement(
5,
Acc,
{some, Language}
),
Skip
)
end
);
<<"copyright"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@4) ->
{Copyright, In@6} = _use0@4,
do_input_channel(
In@6,
erlang:setelement(
6,
Acc,
{some, Copyright}
),
Skip
)
end
);
<<"managingEditor"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@5) ->
{Managing_editor, In@7} = _use0@5,
do_input_channel(
In@7,
erlang:setelement(
7,
Acc,
{some, Managing_editor}
),
Skip
)
end
);
<<"webMaster"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@6) ->
{Web_master, In@8} = _use0@6,
do_input_channel(
In@8,
erlang:setelement(
8,
Acc,
{some, Web_master}
),
Skip
)
end
);
<<"pubDate"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@7) ->
{Pub_date, In@9} = _use0@7,
gleam@result:'try'(
begin
_pipe = glrss_parser@rss@date:parse(
Pub_date
),
party_error(_pipe)
end,
fun(Pub_date@1) ->
do_input_channel(
In@9,
erlang:setelement(
9,
Acc,
{some, Pub_date@1}
),
Skip
)
end
)
end
);
<<"lastBuildDate"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@8) ->
{Last_build_date, In@10} = _use0@8,
gleam@result:'try'(
begin
_pipe@1 = glrss_parser@rss@date:parse(
Last_build_date
),
party_error(_pipe@1)
end,
fun(Last_build_date@1) ->
do_input_channel(
In@10,
erlang:setelement(
10,
Acc,
{some, Last_build_date@1}
),
Skip
)
end
)
end
);
<<"category"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@9) ->
{Categories, In@11} = _use0@9,
Domain@1 = case Attrs of
[{attribute,
{name,
<<""/utf8>>,
<<"domain"/utf8>>},
Domain}] ->
{some, Domain};
_ ->
none
end,
Categories@1 = gleam@string:split(
Categories,
<<"/"/utf8>>
),
Category = {some,
{category, Domain@1, Categories@1}},
do_input_channel(
In@11,
erlang:setelement(11, Acc, Category),
Skip
)
end
);
<<"generator"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@10) ->
{Generator, In@12} = _use0@10,
do_input_channel(
In@12,
erlang:setelement(
12,
Acc,
{some, Generator}
),
Skip
)
end
);
<<"docs"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@11) ->
{Docs, In@13} = _use0@11,
do_input_channel(
In@13,
erlang:setelement(13, Acc, {some, Docs}),
Skip
)
end
);
<<"cloud"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@12) ->
{_, In@14} = _use0@12,
Attrs_d = begin
_pipe@2 = Attrs,
_pipe@3 = gleam@list:map(
_pipe@2,
fun(Attr) ->
{erlang:element(
3,
erlang:element(2, Attr)
),
erlang:element(3, Attr)}
end
),
maps:from_list(_pipe@3)
end,
G = fun(A) -> _pipe@4 = Attrs_d,
gleam@dict:get(_pipe@4, A) end,
case {G(<<"domain"/utf8>>),
G(<<"port"/utf8>>),
G(<<"path"/utf8>>),
G(<<"registerProcedure"/utf8>>),
G(<<"protocol"/utf8>>)} of
{{ok, Domain@2},
{ok, Port},
{ok, Path},
{ok, Register_procedure},
{ok, Protocol}} ->
gleam@result:'try'(
begin
_pipe@5 = gleam@int:parse(
Port
),
gleam@result:map_error(
_pipe@5,
fun(_) ->
{unexpected_attribute,
Attrs}
end
)
end,
fun(Port@1) ->
Cloud = {some,
{cloud,
Domain@2,
Port@1,
Path,
Register_procedure,
Protocol}},
do_input_channel(
In@14,
erlang:setelement(
14,
Acc,
Cloud
),
Skip
)
end
);
{_, _, _, _, _} ->
{error,
{unexpected_attribute, Attrs}}
end
end
);
<<"ttl"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@13) ->
{Ttl, In@15} = _use0@13,
gleam@result:'try'(
begin
_pipe@6 = gleam@int:parse(Ttl),
gleam@result:map_error(
_pipe@6,
fun(_) ->
{unexpected_data, Ttl}
end
)
end,
fun(Ttl@1) ->
do_input_channel(
In@15,
erlang:setelement(
15,
Acc,
{some, Ttl@1}
),
Skip
)
end
)
end
);
<<"image"/utf8>> ->
gleam@result:'try'(
input_image(In@1, Skip),
fun(_use0@14) ->
{Image, In@16} = _use0@14,
do_input_channel(
In@16,
erlang:setelement(
16,
Acc,
{some, Image}
),
Skip
)
end
);
<<"rating"/utf8>> ->
gleam@result:'try'(
read_data(In@1, Skip),
fun(_use0@15) ->
{Rating, In@17} = _use0@15,
do_input_channel(
In@17,
erlang:setelement(
17,
Acc,
{some, Rating}
),
Skip
)
end
);
<<"textInput"/utf8>> ->
gleam@result:'try'(
input_text_input(In@1, Skip),
fun(_use0@16) ->
{Text_input, In@18} = _use0@16,
do_input_channel(
In@18,
erlang:setelement(
18,
Acc,
{some, Text_input}
),
Skip
)
end
);
<<"skipHours"/utf8>> ->
gleam@result:'try'(
read_multiple(In@1, Skip),
fun(_use0@17) ->
{Skip_hours, In@19} = _use0@17,
gleam@result:'try'(
begin
_pipe@9 = gleam@list:try_map(
Skip_hours,
fun(A@1) -> _pipe@7 = A@1,
_pipe@8 = gleam@int:parse(
_pipe@7
),
gleam@result:replace_error(
_pipe@8,
A@1
) end
),
gleam@result:map_error(
_pipe@9,
fun(Field@0) -> {unexpected_data, Field@0} end
)
end,
fun(Skip_hours@1) ->
do_input_channel(
In@19,
erlang:setelement(
19,
Acc,
Skip_hours@1
),
Skip
)
end
)
end
);
<<"skipDays"/utf8>> ->
gleam@result:'try'(
read_multiple(In@1, Skip),
fun(_use0@18) ->
{Skip_days, In@20} = _use0@18,
gleam@result:'try'(
begin
_pipe@12 = gleam@list:try_map(
Skip_days,
fun(A@2) -> _pipe@10 = A@2,
_pipe@11 = glrss_parser@rss@date:dow_from(
_pipe@10
),
gleam@result:replace_error(
_pipe@11,
A@2
) end
),
gleam@result:map_error(
_pipe@12,
fun(Field@0) -> {unexpected_data, Field@0} end
)
end,
fun(Skip_days@1) ->
do_input_channel(
In@20,
erlang:setelement(
20,
Acc,
Skip_days@1
),
Skip
)
end
)
end
);
<<"item"/utf8>> ->
gleam@result:'try'(
input_item(In@1, Skip),
fun(_use0@19) ->
{Item, In@21} = _use0@19,
do_input_channel(
In@21,
erlang:setelement(
21,
Acc,
[Item | erlang:element(21, Acc)]
),
Skip
)
end
);
_ ->
{error, nil_error}
end;
_ ->
{error, nil_error}
end end
).
-spec input_channel(xmlm:input(), boolean()) -> {ok, {channel(), xmlm:input()}} |
{error, parse_error()}.
input_channel(In, Skip) ->
do_input_channel(In, empty_channel(), Skip).
-spec do_input_rss(xmlm:input(), rss(), boolean()) -> {ok,
{rss(), xmlm:input()}} |
{error, parse_error()}.
do_input_rss(In, Acc, Skip) ->
handle_exceptions(
In,
Acc,
Skip,
fun do_input_rss/3,
fun(In@1, _, Uri, Name) -> case {Uri, Name} of
{<<""/utf8>>, <<"channel"/utf8>>} ->
gleam@result:'try'(
input_channel(In@1, Skip),
fun(_use0) ->
{Channel, In@2} = _use0,
do_input_rss(
In@2,
erlang:setelement(3, Acc, Channel),
Skip
)
end
);
{_, _} ->
{error, nil_error}
end end
).
-spec input_rss(xmlm:input(), list(xmlm:attribute()), boolean()) -> {ok,
{rss(), xmlm:input()}} |
{error, parse_error()}.
input_rss(In, Attrs, Skip) ->
case Attrs of
[{attribute, {name, <<""/utf8>>, <<"version"/utf8>>}, Version}] ->
gleam@result:map(
do_input_rss(In, empty_rss(), Skip),
fun(_use0) ->
{Done, In@1} = _use0,
{erlang:setelement(2, Done, Version), In@1}
end
);
_ ->
{error, {unexpected_attribute, Attrs}}
end.
-spec do_parse(xmlm:input(), rss(), boolean()) -> {ok, {rss(), xmlm:input()}} |
{error, parse_error()}.
do_parse(In, Acc, Skip) ->
case xmlm:signal(In) of
{ok, {{dtd, _}, In@1}} ->
do_parse(In@1, Acc, Skip);
_ ->
handle_exceptions(
In,
Acc,
Skip,
fun do_parse/3,
fun(In@2, Attrs, Uri, Name) -> case {Uri, Name} of
{<<""/utf8>>, <<"rss"/utf8>>} ->
input_rss(In@2, Attrs, Skip);
{_, _} ->
{error, nil_error}
end end
)
end.
-spec parse(binary(), boolean()) -> {ok, rss()} | {error, parse_error()}.
parse(Rss_xml, Skip) ->
Input = begin
_pipe = Rss_xml,
_pipe@1 = xmlm:from_string(_pipe),
xmlm:with_stripping(_pipe@1, true)
end,
_pipe@2 = do_parse(Input, empty_rss(), Skip),
gleam@result:map(_pipe@2, fun(A) -> erlang:element(1, A) end).
-spec parse_bits(bitstring(), boolean()) -> {ok, rss()} | {error, parse_error()}.
parse_bits(Rss_xml, Skip) ->
Input = begin
_pipe = Rss_xml,
_pipe@1 = xmlm:from_bit_array(_pipe),
xmlm:with_stripping(_pipe@1, true)
end,
_pipe@2 = do_parse(Input, empty_rss(), Skip),
gleam@result:map(_pipe@2, fun(A) -> erlang:element(1, A) end).