[latex3-commits] [git/LaTeX3-latex3-latex3] scan-quark: Have make conditional-generating function read the quark name from the arg (2f2123194)

PhelypeOleinik tex.phelype at gmail.com
Tue Apr 28 22:32:00 CEST 2020


Repository : https://github.com/latex3/latex3
On branch  : scan-quark
Link       : https://github.com/latex3/latex3/commit/2f2123194cba342334b8ce18d272af6c2bc685c1

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

commit 2f2123194cba342334b8ce18d272af6c2bc685c1
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date:   Tue Apr 28 17:32:00 2020 -0300

    Have make conditional-generating function read the quark name from the arg


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

2f2123194cba342334b8ce18d272af6c2bc685c1
 l3kernel/l3file.dtx             |  3 +-
 l3kernel/l3kernel-functions.dtx | 17 +++++++---
 l3kernel/l3keys.dtx             |  6 ++--
 l3kernel/l3quark.dtx            | 70 ++++++++++++++++++++++++++++++++++++++---
 l3kernel/l3regex.dtx            |  3 +-
 l3kernel/l3text.dtx             |  3 +-
 l3kernel/l3tl.dtx               |  3 +-
 l3kernel/l3token.dtx            |  3 +-
 8 files changed, 86 insertions(+), 22 deletions(-)

diff --git a/l3kernel/l3file.dtx b/l3kernel/l3file.dtx
index fab494feb..198298ae2 100644
--- a/l3kernel/l3file.dtx
+++ b/l3kernel/l3file.dtx
@@ -2432,8 +2432,7 @@
 % \begin{macro}[pTF]{\@@_quark_if_nil:n}
 %   Branching quark conditional.
 %    \begin{macrocode}
-\__kernel_quark_conditional_generate:NNnn \@@_quark_if_nil:n
-  \q_@@_nil { @@ } { TF }
+\__kernel_quark_conditional_generate:Nn \@@_quark_if_nil:n { TF }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3kernel/l3kernel-functions.dtx b/l3kernel/l3kernel-functions.dtx
index 5f70f4670..8b736e369 100644
--- a/l3kernel/l3kernel-functions.dtx
+++ b/l3kernel/l3kernel-functions.dtx
@@ -389,9 +389,9 @@
 %   They should be manually defined with \cs{quark_new:N}.
 % \end{function}
 %
-% \begin{function}{\__kernel_quark_conditional_generate:NNnn}
+% \begin{function}{\__kernel_quark_conditional_generate:Nn}
 %   \begin{syntax}
-%     \cs{__kernel_quark_conditional_generate:NNnn} \cs[no-index]{\meta{name}:\meta{arg spec}} \cs[no-index]{\meta{test-quark}} \Arg{namespace} \Arg{conditions}
+%     \cs{__kernel_quark_conditional_generate:Nn} \cs[no-index]{\meta{name}:\meta{arg spec}} \Arg{conditions}
 %   \end{syntax}
 %   Defines a quark conditional \cs[no-index]{\meta{name}:\meta{arg spec}}
 %   which tests if its argument is the \cs[no-index]{\meta{test-quark}},
@@ -399,6 +399,15 @@
 %   a comma-separated list of one or more of |p|, |T|, |F|, and |TF|, and
 %   defines one function for each \meta{condition} as described for
 %   \cs{prg_new_conditional:Npnn}.
+%   The \meta{name} of the function should indicate the \meta{namespace}
+%   (module) and the name of the quark being tested. The name should
+%   be of the form:
+%   \begin{verbatim}
+%     \__<module>_quark_if_<name>:<signature>
+%   \end{verbatim}
+%   where |<module>| is the identifier of the current module and |<name>|
+%   is the name of the quark to be tested.  The function will be defined
+%   to test for the quark \cs[no-index]{q__<module>_<name>}.
 %
 %   The \meta{arg spec} \emph{must} be one of the options listed
 %   below. \cs[no-index]{\meta{test-quark}}
@@ -406,7 +415,7 @@
 %   \meta{namespace} should be the name space to be used internally
 %   in the definition of auxiliaries (for example |__module|).
 %
-%   \cs{__kernel_quark_conditional_generate:NNNn} can define $2$ different
+%   \cs{__kernel_quark_conditional_generate:Nn} can define $2$ different
 %   types of quark-test functions. Which one is defined depends on
 %   the \meta{arg spec} of the given function:
 %   \begin{description}
@@ -423,7 +432,7 @@
 %   Any other signature, as well as a function without signature
 %   are errors, and in such case the definition is aborted.
 %
