[latex3-commits] [git/LaTeX3-latex3-latex3] main: Support (x)template choices (d370a449c)
Joseph Wright
joseph.wright at morningstar2.co.uk
Mon May 30 14:49:40 CEST 2022
Repository : https://github.com/latex3/latex3
On branch : main
Link : https://github.com/latex3/latex3/commit/d370a449cb6f6e59283ec20276dc27af0f19e65d
>---------------------------------------------------------------
commit d370a449cb6f6e59283ec20276dc27af0f19e65d
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Mon May 30 13:49:40 2022 +0100
Support (x)template choices
>---------------------------------------------------------------
d370a449cb6f6e59283ec20276dc27af0f19e65d
l3packages/xtemplate/xtemplate.dtx | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/l3packages/xtemplate/xtemplate.dtx b/l3packages/xtemplate/xtemplate.dtx
index 656506f89..503db8acc 100644
--- a/l3packages/xtemplate/xtemplate.dtx
+++ b/l3packages/xtemplate/xtemplate.dtx
@@ -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}
@@ -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: }
@@ -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}
More information about the latex3-commits
mailing list.