Current section

Files

Jump to
parser_gleam src parser_gleam@parser.erl
Raw

src/parser_gleam@parser.erl

-module(parser_gleam@parser).
-compile(no_auto_import).
-export([succeed/1, fail/0, fail_at/1, expected/2, item/0, cut/1, seq/2, either/2, with_start/1, eof/0, alt/2, chain/2, chain_first/2, 'of'/1, map/2, ap/2, ap_first/1, ap_second/1, flatten/1, zero/0, chain_rec/2, sat/1, cut_with/2, maybe/1, many/1, many1/1, sep_by/2, sep_by1/2, sep_by_cut/2, filter/1, between/2, surrounded_by/1, look_ahead/1, take_until/1, optional/1, many_till/2, many1_till/2, get_semigroup/1, get_monoid/1]).
-export_type([next/2]).
-type next(ESY, ESZ) :: {next, ESZ, parser_gleam@stream:stream(ESY)}.
-spec succeed(ETC) -> fun((parser_gleam@stream:stream(ETB)) -> {ok,
parser_gleam@parse_result:parse_success(ETB, ETC)} |
{error, parser_gleam@parse_result:parse_error(ETB)}).
succeed(A) ->
fun(I) -> parser_gleam@parse_result:success(A, I, I) end.
-spec fail() -> fun((parser_gleam@stream:stream(ETF)) -> {ok,
parser_gleam@parse_result:parse_success(ETF, any())} |
{error, parser_gleam@parse_result:parse_error(ETF)}).
fail() ->
fun(I) -> parser_gleam@parse_result:error(I, none, none) end.
-spec fail_at(parser_gleam@stream:stream(ETJ)) -> fun((parser_gleam@stream:stream(ETJ)) -> {ok,
parser_gleam@parse_result:parse_success(ETJ, any())} |
{error, parser_gleam@parse_result:parse_error(ETJ)}).
fail_at(I) ->
fun(_) -> parser_gleam@parse_result:error(I, none, none) end.
-spec expected(
fun((parser_gleam@stream:stream(ETO)) -> {ok,
parser_gleam@parse_result:parse_success(ETO, ETP)} |
{error, parser_gleam@parse_result:parse_error(ETO)}),
binary()
) -> fun((parser_gleam@stream:stream(ETO)) -> {ok,
parser_gleam@parse_result:parse_success(ETO, ETP)} |
{error, parser_gleam@parse_result:parse_error(ETO)}).
expected(P, Message) ->
fun(I) ->
_pipe = P(I),
gleam@result:map_error(
_pipe,
fun(Err) ->
parser_gleam@parse_result:with_expected(Err, [Message])
end
)
end.
-spec item() -> fun((parser_gleam@stream:stream(ETU)) -> {ok,
parser_gleam@parse_result:parse_success(ETU, ETU)} |
{error, parser_gleam@parse_result:parse_error(ETU)}).
item() ->
fun(I) -> case parser_gleam@stream:get_and_next(I) of
none ->
parser_gleam@parse_result:error(I, none, none);
{some, E} ->
parser_gleam@parse_result:success(
erlang:element(2, E),
erlang:element(3, E),
I
)
end end.
-spec cut(
fun((parser_gleam@stream:stream(ETX)) -> {ok,
parser_gleam@parse_result:parse_success(ETX, ETY)} |
{error, parser_gleam@parse_result:parse_error(ETX)})
) -> fun((parser_gleam@stream:stream(ETX)) -> {ok,
parser_gleam@parse_result:parse_success(ETX, ETY)} |
{error, parser_gleam@parse_result:parse_error(ETX)}).
cut(P) ->
fun(I) ->
_pipe = P(I),
gleam@result:map_error(_pipe, fun parser_gleam@parse_result:escalate/1)
end.
-spec seq(
fun((parser_gleam@stream:stream(EUD)) -> {ok,
parser_gleam@parse_result:parse_success(EUD, EUE)} |
{error, parser_gleam@parse_result:parse_error(EUD)}),
fun((EUE) -> fun((parser_gleam@stream:stream(EUD)) -> {ok,
parser_gleam@parse_result:parse_success(EUD, EUH)} |
{error, parser_gleam@parse_result:parse_error(EUD)}))
) -> fun((parser_gleam@stream:stream(EUD)) -> {ok,
parser_gleam@parse_result:parse_success(EUD, EUH)} |
{error, parser_gleam@parse_result:parse_error(EUD)}).
seq(Fa, F) ->
fun(I) ->
_pipe = Fa(I),
gleam@result:then(
_pipe,
fun(S) ->
_pipe@1 = (F(erlang:element(2, S)))(erlang:element(3, S)),
gleam@result:then(
_pipe@1,
fun(Next) ->
parser_gleam@parse_result:success(
erlang:element(2, Next),
erlang:element(3, Next),
I
)
end
)
end
)
end.
-spec either(
fun((parser_gleam@stream:stream(EUL)) -> {ok,
parser_gleam@parse_result:parse_success(EUL, EUM)} |
{error, parser_gleam@parse_result:parse_error(EUL)}),
fun(() -> fun((parser_gleam@stream:stream(EUL)) -> {ok,
parser_gleam@parse_result:parse_success(EUL, EUM)} |
{error, parser_gleam@parse_result:parse_error(EUL)}))
) -> fun((parser_gleam@stream:stream(EUL)) -> {ok,
parser_gleam@parse_result:parse_success(EUL, EUM)} |
{error, parser_gleam@parse_result:parse_error(EUL)}).
either(P, F) ->
fun(I) ->
E = P(I),
case E of
{ok, E@1} ->
{ok, E@1};
{error, E@2} ->
case erlang:element(4, E@2) of
true ->
{error, E@2};
false ->
_pipe = (F())(I),
gleam@result:map_error(
_pipe,
fun(Err) ->
parser_gleam@parse_result:extend(E@2, Err)
end
)
end
end
end.
-spec with_start(
fun((parser_gleam@stream:stream(EUT)) -> {ok,
parser_gleam@parse_result:parse_success(EUT, EUU)} |
{error, parser_gleam@parse_result:parse_error(EUT)})
) -> fun((parser_gleam@stream:stream(EUT)) -> {ok,
parser_gleam@parse_result:parse_success(EUT, {EUU,
parser_gleam@stream:stream(EUT)})} |
{error, parser_gleam@parse_result:parse_error(EUT)}).
with_start(P) ->
fun(I) ->
_pipe = P(I),
gleam@result:map(
_pipe,
fun(P@1) ->
{parse_success,
{erlang:element(2, P@1), I},
erlang:element(3, P@1),
erlang:element(4, P@1)}
end
)
end.
-spec eof() -> fun((parser_gleam@stream:stream(EVA)) -> {ok,
parser_gleam@parse_result:parse_success(EVA, nil)} |
{error, parser_gleam@parse_result:parse_error(EVA)}).
eof() ->
expected(fun(I) -> case parser_gleam@stream:at_end(I) of
true ->
parser_gleam@parse_result:success(nil, I, I);
false ->
parser_gleam@parse_result:error(I, none, none)
end end, <<"end of file"/utf8>>).
-spec alt(
fun((parser_gleam@stream:stream(EVD)) -> {ok,
parser_gleam@parse_result:parse_success(EVD, EVE)} |
{error, parser_gleam@parse_result:parse_error(EVD)}),
fun(() -> fun((parser_gleam@stream:stream(EVD)) -> {ok,
parser_gleam@parse_result:parse_success(EVD, EVE)} |
{error, parser_gleam@parse_result:parse_error(EVD)}))
) -> fun((parser_gleam@stream:stream(EVD)) -> {ok,
parser_gleam@parse_result:parse_success(EVD, EVE)} |
{error, parser_gleam@parse_result:parse_error(EVD)}).
alt(Fa, That) ->
either(Fa, That).
-spec chain(
fun((parser_gleam@stream:stream(EVL)) -> {ok,
parser_gleam@parse_result:parse_success(EVL, EVM)} |
{error, parser_gleam@parse_result:parse_error(EVL)}),
fun((EVM) -> fun((parser_gleam@stream:stream(EVL)) -> {ok,
parser_gleam@parse_result:parse_success(EVL, EVP)} |
{error, parser_gleam@parse_result:parse_error(EVL)}))
) -> fun((parser_gleam@stream:stream(EVL)) -> {ok,
parser_gleam@parse_result:parse_success(EVL, EVP)} |
{error, parser_gleam@parse_result:parse_error(EVL)}).
chain(Ma, F) ->
seq(Ma, F).
-spec chain_first(
fun((parser_gleam@stream:stream(EVT)) -> {ok,
parser_gleam@parse_result:parse_success(EVT, EVU)} |
{error, parser_gleam@parse_result:parse_error(EVT)}),
fun((EVU) -> fun((parser_gleam@stream:stream(EVT)) -> {ok,
parser_gleam@parse_result:parse_success(EVT, any())} |
{error, parser_gleam@parse_result:parse_error(EVT)}))
) -> fun((parser_gleam@stream:stream(EVT)) -> {ok,
parser_gleam@parse_result:parse_success(EVT, EVU)} |
{error, parser_gleam@parse_result:parse_error(EVT)}).
chain_first(Ma, F) ->
chain(Ma, fun(A) -> map(F(A), fun(_) -> A end) end).
-spec 'of'(EWE) -> fun((parser_gleam@stream:stream(EWD)) -> {ok,
parser_gleam@parse_result:parse_success(EWD, EWE)} |
{error, parser_gleam@parse_result:parse_error(EWD)}).
'of'(A) ->
succeed(A).
-spec map(
fun((parser_gleam@stream:stream(EWH)) -> {ok,
parser_gleam@parse_result:parse_success(EWH, EWI)} |
{error, parser_gleam@parse_result:parse_error(EWH)}),
fun((EWI) -> EWL)
) -> fun((parser_gleam@stream:stream(EWH)) -> {ok,
parser_gleam@parse_result:parse_success(EWH, EWL)} |
{error, parser_gleam@parse_result:parse_error(EWH)}).
map(Ma, F) ->
fun(I) ->
_pipe = Ma(I),
gleam@result:map(
_pipe,
fun(S) ->
{parse_success,
F(erlang:element(2, S)),
erlang:element(3, S),
erlang:element(4, S)}
end
)
end.
-spec ap(
fun((parser_gleam@stream:stream(EWO)) -> {ok,
parser_gleam@parse_result:parse_success(EWO, fun((EWP) -> EWQ))} |
{error, parser_gleam@parse_result:parse_error(EWO)}),
fun((parser_gleam@stream:stream(EWO)) -> {ok,
parser_gleam@parse_result:parse_success(EWO, EWP)} |
{error, parser_gleam@parse_result:parse_error(EWO)})
) -> fun((parser_gleam@stream:stream(EWO)) -> {ok,
parser_gleam@parse_result:parse_success(EWO, EWQ)} |
{error, parser_gleam@parse_result:parse_error(EWO)}).
ap(Mab, Ma) ->
chain(Mab, fun(F) -> map(Ma, F) end).
-spec ap_first(
fun((parser_gleam@stream:stream(EWX)) -> {ok,
parser_gleam@parse_result:parse_success(EWX, any())} |
{error, parser_gleam@parse_result:parse_error(EWX)})
) -> fun((fun((parser_gleam@stream:stream(EWX)) -> {ok,
parser_gleam@parse_result:parse_success(EWX, FIC)} |
{error, parser_gleam@parse_result:parse_error(EWX)})) -> fun((parser_gleam@stream:stream(EWX)) -> {ok,
parser_gleam@parse_result:parse_success(EWX, FIC)} |
{error, parser_gleam@parse_result:parse_error(EWX)})).
ap_first(Fb) ->
fun(Fa) -> ap(map(Fa, fun(A) -> fun(_) -> A end end), Fb) end.
-spec ap_second(
fun((parser_gleam@stream:stream(EXC)) -> {ok,
parser_gleam@parse_result:parse_success(EXC, EXD)} |
{error, parser_gleam@parse_result:parse_error(EXC)})
) -> fun((fun((parser_gleam@stream:stream(EXC)) -> {ok,
parser_gleam@parse_result:parse_success(EXC, any())} |
{error, parser_gleam@parse_result:parse_error(EXC)})) -> fun((parser_gleam@stream:stream(EXC)) -> {ok,
parser_gleam@parse_result:parse_success(EXC, EXD)} |
{error, parser_gleam@parse_result:parse_error(EXC)})).
ap_second(Fb) ->
fun(Fa) -> ap(map(Fa, fun(_) -> fun(B) -> B end end), Fb) end.
-spec flatten(
fun((parser_gleam@stream:stream(EXH)) -> {ok,
parser_gleam@parse_result:parse_success(EXH, fun((parser_gleam@stream:stream(EXH)) -> {ok,
parser_gleam@parse_result:parse_success(EXH, EXI)} |
{error,
parser_gleam@parse_result:parse_error(EXH)}))} |
{error, parser_gleam@parse_result:parse_error(EXH)})
) -> fun((parser_gleam@stream:stream(EXH)) -> {ok,
parser_gleam@parse_result:parse_success(EXH, EXI)} |
{error, parser_gleam@parse_result:parse_error(EXH)}).
flatten(Mma) ->
chain(Mma, fun fp2@function:identity/1).
-spec zero() -> fun((parser_gleam@stream:stream(EXP)) -> {ok,
parser_gleam@parse_result:parse_success(EXP, any())} |
{error, parser_gleam@parse_result:parse_error(EXP)}).
zero() ->
fail().
-spec chain_rec(
EXV,
fun((EXV) -> fun((parser_gleam@stream:stream(EXW)) -> {ok,
parser_gleam@parse_result:parse_success(EXW, {ok,
EXX} |
{error, EXV})} |
{error, parser_gleam@parse_result:parse_error(EXW)}))
) -> fun((parser_gleam@stream:stream(EXW)) -> {ok,
parser_gleam@parse_result:parse_success(EXW, EXX)} |
{error, parser_gleam@parse_result:parse_error(EXW)}).
chain_rec(A, F) ->
Split = fun(Start) -> fun(Result) -> case erlang:element(2, Result) of
{error, E} ->
{error, {next, E, erlang:element(3, Result)}};
{ok, R} ->
{ok,
parser_gleam@parse_result:success(
R,
erlang:element(3, Result),
Start
)}
end end end,
fun(Start@1) ->
fp2@chain_rec:tail_rec(
{next, A, Start@1},
fun(State) ->
Result@1 = (F(erlang:element(2, State)))(
erlang:element(3, State)
),
case Result@1 of
{error, R@1} ->
{ok,
parser_gleam@parse_result:error(
erlang:element(3, State),
{some, erlang:element(3, R@1)},
{some, erlang:element(4, R@1)}
)};
{ok, R@2} ->
(Split(Start@1))(R@2)
end
end
)
end.
-spec sat(fun((EYE) -> boolean())) -> fun((parser_gleam@stream:stream(EYE)) -> {ok,
parser_gleam@parse_result:parse_success(EYE, EYE)} |
{error, parser_gleam@parse_result:parse_error(EYE)}).
sat(Predicate) ->
_pipe = with_start(item()),
chain(
_pipe,
fun(T) ->
{A, Start} = T,
case Predicate(A) of
true ->
'of'(A);
false ->
fail_at(Start)
end
end
).
-spec cut_with(
fun((parser_gleam@stream:stream(EYI)) -> {ok,
parser_gleam@parse_result:parse_success(EYI, any())} |
{error, parser_gleam@parse_result:parse_error(EYI)}),
fun((parser_gleam@stream:stream(EYI)) -> {ok,
parser_gleam@parse_result:parse_success(EYI, EYM)} |
{error, parser_gleam@parse_result:parse_error(EYI)})
) -> fun((parser_gleam@stream:stream(EYI)) -> {ok,
parser_gleam@parse_result:parse_success(EYI, EYM)} |
{error, parser_gleam@parse_result:parse_error(EYI)}).
cut_with(P1, P2) ->
_pipe = P1,
(ap_second(cut(P2)))(_pipe).
-spec maybe(fp2@monoid:monoid(EYR)) -> fun((fun((parser_gleam@stream:stream(FMC)) -> {ok,
parser_gleam@parse_result:parse_success(FMC, EYR)} |
{error, parser_gleam@parse_result:parse_error(FMC)})) -> fun((parser_gleam@stream:stream(FMC)) -> {ok,
parser_gleam@parse_result:parse_success(FMC, EYR)} |
{error, parser_gleam@parse_result:parse_error(FMC)})).
maybe(M) ->
fun(P) ->
_pipe = P,
alt(_pipe, fun() -> 'of'(erlang:element(3, M)) end)
end.
-spec many(
fun((parser_gleam@stream:stream(EYU)) -> {ok,
parser_gleam@parse_result:parse_success(EYU, EYV)} |
{error, parser_gleam@parse_result:parse_error(EYU)})
) -> fun((parser_gleam@stream:stream(EYU)) -> {ok,
parser_gleam@parse_result:parse_success(EYU, list(EYV))} |
{error, parser_gleam@parse_result:parse_error(EYU)}).
many(P) ->
_pipe = many1(P),
_pipe@1 = map(_pipe, fun fp2@non_empty_list:to_list/1),
alt(_pipe@1, fun() -> 'of'([]) end).
-spec many1(
fun((parser_gleam@stream:stream(EZB)) -> {ok,
parser_gleam@parse_result:parse_success(EZB, EZC)} |
{error, parser_gleam@parse_result:parse_error(EZB)})
) -> fun((parser_gleam@stream:stream(EZB)) -> {ok,
parser_gleam@parse_result:parse_success(EZB, fp2@non_empty_list:non_empty_list(EZC))} |
{error, parser_gleam@parse_result:parse_error(EZB)}).
many1(Parser) ->
_pipe = Parser,
chain(
_pipe,
fun(Head) ->
chain_rec(
fp2@non_empty_list:'of'(Head),
fun(Acc) ->
_pipe@1 = Parser,
_pipe@2 = map(
_pipe@1,
fun(A) -> {error, fp2@non_empty_list:append(Acc, A)} end
),
alt(_pipe@2, fun() -> 'of'({ok, Acc}) end)
end
)
end
).
-spec sep_by(
fun((parser_gleam@stream:stream(EZI)) -> {ok,
parser_gleam@parse_result:parse_success(EZI, any())} |
{error, parser_gleam@parse_result:parse_error(EZI)}),
fun((parser_gleam@stream:stream(EZI)) -> {ok,
parser_gleam@parse_result:parse_success(EZI, EZM)} |
{error, parser_gleam@parse_result:parse_error(EZI)})
) -> fun((parser_gleam@stream:stream(EZI)) -> {ok,
parser_gleam@parse_result:parse_success(EZI, list(EZM))} |
{error, parser_gleam@parse_result:parse_error(EZI)}).
sep_by(Sep, P) ->
_pipe = sep_by1(Sep, P),
_pipe@1 = map(_pipe, fun fp2@non_empty_list:to_list/1),
alt(_pipe@1, fun() -> 'of'([]) end).
-spec sep_by1(
fun((parser_gleam@stream:stream(EZS)) -> {ok,
parser_gleam@parse_result:parse_success(EZS, any())} |
{error, parser_gleam@parse_result:parse_error(EZS)}),
fun((parser_gleam@stream:stream(EZS)) -> {ok,
parser_gleam@parse_result:parse_success(EZS, EZW)} |
{error, parser_gleam@parse_result:parse_error(EZS)})
) -> fun((parser_gleam@stream:stream(EZS)) -> {ok,
parser_gleam@parse_result:parse_success(EZS, fp2@non_empty_list:non_empty_list(EZW))} |
{error, parser_gleam@parse_result:parse_error(EZS)}).
sep_by1(Sep, P) ->
_pipe = P,
chain(
_pipe,
fun(Head) ->
_pipe@2 = many(
begin
_pipe@1 = Sep,
(ap_second(P))(_pipe@1)
end
),
map(
_pipe@2,
fun(Tail) ->
_pipe@3 = Tail,
fp2@non_empty_list:prepend_list(_pipe@3, Head)
end
)
end
).
-spec sep_by_cut(
fun((parser_gleam@stream:stream(FAC)) -> {ok,
parser_gleam@parse_result:parse_success(FAC, any())} |
{error, parser_gleam@parse_result:parse_error(FAC)}),
fun((parser_gleam@stream:stream(FAC)) -> {ok,
parser_gleam@parse_result:parse_success(FAC, FAG)} |
{error, parser_gleam@parse_result:parse_error(FAC)})
) -> fun((parser_gleam@stream:stream(FAC)) -> {ok,
parser_gleam@parse_result:parse_success(FAC, fp2@non_empty_list:non_empty_list(FAG))} |
{error, parser_gleam@parse_result:parse_error(FAC)}).
sep_by_cut(Sep, P) ->
_pipe = P,
chain(
_pipe,
fun(Head) ->
_pipe@1 = many(cut_with(Sep, P)),
map(
_pipe@1,
fun(Tail) ->
_pipe@2 = Tail,
fp2@non_empty_list:prepend_list(_pipe@2, Head)
end
)
end
).
-spec filter(fun((FAM) -> boolean())) -> fun((fun((parser_gleam@stream:stream(FPH)) -> {ok,
parser_gleam@parse_result:parse_success(FPH, FAM)} |
{error, parser_gleam@parse_result:parse_error(FPH)})) -> fun((parser_gleam@stream:stream(FPH)) -> {ok,
parser_gleam@parse_result:parse_success(FPH, FAM)} |
{error, parser_gleam@parse_result:parse_error(FPH)})).
filter(Predicate) ->
fun(P) ->
fun(I) ->
_pipe = P(I),
gleam@result:then(
_pipe,
fun(Next) -> case Predicate(erlang:element(2, Next)) of
true ->
{ok, Next};
false ->
parser_gleam@parse_result:error(I, none, none)
end end
)
end
end.
-spec between(
fun((parser_gleam@stream:stream(FAP)) -> {ok,
parser_gleam@parse_result:parse_success(FAP, FAQ)} |
{error, parser_gleam@parse_result:parse_error(FAP)}),
fun((parser_gleam@stream:stream(FAP)) -> {ok,
parser_gleam@parse_result:parse_success(FAP, FAQ)} |
{error, parser_gleam@parse_result:parse_error(FAP)})
) -> fun((fun((parser_gleam@stream:stream(FAP)) -> {ok,
parser_gleam@parse_result:parse_success(FAP, FQA)} |
{error, parser_gleam@parse_result:parse_error(FAP)})) -> fun((parser_gleam@stream:stream(FAP)) -> {ok,
parser_gleam@parse_result:parse_success(FAP, FQA)} |
{error, parser_gleam@parse_result:parse_error(FAP)})).
between(Left, Right) ->
fun(P) ->
_pipe = Left,
_pipe@1 = chain(_pipe, fun(_) -> P end),
chain_first(_pipe@1, fun(_) -> Right end)
end.
-spec surrounded_by(
fun((parser_gleam@stream:stream(FAW)) -> {ok,
parser_gleam@parse_result:parse_success(FAW, any())} |
{error, parser_gleam@parse_result:parse_error(FAW)})
) -> fun((fun((parser_gleam@stream:stream(FAW)) -> {ok,
parser_gleam@parse_result:parse_success(FAW, FQN)} |
{error, parser_gleam@parse_result:parse_error(FAW)})) -> fun((parser_gleam@stream:stream(FAW)) -> {ok,
parser_gleam@parse_result:parse_success(FAW, FQN)} |
{error, parser_gleam@parse_result:parse_error(FAW)})).
surrounded_by(Bound) ->
fun(P) -> (between(Bound, Bound))(P) end.
-spec look_ahead(
fun((parser_gleam@stream:stream(FBB)) -> {ok,
parser_gleam@parse_result:parse_success(FBB, FBC)} |
{error, parser_gleam@parse_result:parse_error(FBB)})
) -> fun((parser_gleam@stream:stream(FBB)) -> {ok,
parser_gleam@parse_result:parse_success(FBB, FBC)} |
{error, parser_gleam@parse_result:parse_error(FBB)}).
look_ahead(P) ->
fun(I) ->
_pipe = P(I),
gleam@result:then(
_pipe,
fun(Next) ->
parser_gleam@parse_result:success(erlang:element(2, Next), I, I)
end
)
end.
-spec take_until(fun((FBH) -> boolean())) -> fun((parser_gleam@stream:stream(FBH)) -> {ok,
parser_gleam@parse_result:parse_success(FBH, list(FBH))} |
{error, parser_gleam@parse_result:parse_error(FBH)}).
take_until(Predicate) ->
_pipe = Predicate,
_pipe@1 = fp2@predicate:'not'(_pipe),
_pipe@2 = sat(_pipe@1),
many(_pipe@2).
-spec optional(
fun((parser_gleam@stream:stream(FBM)) -> {ok,
parser_gleam@parse_result:parse_success(FBM, FBN)} |
{error, parser_gleam@parse_result:parse_error(FBM)})
) -> fun((parser_gleam@stream:stream(FBM)) -> {ok,
parser_gleam@parse_result:parse_success(FBM, gleam@option:option(FBN))} |
{error, parser_gleam@parse_result:parse_error(FBM)}).
optional(Parser) ->
_pipe = Parser,
_pipe@1 = map(_pipe, fun(A) -> {some, A} end),
alt(_pipe@1, fun() -> succeed(none) end).
-spec many_till(
fun((parser_gleam@stream:stream(FBT)) -> {ok,
parser_gleam@parse_result:parse_success(FBT, FBU)} |
{error, parser_gleam@parse_result:parse_error(FBT)}),
fun((parser_gleam@stream:stream(FBT)) -> {ok,
parser_gleam@parse_result:parse_success(FBT, any())} |
{error, parser_gleam@parse_result:parse_error(FBT)})
) -> fun((parser_gleam@stream:stream(FBT)) -> {ok,
parser_gleam@parse_result:parse_success(FBT, list(FBU))} |
{error, parser_gleam@parse_result:parse_error(FBT)}).
many_till(Parser, Terminator) ->
_pipe = Terminator,
_pipe@1 = map(_pipe, fun(_) -> [] end),
alt(
_pipe@1,
fun() ->
_pipe@2 = many1_till(Parser, Terminator),
map(_pipe@2, fun fp2@non_empty_list:to_list/1)
end
).
-spec many1_till(
fun((parser_gleam@stream:stream(FCD)) -> {ok,
parser_gleam@parse_result:parse_success(FCD, FCE)} |
{error, parser_gleam@parse_result:parse_error(FCD)}),
fun((parser_gleam@stream:stream(FCD)) -> {ok,
parser_gleam@parse_result:parse_success(FCD, any())} |
{error, parser_gleam@parse_result:parse_error(FCD)})
) -> fun((parser_gleam@stream:stream(FCD)) -> {ok,
parser_gleam@parse_result:parse_success(FCD, fp2@non_empty_list:non_empty_list(FCE))} |
{error, parser_gleam@parse_result:parse_error(FCD)}).
many1_till(Parser, Terminator) ->
_pipe = Parser,
chain(
_pipe,
fun(X) ->
chain_rec(
fp2@non_empty_list:'of'(X),
fun(Acc) ->
_pipe@1 = Terminator,
_pipe@2 = map(_pipe@1, fun(_) -> {ok, Acc} end),
alt(
_pipe@2,
fun() ->
_pipe@3 = Parser,
map(
_pipe@3,
fun(A) ->
{error, fp2@non_empty_list:append(Acc, A)}
end
)
end
)
end
)
end
).
-spec get_semigroup(fp2@semigroup:semigroup(FCN)) -> fp2@semigroup:semigroup(fun((parser_gleam@stream:stream(FCP)) -> {ok,
parser_gleam@parse_result:parse_success(FCP, FCN)} |
{error, parser_gleam@parse_result:parse_error(FCP)})).
get_semigroup(S) ->
{semigroup,
fun(X, Y) ->
ap(
map(
X,
fun(X@1) ->
fun(Y@1) -> (erlang:element(2, S))(X@1, Y@1) end
end
),
Y
)
end}.
-spec get_monoid(fp2@monoid:monoid(FCT)) -> fp2@monoid:monoid(fun((parser_gleam@stream:stream(FCV)) -> {ok,
parser_gleam@parse_result:parse_success(FCV, FCT)} |
{error, parser_gleam@parse_result:parse_error(FCV)})).
get_monoid(M) ->
{semigroup, Concat} = begin
_pipe = M,
_pipe@1 = fp2@monoid:to_semigroup(_pipe),
get_semigroup(_pipe@1)
end,
{monoid, Concat, succeed(erlang:element(3, M))}.