[latex3-commits] [git/LaTeX3-latex3-latex3] master: allow n-type arguments for keyval_parse (5583ee118)

Joseph Wright joseph.wright at morningstar2.co.uk
Thu Dec 31 12:05:47 CET 2020


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

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

commit 5583ee11859379518de7a1bc9867918c517a1e6f
Author: Jonathan Spratte <jspratte at yahoo.de>
Date:   Sat Dec 19 20:04:10 2020 +0100

    allow n-type arguments for keyval_parse
    
    In https://tex.stackexchange.com/questions/573812/ Ulrich asked why
    \keyval_parse:NNn is restricted to N-type arguments, so I've implemented
    the n-type arguments.
    
    I've also ported a few minor performance tweaks from expkv. This way the
    performance loss of this commit stays minimal.


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

5583ee11859379518de7a1bc9867918c517a1e6f
 l3kernel/l3keys.dtx | 89 +++++++++++++++++++++++++++--------------------------
 1 file changed, 45 insertions(+), 44 deletions(-)

diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index d1f9f1926..65a2c70e9 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -969,30 +969,30 @@
     {
 %    \end{macrocode}
 %
-% \begin{macro}[EXP]{\keyval_parse:NNn}
+% \begin{macro}[EXP]{\keyval_parse:nnn, \keyval_parse:NNn}
 %   The main function starts the first of two loops. The outer loop splits the
 %   key--value list at active commas, the inner loop will do so at other commas.
 %   The use of \cs{s_@@_mark} here prevents loss of braces from the key
 %   argument.
 %    \begin{macrocode}
-      \cs_new:Npn \keyval_parse:NNn ##1 ##2 ##3
-        { \@@_loop_active:NNw ##1 ##2 \s_@@_mark ##3 #1 \s_@@_tail #1 }
+      \cs_new:Npn \keyval_parse:nnn ##1 ##2 ##3
+        { \@@_loop_active:nnw {##1} {##2} \s_@@_mark ##3 #1 \s_@@_tail #1 }
+      \cs_new_eq:NN \keyval_parse:NNn \keyval_parse:nnn
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[EXP]{\@@_loop_active:NNw}
+% \begin{macro}[EXP]{\@@_loop_active:nnw}
 %   First a fast test for the end of the loop is done, it'll gobble everything
 %   up to a \cs{s_@@_tail}. The loop ending macro will gobble everything to the
 %   last \cs{s_@@_mark} in this definition.
 %   If the end isn't reached yet, start the second loop splitting at other
 %   commas, and after that one iterate the current loop.
 %    \begin{macrocode}
-      \cs_new:Npn \@@_loop_active:NNw ##1 ##2 ##3 #1
+      \cs_new:Npn \@@_loop_active:nnw ##1 ##2 ##3 #1
         {
           \@@_if_recursion_tail:w ##3
             \@@_end_loop_active:w \s_@@_tail
-          \@@_loop_other:NNw ##1 ##2 ##3 , \s_@@_tail ,
-          \@@_loop_active:NNw ##1 ##2 \s_@@_mark
+          \@@_loop_other:nnw {##1} {##2} ##3 , \s_@@_tail ,
         }
 %    \end{macrocode}
 % \end{macro}
@@ -1003,14 +1003,14 @@
 %   token following \cs{s_@@_mark} that followed the equals sign. Hence they
 %   also test for the presence of such an equals sign simultaneously.
 %    \begin{macrocode}
-      \cs_new:Npn \@@_split_other:w ##1 = ##2 \s_@@_mark ##3 ##4 \s_@@_stop
+      \cs_new:Npn \@@_split_other:w ##1 = ##2 \s_@@_mark ##3
         { ##3 ##1 \s_@@_stop \s_@@_mark ##2 }
-      \cs_new:Npn \@@_split_active:w ##1 #2 ##2 \s_@@_mark ##3 ##4 \s_@@_stop
+      \cs_new:Npn \@@_split_active:w ##1 #2 ##2 \s_@@_mark ##3
         { ##3 ##1 \s_@@_stop \s_@@_mark ##2 }
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[EXP]{\@@_loop_other:NNw}
+% \begin{macro}[EXP]{\@@_loop_other:nnw}
 %   The second loop uses the same test for its end as the first loop, next it
 %   splits at the first active equals sign using \cs{@@_split_active:w}.  The
 %   \cs{s_@@_nil} prevents accidental brace stripping and acts as a delimiter in
@@ -1018,16 +1018,15 @@
 %   number of necessary expansion steps for the expected average use case of
 %   other equals signs and hence perform better on average.
 %    \begin{macrocode}
-      \cs_new:Npn \@@_loop_other:NNw ##1 ##2 ##3 ,
+      \cs_new:Npn \@@_loop_other:nnw ##1 ##2 ##3 ,
         {
           \@@_if_recursion_tail:w ##3
             \@@_end_loop_other:w \s_@@_tail
           \@@_split_active:w ##3 \s_@@_nil
             \s_@@_mark \@@_split_active_auxi:w
             #2 \s_@@_mark \@@_clean_up_active:w
-            \s_@@_stop
-          ##1 ##2
-          \@@_loop_other:NNw ##1 ##2 \s_@@_mark
+          {##1} {##2}
+          \s_@@_mark
         }
 %    \end{macrocode}
 % \end{macro}
@@ -1050,7 +1049,6 @@
           \@@_split_other:w ##1 \s_@@_nil
             \s_@@_mark \@@_misplaced_equal_after_active_error:w
             = \s_@@_mark \@@_split_active_auxii:w
-            \s_@@_stop
         }
 %    \end{macrocode}
 %   \cs{@@_split_active_auxii:w} gets the correct key name with a leading
@@ -1061,7 +1059,8 @@
       \cs_new:Npn \@@_split_active_auxii:w
           ##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_after_active_error:w
           \s_@@_stop \s_@@_mark
-        { \@@_trim:nN { ##1 } \@@_split_active_auxiii:w }
+          ##2 \s_@@_nil #2 \s_@@_mark \@@_clean_up_active:w
+        { \@@_trim:nN {##1} \@@_split_active_auxiii:w ##2 \s_@@_nil }
 %    \end{macrocode}
 %   Next we test for a misplaced active equals sign in the value, if none is
 %   found \cs{@@_split_active_auxiv:w} will be called.
@@ -1071,8 +1070,7 @@
           \@@_split_active:w ##2 \s_@@_nil
             \s_@@_mark \@@_misplaced_equal_in_split_error:w
             #2 \s_@@_mark \@@_split_active_auxiv:w
-            \s_@@_stop
-            { ##1 }
+            {##1}
         }
 %    \end{macrocode}
 %   This runs the last test after sanitising the remainder of the previous one.
@@ -1086,16 +1084,15 @@
           \@@_split_other:w ##1 \s_@@_nil
             \s_@@_mark \@@_misplaced_equal_in_split_error:w
             = \s_@@_mark \@@_split_active_auxv:w
-            \s_@@_stop
         }
 %    \end{macrocode}
 %   This last macro in this execution branch sanitises the last test, trims the
-%   value and passes it to \cs{@@_pair:nnNN}.
+%   value and passes it to \cs{@@_pair:nnnn}.
 %    \begin{macrocode}
       \cs_new:Npn \@@_split_active_auxv:w
           ##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_in_split_error:w
           \s_@@_stop \s_@@_mark
-        { \@@_trim:nN { ##1 } \@@_pair:nnNN }
+        { \@@_trim:nN { ##1 } \@@_pair:nnnn }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
@@ -1115,7 +1112,6 @@
           \@@_split_other:w ##1 \s_@@_nil
             \s_@@_mark \@@_split_other_auxi:w
             = \s_@@_mark \@@_clean_up_other:w
-            \s_@@_stop
         }
 %    \end{macrocode}
 % \end{macro}
@@ -1134,22 +1130,22 @@
 %   We know that the value doesn't contain misplaced active equals signs but we
 %   have to test for others.
 %    \begin{macrocode}
-      \cs_new:Npn \@@_split_other_auxii:w ##1 ##2 \s_@@_nil
+      \cs_new:Npn \@@_split_other_auxii:w
+          ##1 ##2 \s_@@_nil = \s_@@_mark \@@_clean_up_other:w
         {
           \@@_split_other:w ##2 \s_@@_nil
             \s_@@_mark \@@_misplaced_equal_in_split_error:w
             = \s_@@_mark \@@_split_other_auxiii:w
-            \s_@@_stop
             { ##1 }
         }
 %    \end{macrocode}
 %   \cs{@@_split_other_auxiii:w} sanitises the test for other equals signs,
-%   trims the value and forwards it to \cs{@@_pair:nnNN}.
+%   trims the value and forwards it to \cs{@@_pair:nnnn}.
 %    \begin{macrocode}
       \cs_new:Npn \@@_split_other_auxiii:w
           ##1 \s_@@_nil \s_@@_mark \@@_misplaced_equal_in_split_error:w
           \s_@@_stop \s_@@_mark
-        { \@@_trim:nN { ##1 } \@@_pair:nnNN }
+        { \@@_trim:nN { ##1 } \@@_pair:nnnn }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
@@ -1159,14 +1155,14 @@
 %   \cs{@@_clean_up_other:w} is the last branch that might exist. It is called
 %   if no equals sign was found, hence the only possibilities left are a blank
 %   list element, which is to be skipped, or a lonely key. If it's no empty list
-%   element this will trim the key name and forward it to \cs{@@_key:nNN}.
+%   element this will trim the key name and forward it to \cs{@@_key:nn}.
 %    \begin{macrocode}
       \cs_new:Npn \@@_clean_up_other:w
           ##1 \s_@@_nil \s_@@_mark \@@_split_other_auxi:w \s_@@_stop \s_@@_mark
         {
           \@@_if_blank:w ##1 \s_@@_nil \s_@@_stop \@@_blank_true:w
-            \s_@@_mark \s_@@_stop \use:n
-            { \@@_trim:nN { ##1 } \@@_key:nNN }
+            \s_@@_mark \s_@@_stop
+            \@@_trim:nN { ##1 } \@@_key:nn
         }
 %    \end{macrocode}
 % \end{macro}
@@ -1178,17 +1174,21 @@
 %    \begin{macrocode}
       \cs_new:Npn \@@_misplaced_equal_after_active_error:w
           \s_@@_mark ##1 \s_@@_stop \s_@@_mark ##2 \s_@@_nil
-          \s_@@_mark ##3 \s_@@_nil ##4 ##5
+           = \s_@@_mark \@@_split_active_auxii:w
+           \s_@@_mark ##3 \s_@@_nil
+           #2 \s_@@_mark \@@_clean_up_active:w
         {
           \__kernel_msg_expandable_error:nn
             { kernel } { misplaced-equals-sign }
+          \@@_loop_other:nnw
         }
       \cs_new:Npn \@@_misplaced_equal_in_split_error:w
           \s_@@_mark ##1 \s_@@_stop \s_@@_mark ##2 \s_@@_nil
-          ##3 ##4 ##5
+          ##3 \s_@@_mark ##4 ##5
         {
           \__kernel_msg_expandable_error:nn
             { kernel } { misplaced-equals-sign }
+          \@@_loop_other:nnw
         }
 %    \end{macrocode}
 % \end{macro}
@@ -1201,17 +1201,15 @@
 %    \begin{macrocode}
       \cs_new:Npn \@@_end_loop_other:w
           \s_@@_tail
-          \@@_split_active:w ##1 \s_@@_nil
-          \s_@@_mark \@@_split_active_auxi:w
+          \@@_split_active:w
+          \s_@@_mark \s_@@_tail
+          \s_@@_nil \s_@@_mark
+          \@@_split_active_auxi:w
           #2 \s_@@_mark \@@_clean_up_active:w
-          \s_@@_stop
-          ##2 ##3
-          \@@_loop_other:NNw ##4 \s_@@_mark
-        { }
+        { \@@_loop_active:nnw }
       \cs_new:Npn \@@_end_loop_active:w
           \s_@@_tail
-          \@@_loop_other:NNw ##1 , \s_@@_tail ,
-          \@@_loop_active:NNw ##2 \s_@@_mark
+          \@@_loop_other:nnw ##1 \s_@@_mark \s_@@_tail , \s_@@_tail ,
         { }
 %    \end{macrocode}
 % \end{macro}
@@ -1226,23 +1224,25 @@
 \group_end:
 %    \end{macrocode}
 %
-% \begin{macro}[EXP]{\@@_pair:nnNN, \@@_key:nNN}
+% \begin{macro}[EXP]{\@@_pair:nnnn, \@@_key:nn}
 %   These macros will be called on the parsed keys and values of the key--value
 %   list. All arguments are completely trimmed. They test for blank key names
-%   and call the functions passed to \cs{keyval_parse:NNn} inside of
+%   and call the functions passed to \cs{keyval_parse:nnn} inside of
 %   \cs{exp_not:n} with the correct arguments.
 %    \begin{macrocode}
-\cs_new:Npn \@@_pair:nnNN #1 #2 #3 #4
+\cs_new:Npn \@@_pair:nnnn #1 #2 #3 #4
   {
     \@@_if_blank:w \s_@@_mark #2 \s_@@_nil \s_@@_stop \@@_blank_key_error:w
       \s_@@_mark \s_@@_stop
     \exp_not:n { #4 { #2 } { #1 } }
+    \@@_loop_other:nnw {#3} {#4}
   }
-\cs_new:Npn \@@_key:nNN #1 #2 #3
+\cs_new:Npn \@@_key:nn #1 #2
   {
     \@@_if_blank:w \s_@@_mark #1 \s_@@_nil \s_@@_stop \@@_blank_key_error:w
       \s_@@_mark \s_@@_stop
     \exp_not:n { #2 { #1 } }
+    \@@_loop_other:nnw {#2}
   }
 %    \end{macrocode}
 % \end{macro}
@@ -1263,7 +1263,8 @@
 %   These macros will be called if the tests above didn't gobble them, they
 %   execute the branching.
 %    \begin{macrocode}
-\cs_new:Npn \@@_blank_true:w \s_@@_mark \s_@@_stop \use:n #1 #2 #3 { }
+\cs_new:Npn \@@_blank_true:w \s_@@_mark \s_@@_stop \@@_trim:nN #1 \@@_key:nn
+  { \@@_loop_other:nnw }
 \cs_new:Npn \@@_blank_key_error:w \s_@@_mark \s_@@_stop \exp_not:n #1
   {
     \__kernel_msg_expandable_error:nn





More information about the latex3-commits mailing list.