[latex3-commits] [latex3/latex3] main: Simplify the peek_analysis_map_inline code regarding outer macros (53f2e851b)

github at latex-project.org github at latex-project.org
Sun Feb 18 13:31:29 CET 2024


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/53f2e851b20ae81de52cc0e45012e4e3abccbeff

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

commit 53f2e851b20ae81de52cc0e45012e4e3abccbeff
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Sun Feb 18 13:31:29 2024 +0100

    Simplify the peek_analysis_map_inline code regarding outer macros


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

53f2e851b20ae81de52cc0e45012e4e3abccbeff
 l3kernel/l3tl-analysis.dtx       | 33 ++++++++++++++-------------------
 l3kernel/testfiles/m3peek003.lvt |  4 +++-
 l3kernel/testfiles/m3peek003.tlg |  1 +
 3 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/l3kernel/l3tl-analysis.dtx b/l3kernel/l3tl-analysis.dtx
index 7044022b4..62ce80c14 100644
--- a/l3kernel/l3tl-analysis.dtx
+++ b/l3kernel/l3tl-analysis.dtx
@@ -1216,7 +1216,7 @@
 %   {
 %     \peek_analysis_map_inline:n,
 %     \@@_peek_analysis_loop:NNn, \@@_peek_analysis_test:,
-%     \@@_peek_analysis_exp:N, \@@_peek_analysis_exp_active:N,
+%     \@@_peek_analysis_exp:N, \@@_peek_analysis_exp_aux:N,
 %     \@@_peek_analysis_nonexp:N, \@@_peek_analysis_cs:N,
 %     \@@_peek_analysis_char:N, \@@_peek_analysis_char:w,
 %     \@@_peek_analysis_special:, \@@_peek_analysis_retest:,
@@ -1323,11 +1323,9 @@
 %   the two cases is easy: since we have made the escape character
 %   printable, \cs{token_to_str:N} gives at least two characters for a
 %   control sequence versus a single one for an active character
-%   (possibly being a space).  Producing the right outcome is trickier,
-%   as |#1| cannot appear in either branch of the conditional (it could
-%   be \tn{outer}, or simply a \TeX{} conditional), and can only be
-%   safely discarded by \cs{use_none:n} if it is first hit with
-%   \cs{exp_not:N}.
+%   (possibly being a space).  Importantly, once we apply
+%   \cs{token_to_str:N} we no longer need to worry about \tn{outer}
+%   tokens.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_peek_analysis_exp:N #1
   {
@@ -1339,22 +1337,19 @@
           \exp_not:n { \__kernel_exp_not:w \exp_after:wN }
             { \exp_not:N \exp_not:N \exp_not:N #1 }
         }
-        \if:w \scan_stop:
-              \exp_after:wN \use_none:n \token_to_str:N #1 \prg_do_nothing:
-              \scan_stop:
-          \exp_after:wN \exp_after:wN
-          \exp_after:wN \@@_peek_analysis_exp_active:N
-        \else:
-          { -1 } 0
-          \exp_after:wN \exp_after:wN
-          \exp_after:wN \use_none:n
-        \fi:
-        \exp_not:N #1
+        \exp_after:wN \@@_peek_analysis_exp_aux:Nw
+        \token_to_str:N #1 \prg_do_nothing: \s_@@
       }
     \l_@@_peek_code_tl
   }
-\cs_new:Npe \@@_peek_analysis_exp_active:N #1
-  { { \exp_not:N \int_value:w `#1 } \token_to_str:N D }
+\cs_new:Npe \@@_peek_analysis_exp_aux:Nw #1#2 \s_@@
+  {
+    \exp_not:N \if:w \scan_stop: #2 \scan_stop:
+      { \exp_not:N \int_value:w `#1 } \token_to_str:N D
+    \exp_not:N \else:
+      { -1 } 0
+    \exp_not:N \fi:
+  }
 %    \end{macrocode}
 %   For normal non-expandable tokens we must distinguish characters
 %   (including active ones and macro parameter characters) from control
diff --git a/l3kernel/testfiles/m3peek003.lvt b/l3kernel/testfiles/m3peek003.lvt
index 177d118f7..836b91a3a 100644
--- a/l3kernel/testfiles/m3peek003.lvt
+++ b/l3kernel/testfiles/m3peek003.lvt
@@ -34,6 +34,8 @@
 % test outer macros
 \cs_set:Npn \test_if:w { \if_meaning:w \outermacro }
 \outer \def \outermacro { }
+\char_set_catcode_active:N \!
+\outer \def ! { ! }
 \peek_analysis_map_inline:n
   {
     \exp_after:wN \exp_after:wN \exp_after:wN \TYPE
@@ -43,7 +45,7 @@
     \fi:
   }
 # \exp_after:wN \c_space_token \c_parameter_token
-\outermacro
+! \outermacro
 \TYPE{TRUE}
 \endgroup
 
diff --git a/l3kernel/testfiles/m3peek003.tlg b/l3kernel/testfiles/m3peek003.tlg
index 55e55c4be..e0bb10126 100644
--- a/l3kernel/testfiles/m3peek003.tlg
+++ b/l3kernel/testfiles/m3peek003.tlg
@@ -19,6 +19,7 @@ macro parameter character #,35,6
 \expandafter,-1,0
 blank space  ,-1,0
 macro parameter character #,-1,0
+\outer macro:->!,33,D
 \outer macro:->,-1,0
 TRUE
 \exp_not:n {\c_group_begin_token },-1,0





More information about the latex3-commits mailing list.