[latex3-commits] [l3svn] r6872 - Avoid defining the same grabber multiple times

noreply at latex-project.org noreply at latex-project.org
Thu Feb 9 23:51:27 CET 2017


Author: bruno
Date: 2017-02-09 23:51:27 +0100 (Thu, 09 Feb 2017)
New Revision: 6872

Modified:
   trunk/l3packages/xparse/testfiles/xparse001.ptex.tlg
   trunk/l3packages/xparse/testfiles/xparse001.tlg
   trunk/l3packages/xparse/testfiles/xparse001.uptex.tlg
   trunk/l3packages/xparse/xparse.dtx
Log:
Avoid defining the same grabber multiple times

For expandable commands, 't' (or 's') type arguments are
implemented by first grabbing the following token (or group)
in the input stream then testing it using an auxiliary.  That
auxiliary does not need to be named after the command; instead
it is now named after its delimiter.



Modified: trunk/l3packages/xparse/testfiles/xparse001.ptex.tlg
===================================================================
--- trunk/l3packages/xparse/testfiles/xparse001.ptex.tlg	2017-02-09 22:45:41 UTC (rev 6871)
+++ trunk/l3packages/xparse/testfiles/xparse001.ptex.tlg	2017-02-09 22:51:27 UTC (rev 6872)
@@ -729,7 +729,7 @@
 . Redefining command \foo with sig. 'sm' on line ....
 .................................................
 > \foo=macro:->\__xparse_start_expandable:nNNNn {sm}\foo  \foo code \foo
-defaults {\__xparse_expandable_grab_t:w \foo (arg 1)
+defaults {\__xparse_expandable_grab_t:w \__xparse_grabber_*:w
 *\__xparse_expandable_grab_m:w }.
 <recently read> }
 l. ...}
@@ -743,7 +743,8 @@
 .................................................
 > \foo=macro:->\__xparse_start_expandable:nNNNn {osm}\foo  \foo code \foo
 defaults {\__xparse_expandable_grab_D:w \foo (arg 1)
-[]\__xparse_expandable_grab_t:w \foo (arg 2) *\__xparse_expandable_grab_m:w }.
+[]\__xparse_expandable_grab_t:w \__xparse_grabber_*:w
+*\__xparse_expandable_grab_m:w }.
 <recently read> }
 l. ...}
 > \foo code=\long macro:#1#2#3->(#1)(#2)(#3).

Modified: trunk/l3packages/xparse/testfiles/xparse001.tlg
===================================================================
--- trunk/l3packages/xparse/testfiles/xparse001.tlg	2017-02-09 22:45:41 UTC (rev 6871)
+++ trunk/l3packages/xparse/testfiles/xparse001.tlg	2017-02-09 22:51:27 UTC (rev 6872)
@@ -729,7 +729,7 @@
 . Redefining command \foo with sig. 'sm' on line ....
 .................................................
 > \foo=macro:->\__xparse_start_expandable:nNNNn {sm}\foo  \foo code \foo
-defaults {\__xparse_expandable_grab_t:w \foo (arg 1)
+defaults {\__xparse_expandable_grab_t:w \__xparse_grabber_*:w
 *\__xparse_expandable_grab_m:w }.
 <recently read> }
 l. ...}
@@ -743,7 +743,8 @@
 .................................................
 > \foo=macro:->\__xparse_start_expandable:nNNNn {osm}\foo  \foo code \foo
 defaults {\__xparse_expandable_grab_D:w \foo (arg 1)
-[]\__xparse_expandable_grab_t:w \foo (arg 2) *\__xparse_expandable_grab_m:w }.
+[]\__xparse_expandable_grab_t:w \__xparse_grabber_*:w
+*\__xparse_expandable_grab_m:w }.
 <recently read> }
 l. ...}
 > \foo code=\long macro:#1#2#3->(#1)(#2)(#3).

Modified: trunk/l3packages/xparse/testfiles/xparse001.uptex.tlg
===================================================================
--- trunk/l3packages/xparse/testfiles/xparse001.uptex.tlg	2017-02-09 22:45:41 UTC (rev 6871)
+++ trunk/l3packages/xparse/testfiles/xparse001.uptex.tlg	2017-02-09 22:51:27 UTC (rev 6872)
@@ -729,7 +729,7 @@
 . Redefining command \foo with sig. 'sm' on line ....
 .................................................
 > \foo=macro:->\__xparse_start_expandable:nNNNn {sm}\foo  \foo code \foo
