Skip to content

Commit

Permalink
Support (x)template choices
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwright committed May 30, 2022
1 parent d3394d2 commit d370a44
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions l3packages/xtemplate/xtemplate.dtx
Expand Up @@ -1606,7 +1606,7 @@
{
\str_case:VnF \l_@@_keytype_tl
{
{ choice } { \@@_implement_choices:n {#3} }
{ choice } { \@@_implement_choices:nn {#1} {#3} }
{ code }
{
\@@_parse_vars_elt_key:nn {#1}
Expand Down Expand Up @@ -1696,18 +1696,20 @@
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_implement_choices:n}
% \begin{macro}{\@@_implement_choices:nn}
% \begin{macro}{\@@_implement_choices_default:}
% Implementing choices requires a second key--value loop. So after a
% little set-up, the standard parser is called.
% \begin{macrocode}
\cs_new_protected:Npn \@@_implement_choices:n #1
\cs_new_protected:Npn \@@_implement_choices:nn #1#2
{
\clist_set:No \l_@@_tmp_clist { \l_@@_keytype_arg_tl }
\prop_put:Non \l_@@_vars_prop \l_@@_key_name_tl { }
\keyval_parse:NNn
\@@_implement_choice_elt:n \@@_implement_choice_elt:nn
{#1}
\keys_define:nx { template / #1 } { \l_@@_key_name_tl .choice: }
\keyval_parse:nnn
{ \@@_implement_choice_elt:nn {#1} }
{ \@@_implement_choice_elt:nnn {#1} }
{#2}
\prop_get:NoNT \l_@@_values_prop \l_@@_key_name_tl
\l_@@_tmp_tl
{ \@@_implement_choices_default: }
Expand Down Expand Up @@ -1749,47 +1751,49 @@
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_implement_choice_elt:n}
% \begin{macro}{\@@_implement_choice_elt:nn}
% \begin{macro}{\@@_implement_choice_elt:nnn}
% The actual storage of the implementation of a choice is mainly about
% error checking. The code here ensures that all choices have to have
% been declared, apart from the special \texttt{unknown} choice, which
% must come last. The code for each choice is stored along with the
% key name in the variables property list.
% \begin{macrocode}
\cs_new_protected:Npn \@@_implement_choice_elt:n #1
\cs_new_protected:Npn \@@_implement_choice_elt:nn #1#2
{
\clist_if_empty:NTF \l_@@_tmp_clist
{
\str_if_eq:nnF {#1} { unknown }
\str_if_eq:nnF {#2} { unknown }
{
\prop_get:NoN \l_@@_keytypes_prop \l_@@_key_name_tl
\l_@@_tmp_tl
\@@_split_keytype_arg:o \l_@@_tmp_tl
\msg_error:nnxxx { xtemplate } { unknown-choice }
{ \l_@@_key_name_tl } {#1}
{ \l_@@_key_name_tl } {#2}
{ \l_@@_keytype_arg_tl }
}
}
{
\clist_if_in:NnTF \l_@@_tmp_clist {#1}
{ \clist_remove_all:Nn \l_@@_tmp_clist {#1} }
\clist_if_in:NnTF \l_@@_tmp_clist {#2}
{ \clist_remove_all:Nn \l_@@_tmp_clist {#2} }
{
\prop_get:NoN \l_@@_keytypes_prop \l_@@_key_name_tl
\l_@@_tmp_tl
\@@_split_keytype_arg:o \l_@@_tmp_tl
\msg_error:nnxxx { xtemplate } { unknown-choice }
{ \l_@@_key_name_tl } {#1}
{ \l_@@_key_name_tl } {#2}
{ \l_@@_keytype_arg_tl }
}
}
}
\cs_new_protected:Npn \@@_implement_choice_elt:nn #1#2
\cs_new_protected:Npn \@@_implement_choice_elt:nnn #1#2#3
{
\@@_implement_choice_elt:n {#1}
\@@_implement_choice_elt:nn {#1} {#2}
\keys_define:nx { template / #1 }
{ \l_@@_key_name_tl / #2 .code:n = { \exp_not:n {#3} } }
\tl_set:Nx \l_@@_tmp_tl
{ \l_@@_key_name_tl \c_space_tl #1 }
\prop_put:Non \l_@@_vars_prop \l_@@_tmp_tl {#2}
{ \l_@@_key_name_tl \c_space_tl #2 }
\prop_put:Non \l_@@_vars_prop \l_@@_tmp_tl {#3}
}
% \end{macrocode}
% \end{macro}
Expand Down

0 comments on commit d370a44

Please sign in to comment.