%<*package>

\tl_new:N \l_@@_loop_command_tl
\tl_new:N \l_@@_task_list_tl
\seq_new:N \l_@@_path_seq
\prop_new:N \l_@@_rule_prop

\cs_new_protected:Nn \_@@_make_prop_loop:Nnn {
    \quark_if_recursion_tail_stop:n {#2}
    \prop_put:Nnn #1 {#2} {#3}
    \_@@_make_prop_loop:Nnn #1
}
\cs_new_protected:Nn \_@@_execute_loop:Nnn {
    \quark_if_recursion_tail_stop:n {#2}
    \prop_get:NnNT #1 {#2} \l_@@_loop_command_tl {
        \l_@@_loop_command_tl #3
    }
    \_@@_execute_loop:Nnn #1
}
\cs_new_protected:Nn \_@@_execute_rule:Nn {
    \prop_clear:N \l_@@_rule_prop
    \_@@_make_prop_loop:Nnn \l_@@_rule_prop #2 \q_recursion_tail \q_recursion_tail \q_recursion_stop
    \tl_set_eq:NN \l_@@_task_list_tl #1
    \tl_put_right:Nn \l_@@_task_list_tl {\q_recursion_tail \q_recursion_tail \q_recursion_stop}
    \exp_after:wN \_@@_execute_loop:Nnn \exp_after:wN \l_@@_rule_prop \l_@@_task_list_tl
}
\cs_new_protected:Nn \_@@_parse_path:nn {
    \clist_map_inline:nn {group, subgroup, subsubgroup, subsubsubgroup} {
        \tl_clear:c {l_#2##1_tl}
    }
    \seq_set_split:Nnn \l_@@_path_seq {/} {#1}
    \exp_args:NNc \seq_pop_right:NN \l_@@_path_seq {l_#2section_tl}
    \seq_map_indexed_inline:Nn \l_@@_path_seq {
        \int_case:nn {##1} {
            {1} {\tl_set:cn {l_@@_#2group_tl} {##2}}
            {2} {\tl_set:cn {l_@@_#2subgroup_tl} {##2}}
            {3} {\tl_set:cn {l_@@_#2subsubgroup_tl} {##2}}
            {4} {\tl_set:cn {l_@@_#2subsubsubgroup_tl} {##2}}
        }
    }
}

%</package>