[latex3-commits] [git/LaTeX3-latex3-latex3] master: Implement \exp_args_generate:n to define new \exp_args:N... functions (e7401e8)

Bruno Le Floch bruno at le-floch.fr
Wed Apr 4 19:04:49 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/e7401e85880352d69f0d1fa4c43469d2a6a27e49

>---------------------------------------------------------------

commit e7401e85880352d69f0d1fa4c43469d2a6a27e49
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Wed Apr 4 13:04:49 2018 -0400

    Implement \exp_args_generate:n to define new \exp_args:N... functions


>---------------------------------------------------------------

e7401e85880352d69f0d1fa4c43469d2a6a27e49
 l3kernel/l3candidates.dtx               |   13 +++++++++++
 l3kernel/l3expan.dtx                    |   39 +++++++++++++++++++++++++++++++
 l3kernel/l3msg.dtx                      |    8 +++++++
 l3kernel/testfiles/m3expan002.lvt       |   11 ++++++++-
 l3kernel/testfiles/m3expan002.tlg       |   26 +++++++++++++++++++++
 l3kernel/testfiles/m3expl001.luatex.tlg |    4 ++++
 l3kernel/testfiles/m3expl001.ptex.tlg   |    4 ++++
 l3kernel/testfiles/m3expl001.tlg        |    4 ++++
 l3kernel/testfiles/m3expl001.uptex.tlg  |    4 ++++
 l3kernel/testfiles/m3expl001.xetex.tlg  |    4 ++++
 l3kernel/testfiles/m3expl003.luatex.tlg |    4 ++++
 l3kernel/testfiles/m3expl003.ptex.tlg   |    4 ++++
 l3kernel/testfiles/m3expl003.tlg        |    4 ++++
 l3kernel/testfiles/m3expl003.uptex.tlg  |    4 ++++
 l3kernel/testfiles/m3expl003.xetex.tlg  |    4 ++++
 15 files changed, 136 insertions(+), 1 deletion(-)

diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index a7ac8da..acd4590 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -255,6 +255,19 @@
 %   should be defined.
 % \end{function}
 %
+% \begin{function}[added = 2018-04-04]{\exp_args_generate:n}
+%   \begin{syntax}
+%     \cs{exp_args_generate:n} \Arg{variant argument specifiers}
+%   \end{syntax}
+%   Defines \cs[no-index]{exp_args:N\meta{variant}} functions for each
+%   \meta{variant} given in the comma list \Arg{variant argument
+%   specifiers}.  Each \meta{variant} should consist of the letters |N|,
+%   |c|, |n|, |V|, |v|, |o|, |f|, |x|, |p| and the resulting function is
+%   protected if the letter |x| appears in the \meta{variant}.  This is
+%   only useful for cases where \cs{cs_generate_variant:Nn} is not
+%   applicable.
+% \end{function}
+%
 % \section{Additions to \pkg{l3file}}
 %
 % \begin{function}[added = 2017-07-11]{\file_get_mdfive_hash:nN}
