[latex3-commits] [git/latex3] master: Allow (with warning) n to N/c and N to n/o/V/v/f/x in \cs_generate_variant:Nn (see #418) (af09f32)
Bruno Le Floch
bruno at le-floch.fr
Tue Nov 28 15:05:23 CET 2017
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/af09f32c8ff23a8888564e4a4141ea8d35976e79
>---------------------------------------------------------------
commit af09f32c8ff23a8888564e4a4141ea8d35976e79
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Tue Nov 28 09:04:28 2017 -0500
Allow (with warning) n to N/c and N to n/o/V/v/f/x in \cs_generate_variant:Nn (see #418)
>---------------------------------------------------------------
af09f32c8ff23a8888564e4a4141ea8d35976e79
l3kernel/l3expan.dtx | 92 ++++++++++++++++++-------------
l3kernel/testfiles/m3expan001.tlg | 28 +++-------
l3kernel/testfiles/m3expl001.luatex.tlg | 1 +
l3kernel/testfiles/m3expl001.ptex.tlg | 1 +
l3kernel/testfiles/m3expl001.tlg | 1 +
l3kernel/testfiles/m3expl001.uptex.tlg | 1 +
l3kernel/testfiles/m3expl001.xetex.tlg | 1 +
l3kernel/testfiles/m3expl003.luatex.tlg | 1 +
l3kernel/testfiles/m3expl003.ptex.tlg | 1 +
l3kernel/testfiles/m3expl003.tlg | 1 +
l3kernel/testfiles/m3expl003.uptex.tlg | 1 +
l3kernel/testfiles/m3expl003.xetex.tlg | 1 +
12 files changed, 71 insertions(+), 59 deletions(-)
diff --git a/l3kernel/l3expan.dtx b/l3kernel/l3expan.dtx
index c36176e..01ba894 100644
--- a/l3kernel/l3expan.dtx
+++ b/l3kernel/l3expan.dtx
@@ -153,18 +153,28 @@
% \cs[no-index]{exp_args:N\meta{variant}} function needed to carry out the
% expansion.
%
-% Only |n|~and |N| arguments can be changed to other types, and
-% |N|~can only be changed to~|c| while |n|~can only be changed to |V|,
-% |v|, |o|, |f|, or~|x|, so that it is unambiguous what the
-% \meta{parent} of a \meta{variant} is. For backwards-compatibility
-% it is currently possible to make an |o|-type variant of an |N|-type
-% argument or a |c|-type variant of an |n|-type argument. Both are
-% deprecated. The first because an |o|-type argument may expand to
-% more than one token. The second because programmers who use that
-% most often want to access the value of a variable given its name,
-% hence should use a |v|-type variant instead of |c|-type. In those
-% cases, using the lower-level \cs{exp_args:No} or \cs{exp_args:Nc}
-% functionns explicitly is preferred to defining confusing variants.
+% Only |n|~and |N| arguments can be changed to other types. The only
+% allowed changes are
+% \begin{itemize}
+% \item |c|~variant of an |N|~parent;
+% \item |o|, |V|, |v|, |f|, or~|x| variant of an |n|~parent;
+% \item |N|, |n|, |T|, |F|, or |p| argument unchanged.
+% \end{itemize}
+% This means the \meta{parent} of a \meta{variant} form is always
+% unambiguous, even in cases where both an |n|-type parent and an
+% |N|-type parent exist, such as for \cs{tl_count:n} and
+% \cs{tl_count:N}.
+%
+% For backward compatibility it is currently possible to make |n|,
+% |o|, |V|, |v|, |f|, or |x|-type variants of an |N|-type argument or
+% |N| or |c|-type variants of an |n|-type argument. Both are
+% deprecated. The first because passing more than one token to an
+% |N|-type argument will typically break the parent function's code.
+% The second because programmers who use that most often want to
+% access the value of a variable given its name, hence should use a
+% |V|-type or |v|-type variant instead of |c|-type. In those cases,
+% using the lower-level \cs{exp_args:No} or \cs{exp_args:Nc}
+% functions explicitly is preferred to defining confusing variants.
% \end{function}
%
% \section{Introducing the variants}
@@ -1715,6 +1725,7 @@
% \begin{macro}[aux, rEXP]
% {
% \@@_generate_variant_loop:nNwN,
+% \@@_generate_variant_loop_base:N,
% \@@_generate_variant_loop_same:w,
% \@@_generate_variant_loop_end:nwwwNNnn,
% \@@_generate_variant_loop_long:wNNnn,
@@ -1773,32 +1784,41 @@
% argument: this empty brace group produces the correct signature for
% the full variant.
%
-% Since people seem to have tried generating |c|-type variants of
-% |n|-type arguments, and |o|-type variants of |N|-type arguments, in
-% those cases we only produce a warning. Once we have waited long
-% enough the first construction involving
-% \cs{@@_generate_variant_loop_special:NNwNNnn} should be removed.
+% Since people seem to have tried generating |N| or |c|-type variants
+% of |n|-type arguments, and |n|, |o|, |V|, |v|, |f|, |x| variants of
+% |N|-type arguments, in those cases we only produce a warning.
% \begin{macrocode}
\cs_new:Npn \@@_generate_variant_loop:nNwN #1#2#3 \q_mark #4
{
\if:w #2 #4
\exp_after:wN \@@_generate_variant_loop_same:w
\else:
- \if:w 0
- \if:w n #4 \if:w c #2 1 \fi: \fi:
- \if:w N #4 \if:w o #2 1 \fi: \fi:
- 0
- \else:
- \@@_generate_variant_loop_special:NNwNNnn #4#2
- \exp_after:wN \reverse_if:N
+ \if:w #4 \@@_generate_variant_loop_base:N #2 \else:
+ \if:w 0
+ \if:w N #4 \else: \if:w n #4 \else: 1 \fi: \fi:
+ \if:w \scan_stop: \@@_generate_variant_loop_base:N #2 1 \fi:
+ 0
+ \@@_generate_variant_loop_special:NNwNNnn #4#2
+ \else:
+ \@@_generate_variant_loop_invalid:NNwNNnn #4#2
+ \fi:
\fi:
- \if:w #4
- \if:w c #2 N \else:
- \if:w o #2 n \else:
- \if:w V #2 n \else:
- \if:w v #2 n \else:
- \if:w f #2 n \else:
- \if:w x #2 n \else:
+ \fi:
+ #1
+ \prg_do_nothing:
+ #2
+ \@@_generate_variant_loop:nNwN { } #3 \q_mark
+ }
+\cs_new:Npn \@@_generate_variant_loop_base:N #1
+ {
+ \if:w c #1 N \else:
+ \if:w o #1 n \else:
+ \if:w V #1 n \else:
+ \if:w v #1 n \else:
+ \if:w f #1 n \else:
+ \if:w x #1 n \else:
+ \if:w n #1 n \else:
+ \if:w N #1 N \else:
\scan_stop:
\fi:
\fi:
@@ -1806,14 +1826,8 @@
\fi:
\fi:
\fi:
- \else:
- \@@_generate_variant_loop_invalid:NNwNNnn #4#2
\fi:
\fi:
- #1
- \prg_do_nothing:
- #2
- \@@_generate_variant_loop:nNwN { } #3 \q_mark
}
\cs_new:Npn \@@_generate_variant_loop_same:w
#1 \prg_do_nothing: #2#3#4
@@ -1854,9 +1868,9 @@
}
}
\cs_new:Npn \@@_generate_variant_loop_invalid:NNwNNnn
- #1#2 \fi: \fi: #3 \q_stop #4#5#6#7
+ #1#2 \fi: \fi: \fi: #3 \q_stop #4#5#6#7
{
- \fi: \fi:
+ \fi: \fi: \fi:
\exp_not:n
{
\q_mark
diff --git a/l3kernel/testfiles/m3expan001.tlg b/l3kernel/testfiles/m3expan001.tlg
index 264bc3e..a598aa7 100644
--- a/l3kernel/testfiles/m3expan001.tlg
+++ b/l3kernel/testfiles/m3expan001.tlg
@@ -251,24 +251,12 @@ Defining \foobar:Nc on line ...
*
* Variant form 'Nc' invalid for base form '\foobar:Nn'.
*************************************************
-Variant \foobar:Nn already defined; not changing it on line ...
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!
-! LaTeX error: "kernel/invalid-variant"
-!
-! Variant form 'n' invalid for base form '\foobar:Nn'.
-!
-! See the LaTeX3 documentation for further information.
-!
-! For immediate help type H <return>.
-!...............................................
-l. ... }
-|'''''''''''''''''''''''''''''''''''''''''''''''
-| This is a coding error.
-|
-| LaTeX has been asked to create a variant of the function '\foobar:Nn' with a
-| signature starting with 'n', but cannot change an argument from type 'N' to
-| type 'n'.
-|...............................................
-\long macro:->\exp_args:No \foobar:Nn ,\long macro:->\exp_args:NNc \foobar:Nn ,undefined,
+Defining \exp_args:Nn on line ...
+Defining \foobar:nn on line ...
+*************************************************
+* LaTeX warning: "kernel/invalid-variant"
+*
+* Variant form 'n' invalid for base form '\foobar:Nn'.
+*************************************************
+\long macro:->\exp_args:No \foobar:Nn ,\long macro:->\exp_args:NNc \foobar:Nn ,\long macro:->\exp_args:Nn \foobar:Nn ,
============================================================
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index c933d13..4b86cd2 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -246,6 +246,7 @@ Defining \__cs_generate_variant:wwNw on line ...
Defining \__cs_generate_variant:nnNN on line ...
Defining \__cs_generate_variant:Nnnw on line ...
Defining \__cs_generate_variant_loop:nNwN on line ...
+Defining \__cs_generate_variant_loop_base:N on line ...
Defining \__cs_generate_variant_loop_same:w on line ...
Defining \__cs_generate_variant_loop_end:nwwwNNnn on line ...
Defining \__cs_generate_variant_loop_long:wNNnn on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index f14e3d5..9f7e5a7 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -245,6 +245,7 @@ Defining \__cs_generate_variant:wwNw on line ...
Defining \__cs_generate_variant:nnNN on line ...
Defining \__cs_generate_variant:Nnnw on line ...
Defining \__cs_generate_variant_loop:nNwN on line ...
+Defining \__cs_generate_variant_loop_base:N on line ...
Defining \__cs_generate_variant_loop_same:w on line ...
Defining \__cs_generate_variant_loop_end:nwwwNNnn on line ...
Defining \__cs_generate_variant_loop_long:wNNnn on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 853492c..1867507 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -245,6 +245,7 @@ Defining \__cs_generate_variant:wwNw on line ...
Defining \__cs_generate_variant:nnNN on line ...
Defining \__cs_generate_variant:Nnnw on line ...
Defining \__cs_generate_variant_loop:nNwN on line ...
+Defining \__cs_generate_variant_loop_base:N on line ...
Defining \__cs_generate_variant_loop_same:w on line ...
Defining \__cs_generate_variant_loop_end:nwwwNNnn on line ...
Defining \__cs_generate_variant_loop_long:wNNnn on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index d36c769..12d663b 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -245,6 +245,7 @@ Defining \__cs_generate_variant:wwNw on line ...
Defining \__cs_generate_variant:nnNN on line ...
Defining \__cs_generate_variant:Nnnw on line ...
Defining \__cs_generate_variant_loop:nNwN on line ...
+Defining \__cs_generate_variant_loop_base:N on line ...
Defining \__cs_generate_variant_loop_same:w on line ...
Defining \__cs_generate_variant_loop_end:nwwwNNnn on line ...
Defining \__cs_generate_variant_loop_long:wNNnn on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 2ee11d1..cf8d05e 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -245,6 +245,7 @@ Defining \__cs_generate_variant:wwNw on line ...
Defining \__cs_generate_variant:nnNN on line ...
Defining \__cs_generate_variant:Nnnw on line ...
Defining \__cs_generate_variant_loop:nNwN on line ...
+Defining \__cs_generate_variant_loop_base:N on line ...
Defining \__cs_generate_variant_loop_same:w on line ...
Defining \__cs_generate_variant_loop_end:nwwwNNnn on line ...
Defining \__cs_generate_variant_loop_long:wNNnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index c933d13..4b86cd2 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -246,6 +246,7 @@ Defining \__cs_generate_variant:wwNw on line ...
Defining \__cs_generate_variant:nnNN on line ...
Defining \__cs_generate_variant:Nnnw on line ...
Defining \__cs_generate_variant_loop:nNwN on line ...
+Defining \__cs_generate_variant_loop_base:N on line ...
Defining \__cs_generate_variant_loop_same:w on line ...
Defining \__cs_generate_variant_loop_end:nwwwNNnn on line ...
Defining \__cs_generate_variant_loop_long:wNNnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index f14e3d5..9f7e5a7 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -245,6 +245,7 @@ Defining \__cs_generate_variant:wwNw on line ...
Defining \__cs_generate_variant:nnNN on line ...
Defining \__cs_generate_variant:Nnnw on line ...
Defining \__cs_generate_variant_loop:nNwN on line ...
+Defining \__cs_generate_variant_loop_base:N on line ...
Defining \__cs_generate_variant_loop_same:w on line ...
Defining \__cs_generate_variant_loop_end:nwwwNNnn on line ...
Defining \__cs_generate_variant_loop_long:wNNnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 853492c..1867507 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -245,6 +245,7 @@ Defining \__cs_generate_variant:wwNw on line ...
Defining \__cs_generate_variant:nnNN on line ...
Defining \__cs_generate_variant:Nnnw on line ...
Defining \__cs_generate_variant_loop:nNwN on line ...
+Defining \__cs_generate_variant_loop_base:N on line ...
Defining \__cs_generate_variant_loop_same:w on line ...
Defining \__cs_generate_variant_loop_end:nwwwNNnn on line ...
Defining \__cs_generate_variant_loop_long:wNNnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index d36c769..12d663b 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -245,6 +245,7 @@ Defining \__cs_generate_variant:wwNw on line ...
Defining \__cs_generate_variant:nnNN on line ...
Defining \__cs_generate_variant:Nnnw on line ...
Defining \__cs_generate_variant_loop:nNwN on line ...
+Defining \__cs_generate_variant_loop_base:N on line ...
Defining \__cs_generate_variant_loop_same:w on line ...
Defining \__cs_generate_variant_loop_end:nwwwNNnn on line ...
Defining \__cs_generate_variant_loop_long:wNNnn on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 2ee11d1..cf8d05e 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -245,6 +245,7 @@ Defining \__cs_generate_variant:wwNw on line ...
Defining \__cs_generate_variant:nnNN on line ...
Defining \__cs_generate_variant:Nnnw on line ...
Defining \__cs_generate_variant_loop:nNwN on line ...
+Defining \__cs_generate_variant_loop_base:N on line ...
Defining \__cs_generate_variant_loop_same:w on line ...
Defining \__cs_generate_variant_loop_end:nwwwNNnn on line ...
Defining \__cs_generate_variant_loop_long:wNNnn on line ...
More information about the latex3-commits
mailing list