[latex3-commits] [l3svn] r7125 - Speed up finding submatch numbers in \g in l3regex replacement

noreply at latex-project.org noreply at latex-project.org
Tue Apr 25 07:05:04 CEST 2017


Author: bruno
Date: 2017-04-25 07:05:03 +0200 (Tue, 25 Apr 2017)
New Revision: 7125

Modified:
   trunk/l3experimental/l3str/l3regex.dtx
Log:
Speed up finding submatch numbers in \g in l3regex replacement

Also remove some outdated comments in the list of things to do


Modified: trunk/l3experimental/l3str/l3regex.dtx
===================================================================
--- trunk/l3experimental/l3str/l3regex.dtx	2017-04-25 04:51:07 UTC (rev 7124)
+++ trunk/l3experimental/l3str/l3regex.dtx	2017-04-25 05:05:03 UTC (rev 7125)
@@ -631,7 +631,8 @@
 %   \item Currently, |a{\x34}| is recognized as |a{4}|.
 %   \item Cleaner error reporting in the replacement phase.
 %   \item Add tracing information.
-%   \item Detect attempts to use back-references.
+%   \item Detect attempts to use back-references and other
+%     non-implemented syntax.
 %   \item Test for the maximum register \cs{c_max_register_int}.
 %   \item Find out whether the fact that |\W| and friends match the
 %     end-marker leads to bugs. Possibly update \cs{__regex_item_reverse:n}.
@@ -644,15 +645,12 @@
 % \begin{itemize}
 %   \item Shift arrays so that the useful information starts at
 %     position~$1$.
-%   \item Optimize |\c{abc}| for matching a specific control sequence.
 %   \item Only build \c{...} once.
 %   \item Use arrays for the left and right state stacks when
 %     compiling a regex.
 %   \item Should \cs{__regex_action_free_group:n} only be used for greedy
 %     |{n,}| quantifier? (I think not.)
 %   \item Quantifiers for |\u| and assertions.
-%   \item Improve digit grabbing for the |\g| escape in replacement.
-%     Allow arbitrary integer expressions for all those numbers?
 %   \item When matching, keep track of an explicit stack of
 %     \texttt{current_state} and \texttt{current_submatches}.
 %   \item If possible, when a state is reused by the same thread, kill
@@ -5124,34 +5122,34 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[aux]{\@@_replacement_g:w, \@@_replacement_g_digits:NN}
-%   An ugly method to grab digits for the |\g| escape sequence. At the
-%   end of the run of digits, check that it ends with a right brace.
+% \begin{macro}[aux]{\@@_replacement_g:w}
+% \begin{macro}[aux,rEXP]{\@@_replacement_g_digits:NN}
+%   Grab digits for the |\g| escape sequence in a primitive assignment
+%   to the integer \cs{l_@@_internal_a_int}.  At the end of the run of
+%   digits, check that it ends with a right brace.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_replacement_g:w #1#2
   {
     \str_if_eq_x:nnTF { #1#2 } { \@@_replacement_normal:n \c_left_brace_str }
-      {
-        \int_zero:N \l_@@_internal_a_int
-        \@@_replacement_g_digits:NN
-      }
+      { \l_@@_internal_a_int = \@@_replacement_g_digits:NN }
       { \@@_replacement_error:NNN g #1 #2 }
   }
-\cs_new_protected:Npn \@@_replacement_g_digits:NN #1#2
+\cs_new:Npn \@@_replacement_g_digits:NN #1#2
   {
     \token_if_eq_meaning:NNTF #1 \@@_replacement_normal:n
       {
         \if_int_compare:w 1 < 1#2 \exp_stop_f:
-          \int_set:Nn \l_@@_internal_a_int
-            { 10 * \l_@@_internal_a_int + #2 }
+          #2
           \exp_after:wN \use_i:nnn
           \exp_after:wN \@@_replacement_g_digits:NN
         \else:
+          \exp_stop_f:
           \exp_after:wN \@@_replacement_error:NNN
           \exp_after:wN g
         \fi:
       }
       {
+        \exp_stop_f:
         \if_meaning:w \@@_replacement_rbrace:N #1
           \exp_args:No \@@_replacement_put_submatch:n
             { \int_use:N \l_@@_internal_a_int }
@@ -5165,6 +5163,7 @@
   }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
 %
 % \subsubsection{Csnames in replacement}
 %



More information about the latex3-commits mailing list