[latex3-commits] [git/LaTeX3-latex3-latex3] gh590: Implement \regex_log:N/n and c variants (see #884) (97778d837)

Bruno Le Floch blflatex at gmail.com
Mon Apr 26 22:59:46 CEST 2021


Repository : https://github.com/latex3/latex3
On branch  : gh590
Link       : https://github.com/latex3/latex3/commit/97778d83743350e996a82c5caf612d75e9c18f64

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

commit 97778d83743350e996a82c5caf612d75e9c18f64
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Mon Apr 26 22:58:31 2021 +0200

    Implement \regex_log:N/n and c variants (see #884)
    
    This is a minor aspect of #884, but it is nice to have consistency
    between different datatypes since we already have \regex_show:N/n


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

97778d83743350e996a82c5caf612d75e9c18f64
 l3kernel/l3regex.dtx              | 46 ++++++++++++++++++++++++++-------------
 l3kernel/testfiles/m3regex007.lvt | 13 ++++++++++-
 l3kernel/testfiles/m3regex007.tlg | 43 ++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 16 deletions(-)

diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index 6c49e90b2..7973ee431 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -510,18 +510,24 @@
 %   which never change.
 % \end{function}
 %
-% \begin{function}[added = 2017-05-26, updated = 2021-04-15]{\regex_show:n, \regex_show:N}
+% \begin{function}[added = 2021-04-26]
+%   {
+%     \regex_show:N, \regex_show:c, \regex_show:n,
+%     \regex_log:N, \regex_log:c, \regex_log:n,
+%   }
 %   \begin{syntax}
 %     \cs{regex_show:n} \Arg{regex}
+%     \cs{regex_log:n} \Arg{regex}
 %   \end{syntax}
-%   Shows how \pkg{l3regex} interprets the \meta{regex}. For instance,
+%   Displays in the terminal or writes in the log file (respectively)
+%   how \pkg{l3regex} interprets the \meta{regex}. For instance,
 %   \cs{regex_show:n} \verb+{\A X|Y}+ shows
 %   \begin{verbatim}
 %     +-branch
 %       anchor at start (\A)
-%       char code 88
+%       char code 88 (X)
 %     +-branch
-%       char code 89
+%       char code 89 (Y)
 %   \end{verbatim}
 %   indicating that the anchor |\A| only applies to the first branch:
 %   the second branch is not anchored to the beginning of the match.
@@ -5918,26 +5924,36 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\regex_show:N, \regex_show:n}
+% \begin{macro}
+%   {
+%     \regex_show:n, \regex_log:n, \@@_show:Nn,
+%     \regex_show:N, \regex_show:c, \regex_log:N, \regex_log:c, \@@_show:NN
+%   }
 %   User functions: the \texttt{n} variant requires compilation first.
 %   Then show the variable with some appropriate text. The auxiliary
-%   is defined in a different section.
+%   \cs{@@_show:N} is defined in a different section.
 %    \begin{macrocode}
-\cs_new_protected:Npn \regex_show:n #1
+\cs_new_protected:Npn \regex_show:n { \@@_show:Nn \__kernel_msg_show:nnxxxx }
+\cs_new_protected:Npn \regex_log:n { \@@_show:Nn \__kernel_msg_log:nnxxxx }
+\cs_new_protected:Npn \@@_show:Nn #1#2
   {
-    \@@_compile:n {#1}
+    \@@_compile:n {#2}
     \@@_show:N \l_@@_internal_regex
-    \__kernel_msg_show:nnxxxx { regex } { show }
-      { \tl_to_str:n {#1} } { }
+    #1 { regex } { show }
+      { \tl_to_str:n {#2} } { }
       { \l_@@_internal_a_tl } { }
   }
-\cs_new_protected:Npn \regex_show:N #1
+\cs_new_protected:Npn \regex_show:N { \@@_show:NN \__kernel_msg_show:nnxxxx }
+\cs_generate_variant:Nn \regex_show:N { c }
+\cs_new_protected:Npn \regex_log:N { \@@_show:NN \__kernel_msg_log:nnxxxx }
+\cs_generate_variant:Nn \regex_log:N { c }
+\cs_new_protected:Npn \@@_show:NN #1#2
   {
-    \__kernel_chk_defined:NT #1
+    \__kernel_chk_defined:NT #2
       {
-        \@@_show:N #1
-        \__kernel_msg_show:nnxxxx { regex } { show }
-          { } { \token_to_str:N #1 }
+        \@@_show:N #2
+        #1 { regex } { show }
+          { } { \token_to_str:N #2 }
           { \l_@@_internal_a_tl } { }
       }
   }
diff --git a/l3kernel/testfiles/m3regex007.lvt b/l3kernel/testfiles/m3regex007.lvt
index b3e40a615..6d64b6030 100644
--- a/l3kernel/testfiles/m3regex007.lvt
+++ b/l3kernel/testfiles/m3regex007.lvt
@@ -30,7 +30,7 @@
     \regex_show:n { \u{l_tmpa_tl}* \c{\u{l_tmpa_tl}|(?:\u{l_tmpa_int})?}{3}|y* }
     \regex_show:n { a(?: bc (?| de | f ){2} g | hi ){3,4}? }
     \regex_new:N \l_bar_regex
-    \regex_show:N \l_bar_regex
+    \regex_show:c { l_bar_regex }
     \regex_show:N \g_undefined_regex
   }
 
@@ -52,5 +52,16 @@
     \regex_show:n { \0\1\2\3\4\5\6\7\8\9 }
   }
 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\TEST { regex_log }
+  {
+    \regex_set:Nn \l_foo_regex { \A a|b| }
+    \regex_log:c { l_foo_regex }
+    \SEPARATOR
+    \regex_log:n { a \ur{l_foo_regex} b \c{\ur{l_foo_regex}{2,7}?|D} }
+    \SEPARATOR
+    \regex_log:N \g_undefined_regex
+  }
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \END
diff --git a/l3kernel/testfiles/m3regex007.tlg b/l3kernel/testfiles/m3regex007.tlg
index 1d6e96754..dd7eda821 100644
--- a/l3kernel/testfiles/m3regex007.tlg
+++ b/l3kernel/testfiles/m3regex007.tlg
@@ -363,3 +363,46 @@ l. ...  }
 <recently read> }
 l. ...  }
 ============================================================
+============================================================
+TEST 4: regex_log
+============================================================
+> Compiled regex variable \l_foo_regex:
++-branch
+  assertion: anchor at start (\A)
+  char code 97 (a)
++-branch
+  char code 98 (b)
++-branch
+============================================================
+> Compiled regex {a\ur {l_foo_regex}b\c {\ur {l_foo_regex}{2,7}?|D}}:
++-branch
+  char code 97 (a)
+  ,-group begin (no capture)
+  | assertion: anchor at start (\A)
+  | char code 97 (a)
+  +-branch
+  | char code 98 (b)
+  +-branch
+  `-group end
+  char code 98 (b)
+  Match
+    control sequence
+    +-branch
+      ,-group begin (no capture)
+      | assertion: anchor at start (\A)
+      | char code 97 (a)
+      +-branch
+      | char code 98 (b)
+      +-branch
+      `-group end, repeated between 2 and 7 times, lazy
+    +-branch
+      char code 68 (D)
+============================================================
+! LaTeX3 Error: Variable \g_undefined_regex undefined.
+For immediate help type H <return>.
+ ...                                              
+l. ...  }
+This is a coding error.
+LaTeX has been asked to show a variable \g_undefined_regex, but this has not
+been defined yet.
+============================================================





More information about the latex3-commits mailing list.