[latex3-commits] [git/LaTeX3-latex3-latex3] master: Avoid suppressing expansion of the next token in \peek_regex_ functions (3b13fa567)

Bruno Le Floch blflatex at gmail.com
Sun Dec 6 08:47:37 CET 2020


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/3b13fa567585c924adc215308912151933f8db7c

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

commit 3b13fa567585c924adc215308912151933f8db7c
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Sun Dec 6 08:42:12 2020 +0100

    Avoid suppressing expansion of the next token in \peek_regex_ functions
    
    To test that, remove \begin{document} in the test file


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

3b13fa567585c924adc215308912151933f8db7c
 l3kernel/l3regex.dtx              | 18 +++++++++++-------
 l3kernel/testfiles/m3regex011.lvt |  6 +++---
 l3kernel/testfiles/m3regex011.tlg |  2 ++
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index 37ea18408..062c300a6 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -6487,12 +6487,16 @@
 % \begin{macro}{\@@_peek_end:, \@@_peek_remove_end:n}
 %   Once the regex matches (or permanently fails to match) we call
 %   \cs{@@_peek_end:}, or \cs{@@_peek_remove_end:n} with argument the
-%   last token seen (or rather tokens that \texttt{o}-expand and
-%   \texttt{x}-expand to it).  For \cs{peek_regex:nTF} we reinsert
-%   tokens seen by calling \cs{@@_peek_reinsert:N} regardless of the
-%   result of the match.  For \cs{peek_regex_remove_once:nTF} we reinsert the
-%   tokens seen only if the match failed; otherwise we just reinsert the
-%   tokens~|#1|, with one expansion.
+%   last token seen.  For \cs{peek_regex:nTF} we reinsert tokens seen by
+%   calling \cs{@@_peek_reinsert:N} regardless of the result of the
+%   match.  For \cs{peek_regex_remove_once:nTF} we reinsert the tokens
+%   seen only if the match failed; otherwise we just reinsert the
+%   tokens~|#1|, with one expansion.  To be more precise, |#1| consists
+%   of tokens that \texttt{o}-expand and \texttt{x}-expand to the last
+%   token seen, for example it is \cs{exp_not:N} \meta{cs} for a control
+%   sequence.  This means that just doing \cs{exp_after:wN}
+%   \cs{l_@@_peek_true_tl} |#1| would be unsafe because the expansion of
+%   \meta{cs} would be suppressed.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_peek_end:
   {
@@ -6503,7 +6507,7 @@
 \cs_new_protected:Npn \@@_peek_remove_end:n #1
   {
     \bool_if:NTF \g_@@_success_bool
-      { \exp_after:wN \l_@@_peek_true_tl #1 }
+      { \exp_args:NNo \use:nn \l_@@_peek_true_tl {#1} }
       { \@@_peek_reinsert:N \l_@@_peek_false_tl }
   }
 %    \end{macrocode}
diff --git a/l3kernel/testfiles/m3regex011.lvt b/l3kernel/testfiles/m3regex011.lvt
index 08bbd2ac9..dd4093328 100644
--- a/l3kernel/testfiles/m3regex011.lvt
+++ b/l3kernel/testfiles/m3regex011.lvt
@@ -8,7 +8,7 @@
 \debug_on:n { check-declarations , deprecation , log-functions }
 \ExplSyntaxOff
 
-\begin{document}
+% \begin{document}
 
 \START
 \AUTHOR{Bruno Le Floch}
@@ -50,7 +50,7 @@
     \SEPARATOR
     \peek_regex_remove_once:nTF { } { \TRUE \test:w } { \ERROR \test:w } \aaa \s_stop
     \peek_regex_remove_once:nT { a } { \TRUE \test:w } a \s_stop
-    \peek_regex_remove_once:nF { . (. a()) } { \ERROR \test:w } \test:w { a b \s_stop \test_show:w } \s_stop
+    \peek_regex_remove_once:nF { . (. a()) } { \ERROR \test:w } \test:w { a \test:w b \s_stop \test_show:w } \s_stop
     \peek_regex_remove_once:nTF { a \{ } { \TRUE \test:w } { \ERROR \test:w } a { b \s_stop \test_show:w } \s_stop
     \peek_regex_remove_once:nTF { \cL. } { \ERROR \test:w } { \FALSE \test:w } \aaa \s_stop
     \peek_regex_remove_once:nT { b } { \ERROR \test:w } \test:w a \s_stop
@@ -66,7 +66,7 @@
     \peek_regex:NF \l_tmpa_regex { \ERROR \test:w } \test:w a \s_stop
     \peek_regex_remove_once:NTF \l_tmpa_regex { \TRUE \test:w } { \ERROR \test:w } a \s_stop
     \peek_regex_remove_once:NT \l_tmpa_regex { \TRUE \test:w } a \s_stop
-    \peek_regex_remove_once:NF \l_tmpa_regex { \ERROR \test:w } \test:w a \s_stop
+    \peek_regex_remove_once:NF \l_tmpa_regex { \ERROR \test:w } \test:w \test_show:w a \s_stop
   }
 
 \TEST { Peek~regex~replace }
diff --git a/l3kernel/testfiles/m3regex011.tlg b/l3kernel/testfiles/m3regex011.tlg
index b0b2a1f48..6a2673df6 100644
--- a/l3kernel/testfiles/m3regex011.tlg
+++ b/l3kernel/testfiles/m3regex011.tlg
@@ -35,6 +35,7 @@ TRUE
 |\aaa |
 TRUE
 ||
+|b|
 |end-group character }|
 TRUE
 |b|
@@ -59,6 +60,7 @@ TRUE
 ||
 TRUE
 ||
+|the letter a|
 ============================================================
 ============================================================
 TEST 5: Peek regex replace





More information about the latex3-commits mailing list.