[latex3-commits] [l3svn] r7122 - Reduce use of ":D" do-not-use control sequences in l3regex

noreply at latex-project.org noreply at latex-project.org
Tue Apr 25 04:51:59 CEST 2017


Author: bruno
Date: 2017-04-25 04:51:59 +0200 (Tue, 25 Apr 2017)
New Revision: 7122

Modified:
   trunk/l3experimental/l3str/l3regex.dtx
Log:
Reduce use of ":D" do-not-use control sequences in l3regex


Modified: trunk/l3experimental/l3str/l3regex.dtx
===================================================================
--- trunk/l3experimental/l3str/l3regex.dtx	2017-04-25 02:24:19 UTC (rev 7121)
+++ trunk/l3experimental/l3str/l3regex.dtx	2017-04-25 02:51:59 UTC (rev 7122)
@@ -856,6 +856,89 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}[int]{\@@_standard_escapechar:}
+%   Make the \tn{escapechar} into the standard backslash.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_standard_escapechar:
+  { \int_set:Nn \tex_escapechar:D { `\\ } }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[int, EXP]{\@@_toks_use:w}
+%   Unpack a \tn{toks} given its number.
+%    \begin{macrocode}
+\cs_new:Npn \@@_toks_use:w { \tex_the:D \tex_toks:D }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[int]{\@@_toks_clear:N, \@@_toks_set:Nn, \@@_toks_set:No}
+%   Empty a \tn{toks} or set it to a value, given its number.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_toks_clear:N #1
+  { \tex_toks:D #1 { } }
+\cs_new_eq:NN \@@_toks_set:Nn \tex_toks:D
+\cs_new_protected:Npn \@@_toks_set:No #1
+  { \@@_toks_set:Nn #1 \exp_after:wN }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[int]{\@@_toks_memcpy:NNn}
+%   Copy |#3| \tn{toks} registers from |#2| onwards to |#1| onwards,
+%   like |C|'s |memcpy|.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_toks_memcpy:NNn #1#2#3
+  {
+    \prg_replicate:nn {#3}
+      {
+        \tex_toks:D #1 = \tex_toks:D #2
+        \int_incr:N #1
+        \int_incr:N #2
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[int]{\@@_toks_put_left:Nx}
+% \begin{macro}[int]{\@@_toks_put_right:Nx, \@@_toks_put_right:Nn}
+%   During the building phase we wish to add \texttt{x}-expanded
+%   material to \tn{toks}, either to the left or to the right. The
+%   expansion is done \enquote{by hand} for optimization (these
+%   operations are used quite a lot). The \texttt{Nn} version of
+%   \cs{@@_toks_put_right:Nx} is provided because it is more
+%   efficient than \texttt{x}-expanding with \cs{exp_not:n}.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_toks_put_left:Nx #1#2
+  {
+    \cs_set:Npx \@@_tmp:w { #2 }
+    \tex_toks:D #1 \exp_after:wN \exp_after:wN \exp_after:wN
+      { \exp_after:wN \@@_tmp:w \tex_the:D \tex_toks:D #1 }
+  }
+\cs_new_protected:Npn \@@_toks_put_right:Nx #1#2
+  {
+    \cs_set:Npx \@@_tmp:w {#2}
+    \tex_toks:D #1 \exp_after:wN
+      { \tex_the:D \tex_toks:D \exp_after:wN #1 \@@_tmp:w }
+  }
+\cs_new_protected:Npn \@@_toks_put_right:Nn #1#2
+  { \tex_toks:D #1 \exp_after:wN { \tex_the:D \tex_toks:D #1 #2 } }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}[int, rEXP]{\@@_current_cs_to_str:}
+%   Expands to the string representation of the token (known to be a
+%   control sequence) at the current position \cs{l_@@_current_pos_int}.
+%   It should only be used in \texttt{x}-expansion to avoid losing a
+%   leading space.
+%    \begin{macrocode}
+\cs_new:Npn \@@_current_cs_to_str:
+  {
+    \exp_after:wN \exp_after:wN \exp_after:wN \cs_to_str:N
+    \tex_the:D \tex_toks:D \l_@@_current_pos_int
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsubsection{Constants and variables}
 %
 % \begin{macro}[aux]{\@@_tmp:w}
@@ -1128,12 +1211,7 @@
     \int_compare:nNnTF \l_@@_current_catcode_int = 0
       {
         \tl_set:Nx \l_@@_internal_a_tl
-          {
-            \scan_stop:
-            \exp_after:wN \exp_after:wN \exp_after:wN \cs_to_str:N
-            \tex_the:D \tex_toks:D \l_@@_current_pos_int
-            \scan_stop:
-          }
+          { \scan_stop: \@@_current_cs_to_str: \scan_stop: }
         \tl_if_in:noTF { \scan_stop: #1 \scan_stop: } \l_@@_internal_a_tl
           { \@@_break_true:w } { }
       }
@@ -1157,12 +1235,7 @@
     \int_compare:nNnT \l_@@_current_catcode_int = 0
       {
         \group_begin:
-          \tl_set:Nx \l_@@_cs_name_tl
-            {
-              \exp_after:wN \exp_after:wN
-              \exp_after:wN \cs_to_str:N
-              \tex_the:D \tex_toks:D \l_@@_current_pos_int
-            }
+          \tl_set:Nx \l_@@_cs_name_tl { \@@_current_cs_to_str: }
           \@@_single_match:
           \@@_disable_submatches:
           \@@_build_for_cs:n {#1}
@@ -1330,7 +1403,7 @@
       \cs_set:Npn \@@_escape_unescaped:N ##1 { #1 }
       \cs_set:Npn \@@_escape_escaped:N ##1 { #2 }
       \cs_set:Npn \@@_escape_raw:N ##1 { #3 }
-      \int_set:Nn \tex_escapechar:D { `\\ }
+      \@@_standard_escapechar:
       \tl_gset:Nx \g_@@_internal_tl { \__str_to_other_fast:n {#4} }
       \tl_set:Nx \l_@@_internal_b_tl
         {
@@ -2031,7 +2104,7 @@
 \cs_new_protected:Npn \@@_compile:n #1
   {
     \@@_compile:w
-      \int_set:Nn \tex_escapechar:D { `\\ }
+      \@@_standard_escapechar:
       \int_set_eq:NN \l_@@_mode_int \c_@@_outer_mode_int
       \@@_escape_use:nnnn
         {
@@ -2955,7 +3028,7 @@
   {
     \if_int_odd:w \__int_eval:w \l_@@_catcodes_int / #1 \__int_eval_end:
     \else:
-      \tex_advance:D \l_@@_catcodes_int #1
+      \int_add:Nn \l_@@_catcodes_int {#1}
     \fi:
   }
 \cs_new_protected:Npn \@@_compile_c_lbrack_end:
@@ -3530,7 +3603,7 @@
 \cs_new_protected:Npn \@@_build:N #1
   {
 %<trace>    \trace_push:nnn { regex } { 1 } { @@_build }
-    \int_set:Nn \tex_escapechar:D { `\\ }
+    \@@_standard_escapechar:
     \int_zero:N \l_@@_capturing_group_int
     \int_set_eq:NN \l_@@_max_state_int \l_@@_min_state_int
     \@@_build_new_state:
@@ -3598,33 +3671,6 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[int]{\@@_toks_put_left:Nx}
-% \begin{macro}[int]{\@@_toks_put_right:Nx, \@@_toks_put_right:Nn}
-%   During the building phase we wish to add \texttt{x}-expanded
-%   material to \tn{toks}, either to the left or to the right. The
-%   expansion is done \enquote{by hand} for optimization (these
-%   operations are used quite a lot). The \texttt{Nn} version of
-%   \cs{@@_toks_put_right:Nx} is provided because it is more
-%   efficient than \texttt{x}-expanding with \cs{exp_not:n}.
-%    \begin{macrocode}
-\cs_new_protected:Npn \@@_toks_put_left:Nx #1#2
-  {
-    \cs_set:Npx \@@_tmp:w { #2 }
-    \tex_toks:D #1 \exp_after:wN \exp_after:wN \exp_after:wN
-      { \exp_after:wN \@@_tmp:w \tex_the:D \tex_toks:D #1 }
-  }
-\cs_new_protected:Npn \@@_toks_put_right:Nx #1#2
-  {
-    \cs_set:Npx \@@_tmp:w {#2}
-    \tex_toks:D #1 \exp_after:wN
-      { \tex_the:D \tex_toks:D \exp_after:wN #1 \@@_tmp:w }
-  }
-\cs_new_protected:Npn \@@_toks_put_right:Nn #1#2
-  { \tex_toks:D #1 \exp_after:wN { \tex_the:D \tex_toks:D #1 #2 } }
-%    \end{macrocode}
-% \end{macro}
-% \end{macro}
-%
 % \begin{macro}[int]
 %   {
 %     \@@_build_transition_left:NNN,
@@ -3661,7 +3707,7 @@
         \int_eval:n { \l_@@_max_state_int + 1 }
       }
 %</trace>
-    \tex_toks:D \l_@@_max_state_int { }
+    \@@_toks_clear:N \l_@@_max_state_int
     \int_set_eq:NN \l_@@_left_state_int \l_@@_right_state_int
     \int_set_eq:NN \l_@@_right_state_int \l_@@_max_state_int
     \int_incr:N \l_@@_max_state_int
@@ -3974,15 +4020,12 @@
           ( #1 - 1 )
           * ( \l_@@_internal_b_int - \l_@@_internal_a_int )
         }
-      \tex_advance:D \l_@@_right_state_int \l_@@_internal_c_int
-      \tex_advance:D \l_@@_max_state_int   \l_@@_internal_c_int
-      \prg_replicate:nn \l_@@_internal_c_int
-        {
-          \tex_toks:D \l_@@_internal_b_int
-            = \tex_toks:D \l_@@_internal_a_int
-          \int_incr:N \l_@@_internal_a_int
-          \int_incr:N \l_@@_internal_b_int
-        }
+      \int_add:Nn \l_@@_right_state_int { \l_@@_internal_c_int }
+      \int_add:Nn \l_@@_max_state_int   { \l_@@_internal_c_int }
+      \@@_toks_memcpy:NNn
+        \l_@@_internal_b_int
+        \l_@@_internal_a_int
+        \l_@@_internal_c_int
     \fi:
   }
 %    \end{macrocode}
@@ -4501,7 +4544,7 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_match_loop:
   {
-    \tex_advance:D \l_@@_step_int 2 \exp_stop_f:
+    \int_add:Nn \l_@@_step_int { 2 }
     \int_incr:N \l_@@_current_pos_int
     \int_set_eq:NN \l_@@_last_char_int \l_@@_current_char_int
     \int_set_eq:NN \l_@@_case_changed_char_int \c_max_int
@@ -4527,7 +4570,7 @@
   {
     \@@_use_state_and_submatches:nn
       { \__intarray_item_fast:Nn \g_@@_thread_state_intarray {#1} }
-      { \tex_the:D \tex_toks:D #1 }
+      { \@@_toks_use:w #1 }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -4548,7 +4591,7 @@
       { \l_@@_current_pos_int } {#2}
     \__intarray_gset_fast:Nnn \g_@@_balance_intarray
       { \l_@@_current_pos_int } { \l_@@_balance_int }
-    \tex_toks:D \l_@@_current_pos_int {#1}
+    \@@_toks_set:Nn \l_@@_current_pos_int {#1}
     \int_incr:N \l_@@_current_pos_int
     \if_case:w #2 \exp_stop_f:
     \or: \int_incr:N \l_@@_balance_int
@@ -4591,7 +4634,7 @@
 %</trace>
     \__intarray_gset_fast:Nnn \g_@@_state_active_intarray
       { \l_@@_current_state_int } { \l_@@_step_int }
-    \tex_the:D \tex_toks:D \l_@@_current_state_int
+    \@@_toks_use:w \l_@@_current_state_int
     \__intarray_gset_fast:Nnn \g_@@_state_active_intarray
       { \l_@@_current_state_int } { \l_@@_step_int + 1 }
   }
@@ -4710,7 +4753,7 @@
   }
 \cs_new_protected:Npn \@@_store_submatches:
   {
-    \tex_toks:D \l_@@_max_active_int \exp_after:wN
+    \@@_toks_set:No \l_@@_max_active_int
       { \l_@@_current_submatches_prop }
   }
 %    \end{macrocode}
@@ -4872,7 +4915,7 @@
     \else:
       \exp_after:wN \__prg_break:
     \fi:
-    \tex_the:D \tex_toks:D #1 \exp_stop_f:
+    \@@_toks_use:w #1 \exp_stop_f:
     \exp_after:wN \@@_query_range_loop:ww
       \__int_value:w \__int_eval:w #1 + 1 ; #2 ;
   }
@@ -6221,7 +6264,7 @@
       { \l_@@_max_state_int - 1 }
       {
         \trace:nnx { regex } { #1 }
-          { \iow_char:N \\toks ##1 = { \tex_the:D \tex_toks:D ##1 } }
+          { \iow_char:N \\toks ##1 = { \@@_toks_use:w ##1 } }
       }
   }
 %</trace>



More information about the latex3-commits mailing list