[latex3-commits] [l3svn] r6121 - Allow \tl_replace to replace \prg_do_nothing: (fixes #273)

noreply at latex-project.org noreply at latex-project.org
Tue Sep 29 22:31:06 CEST 2015


Author: bruno
Date: 2015-09-29 22:31:06 +0200 (Tue, 29 Sep 2015)
New Revision: 6121

Modified:
   trunk/l3kernel/l3tl.dtx
   trunk/l3kernel/testfiles/m3tl004.lvt
   trunk/l3kernel/testfiles/m3tl004.tlg
Log:
Allow \tl_replace to replace \prg_do_nothing: (fixes #273)

Instead of using \prg_do_nothing: to avoid losing braces,
use two empty brace groups (brace groups cannot appear in
the search text so that's safe; a single empty brace group
would disappear in some cases so two are needed).


Modified: trunk/l3kernel/l3tl.dtx
===================================================================
--- trunk/l3kernel/l3tl.dtx	2015-09-29 17:44:31 UTC (rev 6120)
+++ trunk/l3kernel/l3tl.dtx	2015-09-29 20:31:06 UTC (rev 6121)
@@ -1833,14 +1833,16 @@
 %   If on the one hand it is found within the \meta{token list}, then
 %   |##1| cannot contain the \meta{delimiter}~|#1| that we worked so
 %   hard to obtain, thus \cs{@@_replace_wrap:w} gets~|##1| as its own
-%   argument~|##1|, and wraps it using \cs{exp_not:o} for consumption by
+%   argument~|##1|, and protects it against
 %   the \texttt{x}-expanding assignment.  It also finds \cs{exp_not:n}
 %   as~|##2| and does nothing to it, thus letting through \cs{exp_not:n}
-%   \Arg{replacement} into the assignment.  (Note that
+%   \Arg{replacement} into the assignment.  Note that
 %   \cs{@@_replace_next:w} and \cs{@@_replace_wrap:w} are always called
-%   followed by \cs{prg_do_nothing:} to avoid losing braces when
-%   grabbing delimited arguments, hence the use of \cs{exp_not:o} rather
-%   than \cs{exp_not:n}.)  Afterwards, \cs{@@_replace_next:w} is called
+%   followed by two empty brace groups.  These are safe because no
+%   delimiter can match them.  They prevent losing braces when grabbing
+%   delimited arguments, but require the use of \cs{exp_not:o} and
+%   \cs{use_none:nn}, rather than simply \cs{exp_not:n}.
+%   Afterwards, \cs{@@_replace_next:w} is called
 %   to repeat the replacement, or \cs{@@_replace_wrap:w} if we only want
 %   a single replacement.  In this second case, |##1| is the
 %   \meta{remaining tokens} in the \meta{token list} and |##2| is some
@@ -1850,9 +1852,9 @@
 %
 %   If on the other hand the argument~|##1| of \cs{@@_replace_next:w} is
 %   delimited by the trailing \meta{pattern}~|#5|, then |##1| is
-%   \enquote{\cs{prg_do_nothing:} \meta{token list} \meta{delimiter}
+%   \enquote{\{ \} \{ \} \meta{token list} \meta{delimiter}
 %     \Arg{ending code}}, hence \cs{@@_replace_wrap:w} finds
-%   \enquote{\cs{prg_do_nothing:} \meta{token list}} as |##1| and the
+%   \enquote{\{ \} \{ \} \meta{token list}} as |##1| and the
 %   \meta{ending code} as~|##2|.  It leaves the \meta{token list} into
 %   the assignment and unbraces the \meta{ending code} which removes
 %   what remains (essentially the \meta{delimiter} and
@@ -1861,25 +1863,27 @@
 \cs_new_protected:Npn \@@_replace_auxii:nNNNnn #1#2#3#4#5#6
   {
     \group_align_safe_begin:
-    \cs_set:Npn \@@_replace_wrap:w ##1 #1 ##2 { \exp_not:o {##1} ##2 }
+    \cs_set:Npn \@@_replace_wrap:w ##1 #1 ##2
+      { \exp_not:o { \use_none:nn ##1 } ##2 }
     \cs_set:Npx \@@_replace_next:w ##1 #5
       {
         \exp_not:N \@@_replace_wrap:w ##1
         \exp_not:n { #1 }
         \exp_not:n { \exp_not:n {#6} }
-        \exp_not:n { #2 \prg_do_nothing: }
+        \exp_not:n { #2 { } { } }
       }
     #3 #4
       {
         \exp_after:wN \@@_replace_next:w
-        \exp_after:wN \prg_do_nothing: #4
+        \exp_after:wN { \exp_after:wN }
+        \exp_after:wN { \exp_after:wN }
+        #4
         #1
         {
           \if_false: { \fi: }
           \exp_after:wN \use_none:n \exp_after:wN { \if_false: } \fi:
         }
         #5
-        \q_recursion_stop
       }
     \group_align_safe_end:
   }

Modified: trunk/l3kernel/testfiles/m3tl004.lvt
===================================================================
--- trunk/l3kernel/testfiles/m3tl004.lvt	2015-09-29 17:44:31 UTC (rev 6120)
+++ trunk/l3kernel/testfiles/m3tl004.lvt	2015-09-29 20:31:06 UTC (rev 6121)
@@ -39,11 +39,15 @@
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-\TEST{bug~fix~for~tl_replace}{
+\TEST{bug~fixes~for~tl_replace}{
   \tl_new:N  \g_my_tl
   \tl_gset:Nn \g_my_tl {aabono}
   \tl_greplace_once:Nnn \g_my_tl {bonobo} {whatever}
   \tl_log:N \g_my_tl
+  \tl_gput_right:Nx \g_my_tl
+    { \prg_replicate:nn { 10 } { \exp_not:N \prg_do_nothing: } }
+  \tl_greplace_all:Nnn \g_my_tl { \prg_do_nothing: } { \x }
+  \tl_log:N \g_my_tl
 }
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Modified: trunk/l3kernel/testfiles/m3tl004.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3tl004.tlg	2015-09-29 17:44:31 UTC (rev 6120)
+++ trunk/l3kernel/testfiles/m3tl004.tlg	2015-09-29 20:31:06 UTC (rev 6121)
@@ -24,10 +24,11 @@
 FFFFFFF
 ============================================================
 ============================================================
-TEST 2: bug fix for tl_replace
+TEST 2: bug fixes for tl_replace
 ============================================================
 Defining \g_my_tl on line ...
 > \g_my_tl=aabono.
+> \g_my_tl=aabono\x \x \x \x \x \x \x \x \x \x .
 ============================================================
 ============================================================
 TEST 3: Trim spaces



More information about the latex3-commits mailing list