-defaults {\__xparse_expandable_grab_t:w \foo (arg 1)
+defaults {\__xparse_expandable_grab_t:w \__xparse_grabber_*:w
 *\__xparse_expandable_grab_m:w }.
 <recently read> }
 l. ...}
@@ -743,7 +743,8 @@
 .................................................
 > \foo=macro:->\__xparse_start_expandable:nNNNn {osm}\foo  \foo code \foo
 defaults {\__xparse_expandable_grab_D:w \foo (arg 1)
-[]\__xparse_expandable_grab_t:w \foo (arg 2) *\__xparse_expandable_grab_m:w }.
+[]\__xparse_expandable_grab_t:w \__xparse_grabber_*:w
+*\__xparse_expandable_grab_m:w }.
 <recently read> }
 l. ...}
 > \foo code=\long macro:#1#2#3->(#1)(#2)(#3).

Modified: trunk/l3packages/xparse/xparse.dtx
===================================================================
--- trunk/l3packages/xparse/xparse.dtx	2017-02-09 22:45:41 UTC (rev 6871)
+++ trunk/l3packages/xparse/xparse.dtx	2017-02-09 22:51:27 UTC (rev 6872)
@@ -874,6 +874,14 @@
 %    \end{macrocode}
 % \end{variable}
 %
+% \begin{variable}{\g_@@_grabber_int}
+%   Used (in exceptional cases) to get unique names for grabbers used by
+%   expandable commands.
+%    \begin{macrocode}
+\int_new:N \g_@@_grabber_int
+%    \end{macrocode}
+% \end{variable}
+%
 % \begin{variable}{\l_@@_fn_tl}
 %   For passing the pre-formed name of the auxiliary to be used as the
 %   parsing function.
@@ -2205,13 +2213,10 @@
   {
     \@@_add_default:
     \@@_add_expandable_grabber:n { t }
-    \bool_if:NTF \l_@@_all_long_bool
-      { \cs_set:cpn }
-      { \cs_set_nopar:cpn }
-      { \l_@@_expandable_aux_name_tl } ##1 #1 {##1}
+    \@@_get_grabber:NN #1 \l_@@_tmpa_tl
     \tl_put_right:Nx \l_@@_signature_tl
       {
-        \exp_not:c { \l_@@_expandable_aux_name_tl }
+        \exp_not:o \l_@@_tmpa_tl
         \exp_not:N #1
       }
     \bool_set_false:N \l_@@_long_bool
@@ -2241,6 +2246,52 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\@@_get_grabber:NN}
+% \begin{macro}[aux]{\@@_get_grabber_auxi:NN}
+% \begin{macro}[aux]{\@@_get_grabber_auxii:NN}
+%   Given a token |#1|, defines an expandable function delimited by that
+%   token and stores it in the token list~|#2|.  The function is named
+%   after the token, unless that function name is already taken by some
+%   other grabber (this can happen in the rare case where delimiters
+%   with different category codes are used in the same document): in
+%   that case use a global counter to get a unique name.  Since the
+%   grabbers are not named after \pkg{xparse} commands they should not
+%   be used to get material from the input stream.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_get_grabber:NN #1#2
+  {
+    \cs_set:Npn \@@_tmp:w ##1 #1 {##1}
+    \exp_args:Nc \@@_get_grabber_auxi:NN
+      { @@_grabber_ \token_to_str:N #1 :w } #2
+  }
+\cs_new_protected:Npn \@@_get_grabber_auxi:NN #1#2
+  {
+    \cs_if_eq:NNTF \@@_tmp:w #1
+      { \tl_set:Nn #2 {#1} }
+      {
+        \cs_if_exist:NTF #1
+          {
+            \int_gincr:N \g_@@_grabber_int
+            \exp_args:Nc \@@_get_grabber_auxi:NN
+              {
+                @@_grabber_
+                - \int_use:N \g_@@_grabber_int :w
+              }
+              #2
+          }
+          { \@@_get_grabber_auxii:NN #1 #2 }
+      }
+  }
+\cs_new_protected:Npn \@@_get_grabber_auxii:NN #1#2
+  {
+    \cs_set_eq:NN #1 \@@_tmp:w
+    \tl_set:Nn #2 {#1}
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
 % \subsection{Grabbing arguments}
 %
 % All of the grabbers follow the same basic pattern. The initial



More information about the latex3-commits mailing list