diff --git a/l3kernel/l3expan.dtx b/l3kernel/l3expan.dtx
index 6c6d5fe..dd6d7d3 100644
--- a/l3kernel/l3expan.dtx
+++ b/l3kernel/l3expan.dtx
@@ -2051,6 +2051,45 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\exp_args_generate:n, \@@_args_generate:Nn}
+% \begin{macro}[EXP]{\@@_args_generate:n}
+%   This function is not used in the kernel hence we can use functions
+%   that are defined in later modules.  It also does not need to be fast
+%   so use inline mappings.  For each requested variant we check that
+%   there are no characters besides |NnpcofVvx|, in particular that
+%   there are no spaces.  Then we loop through the variant specifier and
+%   convert each letter to \cs[no-index]{::\meta{variant letter}}, with a
+%   trailing \cs{:::}.
+%    \begin{macrocode}
+\cs_new_protected:Npn \exp_args_generate:n #1
+  {
+    \exp_args:No \clist_map_inline:nn { \tl_to_str:n {#1} }
+      {
+        \str_map_inline:nn {##1}
+          {
+            \str_if_in:nnF { NnpcofVvx } {####1}
+              {
+                \__kernel_msg_error:nnnn { kernel } { invalid-exp-args }
+                  {####1} {##1}
+                \str_map_break:n { \use_none:nnnn }
+              }
+          }
+        \exp_args:Nc \@@_args_generate:Nn { exp_args:N ##1 } {##1}
+      }
+  }
+\cs_new_protected:Npn \@@_args_generate:Nn #1#2
+  {
+    \cs_if_exist:NF #1
+      {
+        \str_if_in:nnTF {#2} { x } { \cs_new_protected:Npx } { \cs_new:Npx }
+          #1 { \tl_map_function:nN { #2 : } \@@_args_generate:n }
+      }
+  }
+\cs_new:Npn \@@_args_generate:n #1 { \exp_not:c { :: #1 } }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 %    \begin{macrocode}
 %</initex|package>
 %    \end{macrocode}
diff --git a/l3kernel/l3msg.dtx b/l3kernel/l3msg.dtx
index 7b8cb29..df43e08 100644
--- a/l3kernel/l3msg.dtx
+++ b/l3kernel/l3msg.dtx
@@ -1786,6 +1786,14 @@
     with~a~signature~starting~with~'#1',~but~cannot~change~an~argument~
     from~type~'#3'~to~type~'#4'.
   }
+\__kernel_msg_new:nnnn { kernel } { invalid-exp-args }
+  { Invalid~variant~specifier~'#1'~in~'#2'. }
+  {
+    \c_@@_coding_error_text_tl
+    LaTeX~has~been~asked~to~create~an~\iow_char:N\\exp_args:N...~
+    function~with~signature~'N#2'~but~'#1'~is~not~a~valid~argument~
+    specifier.
+  }
 \__kernel_msg_new:nnn { kernel } { deprecated-variant }
   {
     Variant~form~'#1'~deprecated~for~base~form~'#2'.~
diff --git a/l3kernel/testfiles/m3expan002.lvt b/l3kernel/testfiles/m3expan002.lvt
index eec8baf..86dd0fb 100644
--- a/l3kernel/testfiles/m3expan002.lvt
+++ b/l3kernel/testfiles/m3expan002.lvt
@@ -1,5 +1,5 @@
 %
-% Copyright (C) 2012 The LaTeX3 Project
+% Copyright (C) 2012, 2018 The LaTeX3 Project
 %
 
 % Input the regression test macros for LaTeX
@@ -70,4 +70,13 @@
     \iow_term:x { \cs_meaning:N \cs_new:Non }
   }
 
+\TEST { \exp_args_generate:n }
+  {
+    \TYPE { \cs_meaning:N \exp_args:Nabc , \cs_meaning:N \exp_args:Nfoo , \cs_meaning:N \exp_args:Nfox }
+    \exp_args_generate:n { abc , foo , fox }
+    \TYPE { \cs_meaning:N \exp_args:Nabc , \cs_meaning:N \exp_args:Nfoo , \cs_meaning:N \exp_args:Nfox }
+    \exp_args_generate:n { foo , fox }
+    \TYPE { \cs_meaning:N \exp_args:Nfoo , \cs_meaning:N \exp_args:Nfox }
+  }
+
 \END
diff --git a/l3kernel/testfiles/m3expan002.tlg b/l3kernel/testfiles/m3expan002.tlg
index ce2623e..9041cf0 100644
--- a/l3kernel/testfiles/m3expan002.tlg
+++ b/l3kernel/testfiles/m3expan002.tlg
@@ -171,3 +171,29 @@ l. ...  }
 |...............................................
 undefined
 ============================================================
+============================================================
+TEST 4: \exp_args_generate:n 
+============================================================
+undefined,undefined,undefined
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/invalid-exp-args"
+! 
+! Invalid variant specifier 'a' in 'abc'.
+! 
+! 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 an \exp_args:N... function with signature
+| 'Nabc' but 'a' is not a valid argument specifier.
+|...............................................
+Defining \exp_args:Nfoo on line ...
+Defining \exp_args:Nfox on line ...
+undefined,\long macro:->\::f \::o \::o \::: ,\protected\long macro:->\::f \::o \::x \::: 
+\long macro:->\::f \::o \::o \::: ,\protected\long macro:->\::f \::o \::x \::: 
+============================================================
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 4c1acd8..201bd01 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -270,6 +270,9 @@ Defining \__cs_generate_variant_p_form:nnn on line ...
 Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
+Defining \exp_args_generate:n on line ...
+Defining \__cs_args_generate:Nn on line ...
+Defining \__cs_args_generate:n on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
@@ -3018,6 +3021,7 @@ Defining message LaTeX/kernel/scanmark-already-defined on line ...
 Defining message LaTeX/kernel/variable-not-defined on line ...
 Defining message LaTeX/kernel/variant-too-long on line ...
 Defining message LaTeX/kernel/invalid-variant on line ...
+Defining message LaTeX/kernel/invalid-exp-args on line ...
 Defining message LaTeX/kernel/deprecated-variant on line ...
 Defining message LaTeX/kernel/debug on line ...
 Defining message LaTeX/kernel/expr on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index f66d1fb..80a1fef 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -269,6 +269,9 @@ Defining \__cs_generate_variant_p_form:nnn on line ...
 Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
+Defining \exp_args_generate:n on line ...
+Defining \__cs_args_generate:Nn on line ...
+Defining \__cs_args_generate:n on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
@@ -2955,6 +2958,7 @@ Defining message LaTeX/kernel/scanmark-already-defined on line ...
 Defining message LaTeX/kernel/variable-not-defined on line ...
 Defining message LaTeX/kernel/variant-too-long on line ...
 Defining message LaTeX/kernel/invalid-variant on line ...
+Defining message LaTeX/kernel/invalid-exp-args on line ...
 Defining message LaTeX/kernel/deprecated-variant on line ...
 Defining message LaTeX/kernel/debug on line ...
 Defining message LaTeX/kernel/expr on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 47fbf05..e6437fb 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -269,6 +269,9 @@ Defining \__cs_generate_variant_p_form:nnn on line ...
 Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
+Defining \exp_args_generate:n on line ...
+Defining \__cs_args_generate:Nn on line ...
+Defining \__cs_args_generate:n on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
@@ -2955,6 +2958,7 @@ Defining message LaTeX/kernel/scanmark-already-defined on line ...
 Defining message LaTeX/kernel/variable-not-defined on line ...
 Defining message LaTeX/kernel/variant-too-long on line ...
 Defining message LaTeX/kernel/invalid-variant on line ...
+Defining message LaTeX/kernel/invalid-exp-args on line ...
 Defining message LaTeX/kernel/deprecated-variant on line ...
 Defining message LaTeX/kernel/debug on line ...
 Defining message LaTeX/kernel/expr on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 1b8e4e3..f75e0c9 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -269,6 +269,9 @@ Defining \__cs_generate_variant_p_form:nnn on line ...
 Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
+Defining \exp_args_generate:n on line ...
+Defining \__cs_args_generate:Nn on line ...
+Defining \__cs_args_generate:n on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
@@ -2955,6 +2958,7 @@ Defining message LaTeX/kernel/scanmark-already-defined on line ...
 Defining message LaTeX/kernel/variable-not-defined on line ...
 Defining message LaTeX/kernel/variant-too-long on line ...
 Defining message LaTeX/kernel/invalid-variant on line ...
+Defining message LaTeX/kernel/invalid-exp-args on line ...
 Defining message LaTeX/kernel/deprecated-variant on line ...
 Defining message LaTeX/kernel/debug on line ...
 Defining message LaTeX/kernel/expr on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 92df2a9..c65d62b 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -269,6 +269,9 @@ Defining \__cs_generate_variant_p_form:nnn on line ...
 Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
+Defining \exp_args_generate:n on line ...
+Defining \__cs_args_generate:Nn on line ...
+Defining \__cs_args_generate:n on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
@@ -3016,6 +3019,7 @@ Defining message LaTeX/kernel/scanmark-already-defined on line ...
 Defining message LaTeX/kernel/variable-not-defined on line ...
 Defining message LaTeX/kernel/variant-too-long on line ...
 Defining message LaTeX/kernel/invalid-variant on line ...
+Defining message LaTeX/kernel/invalid-exp-args on line ...
 Defining message LaTeX/kernel/deprecated-variant on line ...
 Defining message LaTeX/kernel/debug on line ...
 Defining message LaTeX/kernel/expr on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 4c1acd8..201bd01 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -270,6 +270,9 @@ Defining \__cs_generate_variant_p_form:nnn on line ...
 Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
+Defining \exp_args_generate:n on line ...
+Defining \__cs_args_generate:Nn on line ...
+Defining \__cs_args_generate:n on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
@@ -3018,6 +3021,7 @@ Defining message LaTeX/kernel/scanmark-already-defined on line ...
 Defining message LaTeX/kernel/variable-not-defined on line ...
 Defining message LaTeX/kernel/variant-too-long on line ...
 Defining message LaTeX/kernel/invalid-variant on line ...
+Defining message LaTeX/kernel/invalid-exp-args on line ...
 Defining message LaTeX/kernel/deprecated-variant on line ...
 Defining message LaTeX/kernel/debug on line ...
 Defining message LaTeX/kernel/expr on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index f66d1fb..80a1fef 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -269,6 +269,9 @@ Defining \__cs_generate_variant_p_form:nnn on line ...
 Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
+Defining \exp_args_generate:n on line ...
+Defining \__cs_args_generate:Nn on line ...
+Defining \__cs_args_generate:n on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
@@ -2955,6 +2958,7 @@ Defining message LaTeX/kernel/scanmark-already-defined on line ...
 Defining message LaTeX/kernel/variable-not-defined on line ...
 Defining message LaTeX/kernel/variant-too-long on line ...
 Defining message LaTeX/kernel/invalid-variant on line ...
+Defining message LaTeX/kernel/invalid-exp-args on line ...
 Defining message LaTeX/kernel/deprecated-variant on line ...
 Defining message LaTeX/kernel/debug on line ...
 Defining message LaTeX/kernel/expr on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 47fbf05..e6437fb 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -269,6 +269,9 @@ Defining \__cs_generate_variant_p_form:nnn on line ...
 Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
+Defining \exp_args_generate:n on line ...
+Defining \__cs_args_generate:Nn on line ...
+Defining \__cs_args_generate:n on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
@@ -2955,6 +2958,7 @@ Defining message LaTeX/kernel/scanmark-already-defined on line ...
 Defining message LaTeX/kernel/variable-not-defined on line ...
 Defining message LaTeX/kernel/variant-too-long on line ...
 Defining message LaTeX/kernel/invalid-variant on line ...
+Defining message LaTeX/kernel/invalid-exp-args on line ...
 Defining message LaTeX/kernel/deprecated-variant on line ...
 Defining message LaTeX/kernel/debug on line ...
 Defining message LaTeX/kernel/expr on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 1b8e4e3..f75e0c9 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -269,6 +269,9 @@ Defining \__cs_generate_variant_p_form:nnn on line ...
 Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
+Defining \exp_args_generate:n on line ...
+Defining \__cs_args_generate:Nn on line ...
+Defining \__cs_args_generate:n on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
@@ -2955,6 +2958,7 @@ Defining message LaTeX/kernel/scanmark-already-defined on line ...
 Defining message LaTeX/kernel/variable-not-defined on line ...
 Defining message LaTeX/kernel/variant-too-long on line ...
 Defining message LaTeX/kernel/invalid-variant on line ...
+Defining message LaTeX/kernel/invalid-exp-args on line ...
 Defining message LaTeX/kernel/deprecated-variant on line ...
 Defining message LaTeX/kernel/debug on line ...
 Defining message LaTeX/kernel/expr on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 92df2a9..c65d62b 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -269,6 +269,9 @@ Defining \__cs_generate_variant_p_form:nnn on line ...
 Defining \__cs_generate_variant_T_form:nnn on line ...
 Defining \__cs_generate_variant_F_form:nnn on line ...
 Defining \__cs_generate_variant_TF_form:nnn on line ...
+Defining \exp_args_generate:n on line ...
+Defining \__cs_args_generate:Nn on line ...
+Defining \__cs_args_generate:n on line ...
 Defining \tl_new:N on line ...
 Defining \tl_new:c on line ...
 Defining \tl_const:Nn on line ...
@@ -3016,6 +3019,7 @@ Defining message LaTeX/kernel/scanmark-already-defined on line ...
 Defining message LaTeX/kernel/variable-not-defined on line ...
 Defining message LaTeX/kernel/variant-too-long on line ...
 Defining message LaTeX/kernel/invalid-variant on line ...
+Defining message LaTeX/kernel/invalid-exp-args on line ...
 Defining message LaTeX/kernel/deprecated-variant on line ...
 Defining message LaTeX/kernel/debug on line ...
 Defining message LaTeX/kernel/expr on line ...





More information about the latex3-commits mailing list