ZR7U7TRCUHXMBXQFA3XXNGJPPYFACMOWPQKGUH7E22KGFM35HSNAC
case parser.(chunk) do
:not_matched ->
{{:error, {:not_matched, chunk}}, state, chunk}
results = parser.(chunk)
new_state = %{state | parsers: rest_parsers}
for result <- results, reduce: {new_state, chunk} do
{state, chunk} ->
case result do
{:add_tag, tag} ->
{%{state | tags: [tag | state.tags]}, chunk}
{:cont, cont} ->
{%{state | parsers: [cont | state.parsers]}, chunk}
{:add_acc, result, tail} ->
{%{state | acc: [result | state.acc]}, tail}
{tag, data, tail, nil} ->
new_state = %{state | parsers: rest_parsers}
{{tag, data}, new_state, tail}
{new_acc, new_tags} =
case state.tags do
[tag] -> {[{tag, last} | acc], []}
[_tag | rest_tags] = tags -> {[{tags |> Enum.reverse(), last} | acc], rest_tags}
end