-%   \cs{__kernel_quark_conditional_generate:NNNn} does \emph{not} define
+%   \cs{__kernel_quark_conditional_generate:Nn} does \emph{not} define
 %   the \cs[no-index]{\meta{test-quark}}.
 %   It~should be manually defined with \cs{quark_new:N}.
 % \end{function}
diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index 2b5c6350d..648282cc8 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -1416,10 +1416,8 @@
 % \begin{macro}[pTF]{\@@_quark_if_nil:n}
 %   Branching quark conditional.
 %    \begin{macrocode}
-\__kernel_quark_conditional_generate:NNnn \@@_quark_if_nil:n
-  \q_@@_nil { @@ } { TF }
-\__kernel_quark_conditional_generate:NNnn \@@_quark_if_no_value:N
-  \q_@@_no_value { @@ } { TF }
+\__kernel_quark_conditional_generate:Nn \@@_quark_if_nil:n { TF }
+\__kernel_quark_conditional_generate:Nn \@@_quark_if_no_value:N { TF }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3kernel/l3quark.dtx b/l3kernel/l3quark.dtx
index 6252a525f..d61158dcf 100644
--- a/l3kernel/l3quark.dtx
+++ b/l3kernel/l3quark.dtx
@@ -408,6 +408,13 @@
 %    \end{macrocode}
 % \end{variable}
 %
+% \begin{variable}{\q_@@_nil}
+%   Private quark use for some tests.
+%    \begin{macrocode}
+\quark_new:N \q_@@_nil
+%    \end{macrocode}
+% \end{variable}
+%
 % \begin{macro}[EXP]{\quark_if_recursion_tail_stop:N}
 % \UnitTested
 % \begin{macro}[EXP]{\quark_if_recursion_tail_stop_do:Nn}
@@ -605,7 +612,7 @@
 %   \end{description}
 %   Any other signature causes an error, as does a function without signature.
 %
-% \begin{macro}{\__kernel_quark_conditional_generate:NNnn}
+% \begin{macro}{\__kernel_quark_conditional_generate:Nn}
 %   Similar to \cs{__kernel_quark_test_generate:N}, but defines
 %   quark branching conditionals like \cs{quark_if_nil:nTF}
 %   using |#2| as the test quark, |#3| as the name-space to define
@@ -622,7 +629,7 @@
 %   \@@_test_generate_aux:nnNNnNnn, \@@_test_generate_choose:nNnNnn}
 %    \begin{macrocode}
 \cs_new_protected:Npn \__kernel_quark_test_generate:N #1
