[latex3-commits] [git/LaTeX3-latex3-latex3] peek-regex: In l3regex, set \l_@@_max_pos_int as late as possible (f9f0a458c)

Joseph Wright joseph.wright at morningstar2.co.uk
Thu Dec 3 16:44:56 CET 2020


Repository : https://github.com/latex3/latex3
On branch  : peek-regex
Link       : https://github.com/latex3/latex3/commit/f9f0a458c84b2305c8973457a5e8066d3aedb4ce

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

commit f9f0a458c84b2305c8973457a5e8066d3aedb4ce
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Sun Jul 19 18:11:46 2020 +0200

    In l3regex, set \l_@@_max_pos_int as late as possible


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

f9f0a458c84b2305c8973457a5e8066d3aedb4ce
 l3kernel/l3regex.dtx | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index 70dbe752c..2b4a26bc0 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -852,6 +852,7 @@
 %     positions $\texttt{min_pos} - 1$ and $\texttt{max_pos}$
 %     correspond to imaginary begin and end markers (with
 %     non-existent category code and character code).
+%     $\texttt{max_pos}$ is only set quite late in the processing.
 %   \item \emph{Query}: the token list to which we apply the regular
 %     expression.
 %   \item \emph{State}: each state of the \textsc{nfa} is labelled by an
@@ -4643,7 +4644,6 @@
 \cs_new_protected:Npn \@@_match:n #1
   {
     \int_set:Nn \l_@@_min_pos_int { 2 }
-    \int_set:Nn \l_@@_max_pos_int { 2 + \tl_count_tokens:n {#1} }
     \@@_match_init:
     \@@_match_once_init:
     \tl_analysis_map_inline:nn {#1}
@@ -4653,8 +4653,7 @@
   }
 \cs_new_protected:Npn \@@_match_cs:n #1
   {
-    \int_set:Nn \l_@@_min_pos_int { 2 + \l_@@_max_pos_int }
-    \int_set:Nn \l_@@_max_pos_int { \l_@@_min_pos_int + \str_count:n {#1} }
+    \int_set:Nn \l_@@_min_pos_int { 2 }
     \int_set_eq:NN \l_@@_min_thread_int \l_@@_max_thread_int
     \@@_match_init:
     \@@_match_once_init:
@@ -4809,7 +4808,7 @@
     \prg_break_point:
     \bool_set_false:N \l_@@_fresh_thread_bool
     \if_int_compare:w \l_@@_max_thread_int > \l_@@_min_thread_int
-      \if_int_compare:w \l_@@_curr_pos_int < \l_@@_max_pos_int
+      \if_int_compare:w -2 < \l_@@_curr_char_int
         \exp_after:wN \exp_after:wN \exp_after:wN \use_none:n
       \fi:
     \fi:
@@ -5950,18 +5949,19 @@
 \cs_new_protected:Npn \@@_query_set:n #1
   {
     \int_zero:N \l_@@_balance_int
-    \int_set:Nn \l_@@_curr_pos_int { 1 }
+    \int_zero:N \l_@@_curr_pos_int
     \@@_query_set_aux:nN { } F
     \tl_analysis_map_inline:nn {#1}
       { \@@_query_set_aux:nN {##1} ##3 }
     \@@_query_set_aux:nN { } F
+    \int_set_eq:NN \l_@@_max_pos_int \l_@@_curr_pos_int
   }
 \cs_new_protected:Npn \@@_query_set_aux:nN #1#2
   {
+    \int_incr:N \l_@@_curr_pos_int
     \@@_toks_set:Nn \l_@@_curr_pos_int {#1}
     \__kernel_intarray_gset:Nnn \g_@@_balance_intarray
       { \l_@@_curr_pos_int } { \l_@@_balance_int }
-    \int_incr:N \l_@@_curr_pos_int
     \if_case:w "#2 \exp_stop_f:
     \or: \int_incr:N \l_@@_balance_int
     \or: \int_decr:N \l_@@_balance_int
@@ -6025,7 +6025,8 @@
       #1
       \@@_match:n {#2}
       \@@_extract:
-    \@@_group_end_extract_seq:Nn #3 {#2}
+      \@@_query_set:n {#2}
+    \@@_group_end_extract_seq:N #3
   }
 \cs_new_protected:Npn \@@_extract_all:nnN #1#2#3
   {
@@ -6033,7 +6034,8 @@
       \@@_multi_match:n { \@@_extract: }
       #1
       \@@_match:n {#2}
-    \@@_group_end_extract_seq:Nn #3 {#2}
+      \@@_query_set:n {#2}
+    \@@_group_end_extract_seq:N #3
   }
 %    \end{macrocode}
 % \end{macro}
@@ -6072,6 +6074,7 @@
         }
       #1
       \@@_match:n {#2}
+      \@@_query_set:n {#2}
       \__kernel_intarray_gset:Nnn \g_@@_submatch_prev_intarray
         { \l_@@_submatch_int } { 0 }
       \__kernel_intarray_gset:Nnn \g_@@_submatch_end_intarray
@@ -6086,12 +6089,12 @@
           \int_decr:N \l_@@_submatch_int
         \fi:
       \fi:
-    \@@_group_end_extract_seq:Nn #3 {#2}
+    \@@_group_end_extract_seq:N #3
   }
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\@@_group_end_extract_seq:Nn}
+% \begin{macro}{\@@_group_end_extract_seq:N}
 %   The end-points of submatches are stored as entries of two arrays
 %   from \cs{l_@@_min_submatch_int} to
 %   \cs{l_@@_submatch_int} (exclusive). Extract the relevant ranges
@@ -6100,9 +6103,8 @@
 %   whenever we see too many begin-group or end-group tokens in a
 %   submatch.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_group_end_extract_seq:Nn #1#2
+\cs_new_protected:Npn \@@_group_end_extract_seq:N #1
   {
-      \@@_query_set:n {#2}
       \flag_clear:n { @@_begin }
       \flag_clear:n { @@_end }
       \seq_set_from_function:NnN \l_@@_internal_seq





More information about the latex3-commits mailing list.