-  { \@@_test_generate_aux:Nn #1 { __ \@@_get_module_name:N #1 } }
+  { \@@_test_generate_aux:Nx #1 { __ \@@_get_module_name:N #1 } }
 \cs_new_protected:Npn \@@_test_generate_aux:Nn #1 #2
   {
     \@@_test_generate:Nccn #1
@@ -636,12 +643,22 @@
       #1 { test }
   }
 \cs_generate_variant:Nn \@@_test_generate:NNNn { Ncc }
-\cs_new_protected:Npn \__kernel_quark_conditional_generate:NNnn #1
+\cs_new_protected:Npn \__kernel_quark_conditional_generate:Nn #1
+  {
+    \@@_conditional_generate_aux:Nxxn #1
+      { __ \@@_get_module_name:N #1 }
+      { \@@_get_quark_name:N #1 }
+  }
+\cs_new_protected:Npn \@@_conditional_generate_aux:Nnnn #1 #2 #3
+  { \@@_conditional_generate:Ncnn #1 { q #2 _ #3 } {#2} }
+\cs_generate_variant:Nn \@@_conditional_generate_aux:Nnnn { Nxx }
+\cs_new_protected:Npn \@@_conditional_generate:NNnn #1
   {
     \exp_last_unbraced:Nf \@@_test_generate_aux:nnNNnNnn
       { \cs_split_function:N #1 }
       #1 { conditional }
   }
+\cs_generate_variant:Nn \@@_conditional_generate:NNnn { Nc }
 \cs_new_protected:Npn \@@_test_generate_aux:nnNNnNnn #1 #2 #3 #4
   {
     \reverse_if:N \if_bool:N #3
@@ -894,7 +911,7 @@
 \cs_new:Npx \@@_get_module_name:N #1
   {
     \exp_not:N \exp_last_unbraced:Nf \exp_not:N \@@_get_module_name_auxi:w
-      { \exp_not:N \cs_to_str:N #1 } \token_to_str:N _ \exp_not:N \s_@@
+      { \exp_not:N \cs_to_str:N #1 } \token_to_str:N _ \s_@@
   }
 \cs_new:Npn \@@_get_module_name_auxi:w #1
   {
@@ -929,6 +946,51 @@
 % \end{macro}
 % \end{macro}
 %
+% \begin{macro}[rEXP]{\@@_get_quark_name:N}
+% \begin{macro}[rEXP]{
+%     \@@_quark_name_after_if:w,
+%     \@@_quark_name_after_if_cleanup:w,
+%     \@@_quark_name_until_colon:w,
+%   }
+%   \cs{@@_get_quark_name:N} takes a quark conditional function, and tries to
+%   guess the quark name that that function queries.  \cs{@@_get_quark_name:N}
+%   looks for the string |_quark_if_| in the function name, and takes everything
+%   up to the |:| as the name of the quark.  If either is not present, an error
+%   is raised and \cs{@@_get_quark_name:N} returns an empty string.
+%    \begin{macrocode}
+\cs_set:Npn \@@_tmp:w #1#2
+  {
+    \cs_new:Npn \@@_get_quark_name:N ##1
+      {
+        \exp_last_unbraced:Nf \@@_quark_name_after_if:w
+          { \cs_to_str:N ##1 } #1 \q_@@_nil \s_@@
+      }
+    \cs_new:Npn \@@_quark_name_after_if:w ##1 #1 ##2 \s_@@
+      {
+        \if_meaning:w \q_@@_nil ##2
+          \__kernel_msg_expandable_error:nn
+            { kernel } { invalid-quark-function }
+          \use_i:nnn
+        \fi:
+        \use:n { \@@_quark_name_after_if_cleanup:w ##2 }
+      }
+    \cs_new:Npn \@@_quark_name_after_if_cleanup:w ##1 #1 \q_@@_nil
+      { \@@_quark_name_until_colon:w ##1 #2 \q_@@_nil \s_@@ }
+    \cs_new:Npn \@@_quark_name_until_colon:w ##1 #2 ##2 \s_@@
+      {
+        \if_meaning:w \q_@@_nil ##2
+          \__kernel_msg_expandable_error:nn
+            { kernel } { invalid-quark-function }
+        \else:
+          ##1
+        \fi:
+      }
+  }
+\exp_args:Nxx \@@_tmp:w { \tl_to_str:n { _quark_if_ } } { \tl_to_str:n { : } }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 % \subsection{Scan marks}
 %
 %    \begin{macrocode}
diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index 64a86588e..609462e77 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -1137,8 +1137,7 @@
 % \begin{macro}[pTF]{\@@_quark_if_nil:n}
 %   Branching quark conditional.
 %    \begin{macrocode}
-\__kernel_quark_conditional_generate:NNnn \@@_quark_if_nil:N
-  \q_@@_nil { @@ } { F }
+\__kernel_quark_conditional_generate:Nn \@@_quark_if_nil:N { F }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3kernel/l3text.dtx b/l3kernel/l3text.dtx
index e24475643..0b9f2de5e 100644
--- a/l3kernel/l3text.dtx
+++ b/l3kernel/l3text.dtx
@@ -271,8 +271,7 @@
 % \begin{macro}[pTF]{\@@_quark_if_nil:n}
 %   Branching quark conditional.
 %    \begin{macrocode}
-\__kernel_quark_conditional_generate:NNnn \@@_quark_if_nil:n
-  \q_@@_nil { @@ } { TF }
+\__kernel_quark_conditional_generate:Nn \@@_quark_if_nil:n { TF }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index 924c7f8b2..702c49af7 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -1529,8 +1529,7 @@
 %   Functions to query recursion quarks.
 %    \begin{macrocode}
 \__kernel_quark_test_generate:N \@@_if_recursion_tail_break:nN
-\__kernel_quark_conditional_generate:NNnn \@@_quark_if_nil:n
-  \q_@@_nil { @@ } { TF }
+\__kernel_quark_conditional_generate:Nn \@@_quark_if_nil:n { TF }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
diff --git a/l3kernel/l3token.dtx b/l3kernel/l3token.dtx
index 5fa826bcb..e7221ca22 100644
--- a/l3kernel/l3token.dtx
+++ b/l3kernel/l3token.dtx
@@ -1120,8 +1120,7 @@
 % \begin{macro}[pTF]{\@@_quark_if_no_value:N}
 %   Functions to query recursion quarks.
 %    \begin{macrocode}
-\__kernel_quark_conditional_generate:NNnn \@@_quark_if_no_value:N
-  \q_@@_no_value { @@ } { TF }
+\__kernel_quark_conditional_generate:Nn \@@_quark_if_no_value:N { TF }
 %    \end{macrocode}
 % \end{macro}
 %





More information about the latex3-commits mailing list.